Skip to content

Commit

Permalink
Merge branch 'DMOJ:master' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo authored Dec 21, 2024
2 parents c0bb093 + d7a2735 commit 6373e30
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
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
2 changes: 1 addition & 1 deletion dmoj/executors/GO.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Executor(CompiledExecutor):
address_grace = 786432
command = 'go'
syscalls = ['mincore', 'pselect6', 'mlock', 'setrlimit']
compiler_syscalls = ['copy_file_range', 'setrlimit']
compiler_syscalls = ['copy_file_range', 'setrlimit', 'pidfd_open', 'pidfd_send_signal']
test_name = 'echo'
test_program = """\
package main
Expand Down
6 changes: 3 additions & 3 deletions dmoj/executors/SBCL.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


# SBCL implements its own heap management, and relies on ASLR being disabled. So, on startup,
# it reads /proc/self/exe do determine if ASLR is disabled. If not, it forks, sets
# it reads /proc/self/exe to determine if ASLR is disabled. If not, it forks, sets
# personality (https://man7.org/linux/man-pages/man2/personality.2.html) to disable ASLR,
# then execve's itself...
# As of https://github.com/DMOJ/judge-server/issues/277 we set personality ourselves to disable ASLR,
Expand All @@ -14,8 +14,8 @@ class Executor(NullStdoutMixin, CompiledExecutor):
command = 'sbcl'
syscalls = ['personality']
test_program = '(write-line (read-line))'
address_grace = 262144
data_grace = 262144
address_grace = 524288
data_grace = 524288
nproc = -1

compile_script = """(compile-file "{code}")"""
Expand Down

0 comments on commit 6373e30

Please sign in to comment.