Remove dead code.
[oota-llvm.git] / include / llvm / CodeGen / MachineModuleInfo.h
1 //===-- llvm/CodeGen/MachineModuleInfo.h ------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Collect meta information for a module.  This information should be in a
11 // neutral form that can be used by different debugging and exception handling
12 // schemes.
13 //
14 // The organization of information is primarily clustered around the source
15 // compile units.  The main exception is source line correspondence where
16 // inlining may interleave code from various compile units.
17 //
18 // The following information can be retrieved from the MachineModuleInfo.
19 //
20 //  -- Source directories - Directories are uniqued based on their canonical
21 //     string and assigned a sequential numeric ID (base 1.)
22 //  -- Source files - Files are also uniqued based on their name and directory
23 //     ID.  A file ID is sequential number (base 1.)
24 //  -- Source line correspondence - A vector of file ID, line#, column# triples.
25 //     A DEBUG_LOCATION instruction is generated  by the DAG Legalizer
26 //     corresponding to each entry in the source line list.  This allows a debug
27 //     emitter to generate labels referenced by debug information tables.
28 //
29 //===----------------------------------------------------------------------===//
30
31 #ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H
32 #define LLVM_CODEGEN_MACHINEMODULEINFO_H
33
34 #include "llvm/Support/Dwarf.h"
35 #include "llvm/Support/DataTypes.h"
36 #include "llvm/ADT/SmallVector.h"
37 #include "llvm/ADT/DenseMap.h"
38 #include "llvm/ADT/UniqueVector.h"
39 #include "llvm/ADT/SmallPtrSet.h"
40 #include "llvm/ADT/StringMap.h"
41 #include "llvm/CodeGen/MachineLocation.h"
42 #include "llvm/GlobalValue.h"
43 #include "llvm/Pass.h"
44
45 namespace llvm {
46
47 //===----------------------------------------------------------------------===//
48 // Forward declarations.
49 class Constant;
50 class GlobalVariable;
51 class MachineBasicBlock;
52 class MachineFunction;
53 class Module;
54 class PointerType;
55 class StructType;
56
57 //===----------------------------------------------------------------------===//
58 /// LandingPadInfo - This structure is used to retain landing pad info for
59 /// the current function.
60 ///
61 struct LandingPadInfo {
62   MachineBasicBlock *LandingPadBlock;   // Landing pad block.
63   SmallVector<unsigned, 1> BeginLabels; // Labels prior to invoke.
64   SmallVector<unsigned, 1> EndLabels;   // Labels after invoke.
65   unsigned LandingPadLabel;             // Label at beginning of landing pad.
66   Function *Personality;                // Personality function.
67   std::vector<int> TypeIds;             // List of type ids (filters negative)
68
69   explicit LandingPadInfo(MachineBasicBlock *MBB)
70   : LandingPadBlock(MBB)
71   , LandingPadLabel(0)
72   , Personality(NULL)  
73   {}
74 };
75
76 //===----------------------------------------------------------------------===//
77 /// MachineModuleInfo - This class contains meta information specific to a
78 /// module.  Queries can be made by different debugging and exception handling 
79 /// schemes and reformated for specific use.
80 ///
81 class MachineModuleInfo : public ImmutablePass {
82 private:
83   // LabelIDList - One entry per assigned label.  Normally the entry is equal to
84   // the list index(+1).  If the entry is zero then the label has been deleted.
85   // Any other value indicates the label has been deleted by is mapped to
86   // another label.
87   std::vector<unsigned> LabelIDList;
88   
89   // FrameMoves - List of moves done by a function's prolog.  Used to construct
90   // frame maps by debug and exception handling consumers.
91   std::vector<MachineMove> FrameMoves;
92   
93   // LandingPads - List of LandingPadInfo describing the landing pad information
94   // in the current function.
95   std::vector<LandingPadInfo> LandingPads;
96   
97   // TypeInfos - List of C++ TypeInfo used in the current function.
98   //
99   std::vector<GlobalVariable *> TypeInfos;
100
101   // FilterIds - List of typeids encoding filters used in the current function.
102   //
103   std::vector<unsigned> FilterIds;
104
105   // FilterEnds - List of the indices in FilterIds corresponding to filter
106   // terminators.
107   //
108   std::vector<unsigned> FilterEnds;
109
110   // Personalities - Vector of all personality functions ever seen. Used to emit
111   // common EH frames.
112   std::vector<Function *> Personalities;
113
114   // UsedFunctions - the functions in the llvm.used list in a more easily
115   // searchable format.
116   SmallPtrSet<const Function *, 32> UsedFunctions;
117
118   bool CallsEHReturn;
119   bool CallsUnwindInit;
120  
121   /// DbgInfoAvailable - True if debugging information is available
122   /// in this module.
123   bool DbgInfoAvailable;
124 public:
125   static char ID; // Pass identification, replacement for typeid
126
127   MachineModuleInfo();
128   ~MachineModuleInfo();
129   
130   /// doInitialization - Initialize the state for a new module.
131   ///
132   bool doInitialization();
133   
134   /// doFinalization - Tear down the state after completion of a module.
135   ///
136   bool doFinalization();
137   
138   /// BeginFunction - Begin gathering function meta information.
139   ///
140   void BeginFunction(MachineFunction *MF);
141   
142   /// EndFunction - Discard function meta information.
143   ///
144   void EndFunction();
145
146   /// AnalyzeModule - Scan the module for global debug information.
147   ///
148   void AnalyzeModule(Module &M);
149   
150   /// hasDebugInfo - Returns true if valid debug info is present.
151   ///
152   bool hasDebugInfo() const { return DbgInfoAvailable; }
153   void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = true; }
154
155   bool callsEHReturn() const { return CallsEHReturn; }
156   void setCallsEHReturn(bool b) { CallsEHReturn = b; }
157
158   bool callsUnwindInit() const { return CallsUnwindInit; }
159   void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
160   
161   /// NextLabelID - Return the next unique label id.
162   ///
163   unsigned NextLabelID() {
164     unsigned ID = (unsigned)LabelIDList.size() + 1;
165     LabelIDList.push_back(ID);
166     return ID;
167   }
168   
169   /// RecordSourceLine - Records location information and associates it with a
170   /// label.  Returns a unique label ID used to generate a label and 
171   /// provide correspondence to the source line list.
172   unsigned RecordSourceLine(unsigned Line, unsigned Column, unsigned Source);
173   
174   /// InvalidateLabel - Inhibit use of the specified label # from
175   /// MachineModuleInfo, for example because the code was deleted.
176   void InvalidateLabel(unsigned LabelID) {
177     // Remap to zero to indicate deletion.
178     RemapLabel(LabelID, 0);
179   }
180
181   /// RemapLabel - Indicate that a label has been merged into another.
182   ///
183   void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
184     assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
185           "Old label ID out of range.");
186     assert(NewLabelID <= LabelIDList.size() &&
187           "New label ID out of range.");
188     LabelIDList[OldLabelID - 1] = NewLabelID;
189   }
190   
191   /// MappedLabel - Find out the label's final ID.  Zero indicates deletion.
192   /// ID != Mapped ID indicates that the label was folded into another label.
193   unsigned MappedLabel(unsigned LabelID) const {
194     assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
195     return LabelID ? LabelIDList[LabelID - 1] : 0;
196   }
197
198   /// getFrameMoves - Returns a reference to a list of moves done in the current
199   /// function's prologue.  Used to construct frame maps for debug and exception
200   /// handling comsumers.
201   std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
202   
203   //===-EH-----------------------------------------------------------------===//
204
205   /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
206   /// specified MachineBasicBlock.
207   LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
208
209   /// addInvoke - Provide the begin and end labels of an invoke style call and
210   /// associate it with a try landing pad block.
211   void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
212                                                 unsigned EndLabel);
213   
214   /// addLandingPad - Add a new panding pad.  Returns the label ID for the 
215   /// landing pad entry.
216   unsigned addLandingPad(MachineBasicBlock *LandingPad);
217   
218   /// addPersonality - Provide the personality function for the exception
219   /// information.
220   void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
221
222   /// getPersonalityIndex - Get index of the current personality function inside
223   /// Personalitites array
224   unsigned getPersonalityIndex() const;
225
226   /// getPersonalities - Return array of personality functions ever seen.
227   const std::vector<Function *>& getPersonalities() const {
228     return Personalities;
229   }
230
231   // UsedFunctions - Return set of the functions in the llvm.used list.
232   const SmallPtrSet<const Function *, 32>& getUsedFunctions() const {
233     return UsedFunctions;
234   }
235
236   /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
237   ///
238   void addCatchTypeInfo(MachineBasicBlock *LandingPad,
239                         std::vector<GlobalVariable *> &TyInfo);
240
241   /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
242   ///
243   void addFilterTypeInfo(MachineBasicBlock *LandingPad,
244                          std::vector<GlobalVariable *> &TyInfo);
245
246   /// addCleanup - Add a cleanup action for a landing pad.
247   ///
248   void addCleanup(MachineBasicBlock *LandingPad);
249
250   /// getTypeIDFor - Return the type id for the specified typeinfo.  This is 
251   /// function wide.
252   unsigned getTypeIDFor(GlobalVariable *TI);
253
254   /// getFilterIDFor - Return the id of the filter encoded by TyIds.  This is
255   /// function wide.
256   int getFilterIDFor(std::vector<unsigned> &TyIds);
257
258   /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
259   /// pads.
260   void TidyLandingPads();
261                         
262   /// getLandingPads - Return a reference to the landing pad info for the
263   /// current function.
264   const std::vector<LandingPadInfo> &getLandingPads() const {
265     return LandingPads;
266   }
267   
268   /// getTypeInfos - Return a reference to the C++ typeinfo for the current
269   /// function.
270   const std::vector<GlobalVariable *> &getTypeInfos() const {
271     return TypeInfos;
272   }
273
274   /// getFilterIds - Return a reference to the typeids encoding filters used in
275   /// the current function.
276   const std::vector<unsigned> &getFilterIds() const {
277     return FilterIds;
278   }
279
280   /// getPersonality - Return a personality function if available.  The presence
281   /// of one is required to emit exception handling info.
282   Function *getPersonality() const;
283
284 }; // End class MachineModuleInfo
285
286 } // End llvm namespace
287
288 #endif