| 1 | //===-- llvm/Support/CodeGen.h - CodeGen Concepts ---------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file define some types which define code generation concepts. For |
| 10 | // example, relocation model. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_SUPPORT_CODEGEN_H |
| 15 | #define LLVM_SUPPORT_CODEGEN_H |
| 16 | |
| 17 | #include "llvm/ADT/StringRef.h" |
| 18 | #include <cstdint> |
| 19 | #include <optional> |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | // Relocation model types. |
| 24 | namespace Reloc { |
| 25 | // Cannot be named PIC due to collision with -DPIC |
| 26 | enum Model { Static, PIC_, DynamicNoPIC, ROPI, RWPI, ROPI_RWPI }; |
| 27 | } |
| 28 | |
| 29 | // Code model types. |
| 30 | namespace CodeModel { |
| 31 | // Sync changes with CodeGenCWrappers.h. |
| 32 | enum Model { Tiny, Small, Kernel, Medium, Large }; |
| 33 | } |
| 34 | |
| 35 | namespace PICLevel { |
| 36 | // This is used to map -fpic/-fPIC. |
| 37 | enum Level { NotPIC=0, SmallPIC=1, BigPIC=2 }; |
| 38 | } |
| 39 | |
| 40 | namespace PIELevel { |
| 41 | enum Level { Default=0, Small=1, Large=2 }; |
| 42 | } |
| 43 | |
| 44 | // TLS models. |
| 45 | namespace TLSModel { |
| 46 | enum Model { |
| 47 | GeneralDynamic, |
| 48 | LocalDynamic, |
| 49 | InitialExec, |
| 50 | LocalExec |
| 51 | }; |
| 52 | } |
| 53 | |
| 54 | enum class ExceptionHandling : int { |
| 55 | None, ///< No exception support |
| 56 | DwarfCFI, ///< DWARF-like instruction based exceptions |
| 57 | SjLj, ///< setjmp/longjmp based exceptions |
| 58 | ARM, ///< ARM EHABI |
| 59 | WinEH, ///< Windows Exception Handling |
| 60 | Wasm, ///< WebAssembly Exception Handling |
| 61 | AIX, ///< AIX Exception Handling |
| 62 | ZOS, ///< z/OS MVS Exception Handling. Very similar to DwarfCFI, but the |
| 63 | ///< PPA1 is used instead of an .eh_frame section. |
| 64 | }; |
| 65 | |
| 66 | /// The floating-point format used for the target's "long double" type. |
| 67 | enum class LongDoubleFormat { |
| 68 | IEEEsingle, |
| 69 | IEEEdouble, |
| 70 | X87DoubleExtended, |
| 71 | IEEEquad, |
| 72 | PPCDoubleDouble, |
| 73 | }; |
| 74 | |
| 75 | /// Returns the IR floating-point type name for a LongDoubleFormat. |
| 76 | inline StringRef getLongDoubleFormatName(LongDoubleFormat Format) { |
| 77 | switch (Format) { |
| 78 | case LongDoubleFormat::IEEEsingle: |
| 79 | return "float" ; |
| 80 | case LongDoubleFormat::IEEEdouble: |
| 81 | return "double" ; |
| 82 | case LongDoubleFormat::X87DoubleExtended: |
| 83 | return "x86_fp80" ; |
| 84 | case LongDoubleFormat::IEEEquad: |
| 85 | return "fp128" ; |
| 86 | case LongDoubleFormat::PPCDoubleDouble: |
| 87 | return "ppc_fp128" ; |
| 88 | } |
| 89 | return "" ; |
| 90 | } |
| 91 | |
| 92 | /// Parses an IR floating-point type name into a LongDoubleFormat, returning |
| 93 | /// std::nullopt if it does not name a supported long double format. |
| 94 | inline std::optional<LongDoubleFormat> parseLongDoubleFormat(StringRef Name) { |
| 95 | if (Name == "float" ) |
| 96 | return LongDoubleFormat::IEEEsingle; |
| 97 | if (Name == "double" ) |
| 98 | return LongDoubleFormat::IEEEdouble; |
| 99 | if (Name == "x86_fp80" ) |
| 100 | return LongDoubleFormat::X87DoubleExtended; |
| 101 | if (Name == "fp128" ) |
| 102 | return LongDoubleFormat::IEEEquad; |
| 103 | if (Name == "ppc_fp128" ) |
| 104 | return LongDoubleFormat::PPCDoubleDouble; |
| 105 | return std::nullopt; |
| 106 | } |
| 107 | |
| 108 | namespace FloatABI { |
| 109 | enum ABIType { |
| 110 | Default, // Target-specific (either soft or hard depending on triple, etc). |
| 111 | Soft, // Soft float. |
| 112 | Hard // Hard float. |
| 113 | }; |
| 114 | |
| 115 | /// Parse the string spelling used by the "float-abi" IR module flag into an |
| 116 | /// ABIType. |
| 117 | inline std::optional<ABIType> parseABIType(StringRef S) { |
| 118 | if (S == "soft" ) |
| 119 | return Soft; |
| 120 | if (S == "hard" ) |
| 121 | return Hard; |
| 122 | return std::nullopt; |
| 123 | } |
| 124 | |
| 125 | /// Returns the string spelling used by the "float-abi" IR module flag for a |
| 126 | /// Soft or Hard ABIType. Default has no spelling. |
| 127 | inline StringRef getABITypeName(ABIType ABI) { |
| 128 | switch (ABI) { |
| 129 | case Soft: |
| 130 | return "soft" ; |
| 131 | case Hard: |
| 132 | return "hard" ; |
| 133 | case Default: |
| 134 | break; |
| 135 | } |
| 136 | return "" ; |
| 137 | } |
| 138 | } // namespace FloatABI |
| 139 | |
| 140 | enum class EABI { |
| 141 | Unknown, |
| 142 | Default, // Default means not specified |
| 143 | EABI4, // Target-specific (either 4, 5 or gnu depending on triple). |
| 144 | EABI5, |
| 145 | GNU |
| 146 | }; |
| 147 | |
| 148 | /// Code generation optimization level. |
| 149 | enum class CodeGenOptLevel { |
| 150 | None = 0, ///< -O0 |
| 151 | Less = 1, ///< -O1 |
| 152 | Default = 2, ///< -O2, -Os, -Oz |
| 153 | Aggressive = 3 ///< -O3 |
| 154 | }; |
| 155 | |
| 156 | namespace CodeGenOpt { |
| 157 | /// Get the \c Level identified by the integer \p OL. |
| 158 | /// |
| 159 | /// Returns std::nullopt if \p OL is invalid. |
| 160 | inline std::optional<CodeGenOptLevel> getLevel(int OL) { |
| 161 | if (OL < 0 || OL > 3) |
| 162 | return std::nullopt; |
| 163 | return static_cast<CodeGenOptLevel>(OL); |
| 164 | } |
| 165 | /// Parse \p C as a single digit integer and get matching \c CodeGenLevel. |
| 166 | /// |
| 167 | /// Returns std::nullopt if the input is not a valid optimization level. |
| 168 | inline std::optional<CodeGenOptLevel> parseLevel(char C) { |
| 169 | if (C < '0') |
| 170 | return std::nullopt; |
| 171 | return getLevel(OL: static_cast<int>(C - '0')); |
| 172 | } |
| 173 | } // namespace CodeGenOpt |
| 174 | |
| 175 | /// These enums are meant to be passed into addPassesToEmitFile to indicate |
| 176 | /// what type of file to emit, and returned by it to indicate what type of |
| 177 | /// file could actually be made. |
| 178 | enum class CodeGenFileType { |
| 179 | AssemblyFile, |
| 180 | ObjectFile, |
| 181 | Null // Do not emit any output. |
| 182 | }; |
| 183 | |
| 184 | // Specify what functions should keep the frame pointer. |
| 185 | enum class FramePointerKind { |
| 186 | None, |
| 187 | NonLeaf, |
| 188 | All, |
| 189 | Reserved, |
| 190 | NonLeafNoReserve |
| 191 | }; |
| 192 | |
| 193 | // Specify what type of zeroing callee-used registers. |
| 194 | namespace ZeroCallUsedRegs { |
| 195 | const unsigned ONLY_USED = 1U << 1; |
| 196 | const unsigned ONLY_GPR = 1U << 2; |
| 197 | const unsigned ONLY_ARG = 1U << 3; |
| 198 | |
| 199 | enum class ZeroCallUsedRegsKind : unsigned int { |
| 200 | // Don't zero any call-used regs. |
| 201 | Skip = 1U << 0, |
| 202 | // Only zeros call-used GPRs used in the fn and pass args. |
| 203 | UsedGPRArg = ONLY_USED | ONLY_GPR | ONLY_ARG, |
| 204 | // Only zeros call-used GPRs used in the fn. |
| 205 | UsedGPR = ONLY_USED | ONLY_GPR, |
| 206 | // Only zeros call-used regs used in the fn and pass args. |
| 207 | UsedArg = ONLY_USED | ONLY_ARG, |
| 208 | // Only zeros call-used regs used in the fn. |
| 209 | Used = ONLY_USED, |
| 210 | // Zeros all call-used GPRs that pass args. |
| 211 | AllGPRArg = ONLY_GPR | ONLY_ARG, |
| 212 | // Zeros all call-used GPRs. |
| 213 | AllGPR = ONLY_GPR, |
| 214 | // Zeros all call-used regs that pass args. |
| 215 | AllArg = ONLY_ARG, |
| 216 | // Zeros all call-used regs. |
| 217 | All = 0, |
| 218 | }; |
| 219 | } // namespace ZeroCallUsedRegs |
| 220 | |
| 221 | enum class UWTableKind { |
| 222 | None = 0, ///< No unwind table requested |
| 223 | Sync = 1, ///< "Synchronous" unwind tables |
| 224 | Async = 2, ///< "Asynchronous" unwind tables (instr precise) |
| 225 | Default = 2, |
| 226 | }; |
| 227 | |
| 228 | enum class FunctionReturnThunksKind : unsigned int { |
| 229 | Keep = 0, ///< No function return thunk. |
| 230 | Extern = 1, ///< Replace returns with jump to thunk, don't emit thunk. |
| 231 | Invalid = 2, ///< Not used. |
| 232 | }; |
| 233 | |
| 234 | enum class WinX64EHUnwindMode { |
| 235 | Default = 4, // Toolchain default/auto. |
| 236 | // Using '4' to avoid renumbering the existing values. |
| 237 | |
| 238 | V1 = 0, // V1 unwind info. |
| 239 | V2BestEffort = 1, // V2 where possible, fall back to V1. |
| 240 | V2Required = 2, // V2 required — error if a function cannot use V2. |
| 241 | V3 = 3, // V3 unwind info. |
| 242 | }; |
| 243 | |
| 244 | enum class ControlFlowGuardMode { |
| 245 | // Don't enable Control Flow Guard. |
| 246 | Disabled = 0, |
| 247 | // Emit the Control Flow Guard tables in the binary, but don't emit any |
| 248 | // checks. |
| 249 | TableOnly = 1, |
| 250 | // Enable Control Flow Guard checks and emit the tables. |
| 251 | Enabled = 2, |
| 252 | }; |
| 253 | |
| 254 | enum class ControlFlowGuardMechanism { |
| 255 | // Choose the mechanism automatically based on the target. |
| 256 | Automatic = 0, |
| 257 | Check = 1, |
| 258 | Dispatch = 2, |
| 259 | }; |
| 260 | |
| 261 | } // namespace llvm |
| 262 | |
| 263 | #endif |
| 264 | |