add method to retrieve host cpu name
add stub method to enginebuilder to setMCPU and setMAttrs -- these are not implemented in llvm3.1
This commit is contained in:
parent
db24036adb
commit
1ed2049395
5 changed files with 65 additions and 3 deletions
|
|
@ -1013,6 +1013,8 @@ _wrap_pass( Internalize2 )
|
|||
/* Target Machine */
|
||||
/*===----------------------------------------------------------------------===*/
|
||||
|
||||
_wrap_none2str(LLVMGetHostCPUName);
|
||||
|
||||
_wrap_obj2obj(LLVMTargetMachineFromEngineBuilder, LLVMEngineBuilderRef,
|
||||
LLVMTargetMachineRef)
|
||||
_wrap_obj2none(LLVMDisposeTargetMachine, LLVMTargetMachineRef)
|
||||
|
|
@ -1133,6 +1135,8 @@ _wrap_obj2none(LLVMDisposeEngineBuilder, LLVMEngineBuilderRef)
|
|||
_wrap_obj2none(LLVMEngineBuilderForceJIT, LLVMEngineBuilderRef)
|
||||
_wrap_obj2none(LLVMEngineBuilderForceInterpreter, LLVMEngineBuilderRef)
|
||||
_wrap_objint2none(LLVMEngineBuilderSetOptLevel, LLVMEngineBuilderRef)
|
||||
_wrap_objstr2none(LLVMEngineBuilderSetMCPU, LLVMEngineBuilderRef)
|
||||
_wrap_objstr2none(LLVMEngineBuilderSetMAttrs, LLVMEngineBuilderRef)
|
||||
|
||||
static PyObject *
|
||||
_wLLVMEngineBuilderCreate(PyObject *self, PyObject *args)
|
||||
|
|
@ -1944,7 +1948,9 @@ static PyMethodDef core_methods[] = {
|
|||
_method( LLVMTargetMachineGetTriple )
|
||||
_method( LLVMTargetMachineGetCPU )
|
||||
_method( LLVMTargetMachineGetFS )
|
||||
|
||||
_method( LLVMPrintRegisteredTargetsForVersion )
|
||||
_method( LLVMGetHostCPUName )
|
||||
|
||||
/* Target Data */
|
||||
_method( LLVMCreateTargetData )
|
||||
|
|
@ -1971,6 +1977,8 @@ static PyMethodDef core_methods[] = {
|
|||
_method( LLVMEngineBuilderForceJIT )
|
||||
_method( LLVMEngineBuilderForceInterpreter )
|
||||
_method( LLVMEngineBuilderSetOptLevel )
|
||||
_method( LLVMEngineBuilderSetMCPU )
|
||||
_method( LLVMEngineBuilderSetMAttrs )
|
||||
_method( LLVMEngineBuilderCreate )
|
||||
|
||||
/* Execution Engine */
|
||||
|
|
|
|||
13
llvm/ee.py
13
llvm/ee.py
|
|
@ -225,6 +225,14 @@ class EngineBuilder(object):
|
|||
_core.LLVMEngineBuilderSetOptLevel(self.ptr, level)
|
||||
return self
|
||||
|
||||
def mattrs(self, string):
|
||||
'''set machine attributes as a comma/space separated string
|
||||
|
||||
e.g: +sse,-3dnow
|
||||
'''
|
||||
_core.LLVMEngineBuilderSetMAttrs(self.ptr, string.replace(',', ' '))
|
||||
return self
|
||||
|
||||
def create(self):
|
||||
ret = _core.LLVMEngineBuilderCreate(self.ptr)
|
||||
if isinstance(ret, str):
|
||||
|
|
@ -310,6 +318,11 @@ def print_registered_targets():
|
|||
'''
|
||||
_core.LLVMPrintRegisteredTargetsForVersion()
|
||||
|
||||
def get_host_cpu_name():
|
||||
'''return the string name of the host CPU
|
||||
'''
|
||||
return _core.LLVMGetHostCPUName()
|
||||
|
||||
class TargetMachine(object):
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@
|
|||
#include "llvm/Target/TargetData.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
|
||||
#include "llvm/IntrinsicInst.h"
|
||||
#include "llvm/Analysis/Verifier.h"
|
||||
|
|
@ -126,6 +127,19 @@ const CodeGenOpt::Level OptLevelMap[] = {
|
|||
} // end anony namespace
|
||||
|
||||
|
||||
const char * LLVMGetHostCPUName()
|
||||
{
|
||||
return strdup(llvm::sys::getHostCPUName().c_str());
|
||||
}
|
||||
|
||||
const char * LLVMGetHostCPUFeatures()
|
||||
{
|
||||
// placeholder
|
||||
// TODO not implemented even in LLVM3.2svn
|
||||
// llvm::sys::getHostCPUFeatures
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int LLVMInitializeNativeTargetAsmPrinter()
|
||||
{
|
||||
return llvm::InitializeNativeTargetAsmPrinter();
|
||||
|
|
@ -442,8 +456,7 @@ LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef builder, LLVMValueRef ptr,
|
|||
|
||||
LLVMEngineBuilderRef LLVMCreateEngineBuilder(LLVMModuleRef mod)
|
||||
{
|
||||
using namespace llvm;
|
||||
return wrap(new EngineBuilder(unwrap(mod)));
|
||||
return llvm::wrap(new EngineBuilder(unwrap(mod)));
|
||||
}
|
||||
|
||||
void LLVMDisposeEngineBuilder(LLVMEngineBuilderRef eb)
|
||||
|
|
@ -468,6 +481,21 @@ void LLVMEngineBuilderSetOptLevel(LLVMEngineBuilderRef eb, int level)
|
|||
unwrap(eb)->setOptLevel(OptLevelMap[level]);
|
||||
}
|
||||
|
||||
void LLVMEngineBuilderSetMCPU(LLVMEngineBuilderRef eb, const char * mcpu)
|
||||
{ // TODO add test when llvm3.2 releases
|
||||
unwrap(eb)->setMCPU(mcpu); // does not work in llvm3.1
|
||||
}
|
||||
|
||||
void LLVMEngineBuilderSetMAttrs(LLVMEngineBuilderRef eb, const char * mattrs)
|
||||
{ // TODO add test when llvm3.2 releases
|
||||
std::vector<std::string> tokenized;
|
||||
std::istringstream iss(mattrs);
|
||||
std::string buf;
|
||||
while ( iss >> buf ){
|
||||
tokenized.push_back(buf);
|
||||
}
|
||||
unwrap(eb)->setMAttrs(tokenized); // does not work in llvm3.1
|
||||
}
|
||||
|
||||
LLVMExecutionEngineRef LLVMEngineBuilderCreate(LLVMEngineBuilderRef eb, std::string & error)
|
||||
{
|
||||
|
|
|
|||
12
llvm/extra.h
12
llvm/extra.h
|
|
@ -55,6 +55,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char * LLVMGetHostCPUName();
|
||||
|
||||
int LLVMInitializeNativeTargetAsmPrinter();
|
||||
|
||||
|
||||
|
|
@ -182,6 +184,16 @@ void LLVMEngineBuilderForceInterpreter(LLVMEngineBuilderRef eb);
|
|||
*/
|
||||
void LLVMEngineBuilderSetOptLevel(LLVMEngineBuilderRef eb, int level);
|
||||
|
||||
/*
|
||||
* Wraps EngineBuilder::setMCPU
|
||||
*/
|
||||
void LLVMEngineBuilderSetMCPU(LLVMEngineBuilderRef eb, const char * mcpu);
|
||||
|
||||
/*
|
||||
* Wraps EngineBuilder::setMAttrs
|
||||
*/
|
||||
void LLVMEngineBuilderSetMAttrs(LLVMEngineBuilderRef eb, const char * mattrs);
|
||||
|
||||
/*
|
||||
* Wraps EngineBuilder::setErrorStr and EngineBuilder::create
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from llvm.core import *
|
||||
from llvm.ee import TargetMachine, EngineBuilder, print_registered_targets
|
||||
from llvm.ee import *
|
||||
import unittest
|
||||
|
||||
class TestTargetMachines(unittest.TestCase):
|
||||
|
|
@ -17,6 +17,7 @@ class TestTargetMachines(unittest.TestCase):
|
|||
self.assertTrue(tm.target_short_description)
|
||||
self.assertTrue(tm.triple)
|
||||
self.assertIn('foo', tm.emit_assembly(m).decode('utf-8'))
|
||||
self.assertTrue(get_host_cpu_name())
|
||||
|
||||
def test_ptx(self):
|
||||
if HAS_PTX:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue