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"
30 raw_ostream &OS = llvm::errs();
31 OS <<
"(ABIArgInfo Kind=";
63 OS <<
"CoerceAndExpand Type=";
67 OS <<
"TargetSpecific Type=";
78 : Info(
std::move(Info)) {}
85 if (
getABIInfo().getCodeGenOpts().hasSEHExceptions())
86 return getABIInfo().getDataLayout().getPointerSizeInBits() > 32 ? 64 : 48;
124 "Kernel calling convention only defined for OpenCL");
125 return llvm::CallingConv::C;
130 FT =
getABIInfo().getContext().adjustFunctionType(
135 llvm::PointerType *T,
QualType QT)
const {
136 return llvm::ConstantPointerNull::get(T);
143 "Address space agnostic languages only");
150 llvm::AtomicOrdering Ordering)
const {
157 llvm::AtomicOrdering Ordering,
158 llvm::LLVMContext &Ctx)
const {
159 return Ctx.getOrInsertSyncScopeID(
165 if (llvm::Function *Fn = dyn_cast_or_null<llvm::Function>(GV)) {
167 Fn->addFnAttr(
"stack-probe-size",
170 Fn->addFnAttr(
"no-stack-arg-probe");
180 CodeGenFunction &CGF, llvm::Function *Invoke, llvm::Type *BlockTy)
const {
181 auto *InvokeFT = Invoke->getFunctionType();
183 std::string Name = Invoke->getName().str() +
"_kernel";
184 auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(
C),
185 InvokeFT->params(),
false);
186 auto *F = llvm::Function::Create(FT, llvm::GlobalValue::ExternalLinkage, Name,
188 llvm::CallingConv::ID KernelCC =
190 F->setCallingConv(KernelCC);
192 llvm::AttrBuilder KernelAttrs(
C);
196 F->addFnAttrs(KernelAttrs);
198 auto IP = CGF.
Builder.saveIP();
199 auto *BB = llvm::BasicBlock::Create(
C,
"entry", F);
201 Builder.SetInsertPoint(BB);
203 llvm::CallInst *
Call = Builder.CreateCall(Invoke, Args);
204 Call->setCallingConv(Invoke->getCallingConv());
206 Builder.CreateRetVoid();
207 Builder.restoreIP(IP);
220 if (F.hasFnAttribute(
"sign-return-address"))
221 F.removeFnAttr(
"sign-return-address");
222 if (F.hasFnAttribute(
"sign-return-address-key"))
223 F.removeFnAttr(
"sign-return-address-key");
226 auto AddRemoveAttributeAsSet = [&](
bool Set,
const StringRef &ModAttr) {
228 F.addFnAttr(ModAttr);
229 else if (F.hasFnAttribute(ModAttr))
230 F.removeFnAttr(ModAttr);
234 "branch-target-enforcement");
236 "branch-protection-pauth-lr");
246 FuncAttrs.addAttribute(
"sign-return-address-key", BPI.
getSignKeyStr());
249 FuncAttrs.addAttribute(
"branch-target-enforcement");
251 FuncAttrs.addAttribute(
"branch-protection-pauth-lr");
253 FuncAttrs.addAttribute(
"guarded-control-stack");
258 auto UpdateAttr = [&F](
bool AttrShouldExist, StringRef AttrName) {
259 if (AttrShouldExist && !F.hasFnAttribute(AttrName))
260 F.addFnAttr(AttrName);
261 if (!AttrShouldExist && F.hasFnAttribute(AttrName))
262 F.removeFnAttr(AttrName);
266 UpdateAttr(Opts.
AuthTraps,
"ptrauth-auth-traps");
274 FuncAttrs.addAttribute(
"ptrauth-returns");
276 FuncAttrs.addAttribute(
"ptrauth-calls");
278 FuncAttrs.addAttribute(
"ptrauth-auth-traps");
280 FuncAttrs.addAttribute(
"ptrauth-indirect-gotos");
282 FuncAttrs.addAttribute(
"aarch64-jump-table-hardening");
293std::unique_ptr<TargetCodeGenInfo>
295 return std::make_unique<DefaultTargetCodeGenInfo>(CGM.
getTypes());
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
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
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.
virtual unsigned getSizeOfUnwindException() const
Determines the size of struct _Unwind_Exception on this platform, in 8-bit units.
virtual void setOCLKernelStubCallingConvention(const FunctionType *&FT) const
virtual void getDependentLibraryOption(llvm::StringRef Lib, llvm::SmallString< 24 > &Opt) const
Gets the linker options necessary to link a dependent library on this platform.
virtual StringRef getLLVMSyncScopeStr(const LangOptions &LangOpts, SyncScope Scope, llvm::AtomicOrdering Ordering) const
Get the syncscope used in LLVM IR as a string.
llvm::SyncScope::ID getLLVMSyncScopeID(const LangOptions &LangOpts, SyncScope Scope, llvm::AtomicOrdering Ordering, llvm::LLVMContext &Ctx) const
Get the syncscope used in LLVM IR as a SyncScope ID.
static void setBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI, llvm::Function &F)
const T & getABIInfo() const
static void initPointerAuthFnAttributes(const PointerAuthOptions &Opts, llvm::AttrBuilder &FuncAttrs)
static void setPointerAuthFnAttributes(const PointerAuthOptions &Opts, llvm::Function &F)
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.
void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const
virtual llvm::Constant * getNullPointer(const CodeGen::CodeGenModule &CGM, llvm::PointerType *T, QualType QT) const
Get target specific null pointer.
static void initBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI, llvm::AttrBuilder &FuncAttrs)
TargetCodeGenInfo(std::unique_ptr< ABIInfo > Info)
virtual llvm::Value * createEnqueuedBlockKernel(CodeGenFunction &CGF, llvm::Function *BlockInvokeFunc, llvm::Type *BlockTy) const
Create an OpenCL kernel for an enqueued block.
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...
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)
The JSON file list parser is used to communicate input to InstallAPI.
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?