llvm.org GIT mirror llvm / 82ec847
Make sure that the go bindings call LLVMInitializeMCJITCompilerOptions 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 Eric Christopher 5 years ago
2 changed file(s) with 16 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
2929 type ExecutionEngine struct {
3030 C C.LLVMExecutionEngineRef
3131 }
32
3233 type MCJITCompilerOptions struct {
33 OptLevel uint
34 CodeModel CodeModel
35 NoFramePointerElim bool
36 EnableFastISel bool
34 C C.struct_LLVMMCJITCompilerOptions
3735 }
3836
3937 // helpers
9593 return
9694 }
9795
96 func NewMCJITCompilerOptions() MCJITCompilerOptions {
97 var options C.struct_LLVMMCJITCompilerOptions
98 C.LLVMInitializeMCJITCompilerOptions(&options, C.size_t(unsafe.Sizeof(C.struct_LLVMMCJITCompilerOptions{})))
99 return MCJITCompilerOptions{options}
100 }
101
102 func SetMCJITOptimizationLevel(options MCJITCompilerOptions, level uint) {
103 options.C.OptLevel = C.uint(level)
104 }
105
98106 func NewMCJITCompiler(m Module, options MCJITCompilerOptions) (ee ExecutionEngine, err error) {
99107 var cmsg *C.char
100 copts := C.struct_LLVMMCJITCompilerOptions{
101 OptLevel: C.unsigned(options.OptLevel),
102 CodeModel: C.LLVMCodeModel(options.CodeModel),
103 NoFramePointerElim: boolToLLVMBool(options.NoFramePointerElim),
104 EnableFastISel: boolToLLVMBool(options.EnableFastISel),
105 }
106 fail := C.LLVMCreateMCJITCompilerForModule(&ee.C, m.C, &copts, C.size_t(unsafe.Sizeof(copts)), &cmsg)
108 fail := C.LLVMCreateMCJITCompilerForModule(&ee.C, m.C, &options.C, C.size_t(unsafe.Sizeof(C.struct_LLVMMCJITCompilerOptions{})), &cmsg)
107109 if fail != 0 {
108110 ee.C = nil
109111 err = errors.New(C.GoString(cmsg))
6565 return
6666 }
6767
68 engine, err := NewMCJITCompiler(mod, MCJITCompilerOptions{OptLevel: 2})
68 options := NewMCJITCompilerOptions()
69 SetMCJITOptimizationLevel(options, 2)
70 engine, err := NewMCJITCompiler(mod, options)
6971 if err != nil {
7072 t.Errorf("Error creating JIT: %s", err)
7173 return