| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
# Copyright 2019 The meson development team |
| 3 |
|
| 4 |
from __future__ import annotations |
| 5 |
|
| 6 |
"""Abstractions for the Intel Compiler families. |
| 7 |
|
| 8 |
Intel provides both a posix/gcc-like compiler (ICC) for MacOS and Linux, |
| 9 |
with Meson mixin IntelGnuLikeCompiler. |
| 10 |
For Windows, the Intel msvc-like compiler (ICL) Meson mixin |
| 11 |
is IntelVisualStudioLikeCompiler. |
| 12 |
""" |
| 13 |
|
| 14 |
import os |
| 15 |
import typing as T |
| 16 |
|
| 17 |
from ... import mesonlib |
| 18 |
from ..compilers import CompileCheckMode |
| 19 |
from .gnu import GnuLikeCompiler |
| 20 |
from .visualstudio import VisualStudioLikeCompiler |
| 21 |
from ...options import OptionKey |
| 22 |
|
| 23 |
# XXX: avoid circular dependencies |
| 24 |
# TODO: this belongs in a posix compiler class |
| 25 |
# NOTE: the default Intel optimization is -O2, unlike GNU which defaults to -O0. |
| 26 |
# this can be surprising, particularly for debug builds, so we specify the |
| 27 |
# default as -O0. |
| 28 |
# https://software.intel.com/en-us/cpp-compiler-developer-guide-and-reference-o |
| 29 |
# https://software.intel.com/en-us/cpp-compiler-developer-guide-and-reference-g |
| 30 |
# https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-o |
| 31 |
# https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-g |
| 32 |
# https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-traceback |
| 33 |
# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html |
| 34 |
|
| 35 |
|
| 36 |
class IntelGnuLikeCompiler(GnuLikeCompiler): |
| 37 |
""" |
| 38 |
Tested on linux for ICC 14.0.3, 15.0.6, 16.0.4, 17.0.1, 19.0 |
| 39 |
debugoptimized: -g -O2 |
| 40 |
release: -O3 |
| 41 |
minsize: -O2 |
| 42 |
""" |
| 43 |
|
| 44 |
DEBUG_ARGS: T.Dict[bool, T.List[str]] = { |
| 45 |
False: [], |
| 46 |
True: ['-g', '-traceback'] |
| 47 |
} |
| 48 |
|
| 49 |
OPTIM_ARGS: T.Dict[str, T.List[str]] = { |
| 50 |
'plain': [], |
| 51 |
'0': ['-O0'], |
| 52 |
'g': ['-O0'], |
| 53 |
'1': ['-O1'], |
| 54 |
'2': ['-O2'], |
| 55 |
'3': ['-O3'], |
| 56 |
's': ['-Os'], |
| 57 |
} |
| 58 |
id = 'intel' |
| 59 |
|
| 60 |
def __init__(self) -> None: |
| 61 |
super().__init__() |
| 62 |
# As of 19.0.0 ICC doesn't have sanitizer, color, or lto support. |
| 63 |
# |
| 64 |
# It does have IPO, which serves much the same purpose as LOT, but |
| 65 |
# there is an unfortunate rule for using IPO (you can't control the |
| 66 |
# name of the output file) which break assumptions meson makes |
| 67 |
self.base_options = {OptionKey(o) for o in [ |
| 68 |
'b_pch', 'b_lundef', 'b_asneeded', 'b_pgo', 'b_coverage', |
| 69 |
'b_ndebug', 'b_staticpic', 'b_pie']} |
| 70 |
self.lang_header = 'none' |
| 71 |
|
| 72 |
def get_pch_suffix(self) -> str: |
| 73 |
return 'pchi' |
| 74 |
|
| 75 |
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: |
| 76 |
return ['-pch', '-pch_dir', os.path.join(pch_dir), '-x', |
| 77 |
self.lang_header, '-include', header, '-x', 'none'] |
| 78 |
|
| 79 |
def get_pch_name(self, name: str) -> str: |
| 80 |
return os.path.basename(name) + '.' + self.get_pch_suffix() |
| 81 |
|
| 82 |
def openmp_flags(self) -> T.List[str]: |
| 83 |
if mesonlib.version_compare(self.version, '>=15.0.0'): |
| 84 |
return ['-qopenmp'] |
| 85 |
else: |
| 86 |
return ['-openmp'] |
| 87 |
|
| 88 |
def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]: |
| 89 |
extra_args = [ |
| 90 |
'-diag-error', '10006', # ignoring unknown option |
| 91 |
'-diag-error', '10148', # Option not supported |
| 92 |
'-diag-error', '10155', # ignoring argument required |
| 93 |
'-diag-error', '10156', # ignoring not argument allowed |
| 94 |
'-diag-error', '10157', # Ignoring argument of the wrong type |
| 95 |
'-diag-error', '10158', # Argument must be separate. Can be hit by trying an option like -foo-bar=foo when -foo=bar is a valid option but -foo-bar isn't |
| 96 |
] |
| 97 |
return super().get_compiler_check_args(mode) + extra_args |
| 98 |
|
| 99 |
def get_profile_generate_args(self) -> T.List[str]: |
| 100 |
return ['-prof-gen=threadsafe'] |
| 101 |
|
| 102 |
def get_profile_use_args(self) -> T.List[str]: |
| 103 |
return ['-prof-use'] |
| 104 |
|
| 105 |
def get_debug_args(self, is_debug: bool) -> T.List[str]: |
| 106 |
return self.DEBUG_ARGS[is_debug] |
| 107 |
|
| 108 |
def get_optimization_args(self, optimization_level: str) -> T.List[str]: |
| 109 |
return self.OPTIM_ARGS[optimization_level] |
| 110 |
|
| 111 |
def get_has_func_attribute_extra_args(self, name: str) -> T.List[str]: |
| 112 |
return ['-diag-error', '1292'] |
| 113 |
|
| 114 |
|
| 115 |
class IntelLLVMLikeCompiler: |
| 116 |
def openmp_flags(self) -> T.List[str]: |
| 117 |
return ['-qopenmp'] |
| 118 |
|
| 119 |
|
| 120 |
class IntelVisualStudioLikeCompiler(VisualStudioLikeCompiler): |
| 121 |
|
| 122 |
"""Abstractions for ICL, the Intel compiler on Windows.""" |
| 123 |
|
| 124 |
DEBUG_ARGS: T.Dict[bool, T.List[str]] = { |
| 125 |
False: [], |
| 126 |
True: ['/Zi', '/traceback'] |
| 127 |
} |
| 128 |
|
| 129 |
OPTIM_ARGS: T.Dict[str, T.List[str]] = { |
| 130 |
'plain': [], |
| 131 |
'0': ['/Od'], |
| 132 |
'g': ['/Od'], |
| 133 |
'1': ['/O1'], |
| 134 |
'2': ['/O2'], |
| 135 |
'3': ['/O3'], |
| 136 |
's': ['/Os'], |
| 137 |
} |
| 138 |
|
| 139 |
id = 'intel-cl' |
| 140 |
|
| 141 |
def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]: |
| 142 |
args = super().get_compiler_check_args(mode) |
| 143 |
if mode is not CompileCheckMode.LINK: |
| 144 |
args.extend([ |
| 145 |
'/Qdiag-error:10006', # ignoring unknown option |
| 146 |
'/Qdiag-error:10148', # Option not supported |
| 147 |
'/Qdiag-error:10155', # ignoring argument required |
| 148 |
'/Qdiag-error:10156', # ignoring not argument allowed |
| 149 |
'/Qdiag-error:10157', # Ignoring argument of the wrong type |
| 150 |
'/Qdiag-error:10158', # Argument must be separate. Can be hit by trying an option like -foo-bar=foo when -foo=bar is a valid option but -foo-bar isn't |
| 151 |
]) |
| 152 |
return args |
| 153 |
|
| 154 |
def openmp_flags(self) -> T.List[str]: |
| 155 |
return ['/Qopenmp'] |
| 156 |
|
| 157 |
def get_debug_args(self, is_debug: bool) -> T.List[str]: |
| 158 |
return self.DEBUG_ARGS[is_debug] |
| 159 |
|
| 160 |
def get_optimization_args(self, optimization_level: str) -> T.List[str]: |
| 161 |
return self.OPTIM_ARGS[optimization_level] |
| 162 |
|
| 163 |
def get_pch_base_name(self, header: str) -> str: |
| 164 |
return os.path.basename(header) |