LLVM API Documentation
00001 //===-- llvm/CodeGen/MachineModuleInfo.h ------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Collect meta information for a module. This information should be in a 00011 // neutral form that can be used by different debugging and exception handling 00012 // schemes. 00013 // 00014 // The organization of information is primarily clustered around the source 00015 // compile units. The main exception is source line correspondence where 00016 // inlining may interleave code from various compile units. 00017 // 00018 // The following information can be retrieved from the MachineModuleInfo. 00019 // 00020 // -- Source directories - Directories are uniqued based on their canonical 00021 // string and assigned a sequential numeric ID (base 1.) 00022 // -- Source files - Files are also uniqued based on their name and directory 00023 // ID. A file ID is sequential number (base 1.) 00024 // -- Source line correspondence - A vector of file ID, line#, column# triples. 00025 // A DEBUG_LOCATION instruction is generated by the DAG Legalizer 00026 // corresponding to each entry in the source line list. This allows a debug 00027 // emitter to generate labels referenced by debug information tables. 00028 // 00029 //===----------------------------------------------------------------------===// 00030 00031 #ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H 00032 #define LLVM_CODEGEN_MACHINEMODULEINFO_H 00033 00034 #include "llvm/Support/Dwarf.h" 00035 #include "llvm/Support/DataTypes.h" 00036 #include "llvm/ADT/SmallVector.h" 00037 #include "llvm/ADT/DenseMap.h" 00038 #include "llvm/ADT/UniqueVector.h" 00039 #include "llvm/ADT/SmallPtrSet.h" 00040 #include "llvm/ADT/SmallSet.h" 00041 #include "llvm/ADT/StringMap.h" 00042 #include "llvm/CodeGen/MachineLocation.h" 00043 #include "llvm/GlobalValue.h" 00044 #include "llvm/Pass.h" 00045 00046 namespace llvm { 00047 00048 //===----------------------------------------------------------------------===// 00049 // Forward declarations. 00050 class Constant; 00051 class GlobalVariable; 00052 class MachineBasicBlock; 00053 class MachineFunction; 00054 class Module; 00055 class PointerType; 00056 class StructType; 00057 00058 //===----------------------------------------------------------------------===// 00059 /// LandingPadInfo - This structure is used to retain landing pad info for 00060 /// the current function. 00061 /// 00062 struct LandingPadInfo { 00063 MachineBasicBlock *LandingPadBlock; // Landing pad block. 00064 SmallVector<unsigned, 1> BeginLabels; // Labels prior to invoke. 00065 SmallVector<unsigned, 1> EndLabels; // Labels after invoke. 00066 unsigned LandingPadLabel; // Label at beginning of landing pad. 00067 Function *Personality; // Personality function. 00068 std::vector<int> TypeIds; // List of type ids (filters negative) 00069 00070 explicit LandingPadInfo(MachineBasicBlock *MBB) 00071 : LandingPadBlock(MBB) 00072 , LandingPadLabel(0) 00073 , Personality(NULL) 00074 {} 00075 }; 00076 00077 //===----------------------------------------------------------------------===// 00078 /// MachineModuleInfo - This class contains meta information specific to a 00079 /// module. Queries can be made by different debugging and exception handling 00080 /// schemes and reformated for specific use. 00081 /// 00082 class MachineModuleInfo : public ImmutablePass { 00083 private: 00084 // LabelIDList - One entry per assigned label. Normally the entry is equal to 00085 // the list index(+1). If the entry is zero then the label has been deleted. 00086 // Any other value indicates the label has been deleted by is mapped to 00087 // another label. 00088 std::vector<unsigned> LabelIDList; 00089 00090 // FrameMoves - List of moves done by a function's prolog. Used to construct 00091 // frame maps by debug and exception handling consumers. 00092 std::vector<MachineMove> FrameMoves; 00093 00094 // LandingPads - List of LandingPadInfo describing the landing pad information 00095 // in the current function. 00096 std::vector<LandingPadInfo> LandingPads; 00097 00098 // TypeInfos - List of C++ TypeInfo used in the current function. 00099 // 00100 std::vector<GlobalVariable *> TypeInfos; 00101 00102 // FilterIds - List of typeids encoding filters used in the current function. 00103 // 00104 std::vector<unsigned> FilterIds; 00105 00106 // FilterEnds - List of the indices in FilterIds corresponding to filter 00107 // terminators. 00108 // 00109 std::vector<unsigned> FilterEnds; 00110 00111 // Personalities - Vector of all personality functions ever seen. Used to emit 00112 // common EH frames. 00113 std::vector<Function *> Personalities; 00114 00115 /// UsedFunctions - The functions in the @llvm.used list in a more easily 00116 /// searchable format. This does not include the functions in 00117 /// llvm.compiler.used. 00118 SmallPtrSet<const Function *, 32> UsedFunctions; 00119 00120 /// UsedDbgLabels - labels are used by debug info entries. 00121 SmallSet<unsigned, 8> UsedDbgLabels; 00122 00123 bool CallsEHReturn; 00124 bool CallsUnwindInit; 00125 00126 /// DbgInfoAvailable - True if debugging information is available 00127 /// in this module. 00128 bool DbgInfoAvailable; 00129 public: 00130 static char ID; // Pass identification, replacement for typeid 00131 00132 MachineModuleInfo(); 00133 ~MachineModuleInfo(); 00134 00135 /// doInitialization - Initialize the state for a new module. 00136 /// 00137 bool doInitialization(); 00138 00139 /// doFinalization - Tear down the state after completion of a module. 00140 /// 00141 bool doFinalization(); 00142 00143 /// BeginFunction - Begin gathering function meta information. 00144 /// 00145 void BeginFunction(MachineFunction *MF); 00146 00147 /// EndFunction - Discard function meta information. 00148 /// 00149 void EndFunction(); 00150 00151 /// AnalyzeModule - Scan the module for global debug information. 00152 /// 00153 void AnalyzeModule(Module &M); 00154 00155 /// hasDebugInfo - Returns true if valid debug info is present. 00156 /// 00157 bool hasDebugInfo() const { return DbgInfoAvailable; } 00158 void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = true; } 00159 00160 bool callsEHReturn() const { return CallsEHReturn; } 00161 void setCallsEHReturn(bool b) { CallsEHReturn = b; } 00162 00163 bool callsUnwindInit() const { return CallsUnwindInit; } 00164 void setCallsUnwindInit(bool b) { CallsUnwindInit = b; } 00165 00166 /// NextLabelID - Return the next unique label id. 00167 /// 00168 unsigned NextLabelID() { 00169 unsigned ID = (unsigned)LabelIDList.size() + 1; 00170 LabelIDList.push_back(ID); 00171 return ID; 00172 } 00173 00174 /// InvalidateLabel - Inhibit use of the specified label # from 00175 /// MachineModuleInfo, for example because the code was deleted. 00176 void InvalidateLabel(unsigned LabelID) { 00177 // Remap to zero to indicate deletion. 00178 RemapLabel(LabelID, 0); 00179 } 00180 00181 /// RemapLabel - Indicate that a label has been merged into another. 00182 /// 00183 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) { 00184 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() && 00185 "Old label ID out of range."); 00186 assert(NewLabelID <= LabelIDList.size() && 00187 "New label ID out of range."); 00188 LabelIDList[OldLabelID - 1] = NewLabelID; 00189 } 00190 00191 /// MappedLabel - Find out the label's final ID. Zero indicates deletion. 00192 /// ID != Mapped ID indicates that the label was folded into another label. 00193 unsigned MappedLabel(unsigned LabelID) const { 00194 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range."); 00195 return LabelID ? LabelIDList[LabelID - 1] : 0; 00196 } 00197 00198 /// isDbgLabelUsed - Return true if label with LabelID is used by 00199 /// DwarfWriter. 00200 bool isDbgLabelUsed(unsigned LabelID) { 00201 return UsedDbgLabels.count(LabelID); 00202 } 00203 00204 /// RecordUsedDbgLabel - Mark label with LabelID as used. This is used 00205 /// by DwarfWriter to inform DebugLabelFolder that certain labels are 00206 /// not to be deleted. 00207 void RecordUsedDbgLabel(unsigned LabelID) { 00208 UsedDbgLabels.insert(LabelID); 00209 } 00210 00211 /// getFrameMoves - Returns a reference to a list of moves done in the current 00212 /// function's prologue. Used to construct frame maps for debug and exception 00213 /// handling comsumers. 00214 std::vector<MachineMove> &getFrameMoves() { return FrameMoves; } 00215 00216 //===-EH-----------------------------------------------------------------===// 00217 00218 /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the 00219 /// specified MachineBasicBlock. 00220 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad); 00221 00222 /// addInvoke - Provide the begin and end labels of an invoke style call and 00223 /// associate it with a try landing pad block. 00224 void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel, 00225 unsigned EndLabel); 00226 00227 /// addLandingPad - Add a new panding pad. Returns the label ID for the 00228 /// landing pad entry. 00229 unsigned addLandingPad(MachineBasicBlock *LandingPad); 00230 00231 /// addPersonality - Provide the personality function for the exception 00232 /// information. 00233 void addPersonality(MachineBasicBlock *LandingPad, Function *Personality); 00234 00235 /// getPersonalityIndex - Get index of the current personality function inside 00236 /// Personalitites array 00237 unsigned getPersonalityIndex() const; 00238 00239 /// getPersonalities - Return array of personality functions ever seen. 00240 const std::vector<Function *>& getPersonalities() const { 00241 return Personalities; 00242 } 00243 00244 /// isUsedFunction - Return true if the functions in the llvm.used list. This 00245 /// does not return true for things in llvm.compiler.used unless they are also 00246 /// in llvm.used. 00247 bool isUsedFunction(const Function *F) { 00248 return UsedFunctions.count(F); 00249 } 00250 00251 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad. 00252 /// 00253 void addCatchTypeInfo(MachineBasicBlock *LandingPad, 00254 std::vector<GlobalVariable *> &TyInfo); 00255 00256 /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad. 00257 /// 00258 void addFilterTypeInfo(MachineBasicBlock *LandingPad, 00259 std::vector<GlobalVariable *> &TyInfo); 00260 00261 /// addCleanup - Add a cleanup action for a landing pad. 00262 /// 00263 void addCleanup(MachineBasicBlock *LandingPad); 00264 00265 /// getTypeIDFor - Return the type id for the specified typeinfo. This is 00266 /// function wide. 00267 unsigned getTypeIDFor(GlobalVariable *TI); 00268 00269 /// getFilterIDFor - Return the id of the filter encoded by TyIds. This is 00270 /// function wide. 00271 int getFilterIDFor(std::vector<unsigned> &TyIds); 00272 00273 /// TidyLandingPads - Remap landing pad labels and remove any deleted landing 00274 /// pads. 00275 void TidyLandingPads(); 00276 00277 /// getLandingPads - Return a reference to the landing pad info for the 00278 /// current function. 00279 const std::vector<LandingPadInfo> &getLandingPads() const { 00280 return LandingPads; 00281 } 00282 00283 /// getTypeInfos - Return a reference to the C++ typeinfo for the current 00284 /// function. 00285 const std::vector<GlobalVariable *> &getTypeInfos() const { 00286 return TypeInfos; 00287 } 00288 00289 /// getFilterIds - Return a reference to the typeids encoding filters used in 00290 /// the current function. 00291 const std::vector<unsigned> &getFilterIds() const { 00292 return FilterIds; 00293 } 00294 00295 /// getPersonality - Return a personality function if available. The presence 00296 /// of one is required to emit exception handling info. 00297 Function *getPersonality() const; 00298 00299 }; // End class MachineModuleInfo 00300 00301 } // End llvm namespace 00302 00303 #endif