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