Simplify creation of TargetMachine
We know exactly which target triple and features the CompilerInstance wants, we don't need to (and probably must not) second-guess that. This brings us closer to upstream clang-repl and also includes the change of https://reviews.llvm.org/D128853 which is crucial for RISC-V.
This commit is contained in:
parent
1603be8b87
commit
1d93ee8d58
@ -419,52 +419,39 @@ static bool UseJITLink(const Triple& TT) {
|
||||
}
|
||||
|
||||
static std::unique_ptr<TargetMachine>
|
||||
CreateHostTargetMachine(const clang::CompilerInstance& CI, bool JITLink) {
|
||||
const clang::TargetOptions& TargetOpts = CI.getTargetOpts();
|
||||
const clang::CodeGenOptions& CGOpt = CI.getCodeGenOpts();
|
||||
const std::string& Triple = TargetOpts.Triple;
|
||||
|
||||
std::string Error;
|
||||
const Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
|
||||
if (!TheTarget) {
|
||||
cling::errs() << "cling::IncrementalExecutor: unable to find target:\n"
|
||||
<< Error;
|
||||
return std::unique_ptr<TargetMachine>();
|
||||
}
|
||||
|
||||
CreateTargetMachine(const clang::CompilerInstance& CI, bool JITLink) {
|
||||
CodeGenOpt::Level OptLevel = CodeGenOpt::Default;
|
||||
switch (CGOpt.OptimizationLevel) {
|
||||
switch (CI.getCodeGenOpts().OptimizationLevel) {
|
||||
case 0: OptLevel = CodeGenOpt::None; break;
|
||||
case 1: OptLevel = CodeGenOpt::Less; break;
|
||||
case 2: OptLevel = CodeGenOpt::Default; break;
|
||||
case 3: OptLevel = CodeGenOpt::Aggressive; break;
|
||||
default: OptLevel = CodeGenOpt::Default;
|
||||
}
|
||||
using namespace llvm::orc;
|
||||
auto JTMB = JITTargetMachineBuilder::detectHost();
|
||||
if (!JTMB)
|
||||
logAllUnhandledErrors(JTMB.takeError(), llvm::errs(),
|
||||
"Error detecting host");
|
||||
|
||||
JTMB->setCodeGenOptLevel(OptLevel);
|
||||
using namespace llvm::orc;
|
||||
auto JTMB = JITTargetMachineBuilder(CI.getTarget().getTriple());
|
||||
JTMB.addFeatures(CI.getTargetOpts().Features);
|
||||
|
||||
JTMB.setCodeGenOptLevel(OptLevel);
|
||||
#ifdef _WIN32
|
||||
JTMB->getOptions().EmulatedTLS = false;
|
||||
JTMB.getOptions().EmulatedTLS = false;
|
||||
#endif // _WIN32
|
||||
|
||||
#if defined(__powerpc64__) || defined(__PPC64__)
|
||||
// We have to use large code model for PowerPC64 because TOC and text sections
|
||||
// can be more than 2GB apart.
|
||||
JTMB->setCodeModel(CodeModel::Large);
|
||||
JTMB.setCodeModel(CodeModel::Large);
|
||||
#endif
|
||||
|
||||
if (JITLink) {
|
||||
// Set up the TargetMachine as otherwise done by
|
||||
// LLJITBuilderState::prepareForConstruction.
|
||||
JTMB->setRelocationModel(Reloc::PIC_);
|
||||
JTMB->setCodeModel(CodeModel::Small);
|
||||
JTMB.setRelocationModel(Reloc::PIC_);
|
||||
JTMB.setCodeModel(CodeModel::Small);
|
||||
}
|
||||
|
||||
std::unique_ptr<TargetMachine> TM = cantFail(JTMB->createTargetMachine());
|
||||
std::unique_ptr<TargetMachine> TM = cantFail(JTMB.createTargetMachine());
|
||||
|
||||
// Forcefully disable GlobalISel, it might be enabled on AArch64 without
|
||||
// optimizations. In tests on an Apple M1 after the upgrade to LLVM 9, this
|
||||
@ -500,7 +487,7 @@ IncrementalJIT::IncrementalJIT(
|
||||
void *ExtraLibHandle, bool Verbose)
|
||||
: SkipHostProcessLookup(false),
|
||||
m_JITLink(UseJITLink(CI.getTarget().getTriple())),
|
||||
m_TM(CreateHostTargetMachine(CI, m_JITLink)),
|
||||
m_TM(CreateTargetMachine(CI, m_JITLink)),
|
||||
SingleThreadedContext(std::make_unique<LLVMContext>()) {
|
||||
ErrorAsOutParameter _(&Err);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user