Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executors/bf: suppress instcombine error for llvm >=18 #1193

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions dmoj/executors/BF.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,22 @@ def compile_to_llvm(source_code: bytes) -> bytes:
return TEMPLATE.replace(b'{code}', '\n'.join(inst).encode())


OPT_PASSES = [
# Shorten instructions
'instcombine',
'gvn',
# Optimize loops
'loop-rotate',
'loop-mssa(licm)',
'indvars',
# Clean up
'simplifycfg',
'instcombine',
'gvn',
]
def get_opt_passes(opt_version: Tuple[int, ...]) -> List[str]:
# https://github.com/llvm/llvm-project/issues/92648
instcombine = 'instcombine<no-verify-fixpoint>' if opt_version >= (18,) else 'instcombine'
return [
# Shorten instructions
instcombine,
'gvn',
# Optimize loops
'loop-rotate',
'loop-mssa(licm)',
'indvars',
# Clean up
'simplifycfg',
instcombine,
'gvn',
]


class Executor(LLCExecutor):
Expand All @@ -214,7 +217,8 @@ def launch(self, *args, **kwargs) -> TracedPopen:
# Do both opt and llc.
def assemble(self) -> Tuple[bytes, List[str]]:
assert self._code is not None
args = [self.runtime_dict[self.opt_name], '-S', f'-passes={",".join(OPT_PASSES)}', self._code, '-o', self._code]
opt_passes = get_opt_passes(self.get_opt_version())
args = [self.runtime_dict[self.opt_name], '-S', f'-passes={",".join(opt_passes)}', self._code, '-o', self._code]
process = self.create_compile_process(args)
opt_output = self.get_compile_output(process)
as_output, to_link = super().assemble()
Expand All @@ -224,6 +228,10 @@ def assemble(self) -> Tuple[bytes, List[str]]:
def get_versionable_commands(cls) -> List[Tuple[str, str]]:
return [(cls.opt_name, cls.runtime_dict[cls.opt_name])] + super().get_versionable_commands()

@classmethod
def get_opt_version(cls) -> Tuple[int, ...]:
return cls.get_runtime_versions()[0][1]

@classmethod
def get_find_first_mapping(cls) -> Optional[Dict[str, List[str]]]:
res = super().get_find_first_mapping()
Expand Down
Loading