summaryrefslogtreecommitdiff
path: root/lib/spack/spack/compilers/xl.py
blob: 1c1be0e41b43785ed0cb12dcf65edd8fe2c72742 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import os

from spack.compiler import Compiler, UnsupportedCompilerFlag
from spack.version import Version


class Xl(Compiler):
    # Subclasses use possible names of C compiler
    cc_names = ["xlc"]

    # Subclasses use possible names of C++ compiler
    cxx_names = ["xlC", "xlc++"]

    # Subclasses use possible names of Fortran 77 compiler
    f77_names = ["xlf"]

    # Subclasses use possible names of Fortran 90 compiler
    fc_names = ["xlf90", "xlf95", "xlf2003", "xlf2008"]

    # Named wrapper links within build_env_path
    link_paths = {
        "cc": os.path.join("xl", "xlc"),
        "cxx": os.path.join("xl", "xlc++"),
        "f77": os.path.join("xl", "xlf"),
        "fc": os.path.join("xl", "xlf90"),
    }

    version_argument = "-qversion"
    version_regex = r"([0-9]?[0-9]\.[0-9])"

    @property
    def verbose_flag(self):
        return "-V"

    @property
    def debug_flags(self):
        return ["-g", "-g0", "-g1", "-g2", "-g8", "-g9"]

    @property
    def opt_flags(self):
        return ["-O", "-O0", "-O1", "-O2", "-O3", "-O4", "-O5", "-Ofast"]

    @property
    def openmp_flag(self):
        return "-qsmp=omp"

    @property
    def cxx11_flag(self):
        if self.real_version < Version("13.1"):
            raise UnsupportedCompilerFlag(self, "the C++11 standard", "cxx11_flag", "< 13.1")
        else:
            return "-qlanglvl=extended0x"

    @property
    def c99_flag(self):
        if self.real_version >= Version("13.1.1"):
            return "-std=gnu99"
        if self.real_version >= Version("10.1"):
            return "-qlanglvl=extc99"
        raise UnsupportedCompilerFlag(self, "the C99 standard", "c99_flag", "< 10.1")

    @property
    def c11_flag(self):
        if self.real_version >= Version("13.1.2"):
            return "-std=gnu11"
        if self.real_version >= Version("12.1"):
            return "-qlanglvl=extc1x"
        raise UnsupportedCompilerFlag(self, "the C11 standard", "c11_flag", "< 12.1")

    @property
    def cxx14_flag(self):
        # .real_version does not have the "y.z" component of "w.x.y.z", which
        # is required to distinguish whether support is available
        if self.version >= Version("16.1.1.8"):
            return "-std=c++14"
        raise UnsupportedCompilerFlag(self, "the C++14 standard", "cxx14_flag", "< 16.1.1.8")

    @property
    def cc_pic_flag(self):
        return "-qpic"

    @property
    def cxx_pic_flag(self):
        return "-qpic"

    @property
    def f77_pic_flag(self):
        return "-qpic"

    @property
    def fc_pic_flag(self):
        return "-qpic"

    @property
    def fflags(self):
        # The -qzerosize flag is effective only for the Fortran 77
        # compilers and allows the use of zero size objects.
        # For Fortran 90 and beyond, it is set by default and has not impact.
        # Its use has no negative side effects.
        return "-qzerosize"

    @classmethod
    def fc_version(cls, fc):
        # The fortran and C/C++ versions of the XL compiler are always
        # two units apart.  By this we mean that the fortran release that
        # goes with XL C/C++ 11.1 is 13.1.  Having such a difference in
        # version number is confusing spack quite a lot.  Most notably
        # if you keep the versions as is the default xl compiler will
        # only have fortran and no C/C++.  So we associate the Fortran
        # compiler with the version associated to the C/C++ compiler.
        # One last stumble. Version numbers over 10 have at least a .1
        # those under 10 a .0. There is no xlf 9.x or under currently
        # available. BG/P and BG/L can such a compiler mix and possibly
        # older version of AIX and linux on power.
        fortran_version = cls.default_version(fc)
        if fortran_version >= 16:
            # Starting with version 16.1, the XL C and Fortran compilers
            # have the same version.  So no need to downgrade the Fortran
            # compiler version to match that of the C compiler version.
            return str(fortran_version)
        c_version = float(fortran_version) - 2
        if c_version < 10:
            c_version = c_version - 0.1
        return str(c_version)

    @classmethod
    def f77_version(cls, f77):
        return cls.fc_version(f77)