| 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 <cstdint> |
| 18 | #include <optional> |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | // Relocation model types. |
| 23 | namespace Reloc { |
| 24 | // Cannot be named PIC due to collision with -DPIC |
| 25 | enum Model { Static, PIC_, DynamicNoPIC, ROPI, RWPI, ROPI_RWPI }; |
| 26 | } |
| 27 | |
| 28 | // Code model types. |
| 29 | namespace CodeModel { |
| 30 | // Sync changes with CodeGenCWrappers.h. |
| 31 | enum Model { Tiny, Small, Kernel, Medium, Large }; |
| 32 | } |
| 33 | |
| 34 | namespace PICLevel { |
| 35 | // This is used to map -fpic/-fPIC. |
| 36 | enum Level { NotPIC=0, SmallPIC=1, BigPIC=2 }; |
| 37 | } |
| 38 | |
| 39 | namespace PIELevel { |
| 40 | enum Level { Default=0, Small=1, Large=2 }; |
| 41 | } |
| 42 | |
| 43 | // TLS models. |
| 44 | namespace TLSModel { |
| 45 | enum Model { |
| 46 | GeneralDynamic, |
| 47 | LocalDynamic, |
| 48 | InitialExec, |
| 49 | LocalExec |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | enum class ExceptionHandling { |
| 54 | None, ///< No exception support |
| 55 | DwarfCFI, ///< DWARF-like instruction based exceptions |
| 56 | SjLj, ///< setjmp/longjmp based exceptions |
| 57 | ARM, ///< ARM EHABI |
| 58 | WinEH, ///< Windows Exception Handling |
| 59 | Wasm, ///< WebAssembly Exception Handling |
| 60 | AIX, ///< AIX Exception Handling |
| 61 | ZOS, ///< z/OS MVS Exception Handling. Very similar to DwarfCFI, but the |
| 62 | ///< PPA1 is used instead of an .eh_frame section. |
| 63 | }; |
| 64 | |
| 65 | namespace FloatABI { |
| 66 | enum ABIType { |
| 67 | Default, // Target-specific (either soft or hard depending on triple, etc). |
| 68 | Soft, // Soft float. |
| 69 | Hard // Hard float. |
| 70 | }; |
| 71 | } |
| 72 | |
| 73 | enum class EABI { |
| 74 | Unknown, |
| 75 | Default, // Default means not specified |
| 76 | EABI4, // Target-specific (either 4, 5 or gnu depending on triple). |
| 77 | EABI5, |
| 78 | GNU |
| 79 | }; |
| 80 | |
| 81 | /// Code generation optimization level. |
| 82 | enum class CodeGenOptLevel { |
| 83 | None = 0, ///< -O0 |
| 84 | Less = 1, ///< -O1 |
| 85 | Default = 2, ///< -O2, -Os, -Oz |
| 86 | Aggressive = 3 ///< -O3 |
| 87 | }; |
| 88 | |
| 89 | namespace CodeGenOpt { |
| 90 | /// Get the \c Level identified by the integer \p OL. |
| 91 | /// |
| 92 | /// Returns std::nullopt if \p OL is invalid. |
| 93 | inline std::optional<CodeGenOptLevel> getLevel(int OL) { |
| 94 | if (OL < 0 || OL > 3) |
| 95 | return std::nullopt; |
| 96 | return static_cast<CodeGenOptLevel>(OL); |
| 97 | } |
| 98 | /// Parse \p C as a single digit integer and get matching \c CodeGenLevel. |
| 99 | /// |
| 100 | /// Returns std::nullopt if the input is not a valid optimization level. |
| 101 | inline std::optional<CodeGenOptLevel> parseLevel(char C) { |
| 102 | if (C < '0') |
| 103 | return std::nullopt; |
| 104 | return getLevel(OL: static_cast<int>(C - '0')); |
| 105 | } |
| 106 | } // namespace CodeGenOpt |
| 107 | |
| 108 | /// These enums are meant to be passed into addPassesToEmitFile to indicate |
| 109 | /// what type of file to emit, and returned by it to indicate what type of |
| 110 | /// file could actually be made. |
| 111 | enum class CodeGenFileType { |
| 112 | AssemblyFile, |
| 113 | ObjectFile, |
| 114 | Null // Do not emit any output. |
| 115 | }; |
| 116 | |
| 117 | // Specify what functions should keep the frame pointer. |
| 118 | enum class FramePointerKind { |
| 119 | None, |
| 120 | NonLeaf, |
| 121 | All, |
| 122 | Reserved, |
| 123 | NonLeafNoReserve |
| 124 | }; |
| 125 | |
| 126 | // Specify what type of zeroing callee-used registers. |
| 127 | namespace ZeroCallUsedRegs { |
| 128 | const unsigned ONLY_USED = 1U << 1; |
| 129 | const unsigned ONLY_GPR = 1U << 2; |
| 130 | const unsigned ONLY_ARG = 1U << 3; |
| 131 | |
| 132 | enum class ZeroCallUsedRegsKind : unsigned int { |
| 133 | // Don't zero any call-used regs. |
| 134 | Skip = 1U << 0, |
| 135 | // Only zeros call-used GPRs used in the fn and pass args. |
| 136 | UsedGPRArg = ONLY_USED | ONLY_GPR | ONLY_ARG, |
| 137 | // Only zeros call-used GPRs used in the fn. |
| 138 | UsedGPR = ONLY_USED | ONLY_GPR, |
| 139 | // Only zeros call-used regs used in the fn and pass args. |
| 140 | UsedArg = ONLY_USED | ONLY_ARG, |
| 141 | // Only zeros call-used regs used in the fn. |
| 142 | Used = ONLY_USED, |
| 143 | // Zeros all call-used GPRs that pass args. |
| 144 | AllGPRArg = ONLY_GPR | ONLY_ARG, |
| 145 | // Zeros all call-used GPRs. |
| 146 | AllGPR = ONLY_GPR, |
| 147 | // Zeros all call-used regs that pass args. |
| 148 | AllArg = ONLY_ARG, |
| 149 | // Zeros all call-used regs. |
| 150 | All = 0, |
| 151 | }; |
| 152 | } // namespace ZeroCallUsedRegs |
| 153 | |
| 154 | enum class UWTableKind { |
| 155 | None = 0, ///< No unwind table requested |
| 156 | Sync = 1, ///< "Synchronous" unwind tables |
| 157 | Async = 2, ///< "Asynchronous" unwind tables (instr precise) |
| 158 | Default = 2, |
| 159 | }; |
| 160 | |
| 161 | enum class FunctionReturnThunksKind : unsigned int { |
| 162 | Keep = 0, ///< No function return thunk. |
| 163 | Extern = 1, ///< Replace returns with jump to thunk, don't emit thunk. |
| 164 | Invalid = 2, ///< Not used. |
| 165 | }; |
| 166 | |
| 167 | enum class WinX64EHUnwindV2Mode { |
| 168 | // Don't use unwind v2 (i.e., use v1). |
| 169 | Disabled = 0, |
| 170 | // Use unwind v2 here possible, otherwise fallback to v1. |
| 171 | BestEffort = 1, |
| 172 | // Use unwind v2 everywhere, otherwise raise an error. |
| 173 | Required = 2, |
| 174 | }; |
| 175 | |
| 176 | enum class ControlFlowGuardMode { |
| 177 | // Don't enable Control Flow Guard. |
| 178 | Disabled = 0, |
| 179 | // Emit the Control Flow Guard tables in the binary, but don't emit any |
| 180 | // checks. |
| 181 | TableOnly = 1, |
| 182 | // Enable Control Flow Guard checks and emit the tables. |
| 183 | Enabled = 2, |
| 184 | }; |
| 185 | |
| 186 | } // namespace llvm |
| 187 | |
| 188 | #endif |
| 189 | |