Add CodeModel

This commit is contained in:
Siu Kwan Lam 2013-01-03 15:37:11 -06:00
commit f01da12e16
4 changed files with 47 additions and 21 deletions

View file

@ -1082,17 +1082,18 @@ static PyObject *
_wLLVMTargetMachineLookup(PyObject * self, PyObject * args)
{
LLVMPY_TRY
const char *arch;
const char *triple;
const char *cpu;
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;
std::string error;
LLVMTargetMachineRef tm = LLVMTargetMachineLookup(arch, cpu, features, opt,
error);
LLVMTargetMachineRef tm = LLVMTargetMachineLookup(triple, cpu, features,
opt, codemodel, error);
if(!error.empty()){
PyErr_SetString(PyExc_RuntimeError, error.c_str());
return NULL;
@ -1109,14 +1110,15 @@ _wLLVMCreateTargetMachine(PyObject * self, PyObject * args)
const char *triple;
const char *cpu;
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;
std::string error;
LLVMTargetMachineRef tm = LLVMCreateTargetMachine(triple, cpu, features, opt,
error);
LLVMTargetMachineRef tm = LLVMCreateTargetMachine(triple, cpu, features,
opt, codemodel, error);
if(!error.empty()){
PyErr_SetString(PyExc_RuntimeError, error.c_str());
return NULL;

View file

@ -51,6 +51,13 @@ from llvm.passes import TargetData
BO_BIG_ENDIAN = 0
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
@ -167,7 +174,8 @@ class EngineBuilder(llvm.Handle):
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:
_util.check_is_unowned(tm)
@ -269,18 +277,19 @@ def get_default_triple():
'''
return _core.LLVMDefaultTargetTriple()
class TargetMachine(llvm.Ownable):
@staticmethod
def new(triple='', cpu='', features='', opt=2):
def new(triple='', cpu='', features='', opt=2, cm=CM_DEFAULT):
if not triple and not cpu:
triple = get_default_triple()
cpu = get_host_cpu_name()
ptr = _core.LLVMCreateTargetMachine(triple, cpu, features, opt)
ptr = _core.LLVMCreateTargetMachine(triple, cpu, features, opt, cm)
return TargetMachine(ptr)
@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
For a list of architectures,
@ -292,7 +301,7 @@ class TargetMachine(llvm.Ownable):
For a list of available attributes (features),
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)
def __init__(self, ptr):

View file

@ -142,6 +142,17 @@ const CodeGenOpt::Level OptLevelMap[] = {
CodeGenOpt::Default,
CodeGenOpt::Aggressive,
};
const CodeModel::Model CodeModelMap[] = {
CodeModel::Default,
CodeModel::JITDefault,
CodeModel::Small,
CodeModel::Kernel,
CodeModel::Medium,
CodeModel::Large,
};
} // end anony namespace
LLVMPassRef LLVMCreateTargetTransformInfo(LLVMTargetMachineRef tmref){
@ -328,6 +339,7 @@ int LLVMInitializeNativeTargetAsmPrinter()
LLVMTargetMachineRef LLVMTargetMachineLookup(const char *arch, const char *cpu,
const char *features, int opt,
int codemodel,
std::string &error)
{
using namespace llvm;
@ -364,11 +376,12 @@ LLVMTargetMachineRef LLVMTargetMachineLookup(const char *arch, const char *cpu,
}
TargetOptions no_target_options;
TargetMachine * tm = TheTarget->createTargetMachine(
TheTriple.str(), cpu, features,
no_target_options,
Reloc::Default, CodeModel::Default,
OptLevelMap[opt]);
TargetMachine * tm = TheTarget->createTargetMachine(TheTriple.str(), cpu,
features,
no_target_options,
Reloc::Default,
CodeModelMap[codemodel],
OptLevelMap[opt]);
if (!tm){
error = "Cannot create target machine";
@ -381,6 +394,7 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(const char *triple,
const char *cpu,
const char *features,
int opt,
int codemodel,
std::string &error)
{
using namespace llvm;
@ -393,7 +407,7 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(const char *triple,
TargetMachine * tm = TheTarget->createTargetMachine(TheTriple, cpu, features,
no_target_options,
Reloc::Default,
CodeModel::Default,
CodeModelMap[codemodel],
OptLevelMap[opt]);
if (!tm) {
error = "Cannot create target machine";

View file

@ -196,10 +196,11 @@ int LLVMInitializeNativeTargetAsmPrinter();
LLVMTargetMachineRef LLVMTargetMachineLookup(const char *arch, const char *cpu,
const char *features, int opt,
std::string &error);
int codemodel, std::string &error);
LLVMTargetMachineRef LLVMCreateTargetMachine(const char *arch, const char *cpu,
const char *features, int opt,
int codemodel,
std::string &error);
/*