Index: bindings/go/llvm/executionengine_test.go =================================================================== --- bindings/go/llvm/executionengine_test.go +++ bindings/go/llvm/executionengine_test.go @@ -81,7 +81,6 @@ pass := NewPassManager() defer pass.Dispose() - pass.Add(engine.TargetData()) pass.AddConstantPropagationPass() pass.AddInstructionCombiningPass() pass.AddPromoteMemoryToRegisterPass() Index: bindings/go/llvm/target.go =================================================================== --- bindings/go/llvm/target.go +++ bindings/go/llvm/target.go @@ -121,13 +121,6 @@ return } -// Adds target data information to a pass manager. This does not take ownership -// of the target data. -// See the method llvm::PassManagerBase::add. -func (pm PassManager) Add(td TargetData) { - C.LLVMAddTargetData(td.C, pm.C) -} - // Converts target data to a target layout string. The string must be disposed // with LLVMDisposeMessage. // See the constructor llvm::TargetData::TargetData. Index: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -481,16 +481,17 @@ /** * Obtain the data layout for a module. * - * @see Module::getDataLayout() + * @see Module::getDataLayoutStr() */ const char *LLVMGetDataLayout(LLVMModuleRef M); +const char *LLVMGetDataLayoutStr(LLVMModuleRef M); /** * Set the data layout for a module. * * @see Module::setDataLayout() */ -void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple); +void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr); /** * Obtain the target triple for a module. Index: include/llvm-c/Target.h =================================================================== --- include/llvm-c/Target.h +++ include/llvm-c/Target.h @@ -183,15 +183,28 @@ /*===-- Target Data -------------------------------------------------------===*/ +/** + * Obtain the data layout for a module. + * + * @see Module::getDataLayout() + */ +LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M); + +/** + * Obtain the data layout for a module. + * + * @see Module::setDataLayout() + */ +void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL); + +/** Deallocates a TargetData. + See the destructor llvm::DataLayout::~DataLayout. */ +void LLVMDisposeTargetData(LLVMTargetDataRef TD); + /** Creates target data from a target layout string. See the constructor llvm::DataLayout::DataLayout. */ LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep); -/** Adds target data information to a pass manager. This does not take ownership - of the target data. - See the method llvm::PassManagerBase::add. */ -void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM); - /** Adds target library information to a pass manager. This does not take ownership of the target library info. See the method llvm::PassManagerBase::add. */ @@ -275,10 +288,6 @@ unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef TD, LLVMTypeRef StructTy, unsigned Element); -/** Deallocates a TargetData. - See the destructor llvm::DataLayout::~DataLayout. */ -void LLVMDisposeTargetData(LLVMTargetDataRef TD); - /** * @} */ Index: include/llvm-c/TargetMachine.h =================================================================== --- include/llvm-c/TargetMachine.h +++ include/llvm-c/TargetMachine.h @@ -88,6 +88,7 @@ LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T); /*===-- Target Machine ----------------------------------------------------===*/ + /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */ LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, const char *CPU, const char *Features, @@ -119,6 +120,9 @@ void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T, LLVMBool VerboseAsm); +/** Create a DataLayout based on the targetMachine. */ +LLVMTargetDataRef LLVMCreateTargetMachineData(LLVMTargetMachineRef T); + /** Emits an asm or object file for the given module to the filename. This wraps several c++ only classes (among them a file stream). Returns any error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */ Index: include/llvm/IR/DataLayout.h =================================================================== --- include/llvm/IR/DataLayout.h +++ include/llvm/IR/DataLayout.h @@ -464,11 +464,11 @@ }; inline DataLayout *unwrap(LLVMTargetDataRef P) { - return reinterpret_cast(P); + return reinterpret_cast(P); } inline LLVMTargetDataRef wrap(const DataLayout *P) { - return reinterpret_cast(const_cast(P)); + return reinterpret_cast(const_cast(P)); } /// Used to lazily calculate structure layout information for a target machine, Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -160,12 +160,17 @@ } /*--.. Data layout .........................................................--*/ -const char * LLVMGetDataLayout(LLVMModuleRef M) { + +const char *LLVMGetDataLayout(LLVMModuleRef M) { + return LLVMGetDataLayoutStr(M); +} + +const char *LLVMGetDataLayoutStr(LLVMModuleRef M) { return unwrap(M)->getDataLayoutStr().c_str(); } -void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple) { - unwrap(M)->setDataLayout(Triple); +void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr) { + unwrap(M)->setDataLayout(DataLayoutStr); } /*--.. Target triple .......................................................--*/ Index: lib/Target/Target.cpp =================================================================== --- lib/Target/Target.cpp +++ lib/Target/Target.cpp @@ -42,11 +42,16 @@ initializeTarget(*unwrap(R)); } -LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) { - return wrap(new DataLayout(StringRep)); +LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M) { + return wrap(&unwrap(M)->getDataLayout()); +} + +void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL) { + unwrap(M)->setDataLayout(*unwrap(DL)); } -void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) { +LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) { + return wrap(new DataLayout(StringRep)); } void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI, Index: lib/Target/TargetMachineC.cpp =================================================================== --- lib/Target/TargetMachineC.cpp +++ lib/Target/TargetMachineC.cpp @@ -171,6 +171,10 @@ unwrap(T)->Options.MCOptions.AsmVerbose = VerboseAsm; } +LLVMTargetDataRef LLVMCreateTargetMachineData(LLVMTargetMachineRef T) { + return wrap(new DataLayout(unwrap(T)->createDataLayout())); +} + static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M, raw_pwrite_stream &OS, LLVMCodeGenFileType codegen, Index: unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp =================================================================== --- unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp +++ unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp @@ -285,7 +285,6 @@ void buildAndRunPasses() { LLVMPassManagerRef pass = LLVMCreatePassManager(); - LLVMAddTargetData(LLVMGetExecutionEngineTargetData(Engine), pass); LLVMAddConstantPropagationPass(pass); LLVMAddInstructionCombiningPass(pass); LLVMRunPassManager(pass, Module); @@ -304,8 +303,6 @@ LLVMPassManagerRef modulePasses = LLVMCreatePassManager(); - LLVMAddTargetData(LLVMGetExecutionEngineTargetData(Engine), modulePasses); - LLVMPassManagerBuilderPopulateFunctionPassManager(passBuilder, functionPasses); LLVMPassManagerBuilderPopulateModulePassManager(passBuilder, modulePasses);