Removoe MachineModuleInfo methods (and related DebugInfoDesc class hierarchy) that...
[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 // Debug info constants.
59
60 enum {
61   LLVMDebugVersion = (7 << 16),         // Current version of debug information.
62   LLVMDebugVersion6 = (6 << 16),        // Constant for version 6.
63   LLVMDebugVersion5 = (5 << 16),        // Constant for version 5.
64   LLVMDebugVersion4 = (4 << 16),        // Constant for version 4.
65   LLVMDebugVersionMask = 0xffff0000     // Mask for version number.
66 };
67
68 //===----------------------------------------------------------------------===//
69 /// SourceLineInfo - This class is used to record source line correspondence.
70 ///
71 class SourceLineInfo {
72   unsigned Line;                        // Source line number.
73   unsigned Column;                      // Source column.
74   unsigned SourceID;                    // Source ID number.
75   unsigned LabelID;                     // Label in code ID number.
76 public:
77   SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
78   : Line(L), Column(C), SourceID(S), LabelID(I) {}
79   
80   // Accessors
81   unsigned getLine()     const { return Line; }
82   unsigned getColumn()   const { return Column; }
83   unsigned getSourceID() const { return SourceID; }
84   unsigned getLabelID()  const { return LabelID; }
85 };
86
87 //===----------------------------------------------------------------------===//
88 /// LandingPadInfo - This structure is used to retain landing pad info for
89 /// the current function.
90 ///
91 struct LandingPadInfo {
92   MachineBasicBlock *LandingPadBlock;   // Landing pad block.
93   SmallVector<unsigned, 1> BeginLabels; // Labels prior to invoke.
94   SmallVector<unsigned, 1> EndLabels;   // Labels after invoke.
95   unsigned LandingPadLabel;             // Label at beginning of landing pad.
96   Function *Personality;                // Personality function.
97   std::vector<int> TypeIds;             // List of type ids (filters negative)
98
99   explicit LandingPadInfo(MachineBasicBlock *MBB)
100   : LandingPadBlock(MBB)
101   , LandingPadLabel(0)
102   , Personality(NULL)  
103   {}
104 };
105
106 //===----------------------------------------------------------------------===//
107 /// MachineModuleInfo - This class contains meta information specific to a
108 /// module.  Queries can be made by different debugging and exception handling 
109 /// schemes and reformated for specific use.
110 ///
111 class MachineModuleInfo : public ImmutablePass {
112 private:
113   // Lines - List of of source line correspondence.
114   std::vector<SourceLineInfo> Lines;
115   
116   // LabelIDList - One entry per assigned label.  Normally the entry is equal to
117   // the list index(+1).  If the entry is zero then the label has been deleted.
118   // Any other value indicates the label has been deleted by is mapped to
119   // another label.
120   std::vector<unsigned> LabelIDList;
121   
122   // FrameMoves - List of moves done by a function's prolog.  Used to construct
123   // frame maps by debug and exception handling consumers.
124   std::vector<MachineMove> FrameMoves;
125   
126   // LandingPads - List of LandingPadInfo describing the landing pad information
127   // in the current function.
128   std::vector<LandingPadInfo> LandingPads;
129   
130   // TypeInfos - List of C++ TypeInfo used in the current function.
131   //
132   std::vector<GlobalVariable *> TypeInfos;
133
134   // FilterIds - List of typeids encoding filters used in the current function.
135   //
136   std::vector<unsigned> FilterIds;
137
138   // FilterEnds - List of the indices in FilterIds corresponding to filter
139   // terminators.
140   //
141   std::vector<unsigned> FilterEnds;
142
143   // Personalities - Vector of all personality functions ever seen. Used to emit
144   // common EH frames.
145   std::vector<Function *> Personalities;
146
147   // UsedFunctions - the functions in the llvm.used list in a more easily
148   // searchable format.
149   SmallPtrSet<const Function *, 32> UsedFunctions;
150
151   bool CallsEHReturn;
152   bool CallsUnwindInit;
153  
154   /// DbgInfoAvailable - True if debugging information is available
155   /// in this module.
156   bool DbgInfoAvailable;
157 public:
158   static char ID; // Pass identification, replacement for typeid
159
160   MachineModuleInfo();
161   ~MachineModuleInfo();
162   
163   /// doInitialization - Initialize the state for a new module.
164   ///
165   bool doInitialization();
166   
167   /// doFinalization - Tear down the state after completion of a module.
168   ///
169   bool doFinalization();
170   
171   /// BeginFunction - Begin gathering function meta information.
172   ///
173   void BeginFunction(MachineFunction *MF);
174   
175   /// EndFunction - Discard function meta information.
176   ///
177   void EndFunction();
178
179   /// AnalyzeModule - Scan the module for global debug information.
180   ///
181   void AnalyzeModule(Module &M);
182   
183   /// hasDebugInfo - Returns true if valid debug info is present.
184   ///
185   bool hasDebugInfo() const { return DbgInfoAvailable; }
186   void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = true; }
187
188   bool callsEHReturn() const { return CallsEHReturn; }
189   void setCallsEHReturn(bool b) { CallsEHReturn = b; }
190
191   bool callsUnwindInit() const { return CallsUnwindInit; }
192   void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
193   
194   /// NextLabelID - Return the next unique label id.
195   ///
196   unsigned NextLabelID() {
197     unsigned ID = (unsigned)LabelIDList.size() + 1;
198     LabelIDList.push_back(ID);
199     return ID;
200   }
201   
202   /// RecordSourceLine - Records location information and associates it with a
203   /// label.  Returns a unique label ID used to generate a label and 
204   /// provide correspondence to the source line list.
205   unsigned RecordSourceLine(unsigned Line, unsigned Column, unsigned Source);
206   
207   /// InvalidateLabel - Inhibit use of the specified label # from
208   /// MachineModuleInfo, for example because the code was deleted.
209   void InvalidateLabel(unsigned LabelID) {
210     // Remap to zero to indicate deletion.
211     RemapLabel(LabelID, 0);
212   }
213
214   /// RemapLabel - Indicate that a label has been merged into another.
215   ///
216   void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
217     assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
218           "Old label ID out of range.");
219     assert(NewLabelID <= LabelIDList.size() &&
220           "New label ID out of range.");
221     LabelIDList[OldLabelID - 1] = NewLabelID;
222   }
223   
224   /// MappedLabel - Find out the label's final ID.  Zero indicates deletion.
225   /// ID != Mapped ID indicates that the label was folded into another label.
226   unsigned MappedLabel(unsigned LabelID) const {
227     assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
228     return LabelID ? LabelIDList[LabelID - 1] : 0;
229   }
230
231   /// getSourceLines - Return a vector of source lines.
232   ///
233   const std::vector<SourceLineInfo> &getSourceLines() const {
234     return Lines;
235   }
236   
237   /// getFrameMoves - Returns a reference to a list of moves done in the current
238   /// function's prologue.  Used to construct frame maps for debug and exception
239   /// handling comsumers.
240   std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
241   
242   //===-EH-----------------------------------------------------------------===//
243
244   /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
245   /// specified MachineBasicBlock.
246   LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
247
248   /// addInvoke - Provide the begin and end labels of an invoke style call and
249   /// associate it with a try landing pad block.
250   void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
251                                                 unsigned EndLabel);
252   
253   /// addLandingPad - Add a new panding pad.  Returns the label ID for the 
254   /// landing pad entry.
255   unsigned addLandingPad(MachineBasicBlock *LandingPad);
256   
257   /// addPersonality - Provide the personality function for the exception
258   /// information.
259   void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
260
261   /// getPersonalityIndex - Get index of the current personality function inside
262   /// Personalitites array
263   unsigned getPersonalityIndex() const;
264
265   /// getPersonalities - Return array of personality functions ever seen.
266   const std::vector<Function *>& getPersonalities() const {
267     return Personalities;
268   }
269
270   // UsedFunctions - Return set of the functions in the llvm.used list.
271   const SmallPtrSet<const Function *, 32>& getUsedFunctions() const {
272     return UsedFunctions;
273   }
274
275   /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
276   ///
277   void addCatchTypeInfo(MachineBasicBlock *LandingPad,
278                         std::vector<GlobalVariable *> &TyInfo);
279
280   /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
281   ///
282   void addFilterTypeInfo(MachineBasicBlock *LandingPad,
283                          std::vector<GlobalVariable *> &TyInfo);
284
285   /// addCleanup - Add a cleanup action for a landing pad.
286   ///
287   void addCleanup(MachineBasicBlock *LandingPad);
288
289   /// getTypeIDFor - Return the type id for the specified typeinfo.  This is 
290   /// function wide.
291   unsigned getTypeIDFor(GlobalVariable *TI);
292
293   /// getFilterIDFor - Return the id of the filter encoded by TyIds.  This is
294   /// function wide.
295   int getFilterIDFor(std::vector<unsigned> &TyIds);
296
297   /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
298   /// pads.
299   void TidyLandingPads();
300                         
301   /// getLandingPads - Return a reference to the landing pad info for the
302   /// current function.
303   const std::vector<LandingPadInfo> &getLandingPads() const {
304     return LandingPads;
305   }
306   
307   /// getTypeInfos - Return a reference to the C++ typeinfo for the current
308   /// function.
309   const std::vector<GlobalVariable *> &getTypeInfos() const {
310     return TypeInfos;
311   }
312
313   /// getFilterIds - Return a reference to the typeids encoding filters used in
314   /// the current function.
315   const std::vector<unsigned> &getFilterIds() const {
316     return FilterIds;
317   }
318
319   /// getPersonality - Return a personality function if available.  The presence
320   /// of one is required to emit exception handling info.
321   Function *getPersonality() const;
322
323 }; // End class MachineModuleInfo
324
325 } // End llvm namespace
326
327 #endif