diff --git a/clang/include/clang/Frontend/BackendUtil.h b/clang/include/clang/Frontend/BackendUtil.h index f963fa0ede80..39c743c63444 100644 --- a/clang/include/clang/Frontend/BackendUtil.h +++ b/clang/include/clang/Frontend/BackendUtil.h @@ -9,7 +9,6 @@ namespace llvm { class Module; - class TargetData; class raw_ostream; } @@ -28,7 +27,6 @@ namespace clang { }; void EmitBackendOutput(Diagnostic &Diags, const CodeGenOptions &CGOpts, - const TargetOptions &TOpts, - llvm::Module *M, llvm::TargetData *TD, + const TargetOptions &TOpts, llvm::Module *M, BackendAction Action, llvm::raw_ostream *OS); } diff --git a/clang/lib/Frontend/BackendUtil.cpp b/clang/lib/Frontend/BackendUtil.cpp index 6b389a6a3bd9..2ceb831a5ebe 100644 --- a/clang/lib/Frontend/BackendUtil.cpp +++ b/clang/lib/Frontend/BackendUtil.cpp @@ -39,7 +39,6 @@ class EmitAssemblyHelper { const CodeGenOptions &CodeGenOpts; const TargetOptions &TargetOpts; Module *TheModule; - TargetData *TheTargetData; Timer CodeGenerationTime; @@ -51,7 +50,7 @@ private: FunctionPassManager *getCodeGenPasses() const { if (!CodeGenPasses) { CodeGenPasses = new FunctionPassManager(TheModule); - CodeGenPasses->add(new TargetData(*TheTargetData)); + CodeGenPasses->add(new TargetData(TheModule)); } return CodeGenPasses; } @@ -59,7 +58,7 @@ private: PassManager *getPerModulePasses() const { if (!PerModulePasses) { PerModulePasses = new PassManager(); - PerModulePasses->add(new TargetData(*TheTargetData)); + PerModulePasses->add(new TargetData(TheModule)); } return PerModulePasses; } @@ -67,7 +66,7 @@ private: FunctionPassManager *getPerFunctionPasses() const { if (!PerFunctionPasses) { PerFunctionPasses = new FunctionPassManager(TheModule); - PerFunctionPasses->add(new TargetData(*TheTargetData)); + PerFunctionPasses->add(new TargetData(TheModule)); } return PerFunctionPasses; } @@ -82,10 +81,9 @@ private: public: EmitAssemblyHelper(Diagnostic &_Diags, const CodeGenOptions &CGOpts, const TargetOptions &TOpts, - Module *M, TargetData *TD) + Module *M) : Diags(_Diags), CodeGenOpts(CGOpts), TargetOpts(TOpts), - TheModule(M), TheTargetData(TD), - CodeGenerationTime("Code Generation Time"), + TheModule(M), CodeGenerationTime("Code Generation Time"), CodeGenPasses(0), PerModulePasses(0), PerFunctionPasses(0) {} ~EmitAssemblyHelper() { @@ -320,9 +318,8 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, raw_ostream *OS) { void clang::EmitBackendOutput(Diagnostic &Diags, const CodeGenOptions &CGOpts, const TargetOptions &TOpts, Module *M, - TargetData *TD, BackendAction Action, - raw_ostream *OS) { - EmitAssemblyHelper AsmHelper(Diags, CGOpts, TOpts, M, TD); + BackendAction Action, raw_ostream *OS) { + EmitAssemblyHelper AsmHelper(Diags, CGOpts, TOpts, M); AsmHelper.EmitAssembly(Action, OS); } diff --git a/clang/lib/Frontend/CodeGenAction.cpp b/clang/lib/Frontend/CodeGenAction.cpp index a3eba0fbd50c..99af838a33ca 100644 --- a/clang/lib/Frontend/CodeGenAction.cpp +++ b/clang/lib/Frontend/CodeGenAction.cpp @@ -20,11 +20,11 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "llvm/LLVMContext.h" #include "llvm/Module.h" +#include "llvm/Pass.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/Timer.h" -#include "llvm/Target/TargetData.h" using namespace clang; using namespace llvm; @@ -42,7 +42,6 @@ namespace { llvm::OwningPtr Gen; llvm::OwningPtr TheModule; - llvm::TargetData *TheTargetData; public: BackendConsumer(BackendAction action, Diagnostic &_Diags, @@ -56,15 +55,10 @@ namespace { TargetOpts(targetopts), AsmOutStream(OS), LLVMIRGeneration("LLVM IR Generation Time"), - Gen(CreateLLVMCodeGen(Diags, infile, compopts, C)), - TheTargetData(0) { + Gen(CreateLLVMCodeGen(Diags, infile, compopts, C)) { llvm::TimePassesIsEnabled = TimePasses; } - ~BackendConsumer() { - delete TheTargetData; - } - llvm::Module *takeModule() { return TheModule.take(); } virtual void Initialize(ASTContext &Ctx) { @@ -76,7 +70,6 @@ namespace { Gen->Initialize(Ctx); TheModule.reset(Gen->GetModule()); - TheTargetData = new llvm::TargetData(Ctx.Target.getTargetDescription()); if (llvm::TimePassesIsEnabled) LLVMIRGeneration.stopTimer(); @@ -109,7 +102,7 @@ namespace { } // Silently ignore if we weren't initialized for some reason. - if (!TheModule || !TheTargetData) + if (!TheModule) return; // Make sure IR generation is happy with the module. This is released by @@ -134,7 +127,7 @@ namespace { this); EmitBackendOutput(Diags, CodeGenOpts, TargetOpts, - TheModule.get(), TheTargetData, Action, AsmOutStream); + TheModule.get(), Action, AsmOutStream); Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext); }