Hi -

Please review and let me know if you have any feedback.

Thanks,

Mark

----------------


Currently the only way to create a CodeGenTypes class is to pass it a
CodeGenModule, which is primarily used to initialize the members of
CodeGenTypes, but is also used in a couple of places to gain access to a
few members of CodeGenModule (OpenCLRuntime, DebugInfo,
and TargetCodeGenInfo).

This change makes it possible to construct a CodeGenTypes class
independently of a CodeGenModule. The constructor to CodeGenTypes is
updated to explicitly have parameters for each of its members, and new
pointer members are added for the information that was being referenced
from CodeGenModule.
---
lib/CodeGen/CGCall.cpp        |   2 +-
lib/CodeGen/CodeGenModule.cpp |  12 +++--
lib/CodeGen/CodeGenTypes.cpp  |  24 ++++++----
lib/CodeGen/CodeGenTypes.h    |  28 +++++++++--
lib/CodeGen/TargetInfo.cpp    | 106 ++++++++++++++++++++++++------------------
5 files changed, 111 insertions(+), 61 deletions(-)

diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index fa25222..8366ecf 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -340,7 +340,7 @@ arrangeFreeFunctionLikeCall(CodeGenTypes &CGT,
   // explicitly use the variadic convention for unprototyped calls,
   // treat all of the arguments as required but preserve the nominal
   // possibility of variadics.
-  } else if (CGT.CGM.getTargetCodeGenInfo()
+  } else if (CGT.getTargetCodeGenInfo()
                .isNoProtoCallVariadic(args, cast<FunctionNoProtoType>(fnType))) {
     required = RequiredArgs(args.size());
   }
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 17bca0a..09ec835 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -73,7 +73,9 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
     : Context(C), LangOpts(C.getLangOpts()), CodeGenOpts(CGO), TheModule(M),
       Diags(diags), TheDataLayout(TD), Target(C.getTargetInfo()),
       ABI(createCXXABI(*this)), VMContext(M.getContext()), TBAA(0),
-      TheTargetCodeGenInfo(0), Types(*this), VTables(*this), ObjCRuntime(0),
+      TheTargetCodeGenInfo(0),
+      Types(C, M, TD, C.getTargetInfo(), ABI, CGO, 0, 0),
+      VTables(*this), ObjCRuntime(0),
       OpenCLRuntime(0), CUDARuntime(0), DebugInfo(0), ARCData(0),
       NoObjCARCExceptionsMetadata(0), RRData(0), CFConstantStringClassRef(0),
       ConstantStringClassRef(0), NSConstantStringType(0),
@@ -106,8 +108,10 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
 
   if (LangOpts.ObjC1)
     createObjCRuntime();
-  if (LangOpts.OpenCL)
+  if (LangOpts.OpenCL) {
     createOpenCLRuntime();
+    Types.setOpenCLRuntime(OpenCLRuntime);
+  }
   if (LangOpts.CUDA)
     createCUDARuntime();
 
@@ -121,8 +125,10 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
   // object.
   if (CodeGenOpts.getDebugInfo() != CodeGenOptions::NoDebugInfo ||
       CodeGenOpts.EmitGcovArcs ||
-      CodeGenOpts.EmitGcovNotes)
+      CodeGenOpts.EmitGcovNotes) {
     DebugInfo = new CGDebugInfo(*this);
+    Types.setDebugInfo(DebugInfo);
+  }
 
   Block.GlobalUniqueCount = 0;
 
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp
index 442f293..0358e19 100644
--- a/lib/CodeGen/CodeGenTypes.cpp
+++ b/lib/CodeGen/CodeGenTypes.cpp
@@ -28,12 +28,14 @@
 using namespace clang;
 using namespace CodeGen;
 
-CodeGenTypes::CodeGenTypes(CodeGenModule &cgm)
-  : CGM(cgm), Context(cgm.getContext()), TheModule(cgm.getModule()),
-    TheDataLayout(cgm.getDataLayout()),
-    Target(cgm.getTarget()), TheCXXABI(cgm.getCXXABI()),
-    CodeGenOpts(cgm.getCodeGenOpts()),
-    TheABIInfo(cgm.getTargetCodeGenInfo().getABIInfo()) {
+CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module &M,
+                           const llvm::DataLayout &DL, const TargetInfo &TI,
+                           CGCXXABI &CXXABI, const CodeGenOptions &CGO,
+                           CGDebugInfo *DBI, CGOpenCLRuntime* OCL)
+  : Context(Ctx), TheModule(M), TheDataLayout(DL), Target(TI),
+    TheCXXABI(CXXABI), CodeGenOpts(CGO), OpenCLRuntime(OCL),
+    DebugInfo(DBI), TheTargetCodeGenInfo(0),
+    TheABIInfo(getTargetCodeGenInfo().getABIInfo()) {
   SkippedLayout = false;
 }
 
@@ -263,8 +265,8 @@ void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) {
 
   // If necessary, provide the full definition of a type only used with a
   // declaration so far.
-  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
-    DI->completeType(RD);
+  if (DebugInfo)
+    DebugInfo->completeType(RD);
 }
 
 static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext,
@@ -385,7 +387,8 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
     case BuiltinType::OCLImage3d:
     case BuiltinType::OCLSampler:
     case BuiltinType::OCLEvent:
-      ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty);
+      assert(OpenCLRuntime && "Expected OpenCLRuntime to be set!");
+      ResultType = OpenCLRuntime->convertOpenCLSpecificType(Ty);
       break;
     
     case BuiltinType::Dependent:
@@ -599,7 +602,8 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
       assert(valueSize < atomicSize);
       llvm::Type *elts[] = {
         ResultType,
-        llvm::ArrayType::get(CGM.Int8Ty, (atomicSize - valueSize) / 8)
+        llvm::ArrayType::get(llvm::Type::getInt8Ty(getLLVMContext()),
+                             (atomicSize - valueSize) / 8)
       };
       ResultType = llvm::StructType::get(getLLVMContext(),
                                          llvm::makeArrayRef(elts));
diff --git a/lib/CodeGen/CodeGenTypes.h b/lib/CodeGen/CodeGenTypes.h
index 452375f..6d49dd7 100644
--- a/lib/CodeGen/CodeGenTypes.h
+++ b/lib/CodeGen/CodeGenTypes.h
@@ -45,12 +45,15 @@ namespace clang {
   class QualType;
   class RecordDecl;
   class TagDecl;
+  class TargetCodeGenInfo;
   class TargetInfo;
   class Type;
   typedef CanQual<Type> CanQualType;
 
 namespace CodeGen {
   class CGCXXABI;
+  class CGDebugInfo;
+  class CGOpenCLRuntime;
   class CGRecordLayout;
   class CodeGenModule;
   class RequiredArgs;
@@ -59,14 +62,16 @@ namespace CodeGen {
 /// while lowering AST types to LLVM types.
 class CodeGenTypes {
 public:
-  // Some of this stuff should probably be left on the CGM.
-  CodeGenModule &CGM;
   ASTContext &Context;
   llvm::Module &TheModule;
   const llvm::DataLayout &TheDataLayout;
   const TargetInfo &Target;
   CGCXXABI &TheCXXABI;
   const CodeGenOptions &CodeGenOpts;
+  CGOpenCLRuntime* OpenCLRuntime;
+  CGDebugInfo* DebugInfo;
+
+  mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
 
   // This should not be moved earlier, since its initialization depends on some
   // of the previous reference members being already initialized
@@ -110,7 +115,10 @@ private:
   llvm::DenseMap<const Type *, llvm::Type *> TypeCache;
 
 public:
-  CodeGenTypes(CodeGenModule &cgm);
+  CodeGenTypes(ASTContext &Ctx, llvm::Module &M, const llvm::DataLayout &DL,
+               const TargetInfo &TI, CGCXXABI &CXXABI,
+               const CodeGenOptions &CGO, CGDebugInfo *DBI,
+               CGOpenCLRuntime *OCL);
   ~CodeGenTypes();
 
   const llvm::DataLayout &getDataLayout() const { return TheDataLayout; }
@@ -121,6 +129,20 @@ public:
   CGCXXABI &getCXXABI() const { return TheCXXABI; }
   llvm::LLVMContext &getLLVMContext() { return TheModule.getContext(); }
 
+  const TargetCodeGenInfo &getTargetCodeGenInfo();
+
+  void setOpenCLRuntime(CGOpenCLRuntime *OCL) {
+    assert(!OpenCLRuntime && "Not expecting to re-set OpenCLRuntime!");
+    assert(OCL && "Non-null CGOpenCLRuntime pointer expected!");
+    OpenCLRuntime = OCL;
+  }
+
+  void setDebugInfo(CGDebugInfo *DI) {
+    assert(!DebugInfo && "Not expecting to re-set DebugInfo!");
+    assert(DI && "Non-null CGDebugInfo pointer expected!");
+    DebugInfo = DI;
+  }
+
   /// ConvertType - Convert type T into a llvm::Type.
   llvm::Type *ConvertType(QualType T);
 
diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
index 9ad17a4..808cb72 100644
--- a/lib/CodeGen/TargetInfo.cpp
+++ b/lib/CodeGen/TargetInfo.cpp
@@ -5466,116 +5466,134 @@ llvm::Value *XCoreABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
 // Driver code
 //===----------------------------------------------------------------------===//
 
-const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
-  if (TheTargetCodeGenInfo)
-    return *TheTargetCodeGenInfo;
 
-  const llvm::Triple &Triple = getTarget().getTriple();
+static TargetCodeGenInfo *getTargetCodeGenInfo(const TargetInfo &Target,
+                                               CodeGenTypes &Types,
+                                               const CodeGenOptions &Options) {
+  const llvm::Triple &Triple = Target.getTriple();
   switch (Triple.getArch()) {
   default:
-    return *(TheTargetCodeGenInfo = new DefaultTargetCodeGenInfo(Types));
+    return new DefaultTargetCodeGenInfo(Types);
 
   case llvm::Triple::le32:
-    return *(TheTargetCodeGenInfo = new PNaClTargetCodeGenInfo(Types));
+    return new PNaClTargetCodeGenInfo(Types);
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
-    return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, true));
+    return new MIPSTargetCodeGenInfo(Types, true);
 
   case llvm::Triple::mips64:
   case llvm::Triple::mips64el:
-    return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, false));
+    return new MIPSTargetCodeGenInfo(Types, false);
 
   case llvm::Triple::aarch64:
-    return *(TheTargetCodeGenInfo = new AArch64TargetCodeGenInfo(Types));
+    return new AArch64TargetCodeGenInfo(Types);
 
   case llvm::Triple::arm:
   case llvm::Triple::thumb:
     {
       ARMABIInfo::ABIKind Kind = ARMABIInfo::AAPCS;
-      if (strcmp(getTarget().getABI(), "apcs-gnu") == 0)
+      if (strcmp(Target.getABI(), "apcs-gnu") == 0)
         Kind = ARMABIInfo::APCS;
-      else if (CodeGenOpts.FloatABI == "hard" ||
-               (CodeGenOpts.FloatABI != "soft" &&
+      else if (Options.FloatABI == "hard" ||
+               (Options.FloatABI != "soft" &&
                 Triple.getEnvironment() == llvm::Triple::GNUEABIHF))
         Kind = ARMABIInfo::AAPCS_VFP;
 
       switch (Triple.getOS()) {
         case llvm::Triple::NaCl:
-          return *(TheTargetCodeGenInfo =
-                   new NaClARMTargetCodeGenInfo(Types, Kind));
+          return new NaClARMTargetCodeGenInfo(Types, Kind);
         default:
-          return *(TheTargetCodeGenInfo =
-                   new ARMTargetCodeGenInfo(Types, Kind));
+          return new ARMTargetCodeGenInfo(Types, Kind);
       }
     }
 
   case llvm::Triple::ppc:
-    return *(TheTargetCodeGenInfo = new PPC32TargetCodeGenInfo(Types));
+    return new PPC32TargetCodeGenInfo(Types);
   case llvm::Triple::ppc64:
     if (Triple.isOSBinFormatELF())
-      return *(TheTargetCodeGenInfo = new PPC64_SVR4_TargetCodeGenInfo(Types));
+      return new PPC64_SVR4_TargetCodeGenInfo(Types);
     else
-      return *(TheTargetCodeGenInfo = new PPC64TargetCodeGenInfo(Types));
+      return new PPC64TargetCodeGenInfo(Types);
   case llvm::Triple::ppc64le:
     assert(Triple.isOSBinFormatELF() && "PPC64 LE non-ELF not supported!");
-    return *(TheTargetCodeGenInfo = new PPC64_SVR4_TargetCodeGenInfo(Types));
+    return new PPC64_SVR4_TargetCodeGenInfo(Types);
 
   case llvm::Triple::nvptx:
   case llvm::Triple::nvptx64:
-    return *(TheTargetCodeGenInfo = new NVPTXTargetCodeGenInfo(Types));
+    return new NVPTXTargetCodeGenInfo(Types);
 
   case llvm::Triple::msp430:
-    return *(TheTargetCodeGenInfo = new MSP430TargetCodeGenInfo(Types));
+    return new MSP430TargetCodeGenInfo(Types);
 
   case llvm::Triple::systemz:
-    return *(TheTargetCodeGenInfo = new SystemZTargetCodeGenInfo(Types));
+    return new SystemZTargetCodeGenInfo(Types);
 
   case llvm::Triple::tce:
-    return *(TheTargetCodeGenInfo = new TCETargetCodeGenInfo(Types));
+    return new TCETargetCodeGenInfo(Types);
 
   case llvm::Triple::x86: {
     bool IsDarwinVectorABI = Triple.isOSDarwin();
     bool IsSmallStructInRegABI =
-        X86_32TargetCodeGenInfo::isStructReturnInRegABI(Triple, CodeGenOpts);
+        X86_32TargetCodeGenInfo::isStructReturnInRegABI(Triple, Options);
     bool IsWin32FloatStructABI = (Triple.getOS() == llvm::Triple::Win32);
 
     if (Triple.getOS() == llvm::Triple::Win32) {
-      return *(TheTargetCodeGenInfo =
-               new WinX86_32TargetCodeGenInfo(Types,
-                                              IsDarwinVectorABI, IsSmallStructInRegABI,
-                                              IsWin32FloatStructABI,
-                                              CodeGenOpts.NumRegisterParameters));
+      return new WinX86_32TargetCodeGenInfo(Types,
+                                            IsDarwinVectorABI, IsSmallStructInRegABI,
+                                            IsWin32FloatStructABI,
+                                            Options.NumRegisterParameters);
     } else {
-      return *(TheTargetCodeGenInfo =
-               new X86_32TargetCodeGenInfo(Types,
-                                           IsDarwinVectorABI, IsSmallStructInRegABI,
-                                           IsWin32FloatStructABI,
-                                           CodeGenOpts.NumRegisterParameters));
+      return new X86_32TargetCodeGenInfo(Types,
+                                         IsDarwinVectorABI, IsSmallStructInRegABI,
+                                         IsWin32FloatStructABI,
+                                         Options.NumRegisterParameters);
     }
   }
 
   case llvm::Triple::x86_64: {
-    bool HasAVX = strcmp(getTarget().getABI(), "avx") == 0;
+    bool HasAVX = strcmp(Target.getABI(), "avx") == 0;
 
     switch (Triple.getOS()) {
     case llvm::Triple::Win32:
     case llvm::Triple::MinGW32:
     case llvm::Triple::Cygwin:
-      return *(TheTargetCodeGenInfo = new WinX86_64TargetCodeGenInfo(Types));
+      return new WinX86_64TargetCodeGenInfo(Types);
     case llvm::Triple::NaCl:
-      return *(TheTargetCodeGenInfo = new NaClX86_64TargetCodeGenInfo(Types,
-                                                                      HasAVX));
+      return new NaClX86_64TargetCodeGenInfo(Types,
+                                                                      HasAVX);
     default:
-      return *(TheTargetCodeGenInfo = new X86_64TargetCodeGenInfo(Types,
-                                                                  HasAVX));
+      return new X86_64TargetCodeGenInfo(Types,
+                                                                  HasAVX);
     }
   }
   case llvm::Triple::hexagon:
-    return *(TheTargetCodeGenInfo = new HexagonTargetCodeGenInfo(Types));
+    return new HexagonTargetCodeGenInfo(Types);
   case llvm::Triple::sparcv9:
-    return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types));
+    return new SparcV9TargetCodeGenInfo(Types);
   case llvm::Triple::xcore:
-    return *(TheTargetCodeGenInfo = new XcoreTargetCodeGenInfo(Types));
+    return new XcoreTargetCodeGenInfo(Types);
 
   }
 }
+
+const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
+  if (TheTargetCodeGenInfo)
+    return *TheTargetCodeGenInfo;
+
+  TheTargetCodeGenInfo = ::getTargetCodeGenInfo(getTarget(), getTypes(),
+                                                getCodeGenOpts());
+  assert(TheTargetCodeGenInfo && "Expected target codegen info!");
+
+  return *TheTargetCodeGenInfo;
+}
+
+const TargetCodeGenInfo &CodeGenTypes::getTargetCodeGenInfo() {
+  if (TheTargetCodeGenInfo)
+    return *TheTargetCodeGenInfo;
+
+  TheTargetCodeGenInfo = ::getTargetCodeGenInfo(getTarget(), *this,
+                                                getCodeGenOpts());
+  assert(TheTargetCodeGenInfo && "Expected target codegen info!");
+
+  return *TheTargetCodeGenInfo;
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to