def optimization_flags(self, compiler): """Returns the flags needed to optimize for this target using the compiler passed as argument. Args: compiler (CompilerSpec or Compiler): object that contains both the name and the version of the compiler we want to use """ # Mixed toolchains are not supported yet import spack.compilers if isinstance(compiler, spack.compiler.Compiler): if spack.compilers.is_mixed_toolchain(compiler): msg = ('microarchitecture specific optimizations are not ' 'supported yet on mixed compiler toolchains [check' ' {0.name}@{0.version} for further details]') warnings.warn(msg.format(compiler)) return '' # Try to check if the current compiler comes with a version number or # has an unexpected suffix. If so, treat it as a compiler with a # custom spec. compiler_version = compiler.version version_number, suffix = cpu.version_components(compiler.version) if not version_number or suffix not in ('', 'apple'): # Try to deduce the correct version. Depending on where this # function is called we might get either a CompilerSpec or a # fully fledged compiler object import spack.spec if isinstance(compiler, spack.spec.CompilerSpec): compiler = spack.compilers.compilers_for_spec(compiler).pop() compiler_version = compiler.cc_version(compiler.cc) return self.microarchitecture.optimization_flags( compiler.name, str(compiler_version))
def optimization_flags(self, compiler): """Returns the flags needed to optimize for this target using the compiler passed as argument. Args: compiler (CompilerSpec or Compiler): object that contains both the name and the version of the compiler we want to use """ # Mixed toolchains are not supported yet import spack.compilers if isinstance(compiler, spack.compiler.Compiler): if spack.compilers.is_mixed_toolchain(compiler): msg = ('microarchitecture specific optimizations are not ' 'supported yet on mixed compiler toolchains [check' ' {0.name}@{0.version} for further details]') warnings.warn(msg.format(compiler)) return '' # Try to check if the current compiler comes with a version number or # has an unexpected suffix. If so, treat it as a compiler with a # custom spec. compiler_version = compiler.version version_number, suffix = cpu.version_components(compiler.version) if not version_number or suffix not in ('', 'apple'): # Try to deduce the underlying version of the compiler, regardless # of its name in compilers.yaml. Depending on where this function # is called we might get either a CompilerSpec or a fully fledged # compiler object. import spack.spec if isinstance(compiler, spack.spec.CompilerSpec): compiler = spack.compilers.compilers_for_spec(compiler).pop() try: compiler_version = compiler.get_real_version() except spack.util.executable.ProcessError as e: # log this and just return compiler.version instead tty.debug(str(e)) return self.microarchitecture.optimization_flags( compiler.name, str(compiler_version) )