llvm.org GIT mirror llvm / 26be214
Revert "Remove access to the DataLayout in the TargetMachine" This reverts commit 0f720d984f419c747709462f7476dff962c0bc41. It breaks clang too badly, I need to prepare a proper patch for clang first. From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243089 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 4 years ago
17 changed file(s) with 60 addition(s) and 74 deletion(s). Raw diff Collapse all Expand all
716716 M(new Module(GenerateUniqueName("jit_module_"),
717717 Session.getLLVMContext())),
718718 Builder(Session.getLLVMContext()) {
719 M->setDataLayout(Session.getTarget().createDataLayout());
719 M->setDataLayout(*Session.getTarget().getDataLayout());
720720 }
721721
722722 SessionContext& getSession() { return Session; }
11781178 {
11791179 raw_string_ostream MangledNameStream(MangledName);
11801180 Mangler::getNameWithPrefix(MangledNameStream, Name,
1181 Session.getTarget().createDataLayout());
1181 *Session.getTarget().getDataLayout());
11821182 }
11831183 return MangledName;
11841184 }
715715 M(new Module(GenerateUniqueName("jit_module_"),
716716 Session.getLLVMContext())),
717717 Builder(Session.getLLVMContext()) {
718 M->setDataLayout(Session.getTarget().createDataLayout());
718 M->setDataLayout(*Session.getTarget().getDataLayout());
719719 }
720720
721721 SessionContext& getSession() { return Session; }
11591159 typedef CompileLayerT::ModuleSetHandleT ModuleHandleT;
11601160
11611161 KaleidoscopeJIT(SessionContext &Session)
1162 : DL(Session.getTarget().createDataLayout()),
1162 : DL(*Session.getTarget().getDataLayout()),
11631163 CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())) {}
11641164
11651165 std::string mangle(const std::string &Name) {
12001200 }
12011201
12021202 private:
1203 const DataLayout DL;
1203 const DataLayout &DL;
12041204 ObjLayerT ObjectLayer;
12051205 CompileLayerT CompileLayer;
12061206 };
715715 M(new Module(GenerateUniqueName("jit_module_"),
716716 Session.getLLVMContext())),
717717 Builder(Session.getLLVMContext()) {
718 M->setDataLayout(Session.getTarget().createDataLayout());
718 M->setDataLayout(*Session.getTarget().getDataLayout());
719719 }
720720
721721 SessionContext& getSession() { return Session; }
11611161 typedef LazyEmitLayerT::ModuleSetHandleT ModuleHandleT;
11621162
11631163 KaleidoscopeJIT(SessionContext &Session)
1164 : DL(Session.getTarget().createDataLayout()),
1164 : DL(*Session.getTarget().getDataLayout()),
11651165 CompileLayer(ObjectLayer, SimpleCompiler(Session.getTarget())),
11661166 LazyEmitLayer(CompileLayer) {}
11671167
12031203 }
12041204
12051205 private:
1206 const DataLayout DL;
1206 const DataLayout &DL;
12071207 ObjLayerT ObjectLayer;
12081208 CompileLayerT CompileLayer;
12091209 LazyEmitLayerT LazyEmitLayer;
715715 M(new Module(GenerateUniqueName("jit_module_"),
716716 Session.getLLVMContext())),
717717 Builder(Session.getLLVMContext()) {
718 M->setDataLayout(Session.getTarget().createDataLayout());
718 M->setDataLayout(*Session.getTarget().getDataLayout());
719719 }
720720
721721 SessionContext& getSession() { return Session; }
11691169 {
11701170 raw_string_ostream MangledNameStream(MangledName);
11711171 Mangler::getNameWithPrefix(MangledNameStream, Name,
1172 Session.getTarget().createDataLayout());
1172 *Session.getTarget().getDataLayout());
11731173 }
11741174 return MangledName;
11751175 }
7575 /// The Target that this machine was created for.
7676 const Target &TheTarget;
7777
78 /// DataLayout for the target: keep ABI type size and alignment.
79 ///
80 /// The DataLayout is created based on the string representation provided
81 /// during construction. It is kept here only to avoid reparsing the string
82 /// but should not really be used during compilation, because it has an
83 /// internal cache that is context specific.
78 /// For ABI type size and alignment.
8479 const DataLayout DL;
8580
8681 /// Triple string, CPU name, and target feature strings the TargetMachine
129124 return *static_cast(getSubtargetImpl(F));
130125 }
131126
132 /// Create a DataLayout.
133 const DataLayout createDataLayout() const { return DL; }
134
135 /// Get the pointer size for this target.
136 ///
137 /// This is the only time the DataLayout in the TargetMachine is used.
138 unsigned getPointerSize() const { return DL.getPointerSize(); }
127 /// This method returns a pointer to the DataLayout for the target. It should
128 /// be unchanging for every subtarget.
129 const DataLayout *getDataLayout() const { return &DL; }
139130
140131 /// \brief Reset the target options based on the function's attributes.
141132 // FIXME: Remove TargetOptions that affect per-function code generation
138138 return MMI->getModule()->getDataLayout();
139139 }
140140
141 // Do not use the cached DataLayout because some client use it without a Module
142 // (llmv-dsymutil, llvm-dwarfdump).
143 unsigned AsmPrinter::getPointerSize() const { return TM.getPointerSize(); }
141 unsigned AsmPrinter::getPointerSize() const {
142 return TM.getDataLayout()->getPointerSize();
143 }
144144
145145 const MCSubtargetInfo &AsmPrinter::getSubtargetInfo() const {
146146 assert(MF && "getSubtargetInfo requires a valid MachineFunction!");
6767 MCJIT::MCJIT(std::unique_ptr M, std::unique_ptr TM,
6868 std::shared_ptr MemMgr,
6969 std::shared_ptr Resolver)
70 : ExecutionEngine(TM->createDataLayout(), std::move(M)), TM(std::move(TM)),
70 : ExecutionEngine(*TM->getDataLayout(), std::move(M)), TM(std::move(TM)),
7171 Ctx(nullptr), MemMgr(std::move(MemMgr)),
7272 Resolver(*this, std::move(Resolver)), Dyld(*this->MemMgr, this->Resolver),
7373 ObjCache(nullptr) {
139139 std::shared_ptr MemMgr,
140140 std::shared_ptr ClientResolver,
141141 std::unique_ptr TM)
142 : ExecutionEngine(TM->createDataLayout()), TM(std::move(TM)),
142 : ExecutionEngine(*TM->getDataLayout()), TM(std::move(TM)),
143143 MemMgr(*this, std::move(MemMgr)), Resolver(*this),
144144 ClientResolver(std::move(ClientResolver)), NotifyObjectLoaded(*this),
145145 NotifyFinalized(*this),
520520 legacy::PassManager passes;
521521
522522 // Add an appropriate DataLayout instance for this module...
523 mergedModule->setDataLayout(TargetMach->createDataLayout());
523 mergedModule->setDataLayout(*TargetMach->getDataLayout());
524524
525525 passes.add(
526526 createTargetTransformInfoWrapperPass(TargetMach->getTargetIRAnalysis()));
231231
232232 TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
233233 options);
234 M->setDataLayout(target->createDataLayout());
234 M->setDataLayout(*target->getDataLayout());
235235
236236 std::unique_ptr IRObj(
237237 new object::IRObjectFile(Buffer, std::move(M)));
13691369 SparcTargetLowering::SparcTargetLowering(TargetMachine &TM,
13701370 const SparcSubtarget &STI)
13711371 : TargetLowering(TM), Subtarget(&STI) {
1372 MVT PtrVT = MVT::getIntegerVT(8 * TM.getPointerSize());
1372 auto &DL = *TM.getDataLayout();
13731373
13741374 // Set up the register classes.
13751375 addRegisterClass(MVT::i32, &SP::IntRegsRegClass);
13951395 setTruncStoreAction(MVT::f128, MVT::f64, Expand);
13961396
13971397 // Custom legalize GlobalAddress nodes into LO/HI parts.
1398 setOperationAction(ISD::GlobalAddress, PtrVT, Custom);
1399 setOperationAction(ISD::GlobalTLSAddress, PtrVT, Custom);
1400 setOperationAction(ISD::ConstantPool, PtrVT, Custom);
1401 setOperationAction(ISD::BlockAddress, PtrVT, Custom);
1398 setOperationAction(ISD::GlobalAddress, getPointerTy(DL), Custom);
1399 setOperationAction(ISD::GlobalTLSAddress, getPointerTy(DL), Custom);
1400 setOperationAction(ISD::ConstantPool, getPointerTy(DL), Custom);
1401 setOperationAction(ISD::BlockAddress, getPointerTy(DL), Custom);
14021402
14031403 // Sparc doesn't have sext_inreg, replace them with shl/sra
14041404 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
8383 SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM,
8484 const SystemZSubtarget &STI)
8585 : TargetLowering(TM), Subtarget(STI) {
86 MVT PtrVT = MVT::getIntegerVT(8 * TM.getPointerSize());
86 auto &DL = *TM.getDataLayout();
87 MVT PtrVT = getPointerTy(DL);
8788
8889 // Set up the register classes.
8990 if (Subtarget.hasHighWord())
3131
3232 using namespace llvm;
3333
34
35 // The TargetMachine uses to offer access to a DataLayout member. This is reflected
36 // in the C API. For backward compatibility reason, this structure allows to keep
37 // a DataLayout member accessible to C client that have a handle to a
38 // LLVMTargetMachineRef.
39 struct LLVMOpaqueTargetMachine {
40 std::unique_ptr Machine;
41 DataLayout DL;
42 };
43
44
4534 inline TargetMachine *unwrap(LLVMTargetMachineRef P) {
46 return P->Machine.get();
35 return reinterpret_cast(P);
4736 }
4837 inline Target *unwrap(LLVMTargetRef P) {
4938 return reinterpret_cast(P);
5039 }
5140 inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
52 return new LLVMOpaqueTargetMachine{ std::unique_ptr(const_cast(P)), P->createDataLayout() };
41 return
42 reinterpret_cast(const_cast(P));
5343 }
5444 inline LLVMTargetRef wrap(const Target * P) {
5545 return reinterpret_cast(const_cast(P));
156146
157147
158148 void LLVMDisposeTargetMachine(LLVMTargetMachineRef T) {
159 delete T;
149 delete unwrap(T);
160150 }
161151
162152 LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T) {
179169 return strdup(StringRep.c_str());
180170 }
181171
182 /// @deprecated: see "struct LLVMOpaqueTargetMachine" description above
183172 LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) {
184 return wrap(&T->DL);
173 return wrap(unwrap(T)->getDataLayout());
185174 }
186175
187176 void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
200189
201190 std::string error;
202191
203 Mod->setDataLayout(TM->createDataLayout());
192 const DataLayout *td = TM->getDataLayout();
193
194 if (!td) {
195 error = "No DataLayout in TargetMachine";
196 *ErrorMessage = strdup(error.c_str());
197 return true;
198 }
199 Mod->setDataLayout(*td);
204200
205201 TargetMachine::CodeGenFileType ft;
206202 switch (codegen) {
7575 : TargetLowering(TM), Subtarget(&STI) {
7676 X86ScalarSSEf64 = Subtarget->hasSSE2();
7777 X86ScalarSSEf32 = Subtarget->hasSSE1();
78 MVT PtrVT = MVT::getIntegerVT(8 * TM.getPointerSize());
78 TD = TM.getDataLayout();
7979
8080 // Set up the TargetLowering object.
8181 static const MVT IntVTs[] = { MVT::i8, MVT::i16, MVT::i32, MVT::i64 };
504504 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
505505 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
506506
507 setOperationAction(ISD::DYNAMIC_STACKALLOC, PtrVT, Custom);
507 setOperationAction(ISD::DYNAMIC_STACKALLOC, getPointerTy(*TD), Custom);
508508
509509 // GC_TRANSITION_START and GC_TRANSITION_END need custom lowering.
510510 setOperationAction(ISD::GC_TRANSITION_START, MVT::Other, Custom);
1651416514
1651516515 for (FunctionType::param_iterator I = FTy->param_begin(),
1651616516 E = FTy->param_end(); I != E; ++I, ++Idx)
16517 if (Attrs.hasAttribute(Idx, Attribute::InReg)) {
16518 auto &DL = DAG.getDataLayout();
16517 if (Attrs.hasAttribute(Idx, Attribute::InReg))
1651916518 // FIXME: should only count parameters that are lowered to integers.
16520 InRegCount += (DL.getTypeSizeInBits(*I) + 31) / 32;
16521 }
16519 InRegCount += (TD->getTypeSizeInBits(*I) + 31) / 32;
1652216520
1652316521 if (InRegCount > 2) {
1652416522 report_fatal_error("Nest register in use - reduce number of inreg"
311311 PM.add(new TargetLibraryInfoWrapperPass(TLII));
312312
313313 // Add the target data from the target machine, if it exists, or the module.
314 M->setDataLayout(Target->createDataLayout());
314 if (const DataLayout *DL = Target->getDataLayout())
315 M->setDataLayout(*DL);
315316
316317 // Override function attributes based on CPUStr, FeaturesStr, and command line
317318 // flags.
135135 }
136136
137137 // Everything looks good. Build the JIT.
138 auto &DL = M->getDataLayout();
139 OrcLazyJIT J(std::move(TM), DL, Context, CallbackMgrBuilder);
138 OrcLazyJIT J(std::move(TM), Context, CallbackMgrBuilder);
140139
141140 // Add the module, look up main and run it.
142141 auto MainHandle = J.addModule(std::move(M));
4545 CallbackManagerBuilder;
4646
4747 static CallbackManagerBuilder createCallbackManagerBuilder(Triple T);
48 const DataLayout &DL;
4948
50 OrcLazyJIT(std::unique_ptr TM, const DataLayout &DL,
51 LLVMContext &Context, CallbackManagerBuilder &BuildCallbackMgr)
52 : DL(DL), TM(std::move(TM)), ObjectLayer(),
53 CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
54 IRDumpLayer(CompileLayer, createDebugDumper()),
55 CCMgr(BuildCallbackMgr(IRDumpLayer, CCMgrMemMgr, Context)),
56 CODLayer(IRDumpLayer, *CCMgr, false),
57 CXXRuntimeOverrides(
58 [this](const std::string &S) { return mangle(S); }) {}
49 OrcLazyJIT(std::unique_ptr TM, LLVMContext &Context,
50 CallbackManagerBuilder &BuildCallbackMgr)
51 : TM(std::move(TM)),
52 ObjectLayer(),
53 CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
54 IRDumpLayer(CompileLayer, createDebugDumper()),
55 CCMgr(BuildCallbackMgr(IRDumpLayer, CCMgrMemMgr, Context)),
56 CODLayer(IRDumpLayer, *CCMgr, false),
57 CXXRuntimeOverrides([this](const std::string &S) { return mangle(S); }) {}
5958
6059 ~OrcLazyJIT() {
6160 // Run any destructors registered with __cxa_atexit.
7372 ModuleHandleT addModule(std::unique_ptr M) {
7473 // Attach a data-layout if one isn't already present.
7574 if (M->getDataLayout().isDefault())
76 M->setDataLayout(DL);
75 M->setDataLayout(*TM->getDataLayout());
7776
7877 // Record the static constructors and destructors. We have to do this before
7978 // we hand over ownership of the module to the JIT.
131130 }
132131
133132 private:
133
134134 std::string mangle(const std::string &Name) {
135135 std::string MangledName;
136136 {
137137 raw_string_ostream MangledNameStream(MangledName);
138 Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
138 Mangler::getNameWithPrefix(MangledNameStream, Name, *TM->getDataLayout());
139139 }
140140 return MangledName;
141141 }