LLVM 18.0.0git
SPIRVCallLowering.cpp
Go to the documentation of this file.
1//===--- SPIRVCallLowering.cpp - Call lowering ------------------*- 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 implements the lowering of LLVM calls to machine code calls for
10// GlobalISel.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SPIRVCallLowering.h"
16#include "SPIRV.h"
17#include "SPIRVBuiltins.h"
18#include "SPIRVGlobalRegistry.h"
19#include "SPIRVISelLowering.h"
20#include "SPIRVRegisterInfo.h"
21#include "SPIRVSubtarget.h"
22#include "SPIRVUtils.h"
24#include "llvm/Support/ModRef.h"
25
26using namespace llvm;
27
30 : CallLowering(&TLI), GR(GR) {}
31
33 const Value *Val, ArrayRef<Register> VRegs,
35 Register SwiftErrorVReg) const {
36 // Currently all return types should use a single register.
37 // TODO: handle the case of multiple registers.
38 if (VRegs.size() > 1)
39 return false;
40 if (Val) {
41 const auto &STI = MIRBuilder.getMF().getSubtarget();
42 return MIRBuilder.buildInstr(SPIRV::OpReturnValue)
43 .addUse(VRegs[0])
44 .constrainAllUses(MIRBuilder.getTII(), *STI.getRegisterInfo(),
45 *STI.getRegBankInfo());
46 }
47 MIRBuilder.buildInstr(SPIRV::OpReturn);
48 return true;
49}
50
51// Based on the LLVM function attributes, get a SPIR-V FunctionControl.
53 MemoryEffects MemEffects = F.getMemoryEffects();
54
55 uint32_t FuncControl = static_cast<uint32_t>(SPIRV::FunctionControl::None);
56
57 if (F.hasFnAttribute(Attribute::AttrKind::NoInline))
58 FuncControl |= static_cast<uint32_t>(SPIRV::FunctionControl::DontInline);
59 else if (F.hasFnAttribute(Attribute::AttrKind::AlwaysInline))
60 FuncControl |= static_cast<uint32_t>(SPIRV::FunctionControl::Inline);
61
62 if (MemEffects.doesNotAccessMemory())
63 FuncControl |= static_cast<uint32_t>(SPIRV::FunctionControl::Pure);
64 else if (MemEffects.onlyReadsMemory())
65 FuncControl |= static_cast<uint32_t>(SPIRV::FunctionControl::Const);
66
67 return FuncControl;
68}
69
70static ConstantInt *getConstInt(MDNode *MD, unsigned NumOp) {
71 if (MD->getNumOperands() > NumOp) {
72 auto *CMeta = dyn_cast<ConstantAsMetadata>(MD->getOperand(NumOp));
73 if (CMeta)
74 return dyn_cast<ConstantInt>(CMeta->getValue());
75 }
76 return nullptr;
77}
78
79// This code restores function args/retvalue types for composite cases
80// because the final types should still be aggregate whereas they're i32
81// during the translation to cope with aggregate flattening etc.
83 auto *NamedMD = F.getParent()->getNamedMetadata("spv.cloned_funcs");
84 if (NamedMD == nullptr)
85 return F.getFunctionType();
86
87 Type *RetTy = F.getFunctionType()->getReturnType();
89 for (auto &Arg : F.args())
90 ArgTypes.push_back(Arg.getType());
91
92 auto ThisFuncMDIt =
93 std::find_if(NamedMD->op_begin(), NamedMD->op_end(), [&F](MDNode *N) {
94 return isa<MDString>(N->getOperand(0)) &&
95 cast<MDString>(N->getOperand(0))->getString() == F.getName();
96 });
97 // TODO: probably one function can have numerous type mutations,
98 // so we should support this.
99 if (ThisFuncMDIt != NamedMD->op_end()) {
100 auto *ThisFuncMD = *ThisFuncMDIt;
101 MDNode *MD = dyn_cast<MDNode>(ThisFuncMD->getOperand(1));
102 assert(MD && "MDNode operand is expected");
103 ConstantInt *Const = getConstInt(MD, 0);
104 if (Const) {
105 auto *CMeta = dyn_cast<ConstantAsMetadata>(MD->getOperand(1));
106 assert(CMeta && "ConstantAsMetadata operand is expected");
107 assert(Const->getSExtValue() >= -1);
108 // Currently -1 indicates return value, greater values mean
109 // argument numbers.
110 if (Const->getSExtValue() == -1)
111 RetTy = CMeta->getType();
112 else
113 ArgTypes[Const->getSExtValue()] = CMeta->getType();
114 }
115 }
116
117 return FunctionType::get(RetTy, ArgTypes, F.isVarArg());
118}
119
120static MDString *getKernelArgAttribute(const Function &KernelFunction,
121 unsigned ArgIdx,
122 const StringRef AttributeName) {
123 assert(KernelFunction.getCallingConv() == CallingConv::SPIR_KERNEL &&
124 "Kernel attributes are attached/belong only to kernel functions");
125
126 // Lookup the argument attribute in metadata attached to the kernel function.
127 MDNode *Node = KernelFunction.getMetadata(AttributeName);
128 if (Node && ArgIdx < Node->getNumOperands())
129 return cast<MDString>(Node->getOperand(ArgIdx));
130
131 // Sometimes metadata containing kernel attributes is not attached to the
132 // function, but can be found in the named module-level metadata instead.
133 // For example:
134 // !opencl.kernels = !{!0}
135 // !0 = !{void ()* @someKernelFunction, !1, ...}
136 // !1 = !{!"kernel_arg_addr_space", ...}
137 // In this case the actual index of searched argument attribute is ArgIdx + 1,
138 // since the first metadata node operand is occupied by attribute name
139 // ("kernel_arg_addr_space" in the example above).
140 unsigned MDArgIdx = ArgIdx + 1;
141 NamedMDNode *OpenCLKernelsMD =
142 KernelFunction.getParent()->getNamedMetadata("opencl.kernels");
143 if (!OpenCLKernelsMD || OpenCLKernelsMD->getNumOperands() == 0)
144 return nullptr;
145
146 // KernelToMDNodeList contains kernel function declarations followed by
147 // corresponding MDNodes for each attribute. Search only MDNodes "belonging"
148 // to the currently lowered kernel function.
149 MDNode *KernelToMDNodeList = OpenCLKernelsMD->getOperand(0);
150 bool FoundLoweredKernelFunction = false;
151 for (const MDOperand &Operand : KernelToMDNodeList->operands()) {
152 ValueAsMetadata *MaybeValue = dyn_cast<ValueAsMetadata>(Operand);
153 if (MaybeValue && dyn_cast<Function>(MaybeValue->getValue())->getName() ==
154 KernelFunction.getName()) {
155 FoundLoweredKernelFunction = true;
156 continue;
157 }
158 if (MaybeValue && FoundLoweredKernelFunction)
159 return nullptr;
160
161 MDNode *MaybeNode = dyn_cast<MDNode>(Operand);
162 if (FoundLoweredKernelFunction && MaybeNode &&
163 cast<MDString>(MaybeNode->getOperand(0))->getString() ==
164 AttributeName &&
165 MDArgIdx < MaybeNode->getNumOperands())
166 return cast<MDString>(MaybeNode->getOperand(MDArgIdx));
167 }
168 return nullptr;
169}
170
171static SPIRV::AccessQualifier::AccessQualifier
172getArgAccessQual(const Function &F, unsigned ArgIdx) {
173 if (F.getCallingConv() != CallingConv::SPIR_KERNEL)
174 return SPIRV::AccessQualifier::ReadWrite;
175
176 MDString *ArgAttribute =
177 getKernelArgAttribute(F, ArgIdx, "kernel_arg_access_qual");
178 if (!ArgAttribute)
179 return SPIRV::AccessQualifier::ReadWrite;
180
181 if (ArgAttribute->getString().compare("read_only") == 0)
182 return SPIRV::AccessQualifier::ReadOnly;
183 if (ArgAttribute->getString().compare("write_only") == 0)
184 return SPIRV::AccessQualifier::WriteOnly;
185 return SPIRV::AccessQualifier::ReadWrite;
186}
187
188static std::vector<SPIRV::Decoration::Decoration>
189getKernelArgTypeQual(const Function &KernelFunction, unsigned ArgIdx) {
190 MDString *ArgAttribute =
191 getKernelArgAttribute(KernelFunction, ArgIdx, "kernel_arg_type_qual");
192 if (ArgAttribute && ArgAttribute->getString().compare("volatile") == 0)
193 return {SPIRV::Decoration::Volatile};
194 return {};
195}
196
197static Type *getArgType(const Function &F, unsigned ArgIdx) {
198 Type *OriginalArgType = getOriginalFunctionType(F)->getParamType(ArgIdx);
199 if (F.getCallingConv() != CallingConv::SPIR_KERNEL ||
200 isSpecialOpaqueType(OriginalArgType))
201 return OriginalArgType;
202
203 MDString *MDKernelArgType =
204 getKernelArgAttribute(F, ArgIdx, "kernel_arg_type");
205 if (!MDKernelArgType || !MDKernelArgType->getString().endswith("_t"))
206 return OriginalArgType;
207
208 std::string KernelArgTypeStr = "opencl." + MDKernelArgType->getString().str();
209 Type *ExistingOpaqueType =
210 StructType::getTypeByName(F.getContext(), KernelArgTypeStr);
211 return ExistingOpaqueType
212 ? ExistingOpaqueType
213 : StructType::create(F.getContext(), KernelArgTypeStr);
214}
215
216static bool isEntryPoint(const Function &F) {
217 // OpenCL handling: any function with the SPIR_KERNEL
218 // calling convention will be a potential entry point.
219 if (F.getCallingConv() == CallingConv::SPIR_KERNEL)
220 return true;
221
222 // HLSL handling: special attribute are emitted from the
223 // front-end.
224 if (F.getFnAttribute("hlsl.shader").isValid())
225 return true;
226
227 return false;
228}
229
230static SPIRV::ExecutionModel::ExecutionModel
232 if (STI.isOpenCLEnv())
233 return SPIRV::ExecutionModel::Kernel;
234
235 auto attribute = F.getFnAttribute("hlsl.shader");
236 if (!attribute.isValid()) {
238 "This entry point lacks mandatory hlsl.shader attribute.");
239 }
240
241 const auto value = attribute.getValueAsString();
242 if (value == "compute")
243 return SPIRV::ExecutionModel::GLCompute;
244
245 report_fatal_error("This HLSL entry point is not supported by this backend.");
246}
247
249 const Function &F,
251 FunctionLoweringInfo &FLI) const {
252 assert(GR && "Must initialize the SPIRV type registry before lowering args.");
253 GR->setCurrentFunc(MIRBuilder.getMF());
254
255 // Assign types and names to all args, and store their types for later.
257 SmallVector<SPIRVType *, 4> ArgTypeVRegs;
258 if (VRegs.size() > 0) {
259 unsigned i = 0;
260 for (const auto &Arg : F.args()) {
261 // Currently formal args should use single registers.
262 // TODO: handle the case of multiple registers.
263 if (VRegs[i].size() > 1)
264 return false;
265 SPIRV::AccessQualifier::AccessQualifier ArgAccessQual =
267 auto *SpirvTy = GR->assignTypeToVReg(getArgType(F, i), VRegs[i][0],
268 MIRBuilder, ArgAccessQual);
269 ArgTypeVRegs.push_back(SpirvTy);
270
271 if (Arg.hasName())
272 buildOpName(VRegs[i][0], Arg.getName(), MIRBuilder);
273 if (Arg.getType()->isPointerTy()) {
274 auto DerefBytes = static_cast<unsigned>(Arg.getDereferenceableBytes());
275 if (DerefBytes != 0)
276 buildOpDecorate(VRegs[i][0], MIRBuilder,
277 SPIRV::Decoration::MaxByteOffset, {DerefBytes});
278 }
279 if (Arg.hasAttribute(Attribute::Alignment)) {
280 auto Alignment = static_cast<unsigned>(
281 Arg.getAttribute(Attribute::Alignment).getValueAsInt());
282 buildOpDecorate(VRegs[i][0], MIRBuilder, SPIRV::Decoration::Alignment,
283 {Alignment});
284 }
285 if (Arg.hasAttribute(Attribute::ReadOnly)) {
286 auto Attr =
287 static_cast<unsigned>(SPIRV::FunctionParameterAttribute::NoWrite);
288 buildOpDecorate(VRegs[i][0], MIRBuilder,
289 SPIRV::Decoration::FuncParamAttr, {Attr});
290 }
291 if (Arg.hasAttribute(Attribute::ZExt)) {
292 auto Attr =
293 static_cast<unsigned>(SPIRV::FunctionParameterAttribute::Zext);
294 buildOpDecorate(VRegs[i][0], MIRBuilder,
295 SPIRV::Decoration::FuncParamAttr, {Attr});
296 }
297 if (Arg.hasAttribute(Attribute::NoAlias)) {
298 auto Attr =
299 static_cast<unsigned>(SPIRV::FunctionParameterAttribute::NoAlias);
300 buildOpDecorate(VRegs[i][0], MIRBuilder,
301 SPIRV::Decoration::FuncParamAttr, {Attr});
302 }
303
304 if (F.getCallingConv() == CallingConv::SPIR_KERNEL) {
305 std::vector<SPIRV::Decoration::Decoration> ArgTypeQualDecs =
307 for (SPIRV::Decoration::Decoration Decoration : ArgTypeQualDecs)
308 buildOpDecorate(VRegs[i][0], MIRBuilder, Decoration, {});
309 }
310
311 MDNode *Node = F.getMetadata("spirv.ParameterDecorations");
312 if (Node && i < Node->getNumOperands() &&
313 isa<MDNode>(Node->getOperand(i))) {
314 MDNode *MD = cast<MDNode>(Node->getOperand(i));
315 for (const MDOperand &MDOp : MD->operands()) {
316 MDNode *MD2 = dyn_cast<MDNode>(MDOp);
317 assert(MD2 && "Metadata operand is expected");
318 ConstantInt *Const = getConstInt(MD2, 0);
319 assert(Const && "MDOperand should be ConstantInt");
320 auto Dec =
321 static_cast<SPIRV::Decoration::Decoration>(Const->getZExtValue());
322 std::vector<uint32_t> DecVec;
323 for (unsigned j = 1; j < MD2->getNumOperands(); j++) {
324 ConstantInt *Const = getConstInt(MD2, j);
325 assert(Const && "MDOperand should be ConstantInt");
326 DecVec.push_back(static_cast<uint32_t>(Const->getZExtValue()));
327 }
328 buildOpDecorate(VRegs[i][0], MIRBuilder, Dec, DecVec);
329 }
330 }
331 ++i;
332 }
333 }
334
335 // Generate a SPIR-V type for the function.
336 auto MRI = MIRBuilder.getMRI();
337 Register FuncVReg = MRI->createGenericVirtualRegister(LLT::scalar(32));
338 MRI->setRegClass(FuncVReg, &SPIRV::IDRegClass);
339 if (F.isDeclaration())
340 GR->add(&F, &MIRBuilder.getMF(), FuncVReg);
341 SPIRVType *RetTy = GR->getOrCreateSPIRVType(FTy->getReturnType(), MIRBuilder);
343 FTy, RetTy, ArgTypeVRegs, MIRBuilder);
344
345 // Build the OpTypeFunction declaring it.
346 uint32_t FuncControl = getFunctionControl(F);
347
348 MIRBuilder.buildInstr(SPIRV::OpFunction)
349 .addDef(FuncVReg)
351 .addImm(FuncControl)
352 .addUse(GR->getSPIRVTypeID(FuncTy));
353
354 // Add OpFunctionParameters.
355 int i = 0;
356 for (const auto &Arg : F.args()) {
357 assert(VRegs[i].size() == 1 && "Formal arg has multiple vregs");
358 MRI->setRegClass(VRegs[i][0], &SPIRV::IDRegClass);
359 MIRBuilder.buildInstr(SPIRV::OpFunctionParameter)
360 .addDef(VRegs[i][0])
361 .addUse(GR->getSPIRVTypeID(ArgTypeVRegs[i]));
362 if (F.isDeclaration())
363 GR->add(&Arg, &MIRBuilder.getMF(), VRegs[i][0]);
364 i++;
365 }
366 // Name the function.
367 if (F.hasName())
368 buildOpName(FuncVReg, F.getName(), MIRBuilder);
369
370 // Handle entry points and function linkage.
371 if (isEntryPoint(F)) {
372 const auto &STI = MIRBuilder.getMF().getSubtarget<SPIRVSubtarget>();
373 auto executionModel = getExecutionModel(STI, F);
374 auto MIB = MIRBuilder.buildInstr(SPIRV::OpEntryPoint)
375 .addImm(static_cast<uint32_t>(executionModel))
376 .addUse(FuncVReg);
377 addStringImm(F.getName(), MIB);
378 } else if (F.getLinkage() == GlobalValue::LinkageTypes::ExternalLinkage ||
379 F.getLinkage() == GlobalValue::LinkOnceODRLinkage) {
380 auto LnkTy = F.isDeclaration() ? SPIRV::LinkageType::Import
381 : SPIRV::LinkageType::Export;
382 buildOpDecorate(FuncVReg, MIRBuilder, SPIRV::Decoration::LinkageAttributes,
383 {static_cast<uint32_t>(LnkTy)}, F.getGlobalIdentifier());
384 }
385
386 return true;
387}
388
390 CallLoweringInfo &Info) const {
391 // Currently call returns should have single vregs.
392 // TODO: handle the case of multiple registers.
393 if (Info.OrigRet.Regs.size() > 1)
394 return false;
395 MachineFunction &MF = MIRBuilder.getMF();
396 GR->setCurrentFunc(MF);
397 FunctionType *FTy = nullptr;
398 const Function *CF = nullptr;
399
400 // Emit a regular OpFunctionCall. If it's an externally declared function,
401 // be sure to emit its type and function declaration here. It will be hoisted
402 // globally later.
403 if (Info.Callee.isGlobal()) {
404 CF = dyn_cast_or_null<const Function>(Info.Callee.getGlobal());
405 // TODO: support constexpr casts and indirect calls.
406 if (CF == nullptr)
407 return false;
408 FTy = getOriginalFunctionType(*CF);
409 }
410
411 MachineRegisterInfo *MRI = MIRBuilder.getMRI();
412 Register ResVReg =
413 Info.OrigRet.Regs.empty() ? Register(0) : Info.OrigRet.Regs[0];
414 std::string FuncName = Info.Callee.getGlobal()->getName().str();
415 std::string DemangledName = getOclOrSpirvBuiltinDemangledName(FuncName);
416 const auto *ST = static_cast<const SPIRVSubtarget *>(&MF.getSubtarget());
417 // TODO: check that it's OCL builtin, then apply OpenCL_std.
418 if (!DemangledName.empty() && CF && CF->isDeclaration() &&
419 ST->canUseExtInstSet(SPIRV::InstructionSet::OpenCL_std)) {
420 const Type *OrigRetTy = Info.OrigRet.Ty;
421 if (FTy)
422 OrigRetTy = FTy->getReturnType();
424 for (auto Arg : Info.OrigArgs) {
425 assert(Arg.Regs.size() == 1 && "Call arg has multiple VRegs");
426 ArgVRegs.push_back(Arg.Regs[0]);
427 SPIRVType *SPIRVTy = GR->getOrCreateSPIRVType(Arg.Ty, MIRBuilder);
428 GR->assignSPIRVTypeToVReg(SPIRVTy, Arg.Regs[0], MIRBuilder.getMF());
429 }
430 if (auto Res = SPIRV::lowerBuiltin(
431 DemangledName, SPIRV::InstructionSet::OpenCL_std, MIRBuilder,
432 ResVReg, OrigRetTy, ArgVRegs, GR))
433 return *Res;
434 }
435 if (CF && CF->isDeclaration() &&
436 !GR->find(CF, &MIRBuilder.getMF()).isValid()) {
437 // Emit the type info and forward function declaration to the first MBB
438 // to ensure VReg definition dependencies are valid across all MBBs.
439 MachineIRBuilder FirstBlockBuilder;
440 FirstBlockBuilder.setMF(MF);
441 FirstBlockBuilder.setMBB(*MF.getBlockNumbered(0));
442
445 for (const Argument &Arg : CF->args()) {
446 if (MIRBuilder.getDataLayout().getTypeStoreSize(Arg.getType()).isZero())
447 continue; // Don't handle zero sized types.
448 Register Reg = MRI->createGenericVirtualRegister(LLT::scalar(32));
449 MRI->setRegClass(Reg, &SPIRV::IDRegClass);
450 ToInsert.push_back({Reg});
451 VRegArgs.push_back(ToInsert.back());
452 }
453 // TODO: Reuse FunctionLoweringInfo
454 FunctionLoweringInfo FuncInfo;
455 lowerFormalArguments(FirstBlockBuilder, *CF, VRegArgs, FuncInfo);
456 }
457
458 // Make sure there's a valid return reg, even for functions returning void.
459 if (!ResVReg.isValid())
460 ResVReg = MIRBuilder.getMRI()->createVirtualRegister(&SPIRV::IDRegClass);
461 SPIRVType *RetType =
462 GR->assignTypeToVReg(FTy->getReturnType(), ResVReg, MIRBuilder);
463
464 // Emit the OpFunctionCall and its args.
465 auto MIB = MIRBuilder.buildInstr(SPIRV::OpFunctionCall)
466 .addDef(ResVReg)
467 .addUse(GR->getSPIRVTypeID(RetType))
468 .add(Info.Callee);
469
470 for (const auto &Arg : Info.OrigArgs) {
471 // Currently call args should have single vregs.
472 if (Arg.Regs.size() > 1)
473 return false;
474 MIB.addUse(Arg.Regs[0]);
475 }
476 return MIB.constrainAllUses(MIRBuilder.getTII(), *ST->getRegisterInfo(),
477 *ST->getRegBankInfo());
478}
unsigned const MachineRegisterInfo * MRI
static AMDGPULibFunc::EType getArgType(const AMDGPULibFunc &FInfo)
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
return RetTy
Given that RA is a live value
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static ConstantInt * getConstInt(MDNode *MD, unsigned NumOp)
static std::vector< SPIRV::Decoration::Decoration > getKernelArgTypeQual(const Function &KernelFunction, unsigned ArgIdx)
static uint32_t getFunctionControl(const Function &F)
static SPIRV::ExecutionModel::ExecutionModel getExecutionModel(const SPIRVSubtarget &STI, const Function &F)
static FunctionType * getOriginalFunctionType(const Function &F)
static SPIRV::AccessQualifier::AccessQualifier getArgAccessQual(const Function &F, unsigned ArgIdx)
static bool isEntryPoint(const Function &F)
static MDString * getKernelArgAttribute(const Function &KernelFunction, unsigned ArgIdx, const StringRef AttributeName)
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
This is the shared class of boolean and integer constants.
Definition: Constants.h:78
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition: DataLayout.h:472
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
Class to represent function types.
Definition: DerivedTypes.h:103
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:135
Type * getReturnType() const
Definition: DerivedTypes.h:124
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
iterator_range< arg_iterator > args()
Definition: Function.h:802
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:239
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1354
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:273
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:51
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition: LowLevelType.h:42
Metadata node.
Definition: Metadata.h:950
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1303
ArrayRef< MDOperand > operands() const
Definition: Metadata.h:1301
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1309
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:772
A single uniqued string.
Definition: Metadata.h:611
StringRef getString() const
Definition: Metadata.cpp:509
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
Helper class to build MachineInstr.
const TargetInstrInfo & getTII()
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
MachineRegisterInfo * getMRI()
Getter for MRI.
const DataLayout & getDataLayout() const
void setMF(MachineFunction &MF)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
bool constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
Definition: MachineInstr.h:68
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool doesNotAccessMemory() const
Whether this function accesses no memory.
Definition: ModRef.h:192
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
Definition: ModRef.h:195
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
Definition: Module.cpp:251
A tuple of MDNodes.
Definition: Metadata.h:1604
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1281
unsigned getNumOperands() const
Definition: Metadata.cpp:1277
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
constexpr bool isValid() const
Definition: Register.h:116
bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const override
This hook must be implemented to lower the given call instruction, including argument and return valu...
bool lowerReturn(MachineIRBuilder &MIRBuiler, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI, Register SwiftErrorVReg) const override
This hook must be implemented to lower outgoing return values, described by Val, into the specified v...
SPIRVCallLowering(const SPIRVTargetLowering &TLI, SPIRVGlobalRegistry *GR)
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< ArrayRef< Register > > VRegs, FunctionLoweringInfo &FLI) const override
This hook must be implemented to lower the incoming (formal) arguments, described by VRegs,...
void setCurrentFunc(MachineFunction &MF)
void add(const Constant *C, MachineFunction *MF, Register R)
Register find(const Constant *C, MachineFunction *MF)
Register getSPIRVTypeID(const SPIRVType *SpirvType) const
SPIRVType * getOrCreateSPIRVType(const Type *Type, MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite, bool EmitIR=true)
void assignSPIRVTypeToVReg(SPIRVType *Type, Register VReg, MachineFunction &MF)
SPIRVType * assignTypeToVReg(const Type *Type, Register VReg, MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite, bool EmitIR=true)
SPIRVType * getOrCreateOpTypeFunctionWithArgs(const Type *Ty, SPIRVType *RetType, const SmallVectorImpl< SPIRVType * > &ArgTypes, MachineIRBuilder &MIRBuilder)
bool isOpenCLEnv() const
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
bool endswith(StringRef Suffix) const
Definition: StringRef.h:280
int compare(StringRef RHS) const
compare - Compare two strings; the result is negative, zero, or positive if this string is lexicograp...
Definition: StringRef.h:177
static StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
Definition: Type.cpp:633
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition: Type.cpp:514
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:344
Value * getValue() const
Definition: Metadata.h:384
LLVM Value Representation.
Definition: Value.h:74
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
constexpr bool isZero() const
Definition: TypeSize.h:151
@ SPIR_KERNEL
Used for SPIR kernel functions.
Definition: CallingConv.h:141
std::optional< bool > lowerBuiltin(const StringRef DemangledCall, SPIRV::InstructionSet::InstructionSet Set, MachineIRBuilder &MIRBuilder, const Register OrigRet, const Type *OrigRetTy, const SmallVectorImpl< Register > &Args, SPIRVGlobalRegistry *GR)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void buildOpName(Register Target, const StringRef &Name, MachineIRBuilder &MIRBuilder)
Definition: SPIRVUtils.cpp:96
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1685
std::string getOclOrSpirvBuiltinDemangledName(StringRef Name)
Definition: SPIRVUtils.cpp:290
void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
Definition: SPIRVUtils.cpp:113
bool isSpecialOpaqueType(const Type *Ty)
Definition: SPIRVUtils.cpp:341
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:156
void addStringImm(const StringRef &Str, MCInst &Inst)
Definition: SPIRVUtils.cpp:50
#define N