Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/DMOJ/judge-server
Browse files Browse the repository at this point in the history
  • Loading branch information
hieplpvip committed Dec 22, 2024
2 parents 35934fa + b199763 commit ba98290
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
EOF
chmod a+x run run-su
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/docker-cache
key: ${{ runner.os }}-python-${{ matrix.python-version }}-pip-${{ hashFiles('**/requirements.txt') }}
Expand Down
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<no-verify-fixpoint>',
'gvn',
# Optimize loops
'loop-rotate',
'loop-mssa(licm)',
'indvars',
# Clean up
'simplifycfg',
'instcombine<no-verify-fixpoint>',
'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
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
12 changes: 8 additions & 4 deletions dmoj/executors/asm_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ class UnknownPlatformMixin(ASMExecutor):
abi = PTBOX_ABI_INVALID


NativeMixin: Any = (
[cls for cls in (PlatformX86Mixin, PlatformX64Mixin, PlatformARMMixin, PlatformARM64Mixin) if cls.abi == NATIVE_ABI]
or [UnknownPlatformMixin] # type: ignore
)[0]
NativeMixin: Any = next(
(
cls
for cls in (PlatformX86Mixin, PlatformX64Mixin, PlatformARMMixin, PlatformARM64Mixin)
if cls.abi == NATIVE_ABI
),
UnknownPlatformMixin,
)

0 comments on commit ba98290

Please sign in to comment.