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