llvm.org GIT mirror llvm / 4688261
Move --march, --mcpu, and --mattr from JIT/TargetSelect.cpp to lli.cpp. llc.cpp also defined these flags, meaning that when I linked all of LLVM's libraries into a single shared library, llc crashed on startup with duplicate flag definitions. This patch passes them through the EngineBuilder into JIT::selectTarget(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95390 91177308-0d34-0410-b5e6-96231b3b80d8 Jeffrey Yasskin 10 years ago
6 changed file(s) with 93 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
1818 #include
1919 #include
2020 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
2122 #include "llvm/ADT/ValueMap.h"
2223 #include "llvm/Support/ValueHandle.h"
2324 #include "llvm/System/Mutex.h"
107108 // To avoid having libexecutionengine depend on the JIT and interpreter
108109 // libraries, the JIT and Interpreter set these functions to ctor pointers
109110 // at startup time if they are linked in.
110 static ExecutionEngine *(*JITCtor)(Module *M,
111 std::string *ErrorStr,
112 JITMemoryManager *JMM,
113 CodeGenOpt::Level OptLevel,
114 bool GVsWithCode,
115 CodeModel::Model CMM);
111 static ExecutionEngine *(*JITCtor)(
112 Module *M,
113 std::string *ErrorStr,
114 JITMemoryManager *JMM,
115 CodeGenOpt::Level OptLevel,
116 bool GVsWithCode,
117 CodeModel::Model CMM,
118 StringRef MArch,
119 StringRef MCPU,
120 const SmallVectorImpl& MAttrs);
116121 static ExecutionEngine *(*InterpCtor)(Module *M,
117122 std::string *ErrorStr);
118123
415420 JITMemoryManager *JMM;
416421 bool AllocateGVsWithCode;
417422 CodeModel::Model CMModel;
423 std::string MArch;
424 std::string MCPU;
425 SmallVector MAttrs;
418426
419427 /// InitEngine - Does the common initialization of default options.
420428 ///
483491 return *this;
484492 }
485493
494 /// setMArch - Override the architecture set by the Module's triple.
495 EngineBuilder &setMArch(StringRef march) {
496 MArch.assign(march.begin(), march.end());
497 return *this;
498 }
499
500 /// setMCPU - Target a specific cpu type.
501 EngineBuilder &setMCPU(StringRef mcpu) {
502 MCPU.assign(mcpu.begin(), mcpu.end());
503 return *this;
504 }
505
506 /// setMAttrs - Set cpu-specific attributes.
507 template
508 EngineBuilder &setMAttrs(const StringSequence &mattrs) {
509 MAttrs.clear();
510 MAttrs.append(mattrs.begin(), mattrs.end());
511 return *this;
512 }
513
486514 ExecutionEngine *create();
487515 };
488516
3434 STATISTIC(NumInitBytes, "Number of bytes of global vars initialized");
3535 STATISTIC(NumGlobals , "Number of global vars initialized");
3636
37 ExecutionEngine *(*ExecutionEngine::JITCtor)(Module *M,
38 std::string *ErrorStr,
39 JITMemoryManager *JMM,
40 CodeGenOpt::Level OptLevel,
41 bool GVsWithCode,
42 CodeModel::Model CMM) = 0;
37 ExecutionEngine *(*ExecutionEngine::JITCtor)(
38 Module *M,
39 std::string *ErrorStr,
40 JITMemoryManager *JMM,
41 CodeGenOpt::Level OptLevel,
42 bool GVsWithCode,
43 CodeModel::Model CMM,
44 StringRef MArch,
45 StringRef MCPU,
46 const SmallVectorImpl& MAttrs) = 0;
4347 ExecutionEngine *(*ExecutionEngine::InterpCtor)(Module *M,
4448 std::string *ErrorStr) = 0;
4549 ExecutionEngine::EERegisterFn ExecutionEngine::ExceptionTableRegister = 0;
411415 if (ExecutionEngine::JITCtor) {
412416 ExecutionEngine *EE =
413417 ExecutionEngine::JITCtor(M, ErrorStr, JMM, OptLevel,
414 AllocateGVsWithCode, CMModel);
418 AllocateGVsWithCode, CMModel,
419 MArch, MCPU, MAttrs);
415420 if (EE) return EE;
416421 }
417422 }
197197 JITMemoryManager *JMM,
198198 CodeGenOpt::Level OptLevel,
199199 bool GVsWithCode,
200 CodeModel::Model CMM) {
201 return JIT::createJIT(M, ErrorStr, JMM, OptLevel, GVsWithCode, CMM);
200 CodeModel::Model CMM) {
201 // Use the defaults for extra parameters. Users can use EngineBuilder to
202 // set them.
203 StringRef MArch = "";
204 StringRef MCPU = "";
205 SmallVector MAttrs;
206 return JIT::createJIT(M, ErrorStr, JMM, OptLevel, GVsWithCode, CMM,
207 MArch, MCPU, MAttrs);
202208 }
203209
204210 ExecutionEngine *JIT::createJIT(Module *M,
206212 JITMemoryManager *JMM,
207213 CodeGenOpt::Level OptLevel,
208214 bool GVsWithCode,
209 CodeModel::Model CMM) {
215 CodeModel::Model CMM,
216 StringRef MArch,
217 StringRef MCPU,
218 const SmallVectorImpl& MAttrs) {
210219 // Make sure we can resolve symbols in the program as well. The zero arg
211220 // to the function tells DynamicLibrary to load the program, not a library.
212221 if (sys::DynamicLibrary::LoadLibraryPermanently(0, ErrorStr))
213222 return 0;
214223
215224 // Pick a target either via -march or by guessing the native arch.
216 TargetMachine *TM = JIT::selectTarget(M, ErrorStr);
225 TargetMachine *TM = JIT::selectTarget(M, MArch, MCPU, MAttrs, ErrorStr);
217226 if (!TM || (ErrorStr && ErrorStr->length() > 0)) return 0;
218227 TM->setCodeModel(CMM);
219228
6969 ~JIT();
7070
7171 static void Register() {
72 JITCtor = create;
72 JITCtor = createJIT;
7373 }
7474
7575 /// getJITInfo - Return the target JIT information structure.
163163
164164 /// selectTarget - Pick a target either via -march or by guessing the native
165165 /// arch. Add any CPU features specified via -mcpu or -mattr.
166 static TargetMachine *selectTarget(Module *M, std::string *Err);
166 static TargetMachine *selectTarget(Module *M,
167 StringRef MArch,
168 StringRef MCPU,
169 const SmallVectorImpl& MAttrs,
170 std::string *Err);
167171
168172 static ExecutionEngine *createJIT(Module *M,
169173 std::string *ErrorStr,
170174 JITMemoryManager *JMM,
171175 CodeGenOpt::Level OptLevel,
172176 bool GVsWithCode,
173 CodeModel::Model CMM);
177 CodeModel::Model CMM,
178 StringRef MArch,
179 StringRef MCPU,
180 const SmallVectorImpl& MAttrs);
174181
175182 // Run the JIT on F and return information about the generated code
176183 void runJITOnFunction(Function *F, MachineCodeInfo *MCI = 0);
2323 #include "llvm/Target/TargetRegistry.h"
2424 using namespace llvm;
2525
26 static cl::opt
27 MArch("march",
28 cl::desc("Architecture to generate assembly for (see --version)"));
29
30 static cl::opt
31 MCPU("mcpu",
32 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
33 cl::value_desc("cpu-name"),
34 cl::init(""));
35
36 static cl::list
37 MAttrs("mattr",
38 cl::CommaSeparated,
39 cl::desc("Target specific attributes (-mattr=help for details)"),
40 cl::value_desc("a1,+a2,-a3,..."));
41
4226 /// selectTarget - Pick a target either via -march or by guessing the native
4327 /// arch. Add any CPU features specified via -mcpu or -mattr.
44 TargetMachine *JIT::selectTarget(Module *Mod, std::string *ErrorStr) {
28 TargetMachine *JIT::selectTarget(Module *Mod,
29 StringRef MArch,
30 StringRef MCPU,
31 const SmallVectorImpl& MAttrs,
32 std::string *ErrorStr) {
4533 Triple TheTriple(Mod->getTargetTriple());
4634 if (TheTriple.getTriple().empty())
4735 TheTriple.setTriple(sys::getHostTriple());
5757 TargetTriple("mtriple", cl::desc("Override target triple for module"));
5858
5959 cl::opt
60 MArch("march",
61 cl::desc("Architecture to generate assembly for (see --version)"));
62
63 cl::opt
64 MCPU("mcpu",
65 cl::desc("Target a specific cpu type (-mcpu=help for details)"),
66 cl::value_desc("cpu-name"),
67 cl::init(""));
68
69 cl::list
70 MAttrs("mattr",
71 cl::CommaSeparated,
72 cl::desc("Target specific attributes (-mattr=help for details)"),
73 cl::value_desc("a1,+a2,-a3,..."));
74
75 cl::opt
6076 EntryFunc("entry-function",
6177 cl::desc("Specify the entry function (default = 'main') "
6278 "of the executable"),
130146 }
131147
132148 EngineBuilder builder(Mod);
149 builder.setMArch(MArch);
150 builder.setMCPU(MCPU);
151 builder.setMAttrs(MAttrs);
133152 builder.setErrorStr(&ErrorMsg);
134153 builder.setEngineKind(ForceInterpreter
135154 ? EngineKind::Interpreter