LLVM 20.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 /// Code generation optimization level.
54 enum class CodeGenOptLevel {
55 None = 0, ///< -O0
56 Less = 1, ///< -O1
57 Default = 2, ///< -O2, -Os
58 Aggressive = 3 ///< -O3
59 };
60
61 namespace CodeGenOpt {
62 /// Get the \c Level identified by the integer \p OL.
63 ///
64 /// Returns std::nullopt if \p OL is invalid.
65 inline std::optional<CodeGenOptLevel> getLevel(int OL) {
66 if (OL < 0 || OL > 3)
67 return std::nullopt;
68 return static_cast<CodeGenOptLevel>(OL);
69 }
70 /// Parse \p C as a single digit integer and get matching \c CodeGenLevel.
71 ///
72 /// Returns std::nullopt if the input is not a valid optimization level.
73 inline std::optional<CodeGenOptLevel> parseLevel(char C) {
74 if (C < '0')
75 return std::nullopt;
76 return getLevel(static_cast<int>(C - '0'));
77 }
78 } // namespace CodeGenOpt
79
80 /// These enums are meant to be passed into addPassesToEmitFile to indicate
81 /// what type of file to emit, and returned by it to indicate what type of
82 /// file could actually be made.
83 enum class CodeGenFileType {
86 Null // Do not emit any output.
87 };
88
89 // Specify what functions should keep the frame pointer.
91
92 // Specify what type of zeroing callee-used registers.
93 namespace ZeroCallUsedRegs {
94 const unsigned ONLY_USED = 1U << 1;
95 const unsigned ONLY_GPR = 1U << 2;
96 const unsigned ONLY_ARG = 1U << 3;
97
98 enum class ZeroCallUsedRegsKind : unsigned int {
99 // Don't zero any call-used regs.
100 Skip = 1U << 0,
101 // Only zeros call-used GPRs used in the fn and pass args.
103 // Only zeros call-used GPRs used in the fn.
105 // Only zeros call-used regs used in the fn and pass args.
107 // Only zeros call-used regs used in the fn.
108 Used = ONLY_USED,
109 // Zeros all call-used GPRs that pass args.
111 // Zeros all call-used GPRs.
113 // Zeros all call-used regs that pass args.
115 // Zeros all call-used regs.
116 All = 0,
117 };
118 } // namespace ZeroCallUsedRegs
119
120 enum class UWTableKind {
121 None = 0, ///< No unwind table requested
122 Sync = 1, ///< "Synchronous" unwind tables
123 Async = 2, ///< "Asynchronous" unwind tables (instr precise)
124 Default = 2,
125 };
126
127 enum class FunctionReturnThunksKind : unsigned int {
128 Keep = 0, ///< No function return thunk.
129 Extern = 1, ///< Replace returns with jump to thunk, don't emit thunk.
130 Invalid = 2, ///< Not used.
131 };
132
133 } // namespace llvm
134
135#endif
This class is the base class for all object file types.
Definition: ObjectFile.h:229
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
std::optional< CodeGenOptLevel > getLevel(int OL)
Get the Level identified by the integer OL.
Definition: CodeGen.h:65
std::optional< CodeGenOptLevel > parseLevel(char C)
Parse C as a single digit integer and get matching CodeGenLevel.
Definition: CodeGen.h:73
@ DynamicNoPIC
Definition: CodeGen.h:25
@ ROPI_RWPI
Definition: CodeGen.h:25
@ GeneralDynamic
Definition: CodeGen.h:46
const unsigned ONLY_GPR
Definition: CodeGen.h:95
const unsigned ONLY_USED
Definition: CodeGen.h:94
const unsigned ONLY_ARG
Definition: CodeGen.h:96
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FramePointerKind
Definition: CodeGen.h:90
UWTableKind
Definition: CodeGen.h:120
@ 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:83
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:54
@ Default
The result values are uniform if and only if all operands are uniform.
FunctionReturnThunksKind
Definition: CodeGen.h:127
@ Keep
No function return thunk.
@ Extern
Replace returns with jump to thunk, don't emit thunk.