CodeGenModule.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen --------------===//
  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. // This is the internal per-translation-unit state used for llvm translation.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef CLANG_CODEGEN_CODEGENMODULE_H
  14. #define CLANG_CODEGEN_CODEGENMODULE_H
  15. #include "CodeGenTypes.h"
  16. #include "CGObjCRuntime.h"
  17. #include "llvm/ADT/DenseMap.h"
  18. #include "llvm/ADT/StringMap.h"
  19. namespace llvm {
  20. class Module;
  21. class Constant;
  22. class Function;
  23. class GlobalVariable;
  24. class TargetData;
  25. }
  26. namespace clang {
  27. class ASTContext;
  28. class FunctionDecl;
  29. class ObjCMethodDecl;
  30. class Decl;
  31. class Expr;
  32. class Stmt;
  33. class ValueDecl;
  34. class VarDecl;
  35. class TypeDecl;
  36. class FileVarDecl;
  37. struct LangOptions;
  38. class Diagnostic;
  39. namespace CodeGen {
  40. class CodeGenFunction;
  41. /// CodeGenModule - This class organizes the cross-module state that is used
  42. /// while generating LLVM code.
  43. class CodeGenModule {
  44. ASTContext &Context;
  45. const LangOptions &Features;
  46. llvm::Module &TheModule;
  47. const llvm::TargetData &TheTargetData;
  48. Diagnostic &Diags;
  49. CodeGenTypes Types;
  50. CGObjCRuntime *Runtime;
  51. llvm::Function *MemCpyFn;
  52. llvm::Function *MemSetFn;
  53. llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap;
  54. std::vector<llvm::Constant*> GlobalCtors;
  55. llvm::StringMap<llvm::Constant*> CFConstantStringMap;
  56. llvm::StringMap<llvm::Constant*> ConstantStringMap;
  57. llvm::Constant *CFConstantStringClassRef;
  58. std::vector<llvm::Function *> BuiltinFunctions;
  59. public:
  60. CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M,
  61. const llvm::TargetData &TD, Diagnostic &Diags);
  62. ~CodeGenModule();
  63. CGObjCRuntime *getObjCRuntime() { return Runtime; }
  64. ASTContext &getContext() const { return Context; }
  65. const LangOptions &getLangOptions() const { return Features; }
  66. llvm::Module &getModule() const { return TheModule; }
  67. CodeGenTypes &getTypes() { return Types; }
  68. Diagnostic &getDiags() const { return Diags; }
  69. const llvm::TargetData &getTargetData() const { return TheTargetData; }
  70. llvm::Constant *GetAddrOfFunctionDecl(const FunctionDecl *D,
  71. bool isDefinition);
  72. llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, bool isDefinition);
  73. /// getBuiltinLibFunction - Given a builtin id for a function like
  74. /// "__builtin_fabsf", return a Function* for "fabsf".
  75. ///
  76. llvm::Function *getBuiltinLibFunction(unsigned BuiltinID);
  77. llvm::Constant *GetAddrOfConstantCFString(const std::string& str);
  78. /// GetAddrOfConstantString -- returns a pointer to the character
  79. /// array containing the literal. The result is pointer to array type.
  80. llvm::Constant *GetAddrOfConstantString(const std::string& str);
  81. llvm::Function *getMemCpyFn();
  82. llvm::Function *getMemSetFn();
  83. llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0,
  84. unsigned NumTys = 0);
  85. void AddGlobalCtor(llvm::Function * Ctor);
  86. void EmitGlobalCtors(void);
  87. void EmitObjCMethod(const ObjCMethodDecl *OMD);
  88. void EmitFunction(const FunctionDecl *FD);
  89. void EmitGlobalVar(const FileVarDecl *D);
  90. void EmitGlobalVarDeclarator(const FileVarDecl *D);
  91. void UpdateCompletedType(const TagDecl *D);
  92. llvm::Constant *EmitGlobalInit(const Expr *E);
  93. llvm::Constant *EmitConstantExpr(const Expr *E, CodeGenFunction *CGF = 0);
  94. /// WarnUnsupported - Print out a warning that codegen doesn't support the
  95. /// specified stmt yet.
  96. void WarnUnsupported(const Stmt *S, const char *Type);
  97. /// WarnUnsupported - Print out a warning that codegen doesn't support the
  98. /// specified decl yet.
  99. void WarnUnsupported(const Decl *D, const char *Type);
  100. private:
  101. /// ReplaceMapValuesWith - This is a really slow and bad function that
  102. /// searches for any entries in GlobalDeclMap that point to OldVal, changing
  103. /// them to point to NewVal. This is badbadbad, FIXME!
  104. void ReplaceMapValuesWith(llvm::Constant *OldVal, llvm::Constant *NewVal);
  105. };
  106. } // end namespace CodeGen
  107. } // end namespace clang
  108. #endif