LLVM 24.0.0git
CodeGen.h
Go to the documentation of this file.
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
21namespace llvm {
22
23 // Relocation model types.
24 namespace Reloc {
25 // Cannot be named PIC due to collision with -DPIC
27 }
28
29 // Code model types.
30 namespace CodeModel {
31 // Sync changes with CodeGenCWrappers.h.
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.
53
54 enum class ExceptionHandling {
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.
74
75 /// Returns the IR floating-point type name for a LongDoubleFormat.
77 switch (Format) {
79 return "float";
81 return "double";
83 return "x86_fp80";
85 return "fp128";
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")
97 if (Name == "double")
99 if (Name == "x86_fp80")
101 if (Name == "fp128")
103 if (Name == "ppc_fp128")
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.
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 {
142 Default, // Default means not specified
143 EABI4, // Target-specific (either 4, 5 or gnu depending on triple).
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(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 {
181 Null // Do not emit any output.
182 };
183
184 // Specify what functions should keep the frame pointer.
192
193 // Specify what type of zeroing callee-used registers.
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.
204 // Only zeros call-used GPRs used in the fn.
206 // Only zeros call-used regs used in the fn and pass args.
208 // Only zeros call-used regs used in the fn.
210 // Zeros all call-used GPRs that pass args.
212 // Zeros all call-used GPRs.
214 // Zeros all call-used regs that pass args.
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)
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
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
245 // Don't enable Control Flow Guard.
247 // Emit the Control Flow Guard tables in the binary, but don't emit any
248 // checks.
250 // Enable Control Flow Guard checks and emit the tables.
252 };
253
255 // Choose the mechanism automatically based on the target.
257 Check = 1,
259 };
260
261 } // namespace llvm
262
263#endif
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This class is the base class for all object file types.
Definition ObjectFile.h:231
Define some predicates that are used for node matching.
Definition ARMEHABI.h:25
std::optional< CodeGenOptLevel > getLevel(int OL)
Get the Level identified by the integer OL.
Definition CodeGen.h:160
std::optional< CodeGenOptLevel > parseLevel(char C)
Parse C as a single digit integer and get matching CodeGenLevel.
Definition CodeGen.h:168
std::optional< ABIType > parseABIType(StringRef S)
Parse the string spelling used by the "float-abi" IR module flag into an ABIType.
Definition CodeGen.h:117
StringRef getABITypeName(ABIType ABI)
Returns the string spelling used by the "float-abi" IR module flag for a Soft or Hard ABIType.
Definition CodeGen.h:127
@ DynamicNoPIC
Definition CodeGen.h:26
const unsigned ONLY_GPR
Definition CodeGen.h:196
const unsigned ONLY_USED
Definition CodeGen.h:195
const unsigned ONLY_ARG
Definition CodeGen.h:197
This is an optimization pass for GlobalISel generic memory operations.
std::optional< LongDoubleFormat > parseLongDoubleFormat(StringRef Name)
Parses an IR floating-point type name into a LongDoubleFormat, returning std::nullopt if it does not ...
Definition CodeGen.h:94
FramePointerKind
Definition CodeGen.h:185
@ Unknown
Not known to have no common set bits.
StringRef getLongDoubleFormatName(LongDoubleFormat Format)
Returns the IR floating-point type name for a LongDoubleFormat.
Definition CodeGen.h:76
LongDoubleFormat
The floating-point format used for the target's "long double" type.
Definition CodeGen.h:67
ExceptionHandling
Definition CodeGen.h:54
@ SjLj
setjmp/longjmp based exceptions
Definition CodeGen.h:57
@ ZOS
z/OS MVS Exception Handling.
Definition CodeGen.h:62
@ AIX
AIX Exception Handling.
Definition CodeGen.h:61
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:56
@ Wasm
WebAssembly Exception Handling.
Definition CodeGen.h:60
ControlFlowGuardMode
Definition CodeGen.h:244
WinX64EHUnwindMode
Definition CodeGen.h:234
UWTableKind
Definition CodeGen.h:221
@ Async
"Asynchronous" unwind tables (instr precise)
Definition CodeGen.h:224
@ Sync
"Synchronous" unwind tables
Definition CodeGen.h:223
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:178
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:149
ControlFlowGuardMechanism
Definition CodeGen.h:254
@ Enabled
Convert any .debug_str_offsets tables to DWARF64 if needed.
Definition DWP.h:31
@ Disabled
Don't do any conversion of .debug_str_offsets tables.
Definition DWP.h:30
@ Default
The result value is uniform if and only if all operands are uniform.
Definition Uniformity.h:20
FunctionReturnThunksKind
Definition CodeGen.h:228
@ Keep
No function return thunk.
Definition CodeGen.h:229
@ Extern
Replace returns with jump to thunk, don't emit thunk.
Definition CodeGen.h:230