llvm.org GIT mirror llvm / d40e103
EngineBuilder: support for custom TargetOptions. Fixes the ExceptionDemo example. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146108 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 8 years ago
4 changed file(s) with 19 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
20042004 }
20052005
20062006 // If not set, exception handling will not be turned on
2007 llvm::JITExceptionHandling = true;
2007 llvm::TargetOptions Opts;
2008 Opts.JITExceptionHandling = true;
20082009
20092010 llvm::InitializeNativeTarget();
20102011 llvm::LLVMContext &context = llvm::getGlobalContext();
20172018 llvm::EngineBuilder factory(module);
20182019 factory.setEngineKind(llvm::EngineKind::JIT);
20192020 factory.setAllocateGVsWithCode(false);
2021 factory.setTargetOptions(Opts);
20202022 llvm::ExecutionEngine *executionEngine = factory.create();
20212023
20222024 {
2525 #include "llvm/Support/ValueHandle.h"
2626 #include "llvm/Support/Mutex.h"
2727 #include "llvm/Target/TargetMachine.h"
28 #include "llvm/Target/TargetOptions.h"
2829
2930 namespace llvm {
3031
461462 CodeGenOpt::Level OptLevel;
462463 JITMemoryManager *JMM;
463464 bool AllocateGVsWithCode;
465 TargetOptions Options;
464466 Reloc::Model RelocModel;
465467 CodeModel::Model CMModel;
466468 std::string MArch;
474476 ErrorStr = NULL;
475477 OptLevel = CodeGenOpt::Default;
476478 JMM = NULL;
479 Options = TargetOptions();
477480 AllocateGVsWithCode = false;
478481 RelocModel = Reloc::Default;
479482 CMModel = CodeModel::JITDefault;
514517 /// defaults to CodeGenOpt::Default.
515518 EngineBuilder &setOptLevel(CodeGenOpt::Level l) {
516519 OptLevel = l;
520 return *this;
521 }
522
523 /// setTargetOptions - Set the target options that the ExecutionEngine
524 /// target is using. Defaults to TargetOptions().
525 EngineBuilder &setTargetOptions(const TargetOptions &Opts) {
526 Options = Opts;
517527 return *this;
518528 }
519529
577587 StringRef MArch,
578588 StringRef MCPU,
579589 const SmallVectorImpl& MAttrs,
590 const TargetOptions &Options,
580591 Reloc::Model RM,
581592 CodeModel::Model CM,
582593 CodeGenOpt::Level OL,
435435 StringRef MCPU = "";
436436 SmallVector MAttrs;
437437
438 // TODO: permit custom TargetOptions here
438439 TargetMachine *TM =
439 EngineBuilder::selectTarget(M, MArch, MCPU, MAttrs, RM, CMM, OL, ErrorStr);
440 EngineBuilder::selectTarget(M, MArch, MCPU, MAttrs, TargetOptions(), RM,
441 CMM, OL, ErrorStr);
440442 if (!TM || (ErrorStr && ErrorStr->length() > 0)) return 0;
441443
442444 return ExecutionEngine::JITCtor(M, ErrorStr, JMM, OL, GVsWithCode, TM);
465467 // try making a JIT.
466468 if (WhichEngine & EngineKind::JIT) {
467469 if (TargetMachine *TM = EngineBuilder::selectTarget(M, MArch, MCPU, MAttrs,
470 Options,
468471 RelocModel, CMModel,
469472 OptLevel, ErrorStr)) {
470473 if (UseMCJIT && ExecutionEngine::MCJITCtor) {
2929 StringRef MArch,
3030 StringRef MCPU,
3131 const SmallVectorImpl& MAttrs,
32 const TargetOptions &Options,
3233 Reloc::Model RM,
3334 CodeModel::Model CM,
3435 CodeGenOpt::Level OL,
8586 }
8687
8788 // Allocate a target...
88 TargetOptions Options;
8989 TargetMachine *Target = TheTarget->createTargetMachine(TheTriple.getTriple(),
9090 MCPU, FeaturesStr,
9191 Options,