Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

405 lines
15 KiB

  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. #ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H
  31. #define LLVM_CODEGEN_MACHINEMODULEINFO_H
  32. #include "llvm/ADT/DenseMap.h"
  33. #include "llvm/ADT/PointerIntPair.h"
  34. #include "llvm/ADT/SmallPtrSet.h"
  35. #include "llvm/ADT/SmallVector.h"
  36. #include "llvm/IR/Metadata.h"
  37. #include "llvm/MC/MCContext.h"
  38. #include "llvm/MC/MachineLocation.h"
  39. #include "llvm/Pass.h"
  40. #include "llvm/Support/DataTypes.h"
  41. #include "llvm/Support/DebugLoc.h"
  42. #include "llvm/Support/Dwarf.h"
  43. #include "llvm/Support/ValueHandle.h"
  44. namespace llvm {
  45. //===----------------------------------------------------------------------===//
  46. // Forward declarations.
  47. class Constant;
  48. class GlobalVariable;
  49. class MDNode;
  50. class MMIAddrLabelMap;
  51. class MachineBasicBlock;
  52. class MachineFunction;
  53. class Module;
  54. class PointerType;
  55. class StructType;
  56. //===----------------------------------------------------------------------===//
  57. /// LandingPadInfo - This structure is used to retain landing pad info for
  58. /// the current function.
  59. ///
  60. struct LandingPadInfo {
  61. MachineBasicBlock *LandingPadBlock; // Landing pad block.
  62. SmallVector<MCSymbol*, 1> BeginLabels; // Labels prior to invoke.
  63. SmallVector<MCSymbol*, 1> EndLabels; // Labels after invoke.
  64. MCSymbol *LandingPadLabel; // Label at beginning of landing pad.
  65. const Function *Personality; // Personality function.
  66. std::vector<int> TypeIds; // List of type ids (filters negative)
  67. explicit LandingPadInfo(MachineBasicBlock *MBB)
  68. : LandingPadBlock(MBB), LandingPadLabel(0), Personality(0) {}
  69. };
  70. //===----------------------------------------------------------------------===//
  71. /// MachineModuleInfoImpl - This class can be derived from and used by targets
  72. /// to hold private target-specific information for each Module. Objects of
  73. /// type are accessed/created with MMI::getInfo and destroyed when the
  74. /// MachineModuleInfo is destroyed.
  75. ///
  76. class MachineModuleInfoImpl {
  77. public:
  78. typedef PointerIntPair<MCSymbol*, 1, bool> StubValueTy;
  79. virtual ~MachineModuleInfoImpl();
  80. typedef std::vector<std::pair<MCSymbol*, StubValueTy> > SymbolListTy;
  81. protected:
  82. static SymbolListTy GetSortedStubs(const DenseMap<MCSymbol*, StubValueTy>&);
  83. };
  84. //===----------------------------------------------------------------------===//
  85. /// MachineModuleInfo - This class contains meta information specific to a
  86. /// module. Queries can be made by different debugging and exception handling
  87. /// schemes and reformated for specific use.
  88. ///
  89. class MachineModuleInfo : public ImmutablePass {
  90. /// Context - This is the MCContext used for the entire code generator.
  91. MCContext Context;
  92. /// TheModule - This is the LLVM Module being worked on.
  93. const Module *TheModule;
  94. /// ObjFileMMI - This is the object-file-format-specific implementation of
  95. /// MachineModuleInfoImpl, which lets targets accumulate whatever info they
  96. /// want.
  97. MachineModuleInfoImpl *ObjFileMMI;
  98. /// FrameMoves - List of moves done by a function's prolog. Used to construct
  99. /// frame maps by debug and exception handling consumers.
  100. std::vector<MachineMove> FrameMoves;
  101. /// CompactUnwindEncoding - If the target supports it, this is the compact
  102. /// unwind encoding. It replaces a function's CIE and FDE.
  103. uint32_t CompactUnwindEncoding;
  104. /// LandingPads - List of LandingPadInfo describing the landing pad
  105. /// information in the current function.
  106. std::vector<LandingPadInfo> LandingPads;
  107. /// LPadToCallSiteMap - Map a landing pad's EH symbol to the call site
  108. /// indexes.
  109. DenseMap<MCSymbol*, SmallVector<unsigned, 4> > LPadToCallSiteMap;
  110. /// CallSiteMap - Map of invoke call site index values to associated begin
  111. /// EH_LABEL for the current function.
  112. DenseMap<MCSymbol*, unsigned> CallSiteMap;
  113. /// CurCallSite - The current call site index being processed, if any. 0 if
  114. /// none.
  115. unsigned CurCallSite;
  116. /// TypeInfos - List of C++ TypeInfo used in the current function.
  117. std::vector<const GlobalVariable *> TypeInfos;
  118. /// FilterIds - List of typeids encoding filters used in the current function.
  119. std::vector<unsigned> FilterIds;
  120. /// FilterEnds - List of the indices in FilterIds corresponding to filter
  121. /// terminators.
  122. std::vector<unsigned> FilterEnds;
  123. /// Personalities - Vector of all personality functions ever seen. Used to
  124. /// emit common EH frames.
  125. std::vector<const Function *> Personalities;
  126. /// UsedFunctions - The functions in the @llvm.used list in a more easily
  127. /// searchable format. This does not include the functions in
  128. /// llvm.compiler.used.
  129. SmallPtrSet<const Function *, 32> UsedFunctions;
  130. /// AddrLabelSymbols - This map keeps track of which symbol is being used for
  131. /// the specified basic block's address of label.
  132. MMIAddrLabelMap *AddrLabelSymbols;
  133. bool CallsEHReturn;
  134. bool CallsUnwindInit;
  135. /// DbgInfoAvailable - True if debugging information is available
  136. /// in this module.
  137. bool DbgInfoAvailable;
  138. /// UsesVAFloatArgument - True if this module calls VarArg function with
  139. /// floating-point arguments. This is used to emit an undefined reference
  140. /// to _fltused on Windows targets.
  141. bool UsesVAFloatArgument;
  142. public:
  143. static char ID; // Pass identification, replacement for typeid
  144. typedef std::pair<unsigned, DebugLoc> UnsignedDebugLocPair;
  145. typedef SmallVector<std::pair<TrackingVH<MDNode>, UnsignedDebugLocPair>, 4>
  146. VariableDbgInfoMapTy;
  147. VariableDbgInfoMapTy VariableDbgInfo;
  148. MachineModuleInfo(); // DUMMY CONSTRUCTOR, DO NOT CALL.
  149. // Real constructor.
  150. MachineModuleInfo(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
  151. const MCObjectFileInfo *MOFI);
  152. ~MachineModuleInfo();
  153. // Initialization and Finalization
  154. virtual bool doInitialization(Module &);
  155. virtual bool doFinalization(Module &);
  156. /// EndFunction - Discard function meta information.
  157. ///
  158. void EndFunction();
  159. const MCContext &getContext() const { return Context; }
  160. MCContext &getContext() { return Context; }
  161. void setModule(const Module *M) { TheModule = M; }
  162. const Module *getModule() const { return TheModule; }
  163. /// getInfo - Keep track of various per-function pieces of information for
  164. /// backends that would like to do so.
  165. ///
  166. template<typename Ty>
  167. Ty &getObjFileInfo() {
  168. if (ObjFileMMI == 0)
  169. ObjFileMMI = new Ty(*this);
  170. return *static_cast<Ty*>(ObjFileMMI);
  171. }
  172. template<typename Ty>
  173. const Ty &getObjFileInfo() const {
  174. return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
  175. }
  176. /// AnalyzeModule - Scan the module for global debug information.
  177. ///
  178. void AnalyzeModule(const Module &M);
  179. /// hasDebugInfo - Returns true if valid debug info is present.
  180. ///
  181. bool hasDebugInfo() const { return DbgInfoAvailable; }
  182. void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = avail; }
  183. bool callsEHReturn() const { return CallsEHReturn; }
  184. void setCallsEHReturn(bool b) { CallsEHReturn = b; }
  185. bool callsUnwindInit() const { return CallsUnwindInit; }
  186. void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
  187. bool usesVAFloatArgument() const {
  188. return UsesVAFloatArgument;
  189. }
  190. void setUsesVAFloatArgument(bool b) {
  191. UsesVAFloatArgument = b;
  192. }
  193. /// getFrameMoves - Returns a reference to a list of moves done in the current
  194. /// function's prologue. Used to construct frame maps for debug and exception
  195. /// handling comsumers.
  196. std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
  197. /// getCompactUnwindEncoding - Returns the compact unwind encoding for a
  198. /// function if the target supports the encoding. This encoding replaces a
  199. /// function's CIE and FDE.
  200. uint32_t getCompactUnwindEncoding() const { return CompactUnwindEncoding; }
  201. /// setCompactUnwindEncoding - Set the compact unwind encoding for a function
  202. /// if the target supports the encoding.
  203. void setCompactUnwindEncoding(uint32_t Enc) { CompactUnwindEncoding = Enc; }
  204. /// getAddrLabelSymbol - Return the symbol to be used for the specified basic
  205. /// block when its address is taken. This cannot be its normal LBB label
  206. /// because the block may be accessed outside its containing function.
  207. MCSymbol *getAddrLabelSymbol(const BasicBlock *BB);
  208. /// getAddrLabelSymbolToEmit - Return the symbol to be used for the specified
  209. /// basic block when its address is taken. If other blocks were RAUW'd to
  210. /// this one, we may have to emit them as well, return the whole set.
  211. std::vector<MCSymbol*> getAddrLabelSymbolToEmit(const BasicBlock *BB);
  212. /// takeDeletedSymbolsForFunction - If the specified function has had any
  213. /// references to address-taken blocks generated, but the block got deleted,
  214. /// return the symbol now so we can emit it. This prevents emitting a
  215. /// reference to a symbol that has no definition.
  216. void takeDeletedSymbolsForFunction(const Function *F,
  217. std::vector<MCSymbol*> &Result);
  218. //===- EH ---------------------------------------------------------------===//
  219. /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
  220. /// specified MachineBasicBlock.
  221. LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
  222. /// addInvoke - Provide the begin and end labels of an invoke style call and
  223. /// associate it with a try landing pad block.
  224. void addInvoke(MachineBasicBlock *LandingPad,
  225. MCSymbol *BeginLabel, MCSymbol *EndLabel);
  226. /// addLandingPad - Add a new panding pad. Returns the label ID for the
  227. /// landing pad entry.
  228. MCSymbol *addLandingPad(MachineBasicBlock *LandingPad);
  229. /// addPersonality - Provide the personality function for the exception
  230. /// information.
  231. void addPersonality(MachineBasicBlock *LandingPad,
  232. const Function *Personality);
  233. /// getPersonalityIndex - Get index of the current personality function inside
  234. /// Personalitites array
  235. unsigned getPersonalityIndex() const;
  236. /// getPersonalities - Return array of personality functions ever seen.
  237. const std::vector<const Function *>& getPersonalities() const {
  238. return Personalities;
  239. }
  240. /// isUsedFunction - Return true if the functions in the llvm.used list. This
  241. /// does not return true for things in llvm.compiler.used unless they are also
  242. /// in llvm.used.
  243. bool isUsedFunction(const Function *F) const {
  244. return UsedFunctions.count(F);
  245. }
  246. /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
  247. ///
  248. void addCatchTypeInfo(MachineBasicBlock *LandingPad,
  249. ArrayRef<const GlobalVariable *> TyInfo);
  250. /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
  251. ///
  252. void addFilterTypeInfo(MachineBasicBlock *LandingPad,
  253. ArrayRef<const GlobalVariable *> TyInfo);
  254. /// addCleanup - Add a cleanup action for a landing pad.
  255. ///
  256. void addCleanup(MachineBasicBlock *LandingPad);
  257. /// getTypeIDFor - Return the type id for the specified typeinfo. This is
  258. /// function wide.
  259. unsigned getTypeIDFor(const GlobalVariable *TI);
  260. /// getFilterIDFor - Return the id of the filter encoded by TyIds. This is
  261. /// function wide.
  262. int getFilterIDFor(std::vector<unsigned> &TyIds);
  263. /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
  264. /// pads.
  265. void TidyLandingPads(DenseMap<MCSymbol*, uintptr_t> *LPMap = 0);
  266. /// getLandingPads - Return a reference to the landing pad info for the
  267. /// current function.
  268. const std::vector<LandingPadInfo> &getLandingPads() const {
  269. return LandingPads;
  270. }
  271. /// setCallSiteLandingPad - Map the landing pad's EH symbol to the call
  272. /// site indexes.
  273. void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef<unsigned> Sites);
  274. /// getCallSiteLandingPad - Get the call site indexes for a landing pad EH
  275. /// symbol.
  276. SmallVectorImpl<unsigned> &getCallSiteLandingPad(MCSymbol *Sym) {
  277. assert(hasCallSiteLandingPad(Sym) &&
  278. "missing call site number for landing pad!");
  279. return LPadToCallSiteMap[Sym];
  280. }
  281. /// hasCallSiteLandingPad - Return true if the landing pad Eh symbol has an
  282. /// associated call site.
  283. bool hasCallSiteLandingPad(MCSymbol *Sym) {
  284. return !LPadToCallSiteMap[Sym].empty();
  285. }
  286. /// setCallSiteBeginLabel - Map the begin label for a call site.
  287. void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site) {
  288. CallSiteMap[BeginLabel] = Site;
  289. }
  290. /// getCallSiteBeginLabel - Get the call site number for a begin label.
  291. unsigned getCallSiteBeginLabel(MCSymbol *BeginLabel) {
  292. assert(hasCallSiteBeginLabel(BeginLabel) &&
  293. "Missing call site number for EH_LABEL!");
  294. return CallSiteMap[BeginLabel];
  295. }
  296. /// hasCallSiteBeginLabel - Return true if the begin label has a call site
  297. /// number associated with it.
  298. bool hasCallSiteBeginLabel(MCSymbol *BeginLabel) {
  299. return CallSiteMap[BeginLabel] != 0;
  300. }
  301. /// setCurrentCallSite - Set the call site currently being processed.
  302. void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }
  303. /// getCurrentCallSite - Get the call site currently being processed, if any.
  304. /// return zero if none.
  305. unsigned getCurrentCallSite() { return CurCallSite; }
  306. /// getTypeInfos - Return a reference to the C++ typeinfo for the current
  307. /// function.
  308. const std::vector<const GlobalVariable *> &getTypeInfos() const {
  309. return TypeInfos;
  310. }
  311. /// getFilterIds - Return a reference to the typeids encoding filters used in
  312. /// the current function.
  313. const std::vector<unsigned> &getFilterIds() const {
  314. return FilterIds;
  315. }
  316. /// getPersonality - Return a personality function if available. The presence
  317. /// of one is required to emit exception handling info.
  318. const Function *getPersonality() const;
  319. /// setVariableDbgInfo - Collect information used to emit debugging
  320. /// information of a variable.
  321. void setVariableDbgInfo(MDNode *N, unsigned Slot, DebugLoc Loc) {
  322. VariableDbgInfo.push_back(std::make_pair(N, std::make_pair(Slot, Loc)));
  323. }
  324. VariableDbgInfoMapTy &getVariableDbgInfo() { return VariableDbgInfo; }
  325. }; // End class MachineModuleInfo
  326. } // End llvm namespace
  327. #endif