Add CodeModel
This commit is contained in:
parent
bc20661343
commit
f01da12e16
4 changed files with 47 additions and 21 deletions
|
|
@ -1082,17 +1082,18 @@ static PyObject *
|
||||||
_wLLVMTargetMachineLookup(PyObject * self, PyObject * args)
|
_wLLVMTargetMachineLookup(PyObject * self, PyObject * args)
|
||||||
{
|
{
|
||||||
LLVMPY_TRY
|
LLVMPY_TRY
|
||||||
const char *arch;
|
const char *triple;
|
||||||
const char *cpu;
|
const char *cpu;
|
||||||
const char *features;
|
const char *features;
|
||||||
int opt;
|
int opt, codemodel;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "sssi", &arch, &cpu, &features, &opt))
|
if (!PyArg_ParseTuple(args, "sssii", &triple, &cpu, &features,
|
||||||
|
&opt, &codemodel))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
std::string error;
|
std::string error;
|
||||||
LLVMTargetMachineRef tm = LLVMTargetMachineLookup(arch, cpu, features, opt,
|
LLVMTargetMachineRef tm = LLVMTargetMachineLookup(triple, cpu, features,
|
||||||
error);
|
opt, codemodel, error);
|
||||||
if(!error.empty()){
|
if(!error.empty()){
|
||||||
PyErr_SetString(PyExc_RuntimeError, error.c_str());
|
PyErr_SetString(PyExc_RuntimeError, error.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -1109,14 +1110,15 @@ _wLLVMCreateTargetMachine(PyObject * self, PyObject * args)
|
||||||
const char *triple;
|
const char *triple;
|
||||||
const char *cpu;
|
const char *cpu;
|
||||||
const char *features;
|
const char *features;
|
||||||
int opt;
|
int opt, codemodel;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "sssi", &triple, &cpu, &features, &opt))
|
if (!PyArg_ParseTuple(args, "sssii", &triple, &cpu, &features,
|
||||||
|
&opt, &codemodel))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
std::string error;
|
std::string error;
|
||||||
LLVMTargetMachineRef tm = LLVMCreateTargetMachine(triple, cpu, features, opt,
|
LLVMTargetMachineRef tm = LLVMCreateTargetMachine(triple, cpu, features,
|
||||||
error);
|
opt, codemodel, error);
|
||||||
if(!error.empty()){
|
if(!error.empty()){
|
||||||
PyErr_SetString(PyExc_RuntimeError, error.c_str());
|
PyErr_SetString(PyExc_RuntimeError, error.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
19
llvm/ee.py
19
llvm/ee.py
|
|
@ -51,6 +51,13 @@ from llvm.passes import TargetData
|
||||||
BO_BIG_ENDIAN = 0
|
BO_BIG_ENDIAN = 0
|
||||||
BO_LITTLE_ENDIAN = 1
|
BO_LITTLE_ENDIAN = 1
|
||||||
|
|
||||||
|
# CodeModel
|
||||||
|
CM_DEFAULT = 0
|
||||||
|
CM_JITDEFAULT = 1
|
||||||
|
CM_SMALL = 2
|
||||||
|
CM_KERNEL = 3
|
||||||
|
CM_MEDIUM = 4
|
||||||
|
CM_LARGE = 5
|
||||||
|
|
||||||
#===----------------------------------------------------------------------===
|
#===----------------------------------------------------------------------===
|
||||||
# Generic value
|
# Generic value
|
||||||
|
|
@ -167,7 +174,8 @@ class EngineBuilder(llvm.Handle):
|
||||||
|
|
||||||
def create(self, tm=None):
|
def create(self, tm=None):
|
||||||
'''
|
'''
|
||||||
tm --- Optional. Provide a TargetMachine.
|
tm --- Optional. Provide a TargetMachine. Ownership is transfered
|
||||||
|
to the returned execution engine.
|
||||||
'''
|
'''
|
||||||
if tm:
|
if tm:
|
||||||
_util.check_is_unowned(tm)
|
_util.check_is_unowned(tm)
|
||||||
|
|
@ -269,18 +277,19 @@ def get_default_triple():
|
||||||
'''
|
'''
|
||||||
return _core.LLVMDefaultTargetTriple()
|
return _core.LLVMDefaultTargetTriple()
|
||||||
|
|
||||||
|
|
||||||
class TargetMachine(llvm.Ownable):
|
class TargetMachine(llvm.Ownable):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new(triple='', cpu='', features='', opt=2):
|
def new(triple='', cpu='', features='', opt=2, cm=CM_DEFAULT):
|
||||||
if not triple and not cpu:
|
if not triple and not cpu:
|
||||||
triple = get_default_triple()
|
triple = get_default_triple()
|
||||||
cpu = get_host_cpu_name()
|
cpu = get_host_cpu_name()
|
||||||
ptr = _core.LLVMCreateTargetMachine(triple, cpu, features, opt)
|
ptr = _core.LLVMCreateTargetMachine(triple, cpu, features, opt, cm)
|
||||||
return TargetMachine(ptr)
|
return TargetMachine(ptr)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def lookup(arch, cpu='', features='', opt=2):
|
def lookup(arch, cpu='', features='', opt=2, cm=CM_DEFAULT):
|
||||||
'''create a targetmachine given an architecture name
|
'''create a targetmachine given an architecture name
|
||||||
|
|
||||||
For a list of architectures,
|
For a list of architectures,
|
||||||
|
|
@ -292,7 +301,7 @@ class TargetMachine(llvm.Ownable):
|
||||||
For a list of available attributes (features),
|
For a list of available attributes (features),
|
||||||
use: `llvm-as < /dev/null | llc -march=xyz -mattr=help`
|
use: `llvm-as < /dev/null | llc -march=xyz -mattr=help`
|
||||||
'''
|
'''
|
||||||
ptr = _core.LLVMTargetMachineLookup(arch, cpu, features, opt)
|
ptr = _core.LLVMTargetMachineLookup(arch, cpu, features, opt, cm)
|
||||||
return TargetMachine(ptr)
|
return TargetMachine(ptr)
|
||||||
|
|
||||||
def __init__(self, ptr):
|
def __init__(self, ptr):
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,17 @@ const CodeGenOpt::Level OptLevelMap[] = {
|
||||||
CodeGenOpt::Default,
|
CodeGenOpt::Default,
|
||||||
CodeGenOpt::Aggressive,
|
CodeGenOpt::Aggressive,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CodeModel::Model CodeModelMap[] = {
|
||||||
|
CodeModel::Default,
|
||||||
|
CodeModel::JITDefault,
|
||||||
|
CodeModel::Small,
|
||||||
|
CodeModel::Kernel,
|
||||||
|
CodeModel::Medium,
|
||||||
|
CodeModel::Large,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // end anony namespace
|
} // end anony namespace
|
||||||
|
|
||||||
LLVMPassRef LLVMCreateTargetTransformInfo(LLVMTargetMachineRef tmref){
|
LLVMPassRef LLVMCreateTargetTransformInfo(LLVMTargetMachineRef tmref){
|
||||||
|
|
@ -328,6 +339,7 @@ int LLVMInitializeNativeTargetAsmPrinter()
|
||||||
|
|
||||||
LLVMTargetMachineRef LLVMTargetMachineLookup(const char *arch, const char *cpu,
|
LLVMTargetMachineRef LLVMTargetMachineLookup(const char *arch, const char *cpu,
|
||||||
const char *features, int opt,
|
const char *features, int opt,
|
||||||
|
int codemodel,
|
||||||
std::string &error)
|
std::string &error)
|
||||||
{
|
{
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
@ -364,11 +376,12 @@ LLVMTargetMachineRef LLVMTargetMachineLookup(const char *arch, const char *cpu,
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetOptions no_target_options;
|
TargetOptions no_target_options;
|
||||||
TargetMachine * tm = TheTarget->createTargetMachine(
|
TargetMachine * tm = TheTarget->createTargetMachine(TheTriple.str(), cpu,
|
||||||
TheTriple.str(), cpu, features,
|
features,
|
||||||
no_target_options,
|
no_target_options,
|
||||||
Reloc::Default, CodeModel::Default,
|
Reloc::Default,
|
||||||
OptLevelMap[opt]);
|
CodeModelMap[codemodel],
|
||||||
|
OptLevelMap[opt]);
|
||||||
|
|
||||||
if (!tm){
|
if (!tm){
|
||||||
error = "Cannot create target machine";
|
error = "Cannot create target machine";
|
||||||
|
|
@ -381,6 +394,7 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(const char *triple,
|
||||||
const char *cpu,
|
const char *cpu,
|
||||||
const char *features,
|
const char *features,
|
||||||
int opt,
|
int opt,
|
||||||
|
int codemodel,
|
||||||
std::string &error)
|
std::string &error)
|
||||||
{
|
{
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
@ -393,7 +407,7 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(const char *triple,
|
||||||
TargetMachine * tm = TheTarget->createTargetMachine(TheTriple, cpu, features,
|
TargetMachine * tm = TheTarget->createTargetMachine(TheTriple, cpu, features,
|
||||||
no_target_options,
|
no_target_options,
|
||||||
Reloc::Default,
|
Reloc::Default,
|
||||||
CodeModel::Default,
|
CodeModelMap[codemodel],
|
||||||
OptLevelMap[opt]);
|
OptLevelMap[opt]);
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
error = "Cannot create target machine";
|
error = "Cannot create target machine";
|
||||||
|
|
|
||||||
|
|
@ -196,10 +196,11 @@ int LLVMInitializeNativeTargetAsmPrinter();
|
||||||
|
|
||||||
LLVMTargetMachineRef LLVMTargetMachineLookup(const char *arch, const char *cpu,
|
LLVMTargetMachineRef LLVMTargetMachineLookup(const char *arch, const char *cpu,
|
||||||
const char *features, int opt,
|
const char *features, int opt,
|
||||||
std::string &error);
|
int codemodel, std::string &error);
|
||||||
|
|
||||||
LLVMTargetMachineRef LLVMCreateTargetMachine(const char *arch, const char *cpu,
|
LLVMTargetMachineRef LLVMCreateTargetMachine(const char *arch, const char *cpu,
|
||||||
const char *features, int opt,
|
const char *features, int opt,
|
||||||
|
int codemodel,
|
||||||
std::string &error);
|
std::string &error);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue