mirror of https://github.com/m-labs/artiq.git
compiler: tune the LLVM optimizer pipeline (fixes #315).
This commit is contained in:
parent
3ee9834197
commit
f5c720c3ee
|
@ -79,6 +79,23 @@ class Target:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.llcontext = ll.Context()
|
self.llcontext = ll.Context()
|
||||||
|
|
||||||
|
def target_machine(self):
|
||||||
|
lltarget = llvm.Target.from_triple(self.triple)
|
||||||
|
return lltarget.create_target_machine(
|
||||||
|
features=",".join(["+{}".format(f) for f in self.features]),
|
||||||
|
reloc="pic", codemodel="default")
|
||||||
|
|
||||||
|
def optimize(self, llmodule):
|
||||||
|
llpassmgr = llvm.create_module_pass_manager()
|
||||||
|
self.target_machine().target_data.add_pass(llpassmgr)
|
||||||
|
llpassmgr.add_constant_merge_pass()
|
||||||
|
llpassmgr.add_cfg_simplification_pass()
|
||||||
|
llpassmgr.add_instruction_combining_pass()
|
||||||
|
llpassmgr.add_sroa_pass()
|
||||||
|
llpassmgr.add_dead_code_elimination_pass()
|
||||||
|
llpassmgr.add_gvn_pass()
|
||||||
|
llpassmgr.run(llmodule)
|
||||||
|
|
||||||
def compile(self, module):
|
def compile(self, module):
|
||||||
"""Compile the module to a relocatable object for this target."""
|
"""Compile the module to a relocatable object for this target."""
|
||||||
|
|
||||||
|
@ -102,14 +119,7 @@ class Target:
|
||||||
_dump(os.getenv("ARTIQ_DUMP_UNOPT_LLVM"), "LLVM IR (generated)", "_unopt.ll",
|
_dump(os.getenv("ARTIQ_DUMP_UNOPT_LLVM"), "LLVM IR (generated)", "_unopt.ll",
|
||||||
lambda: str(llparsedmod))
|
lambda: str(llparsedmod))
|
||||||
|
|
||||||
llpassmgrbuilder = llvm.create_pass_manager_builder()
|
self.optimize(llparsedmod)
|
||||||
llpassmgrbuilder.opt_level = 2 # -O2
|
|
||||||
llpassmgrbuilder.size_level = 1 # -Os
|
|
||||||
llpassmgrbuilder.inlining_threshold = 75 # -Os threshold
|
|
||||||
|
|
||||||
llpassmgr = llvm.create_module_pass_manager()
|
|
||||||
llpassmgrbuilder.populate(llpassmgr)
|
|
||||||
llpassmgr.run(llparsedmod)
|
|
||||||
|
|
||||||
_dump(os.getenv("ARTIQ_DUMP_LLVM"), "LLVM IR (optimized)", ".ll",
|
_dump(os.getenv("ARTIQ_DUMP_LLVM"), "LLVM IR (optimized)", ".ll",
|
||||||
lambda: str(llparsedmod))
|
lambda: str(llparsedmod))
|
||||||
|
@ -117,10 +127,7 @@ class Target:
|
||||||
return llparsedmod
|
return llparsedmod
|
||||||
|
|
||||||
def assemble(self, llmodule):
|
def assemble(self, llmodule):
|
||||||
lltarget = llvm.Target.from_triple(self.triple)
|
llmachine = self.target_machine()
|
||||||
llmachine = lltarget.create_target_machine(
|
|
||||||
features=",".join(["+{}".format(f) for f in self.features]),
|
|
||||||
reloc="pic", codemodel="default")
|
|
||||||
|
|
||||||
_dump(os.getenv("ARTIQ_DUMP_ASM"), "Assembly", ".s",
|
_dump(os.getenv("ARTIQ_DUMP_ASM"), "Assembly", ".s",
|
||||||
lambda: llmachine.emit_assembly(llmodule))
|
lambda: llmachine.emit_assembly(llmodule))
|
||||||
|
|
Loading…
Reference in New Issue