Skip to content

Allow codemodel and relocmodel to be optional when creating target machine #406

Open
@sklam

Description

@sklam

Change

llvmlite/ffi/targets.cpp

Lines 167 to 231 in ebc4c59

API_EXPORT(LLVMTargetMachineRef)
LLVMPY_CreateTargetMachine(LLVMTargetRef T,
const char *Triple,
const char *CPU,
const char *Features,
int OptLevel,
const char *RelocModel,
const char *CodeModel,
int EmitJITDebug,
int PrintMC)
{
using namespace llvm;
CodeGenOpt::Level cgol;
switch(OptLevel) {
case 0:
cgol = CodeGenOpt::None;
break;
case 1:
cgol = CodeGenOpt::Less;
break;
case 3:
cgol = CodeGenOpt::Aggressive;
break;
case 2:
default:
cgol = CodeGenOpt::Default;
}
CodeModel::Model cm;
std::string cms(CodeModel);
if (cms == "small")
cm = CodeModel::Small;
else if (cms == "kernel")
cm = CodeModel::Kernel;
else if (cms == "medium")
cm = CodeModel::Medium;
else if (cms == "large")
cm = CodeModel::Large;
else if (cms == "default") // As per LLVM 5, needed for AOT
cm = CodeModel::Small;
else { // catches "jitdefault" and not set, as per LLVM 5, needed for MCJIT
// fall through, use model based on bitness
int bits = sizeof(void *);
if (bits == 4)
cm = CodeModel::Small;
else
cm = CodeModel::Large;
}
Optional<Reloc::Model> rm;
std::string rms(RelocModel);
if (rms == "static")
rm = Reloc::Static;
else if (rms == "pic")
rm = Reloc::PIC_;
else if (rms == "dynamicnopic")
rm = Reloc::DynamicNoPIC;
TargetOptions opt;
// opt.JITEmitDebugInfo = EmitJITDebug;
opt.PrintMachineCode = PrintMC;
return wrap(unwrap(T)->createTargetMachine(Triple, CPU, Features, opt,
rm, cm, cgol));
}

to accept optional codemodel and relocmodel. The createTagetMachine now takes them as Optional in
http://llvm.org/doxygen/classllvm_1_1Target.html#a3a99d5ba8f023d04d34f652af7494b35.
This will simplify the targetmachine creation process as codemodel and relocmodel is set differently of different platform.
Thus, avoiding the need of code like: https://github.com/numba/numba/pull/3437/files#diff-ec37b531d0f5e6e4ff2bb91a63bd651dR800

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions