LLVM 17.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 <cstdint>
18#include <optional>
19
20namespace llvm {
21
22 // Relocation model types.
23 namespace Reloc {
24 // Cannot be named PIC due to collision with -DPIC
26 }
27
28 // Code model types.
29 namespace CodeModel {
30 // Sync changes with CodeGenCWrappers.h.
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 {
50 };
51 }
52
53 namespace CodeGenOpt {
54 /// Type for the unique integer IDs of code generation optimization levels.
55 using IDType = int;
56 /// Code generation optimization level.
57 enum Level : IDType {
58 None = 0, ///< -O0
59 Less = 1, ///< -O1
60 Default = 2, ///< -O2, -Os
61 Aggressive = 3 ///< -O3
62 };
63 /// Get the \c Level identified by the integer \p ID.
64 ///
65 /// Returns std::nullopt if \p ID is invalid.
66 inline std::optional<Level> getLevel(IDType ID) {
67 if (ID < 0 || ID > 3)
68 return std::nullopt;
69 return static_cast<Level>(ID);
70 }
71 /// Parse \p C as a single digit integer ID and get matching \c Level.
72 ///
73 /// Returns std::nullopt if the input is not a valid digit or not a valid ID.
74 inline std::optional<Level> parseLevel(char C) {
75 if (C < '0')
76 return std::nullopt;
77 return getLevel(static_cast<IDType>(C - '0'));
78 }
79 } // namespace CodeGenOpt
80
81 /// These enums are meant to be passed into addPassesToEmitFile to indicate
82 /// what type of file to emit, and returned by it to indicate what type of
83 /// file could actually be made.
87 CGFT_Null // Do not emit any output.
88 };
89
90 // Specify what functions should keep the frame pointer.
91 enum class FramePointerKind { None, NonLeaf, All };
92
93 // Specify what type of zeroing callee-used registers.
94 namespace ZeroCallUsedRegs {
95 const unsigned ONLY_USED = 1U << 1;
96 const unsigned ONLY_GPR = 1U << 2;
97 const unsigned ONLY_ARG = 1U << 3;
98
99 enum class ZeroCallUsedRegsKind : unsigned int {
100 // Don't zero any call-used regs.
101 Skip = 1U << 0,
102 // Only zeros call-used GPRs used in the fn and pass args.
104 // Only zeros call-used GPRs used in the fn.
106 // Only zeros call-used regs used in the fn and pass args.
108 // Only zeros call-used regs used in the fn.
109 Used = ONLY_USED,
110 // Zeros all call-used GPRs that pass args.
112 // Zeros all call-used GPRs.
114 // Zeros all call-used regs that pass args.
116 // Zeros all call-used regs.
117 All = 0,
118 };
119 } // namespace ZeroCallUsedRegs
120
121 enum class UWTableKind {
122 None = 0, ///< No unwind table requested
123 Sync = 1, ///< "Synchronous" unwind tables
124 Async = 2, ///< "Asynchronous" unwind tables (instr precise)
125 Default = 2,
126 };
127
128 enum class FunctionReturnThunksKind : unsigned int {
129 Keep = 0, ///< No function return thunk.
130 Extern = 1, ///< Replace returns with jump to thunk, don't emit thunk.
131 Invalid = 2, ///< Not used.
132 };
133
134 } // namespace llvm
135
136#endif
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
std::optional< Level > parseLevel(char C)
Parse C as a single digit integer ID and get matching Level.
Definition: CodeGen.h:74
std::optional< Level > getLevel(IDType ID)
Get the Level identified by the integer ID.
Definition: CodeGen.h:66
Level
Code generation optimization level.
Definition: CodeGen.h:57
@ Default
-O2, -Os
Definition: CodeGen.h:60
@ Aggressive
-O3
Definition: CodeGen.h:61
int IDType
Type for the unique integer IDs of code generation optimization levels.
Definition: CodeGen.h:55
@ DynamicNoPIC
Definition: CodeGen.h:25
@ ROPI_RWPI
Definition: CodeGen.h:25
@ GeneralDynamic
Definition: CodeGen.h:46
const unsigned ONLY_GPR
Definition: CodeGen.h:96
const unsigned ONLY_USED
Definition: CodeGen.h:95
const unsigned ONLY_ARG
Definition: CodeGen.h:97
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FramePointerKind
Definition: CodeGen.h:91
UWTableKind
Definition: CodeGen.h:121
@ Async
"Asynchronous" unwind tables (instr precise)
@ Sync
"Synchronous" unwind tables
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition: CodeGen.h:84
@ CGFT_AssemblyFile
Definition: CodeGen.h:85
@ CGFT_Null
Definition: CodeGen.h:87
@ CGFT_ObjectFile
Definition: CodeGen.h:86
@ Invalid
Denotes invalid value.
@ Default
The result values are uniform if and only if all operands are uniform.
constexpr std::nullopt_t None
Definition: None.h:28
FunctionReturnThunksKind
Definition: CodeGen.h:128
@ Keep
No function return thunk.
@ Extern
Replace returns with jump to thunk, don't emit thunk.