Skip to content

Commit e4308a0

Browse files
committed
Implement _compiler_options
1 parent b0c7504 commit e4308a0

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

tadashi/translators.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
ABC_ERROR_MSG = "Translator is an abstract base class, use a derived class."
2424
DOUBLE_SET_SOURCE = "Translator.set_source() should only be called once."
2525

26-
FLANG_COMPILERS = ["mpifort", "mpif90", "mpif77", "flang", "flang-new"]
27-
CLANG_COMPILERS = ["mpic++", "mpicc", "mpiCC", "mpicxx", "clang", "clang++", "acpp"]
28-
2926

3027
@cython.cclass
3128
class Translator:
@@ -279,19 +276,23 @@ def populate_ccscops(self, options: list[str]):
279276
jscop = json.load(fp)
280277
self._proc_jscop(jscop)
281278

279+
def _compiler_options(self):
280+
for flang in ["mpifort", "mpif90", "mpif77", "flang", "flang-new"]:
281+
if flang in self.compiler:
282+
return ["-O0"]
283+
for clang in ["mpic++", "mpicc", "mpiCC", "mpicxx", "clang", "clang++", "acpp"]:
284+
if clang in self.compiler:
285+
return ["-O0", "-Xclang", "-disable-O0-optnone"]
286+
raise ValueError(f"Unsupported compiler: {self.compiler}")
287+
282288
def _get_pre_polly_bc(self, options: list[str]) -> Path:
283289
compile_O0_bc = self.cwd / self.source.with_suffix(".pre_polly.bc").name
284290
pre_polly_bc = self.cwd / self.source.with_suffix(".pre_polly.bc").name
285291
if pre_polly_bc.exists():
286292
return pre_polly_bc
287-
if self.compiler in FLANG_COMPILERS:
288-
compiler_opts = ["-O0"]
289-
elif self.compiler in CLANG_COMPILERS:
290-
compiler_opts = ["-O0", "-Xclang", "-disable-O0-optnone"]
291-
else:
292-
raise ValueError(f"Unsupported compiler: {self.compiler}")
293-
compile_cmd = [self.compiler, *options, "-c", "-emit-llvm", str(self.source)]
294-
compile_cmd += [*compiler_opts, "-o", str(compile_O0_bc)]
293+
compiler_opts = self._compiler_options()
294+
compile_cmd = [self.compiler, *compiler_opts, *options, "-c", "-emit-llvm"]
295+
compile_cmd += [str(self.source), "-o", str(compile_O0_bc)]
295296
self._run(compile_cmd, "compiling with O0")
296297
opt_cmd = ["opt", f"-passes={self.before_polly_passes}"]
297298
opt_cmd += [str(compile_O0_bc), f"-o={str(pre_polly_bc)}"]

0 commit comments

Comments
 (0)