Make sure that the go bindings call LLVMInitializeMCJITCompilerOptions
authorEric Christopher <echristo@gmail.com>
Wed, 26 Nov 2014 02:27:46 +0000 (02:27 +0000)
committerEric Christopher <echristo@gmail.com>
Wed, 26 Nov 2014 02:27:46 +0000 (02:27 +0000)
so that they initialize the code generation model to the correct
(non-zero) default model.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222804 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/go/llvm/executionengine.go
bindings/go/llvm/executionengine_test.go

index 26b75247348f64dee247a9f5eecbb773eab6915a..db2c2153401811c9fc81e14dfe8d6a0986a3552f 100644 (file)
@@ -30,11 +30,9 @@ type GenericValue struct {
 type ExecutionEngine struct {
        C C.LLVMExecutionEngineRef
 }
 type ExecutionEngine struct {
        C C.LLVMExecutionEngineRef
 }
+
 type MCJITCompilerOptions struct {
 type MCJITCompilerOptions struct {
-       OptLevel           uint
-       CodeModel          CodeModel
-       NoFramePointerElim bool
-       EnableFastISel     bool
+       C C.struct_LLVMMCJITCompilerOptions
 }
 
 // helpers
 }
 
 // helpers
@@ -96,15 +94,19 @@ func NewInterpreter(m Module) (ee ExecutionEngine, err error) {
        return
 }
 
        return
 }
 
+func NewMCJITCompilerOptions() MCJITCompilerOptions {
+       var options C.struct_LLVMMCJITCompilerOptions
+       C.LLVMInitializeMCJITCompilerOptions(&options, C.size_t(unsafe.Sizeof(C.struct_LLVMMCJITCompilerOptions{})))
+       return MCJITCompilerOptions{options}
+}
+
+func SetMCJITOptimizationLevel(options MCJITCompilerOptions, level uint) {
+       options.C.OptLevel = C.uint(level)
+}
+
 func NewMCJITCompiler(m Module, options MCJITCompilerOptions) (ee ExecutionEngine, err error) {
        var cmsg *C.char
 func NewMCJITCompiler(m Module, options MCJITCompilerOptions) (ee ExecutionEngine, err error) {
        var cmsg *C.char
-       copts := C.struct_LLVMMCJITCompilerOptions{
-               OptLevel:           C.unsigned(options.OptLevel),
-               CodeModel:          C.LLVMCodeModel(options.CodeModel),
-               NoFramePointerElim: boolToLLVMBool(options.NoFramePointerElim),
-               EnableFastISel:     boolToLLVMBool(options.EnableFastISel),
-       }
-       fail := C.LLVMCreateMCJITCompilerForModule(&ee.C, m.C, &copts, C.size_t(unsafe.Sizeof(copts)), &cmsg)
+       fail := C.LLVMCreateMCJITCompilerForModule(&ee.C, m.C, &options.C, C.size_t(unsafe.Sizeof(C.struct_LLVMMCJITCompilerOptions{})), &cmsg)
        if fail != 0 {
                ee.C = nil
                err = errors.New(C.GoString(cmsg))
        if fail != 0 {
                ee.C = nil
                err = errors.New(C.GoString(cmsg))
index 1a3fd456abe9571534996dab593b946c86a064da..2d5ca721a2a6de0f1a8dc135e4a44e82845f61ef 100644 (file)
@@ -66,7 +66,9 @@ func TestFactorial(t *testing.T) {
                return
        }
 
                return
        }
 
-       engine, err := NewMCJITCompiler(mod, MCJITCompilerOptions{OptLevel: 2})
+       options := NewMCJITCompilerOptions()
+       SetMCJITOptimizationLevel(options, 2)
+       engine, err := NewMCJITCompiler(mod, options)
        if err != nil {
                t.Errorf("Error creating JIT: %s", err)
                return
        if err != nil {
                t.Errorf("Error creating JIT: %s", err)
                return