[cfe-commits] r43536 - in /cfe/trunk: CodeGen/CodeGenModule.cpp CodeGen/CodeGenModule.h CodeGen/CodeGenTypes.cpp CodeGen/CodeGenTypes.h CodeGen/ModuleBuilder.cpp Driver/ASTConsumers.cpp Driver/Makefile include/clang/Basic/TargetInfo.h include/clang/CodeGen/ModuleBuilder.h

Chris Lattner clattner at apple.com
Tue Oct 30 21:50:19 PDT 2007


Devang, please don't link in a bunch of new libraries to clang.  This  
regresses in at least one way ("conflicting -stats options" error  
message from commandline), and introduces unneeded dependencies.

Lets find another way to do this.

-Chris

On Oct 30, 2007, at 5:59 PM, Devang Patel wrote:

> Author: dpatel
> Date: Tue Oct 30 19:59:29 2007
> New Revision: 43536
>
> URL: http://llvm.org/viewvc/llvm-project?rev=43536&view=rev
> Log:
> Make target info available to clang code generator.
> This is far from complete but this helps clang codegen module
> make progress.
>
> Modified:
>    cfe/trunk/CodeGen/CodeGenModule.cpp
>    cfe/trunk/CodeGen/CodeGenModule.h
>    cfe/trunk/CodeGen/CodeGenTypes.cpp
>    cfe/trunk/CodeGen/CodeGenTypes.h
>    cfe/trunk/CodeGen/ModuleBuilder.cpp
>    cfe/trunk/Driver/ASTConsumers.cpp
>    cfe/trunk/Driver/Makefile
>    cfe/trunk/include/clang/Basic/TargetInfo.h
>    cfe/trunk/include/clang/CodeGen/ModuleBuilder.h
>
> Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=43536&r1=43535&r2=43536&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/CodeGen/CodeGenModule.cpp Tue Oct 30 19:59:29 2007
> @@ -24,8 +24,10 @@
> using namespace CodeGen;
>
>
> -CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M)
> -  : Context(C), TheModule(M), Types(C, M),  
> CFConstantStringClassRef(0) {}
> +CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M,
> +                             const llvm::TargetData &TD)
> +  : Context(C), TheModule(M), TheTargetData(TD),
> +    Types(C, M, TD), CFConstantStringClassRef(0) {}
>
> llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const ValueDecl  
> *D) {
>   // See if it is already in the map.
>
> Modified: cfe/trunk/CodeGen/CodeGenModule.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.h?rev=43536&r1=43535&r2=43536&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/CodeGen/CodeGenModule.h (original)
> +++ cfe/trunk/CodeGen/CodeGenModule.h Tue Oct 30 19:59:29 2007
> @@ -23,6 +23,7 @@
>   class Constant;
>   class Function;
>   class GlobalVariable;
> +  class TargetData;
> }
>
> namespace clang {
> @@ -39,6 +40,7 @@
> class CodeGenModule {
>   ASTContext &Context;
>   llvm::Module &TheModule;
> +  const llvm::TargetData &TheTargetData;
>   CodeGenTypes Types;
>
>   llvm::Function *MemCpyFn;
> @@ -49,7 +51,7 @@
>
>   std::vector<llvm::Function *> BuiltinFunctions;
> public:
> -  CodeGenModule(ASTContext &C, llvm::Module &M);
> +  CodeGenModule(ASTContext &C, llvm::Module &M, const  
> llvm::TargetData &TD);
>
>   ASTContext &getContext() const { return Context; }
>   llvm::Module &getModule() const { return TheModule; }
>
> Modified: cfe/trunk/CodeGen/CodeGenTypes.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.cpp?rev=43536&r1=43535&r2=43536&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/CodeGen/CodeGenTypes.cpp (original)
> +++ cfe/trunk/CodeGen/CodeGenTypes.cpp Tue Oct 30 19:59:29 2007
> @@ -60,8 +60,9 @@
>   };
> }
>
> -CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M)
> -  : Context(Ctx), Target(Ctx.Target), TheModule(M) {
> +CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M,
> +                           const llvm::TargetData &TD)
> +  : Context(Ctx), Target(Ctx.Target), TheModule(M),  
> TheTargetData(TD) {
> }
>
> CodeGenTypes::~CodeGenTypes() {
>
> Modified: cfe/trunk/CodeGen/CodeGenTypes.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.h?rev=43536&r1=43535&r2=43536&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/CodeGen/CodeGenTypes.h (original)
> +++ cfe/trunk/CodeGen/CodeGenTypes.h Tue Oct 30 19:59:29 2007
> @@ -21,6 +21,7 @@
>   class Module;
>   class Type;
>   class PATypeHolder;
> +  class TargetData;
> }
>
> namespace clang {
> @@ -61,6 +62,7 @@
>   ASTContext &Context;
>   TargetInfo &Target;
>   llvm::Module& TheModule;
> +  const llvm::TargetData& TheTargetData;
>
>   llvm::DenseMap<const TagDecl*, llvm::Type*> TagDeclTypes;
>
> @@ -91,7 +93,7 @@
>   /// interface to convert type T into a llvm::Type.
>   const llvm::Type *ConvertNewType(QualType T);
> public:
> -  CodeGenTypes(ASTContext &Ctx, llvm::Module &M);
> +  CodeGenTypes(ASTContext &Ctx, llvm::Module &M, const  
> llvm::TargetData &TD);
>   ~CodeGenTypes();
>
>   TargetInfo &getTarget() const { return Target; }
>
> Modified: cfe/trunk/CodeGen/ModuleBuilder.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/ModuleBuilder.cpp?rev=43536&r1=43535&r2=43536&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/CodeGen/ModuleBuilder.cpp (original)
> +++ cfe/trunk/CodeGen/ModuleBuilder.cpp Tue Oct 30 19:59:29 2007
> @@ -18,8 +18,9 @@
>
> /// Init - Create an ModuleBuilder with the specified ASTContext.
> clang::CodeGen::BuilderTy *
> -clang::CodeGen::Init(ASTContext &Context, llvm::Module &M) {
> -  return new CodeGenModule(Context, M);
> +clang::CodeGen::Init(ASTContext &Context, llvm::Module &M,
> +                     const llvm::TargetData &TD) {
> +  return new CodeGenModule(Context, M, TD);
> }
>
> void clang::CodeGen::Terminate(BuilderTy *B) {
>
> Modified: cfe/trunk/Driver/ASTConsumers.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=43536&r1=43535&r2=43536&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/Driver/ASTConsumers.cpp (original)
> +++ cfe/trunk/Driver/ASTConsumers.cpp Tue Oct 30 19:59:29 2007
> @@ -379,14 +379,19 @@
> // LLVM Emitter
>
> #include "clang/Basic/Diagnostic.h"
> +#include "clang/Basic/TargetInfo.h"
> #include "clang/CodeGen/ModuleBuilder.h"
> #include "llvm/Module.h"
> +#include "llvm/Target/TargetData.h"
> +#include "llvm/Target/TargetMachine.h"
> +#include "llvm/Target/TargetMachineRegistry.h"
> #include <iostream>
>
> namespace {
>   class LLVMEmitter : public ASTConsumer {
>     Diagnostic &Diags;
>     llvm::Module *M;
> +    const llvm::TargetData *TD;
>     ASTContext *Ctx;
>     CodeGen::BuilderTy *Builder;
>   public:
> @@ -394,7 +399,16 @@
>     virtual void Initialize(ASTContext &Context, unsigned  
> MainFileID) {
>       Ctx = &Context;
>       M = new llvm::Module("foo");
> -      Builder = CodeGen::Init(Context, *M);
> +      M->setTargetTriple(Ctx->Target.getTargetTriple());
> +      std::string Err;
> +      const llvm::TargetMachineRegistry::entry *TME =
> +         
> llvm::TargetMachineRegistry::getClosestStaticTargetForModule(*M, Err);
> +      assert(TME && "Unable to determine target machine");
> +      // FIXME : Set appropriate subtarget features.
> +      std::string FeatureStr;
> +      llvm::TargetMachine *TheMachine =  TME->CtorFn(*M, FeatureStr);
> +      TD = TheMachine->getTargetData();
> +      Builder = CodeGen::Init(Context, *M, *TD);
>     }
>
>     virtual void HandleTopLevelDecl(Decl *D) {
>
> Modified: cfe/trunk/Driver/Makefile
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/Makefile?rev=43536&r1=43535&r2=43536&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/Driver/Makefile (original)
> +++ cfe/trunk/Driver/Makefile Tue Oct 30 19:59:29 2007
> @@ -4,8 +4,12 @@
>
> TOOLNAME = clang
> USEDLIBS = clangCodeGen.a clangAnalysis.a clangRewrite.a clangSEMA.a \
> -           clangAST.a clangParse.a clangLex.a clangBasic.a \
> +           clangAST.a clangParse.a clangLex.a clangBasic.a LLVMX86 \
>            LLVMCore.a LLVMSupport.a LLVMSystem.a \
> -           LLVMBitWriter.a LLVMBitReader.a
> +           LLVMBitWriter.a LLVMBitReader.a LLVMTarget.a  
> LLVMCodeGen.a \
> +           LLVMSelectionDAG.a LLVMScalarOpts.a LLVMTransformUtils.a \
> +           LLVMCore.a LLVMAnalysis.a
> +	
> +	
>
> include $(LEVEL)/Makefile.common
>
> Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=43536&r1=43535&r2=43536&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
> +++ cfe/trunk/include/clang/Basic/TargetInfo.h Tue Oct 30 19:59:29  
> 2007
> @@ -218,6 +218,11 @@
>     getLongLongInfo(Size, Align, Loc);
>     return static_cast<unsigned>(Size);
>   }
> +
> +  const char *getTargetTriple() {
> +    // FIXME !
> +    return "i686-apple-darwin9";
> +  }
> private:
>   void ComputeWCharInfo(SourceLocation Loc);
> };
>
> Modified: cfe/trunk/include/clang/CodeGen/ModuleBuilder.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/ModuleBuilder.h?rev=43536&r1=43535&r2=43536&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/include/clang/CodeGen/ModuleBuilder.h (original)
> +++ cfe/trunk/include/clang/CodeGen/ModuleBuilder.h Tue Oct 30  
> 19:59:29 2007
> @@ -16,6 +16,7 @@
>
> namespace llvm {
>   class Module;
> +  class TargetData;
> }
>
> namespace clang {
> @@ -29,7 +30,8 @@
>   typedef void BuilderTy;
>
>   /// Init - Create an ModuleBuilder with the specified ASTContext.
> -  BuilderTy *Init(ASTContext &Context, llvm::Module &M);
> +  BuilderTy *Init(ASTContext &Context, llvm::Module &M,
> +                  const llvm::TargetData &TD);
>
>   /// CodeGenFunction - Convert the AST node for a FunctionDecl into  
> LLVM.
>   ///
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list