@@ -13,30 +13,41 @@ def _initialize_llvm():
13
13
llvm .initialize_native_asmprinter ()
14
14
15
15
16
- def _get_target_machine (fcodemodel = "large" ):
16
+ def _get_target_machine (fcodemodel = "large" , target_cpu = None , target_cpu_features = None ):
17
17
target = llvm .Target .from_triple (llvm .get_process_triple ())
18
- try :
19
- # LLVM raises if features cannot be detected
20
- features = llvm .get_host_cpu_features ().flatten ()
21
- except RuntimeError :
22
- features = ""
18
+
19
+ if target_cpu is None :
20
+ target_cpu = llvm .get_host_cpu_name ()
21
+
22
+ if target_cpu_features is None :
23
+ try :
24
+ # LLVM raises if features cannot be detected
25
+ target_cpu_features = llvm .get_host_cpu_features ().flatten ()
26
+ except RuntimeError :
27
+ target_cpu_features = ""
23
28
24
29
# large codemodel is necessary for large, ~1000 tree models.
25
30
# for smaller models "default" codemodel would be faster.
26
31
target_machine = target .create_target_machine (
27
- cpu = llvm . get_host_cpu_name () ,
28
- features = features ,
32
+ cpu = target_cpu ,
33
+ features = target_cpu_features ,
29
34
reloc = "pic" ,
30
35
codemodel = fcodemodel ,
31
36
)
32
37
return target_machine
33
38
34
39
35
- def compile_module_to_asm (module , cache_path = None , fcodemodel = "large" ):
40
+ def compile_module_to_asm (
41
+ module ,
42
+ cache_path = None ,
43
+ fcodemodel = "large" ,
44
+ target_cpu = None ,
45
+ target_cpu_features = None ,
46
+ ):
36
47
_initialize_llvm ()
37
48
38
49
# Create a target machine representing the host
39
- target_machine = _get_target_machine (fcodemodel )
50
+ target_machine = _get_target_machine (fcodemodel , target_cpu , target_cpu_features )
40
51
41
52
# Create execution engine for our module
42
53
execution_engine = llvm .create_mcjit_compiler (module , target_machine )
0 commit comments