clang: lib/CodeGen/TargetInfo.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
20#include "llvm/ADT/StringExtras.h"
21#include "llvm/ADT/Twine.h"
22#include "llvm/IR/Function.h"
23#include "llvm/IR/Type.h"
24#include "llvm/Support/raw_ostream.h"
25
26using namespace clang;
28
30 raw_ostream &OS = llvm::errs();
31 OS << "(ABIArgInfo Kind=";
32 switch (TheKind) {
34 OS << "Direct Type=";
36 Ty->print(OS);
37 else
38 OS << "null";
39 break;
41 OS << "Extend";
42 break;
44 OS << "Ignore";
45 break;
48 break;
53 break;
58 break;
60 OS << "Expand";
61 break;
63 OS << "CoerceAndExpand Type=";
65 break;
67 OS << "TargetSpecific Type=";
69 Ty->print(OS);
70 else
71 OS << "null";
72 break;
73 }
74 OS << ")\n";
75}
76
78 : Info(std::move(Info)) {}
79
81
82
83
85 if (getABIInfo().getCodeGenOpts().hasSEHExceptions())
86 return getABIInfo().getDataLayout().getPointerSizeInBits() > 32 ? 64 : 48;
87
88
89
90
91
92
93 return 32;
94}
95
98
99
100
101
102 return false;
103}
104
105void
108
109
110
111 Opt = "-l";
112 Opt += Lib;
113}
114
117
118
119
120
121
122
123
124
125
126
127 return llvm::CallingConv::SPIR_KERNEL;
128 }
129 llvm_unreachable("Unknown kernel calling convention");
130}
131
134 FT = getABIInfo().getContext().adjustFunctionType(
136}
137
139 llvm::PointerType *T, QualType QT) const {
140 return llvm::ConstantPointerNull::get(T);
141}
142
144 const VarDecl *D) const {
147 "Address space agnostic languages only");
149}
150
153 llvm::Type *DestTy, bool isNonNull) const {
154
155
156 if (auto *C = dyn_castllvm::Constant(Src))
158
160 Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
161}
162
163llvm::Constant *
166 llvm::Type *DestTy) const {
167
168
169 return llvm::ConstantExpr::getPointerCast(Src, DestTy);
170}
171
172llvm::SyncScope::ID
175 llvm::AtomicOrdering Ordering,
176 llvm::LLVMContext &Ctx) const {
177 return Ctx.getOrInsertSyncScopeID("");
178}
179
182 if (llvm::Function *Fn = dyn_cast_or_nullllvm::Function(GV)) {
184 Fn->addFnAttr("stack-probe-size",
187 Fn->addFnAttr("no-stack-arg-probe");
188 }
189}
190
191
192
193
194
195
197 CodeGenFunction &CGF, llvm::Function *Invoke, llvm::Type *BlockTy) const {
198 auto *InvokeFT = Invoke->getFunctionType();
200 std::string Name = Invoke->getName().str() + "_kernel";
201 auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C),
202 InvokeFT->params(), false);
203 auto *F = llvm::Function::Create(FT, llvm::GlobalValue::ExternalLinkage, Name,
205 llvm::CallingConv::ID KernelCC =
207 F->setCallingConv(KernelCC);
208
209 llvm::AttrBuilder KernelAttrs(C);
210
211
213 F->addFnAttrs(KernelAttrs);
214
215 auto IP = CGF.Builder.saveIP();
216 auto *BB = llvm::BasicBlock::Create(C, "entry", F);
217 auto &Builder = CGF.Builder;
218 Builder.SetInsertPoint(BB);
220 llvm::CallInst *Call = Builder.CreateCall(Invoke, Args);
221 Call->setCallingConv(Invoke->getCallingConv());
222
223 Builder.CreateRetVoid();
224 Builder.restoreIP(IP);
225 return F;
226}
227
230
231
232
235 F.addFnAttr("sign-return-address-key", BPI.getSignKeyStr());
236 } else {
237 if (F.hasFnAttribute("sign-return-address"))
238 F.removeFnAttr("sign-return-address");
239 if (F.hasFnAttribute("sign-return-address-key"))
240 F.removeFnAttr("sign-return-address-key");
241 }
242
243 auto AddRemoveAttributeAsSet = [&](bool Set, const StringRef &ModAttr) {
245 F.addFnAttr(ModAttr);
246 else if (F.hasFnAttribute(ModAttr))
247 F.removeFnAttr(ModAttr);
248 };
249
251 "branch-target-enforcement");
253 "branch-protection-pauth-lr");
254 AddRemoveAttributeAsSet(BPI.GuardedControlStack, "guarded-control-stack");
255}
256
259
260
263 FuncAttrs.addAttribute("sign-return-address-key", BPI.getSignKeyStr());
264 }
266 FuncAttrs.addAttribute("branch-target-enforcement");
268 FuncAttrs.addAttribute("branch-protection-pauth-lr");
270 FuncAttrs.addAttribute("guarded-control-stack");
271}
272
275 auto UpdateAttr = [&F](bool AttrShouldExist, StringRef AttrName) {
276 if (AttrShouldExist && !F.hasFnAttribute(AttrName))
277 F.addFnAttr(AttrName);
278 if (!AttrShouldExist && F.hasFnAttribute(AttrName))
279 F.removeFnAttr(AttrName);
280 };
283 UpdateAttr(Opts.AuthTraps, "ptrauth-auth-traps");
284 UpdateAttr(Opts.IndirectGotos, "ptrauth-indirect-gotos");
286}
287
291 FuncAttrs.addAttribute("ptrauth-returns");
293 FuncAttrs.addAttribute("ptrauth-calls");
295 FuncAttrs.addAttribute("ptrauth-auth-traps");
297 FuncAttrs.addAttribute("ptrauth-indirect-gotos");
299 FuncAttrs.addAttribute("aarch64-jump-table-hardening");
300}
301
302namespace {
304public:
307};
308}
309
310std::unique_ptr
312 return std::make_unique(CGM.getTypes());
313}
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
unsigned getInAllocaFieldIndex() const
bool getIndirectByVal() const
llvm::StructType * getCoerceAndExpandType() const
bool getIndirectRealign() const
void dump() const
Definition TargetInfo.cpp:29
unsigned getIndirectAddrSpace() const
@ Extend
Extend - Valid only for integer argument types.
@ Ignore
Ignore - Ignore the argument (treat as void).
@ IndirectAliased
IndirectAliased - Similar to Indirect, but the pointer may be to an object that is otherwise referenc...
@ Expand
Expand - Only valid for aggregate argument types.
@ TargetSpecific
TargetSpecific - Some argument types are passed as target specific types such as RISC-V's tuple type,...
@ InAlloca
InAlloca - Pass the argument directly using the LLVM inalloca attribute.
@ Indirect
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
@ CoerceAndExpand
CoerceAndExpand - Only valid for aggregate argument types.
@ Direct
Direct - Pass the argument directly using the normal converted LLVM type, or by coercing to another s...
llvm::Type * getCoerceToType() const
CharUnits getIndirectAlign() const
Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, const llvm::Twine &Name="")
CallArgList - Type for representing both the value and type of arguments in a call.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
CodeGenTypes & getTypes() const
llvm::LLVMContext & getLLVMContext()
This class organizes the cross-function state that is used while generating LLVM code.
llvm::Module & getModule() const
const LangOptions & getLangOpts() const
CodeGenTypes & getTypes()
const CodeGenOptions & getCodeGenOpts() const
void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs)
Like the overload taking a Function &, but intended specifically for frontends that want to build on ...
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
unsigned ClangCallConvToLLVMCallConv(CallingConv CC)
Convert clang calling convention to LLVM callilng convention.
DefaultABIInfo - The default implementation for ABI specific details.
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
virtual unsigned getDeviceKernelCallingConv() const
Get LLVM calling convention for device kernels.
Definition TargetInfo.cpp:115
virtual unsigned getSizeOfUnwindException() const
Determines the size of struct _Unwind_Exception on this platform, in 8-bit units.
Definition TargetInfo.cpp:84
virtual void setOCLKernelStubCallingConvention(const FunctionType *&FT) const
Definition TargetInfo.cpp:132
virtual void getDependentLibraryOption(llvm::StringRef Lib, llvm::SmallString< 24 > &Opt) const
Gets the linker options necessary to link a dependent library on this platform.
Definition TargetInfo.cpp:106
Address performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, Address Addr, LangAS SrcAddr, llvm::Type *DestTy, bool IsNonNull=false) const
virtual llvm::SyncScope::ID getLLVMSyncScopeID(const LangOptions &LangOpts, SyncScope Scope, llvm::AtomicOrdering Ordering, llvm::LLVMContext &Ctx) const
Get the syncscope used in LLVM IR.
Definition TargetInfo.cpp:173
static void setBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI, llvm::Function &F)
Definition TargetInfo.cpp:228
const T & getABIInfo() const
static void initPointerAuthFnAttributes(const PointerAuthOptions &Opts, llvm::AttrBuilder &FuncAttrs)
Definition TargetInfo.cpp:288
static void setPointerAuthFnAttributes(const PointerAuthOptions &Opts, llvm::Function &F)
Definition TargetInfo.cpp:273
virtual LangAS getGlobalVarAddressSpace(CodeGenModule &CGM, const VarDecl *D) const
Get target favored AST address space of a global variable for languages other than OpenCL and CUDA.
Definition TargetInfo.cpp:143
void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const
Definition TargetInfo.cpp:180
virtual llvm::Constant * getNullPointer(const CodeGen::CodeGenModule &CGM, llvm::PointerType *T, QualType QT) const
Get target specific null pointer.
Definition TargetInfo.cpp:138
static void initBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI, llvm::AttrBuilder &FuncAttrs)
Definition TargetInfo.cpp:257
TargetCodeGenInfo(std::unique_ptr< ABIInfo > Info)
Definition TargetInfo.cpp:77
virtual llvm::Value * createEnqueuedBlockKernel(CodeGenFunction &CGF, llvm::Function *BlockInvokeFunc, llvm::Type *BlockTy) const
Create an OpenCL kernel for an enqueued block.
Definition TargetInfo.cpp:196
virtual ~TargetCodeGenInfo()
virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args, const FunctionNoProtoType *fnType) const
Determine whether a call to an unprototyped functions under the given calling convention should use t...
Definition TargetInfo.cpp:96
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
ExtInfo withCallingConv(CallingConv cc) const
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
@ None
No signing for any function.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A (possibly-)qualified type.
LangAS getAddressSpace() const
Return the address space of this type.
Scope - A scope is a transient data structure that is used while parsing the program.
LangOptions::SignReturnAddressScopeKind SignReturnAddr
const char * getSignKeyStr() const
bool BranchProtectionPAuthLR
bool BranchTargetEnforcement
const char * getSignReturnAddrStr() const
Represents a variable declaration or definition.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
std::unique_ptr< TargetCodeGenInfo > createDefaultTargetCodeGenInfo(CodeGenModule &CGM)
Definition TargetInfo.cpp:311
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
LangAS
Defines the address space values used by the address space qualifier of QualType.
SyncScope
Defines sync scope values used internally by clang.
bool ReturnAddresses
Should return addresses be authenticated?
bool AArch64JumpTableHardening
Use hardened lowering for jump-table dispatch?
PointerAuthSchema FunctionPointers
The ABI for C function pointers.
bool AuthTraps
Do authentication failures cause a trap?
bool IndirectGotos
Do indirect goto label addresses need to be authenticated?