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;

27using namespace CodeGen;

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;

66 }

67 OS << ")\n";

68}

69

71 : Info(std::move(Info)) {}

72

74

75

76

78

79

80

81

82

83

84 return 32;

85}

86

89

90

91

92

93 return false;

94}

95

96void

99

100

101

102 Opt = "-l";

103 Opt += Lib;

104}

105

107

108

109

110

111

112

113

114

115

116

117 return llvm::CallingConv::SPIR_KERNEL;

118}

119

121 llvm::PointerType *T, QualType QT) const {

122 return llvm::ConstantPointerNull::get(T);

123}

124

129 "Address space agnostic languages only");

131}

132

135 LangAS DestAddr, llvm::Type *DestTy, bool isNonNull) const {

136

137

138 if (auto *C = dyn_castllvm::Constant(Src))

140

142 Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");

143}

144

145llvm::Constant *

148 llvm::Type *DestTy) const {

149

150

151 return llvm::ConstantExpr::getPointerCast(Src, DestTy);

152}

153

154llvm::SyncScope::ID

157 llvm::AtomicOrdering Ordering,

158 llvm::LLVMContext &Ctx) const {

159 return Ctx.getOrInsertSyncScopeID("");

160}

161

164 if (llvm::Function *Fn = dyn_cast_or_nullllvm::Function(GV)) {

166 Fn->addFnAttr("stack-probe-size",

169 Fn->addFnAttr("no-stack-arg-probe");

170 }

171}

172

173

174

175

176

177

179 CodeGenFunction &CGF, llvm::Function *Invoke, llvm::Type *BlockTy) const {

180 auto *InvokeFT = Invoke->getFunctionType();

182 std::string Name = Invoke->getName().str() + "_kernel";

183 auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C),

184 InvokeFT->params(), false);

185 auto *F = llvm::Function::Create(FT, llvm::GlobalValue::ExternalLinkage, Name,

187 llvm::CallingConv::ID KernelCC =

189 F->setCallingConv(KernelCC);

190

191 llvm::AttrBuilder KernelAttrs(C);

192

193

195 F->addFnAttrs(KernelAttrs);

196

197 auto IP = CGF.Builder.saveIP();

198 auto *BB = llvm::BasicBlock::Create(C, "entry", F);

199 auto &Builder = CGF.Builder;

200 Builder.SetInsertPoint(BB);

202 llvm::CallInst *Call = Builder.CreateCall(Invoke, Args);

203 Call->setCallingConv(Invoke->getCallingConv());

204

205 Builder.CreateRetVoid();

206 Builder.restoreIP(IP);

207 return F;

208}

209

212

213

214

217 F.addFnAttr("sign-return-address-key", BPI.getSignKeyStr());

218 } else {

219 if (F.hasFnAttribute("sign-return-address"))

220 F.removeFnAttr("sign-return-address");

221 if (F.hasFnAttribute("sign-return-address-key"))

222 F.removeFnAttr("sign-return-address-key");

223 }

224

225 auto AddRemoveAttributeAsSet = [&](bool Set, const StringRef &ModAttr) {

227 F.addFnAttr(ModAttr);

228 else if (F.hasFnAttribute(ModAttr))

229 F.removeFnAttr(ModAttr);

230 };

231

233 "branch-target-enforcement");

235 "branch-protection-pauth-lr");

236 AddRemoveAttributeAsSet(BPI.GuardedControlStack, "guarded-control-stack");

237}

238

241

242

245 FuncAttrs.addAttribute("sign-return-address-key", BPI.getSignKeyStr());

246 }

248 FuncAttrs.addAttribute("branch-target-enforcement");

250 FuncAttrs.addAttribute("branch-protection-pauth-lr");

252 FuncAttrs.addAttribute("guarded-control-stack");

253}

254

255namespace {

257public:

260};

261}

262

263std::unique_ptr

265 return std::make_unique(CGM.getTypes());

266}

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.

@ 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 getSizeOfUnwindException() const

Determines the size of struct _Unwind_Exception on this platform, in 8-bit units.

virtual void getDependentLibraryOption(llvm::StringRef Lib, llvm::SmallString< 24 > &Opt) const

Gets the linker options necessary to link a dependent library on this platform.

Address performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, Address Addr, LangAS SrcAddr, LangAS DestAddr, 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.

static void setBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI, llvm::Function &F)

virtual unsigned getOpenCLKernelCallingConv() const

Get LLVM calling convention for OpenCL kernel.

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...

Decl - This represents one declaration (or definition), e.g.

Represents a K&R-style 'int foo()' function, which has no information available about its arguments.

@ 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.

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.

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.

const FunctionProtoType * T

SyncScope

Defines synch scope values used internally by clang.