LLVM: lib/Target/SPIRV/SPIRVUtils.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
14#define LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
15
23#include
24#include
25#include <unordered_map>
26#include <unordered_set>
27
28namespace llvm {
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
72
73 std::unordered_set<BasicBlock *> Queued = {};
74 std::queue<BasicBlock *> ToVisit = {};
75
76 struct OrderInfo {
77 size_t Rank;
78 size_t TraversalIndex;
79 };
80
81 using BlockToOrderInfoMap = std::unordered_map<BasicBlock *, OrderInfo>;
82 BlockToOrderInfoMap BlockToOrder;
83 std::vector<BasicBlock *> Order = {};
84
85
86 std::unordered_set<BasicBlock *> getReachableFrom(BasicBlock *Start);
87
88
89
90 size_t visit(BasicBlock *BB, size_t Rank);
91
92 bool CanBeVisited(BasicBlock *BB) const;
93
94public:
96
97
99
100
101
102
104
105
106
107
108
109
110
111
114};
115
120
121
122
123
124
125
126
127
128
132
142};
143
145 : public SmallVector<SPIRV::FPFastMathDefaultInfo, 3> {
148 case 16:
149 return 0;
150 case 32:
151 return 1;
152 case 64:
153 return 2;
154 default:
156 }
158 "Unreachable code in computeFPFastMathDefaultInfoVecIndex");
159 }
160};
161
162
163
164
167}
168
169
170
171
172void addStringImm(const StringRef &Str, MCInst &Inst);
173void addStringImm(const StringRef &Str, MachineInstrBuilder &MIB);
175 std::vector<Value *> &Args);
176
177
178
179std::string getStringImm(const MachineInstr &MI, unsigned StartIndex);
180
181
182
184
185
186void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB);
187
188
190 MachineIRBuilder &MIRBuilder);
192 const SPIRVInstrInfo &TII);
193
194
196 SPIRV::Decoration::Decoration Dec,
197 const std::vector<uint32_t> &DecArgs,
198 StringRef StrImm = "");
200 SPIRV::Decoration::Decoration Dec,
201 const std::vector<uint32_t> &DecArgs,
202 StringRef StrImm = "");
203
204
206 SPIRV::Decoration::Decoration Dec, uint32_t Member,
207 const std::vector<uint32_t> &DecArgs,
208 StringRef StrImm = "");
210 const SPIRVInstrInfo &TII,
211 SPIRV::Decoration::Decoration Dec, uint32_t Member,
212 const std::vector<uint32_t> &DecArgs,
213 StringRef StrImm = "");
214
215
217 const MDNode *GVarMD, const SPIRVSubtarget &ST);
218
219
220
222
223
224
226
227
228
230 switch (SC) {
231 case SPIRV::StorageClass::Workgroup:
232 case SPIRV::StorageClass::CrossWorkgroup:
233 case SPIRV::StorageClass::Function:
234 return true;
235 default:
236 return false;
237 }
238}
239
240
241
242
243constexpr unsigned
245 switch (SC) {
246 case SPIRV::StorageClass::Function:
247 return 0;
248 case SPIRV::StorageClass::CrossWorkgroup:
249 return 1;
250 case SPIRV::StorageClass::UniformConstant:
251 return 2;
252 case SPIRV::StorageClass::Workgroup:
253 return 3;
254 case SPIRV::StorageClass::Generic:
255 return 4;
256 case SPIRV::StorageClass::DeviceOnlyINTEL:
257 return 5;
258 case SPIRV::StorageClass::HostOnlyINTEL:
259 return 6;
260 case SPIRV::StorageClass::Input:
261 return 7;
262 case SPIRV::StorageClass::Output:
263 return 8;
264 case SPIRV::StorageClass::CodeSectionINTEL:
265 return 9;
266 case SPIRV::StorageClass::Private:
267 return 10;
268 case SPIRV::StorageClass::StorageBuffer:
269 return 11;
270 case SPIRV::StorageClass::Uniform:
271 return 12;
272 default:
274 }
275}
276
277
278SPIRV::StorageClass::StorageClass
280
281SPIRV::MemorySemantics::MemorySemantics
283
284SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord);
285
287
288
289
290
292 const MachineRegisterInfo *MRI);
293
294
296
297
299
300
302
304
305
307
308
309
311
312
314
315
317
318
320
321
323
324
325
326
328
329
330
331
332
333
334
337
338
339
340
341
343
347
348
352
353
357
358
362
363
364
366 Type *SubT = T->getScalarType();
370}
371
372
376
377
387
390 for (unsigned i = 0; i < F->arg_size(); ++i)
391 ArgTys.push_back(F->getArg(i)->getType());
393}
394
395#define TYPED_PTR_TARGET_EXT_NAME "spirv.$TypedPointerType"
398 {ElemTy}, {AS});
399}
400
406
407
413
418 ExtTy->getIntParameter(0));
420 Type *ElemTy = VecTy->getElementType();
422 if (NewElemTy != ElemTy)
423 return VectorType::get(NewElemTy, VecTy->getElementCount());
424 }
425 return Ty;
426}
427
429 if (Ty) {
431 return PType->getElementType();
434 return ExtTy->getTypeParameter(0);
435 }
436 return nullptr;
437}
438
441 return false;
444 ExtTy->getTypeParameter(0) ==
446 ExtTy->getIntParameter(0) == cast(Ty1)->getAddressSpace())
447 return true;
448 return false;
449}
450
455
458 return NewTy;
462 : Ty;
463}
464
468 bool IsUntypedPtr = false;
471 IsUntypedPtr = true;
472 break;
473 }
474 }
475 if (!IsUntypedPtr && RetTy == OrigRetTy)
476 return FTy;
481}
482
488
491 return FVTy && FVTy->getNumElements() == 1;
492}
493
494
495
496
499 if (!FVTy || FVTy->getNumElements() != 1)
500 return Ty;
501
502
503
505}
506
510
516
520
522
523#define SPIRV_BACKEND_SERVICE_FUN_NAME "__spirv_backend_service_fun"
525
527 MachineIRBuilder &MIRBuilder,
528 SPIRV::AccessQualifier::AccessQualifier AccessQual,
529 bool EmitIR, bool Force = false);
542 SPIRV::AccessQualifier::AccessQualifier AccessQual, bool EmitIR);
543
544
546
548
550 static std::unordered_map<std::string, FPDecorationId> Mapping = {
556 auto It = Mapping.find(S);
558}
559
560SmallVector<MachineInstr *, 4>
562 unsigned MinWC, unsigned ContinuedOpcode,
565
566
569
570
572
573
574MachineInstr *passCopy(MachineInstr *Def, const MachineRegisterInfo *MRI);
575MachineInstr *getDef(const MachineOperand &MO, const MachineRegisterInfo *MRI);
576MachineInstr *getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI);
577int64_t foldImm(const MachineOperand &MO, const MachineRegisterInfo *MRI);
579 const MachineInstr *ResType);
582
583std::optionalSPIRV::LinkageType::LinkageType
585}
586#endif
unsigned const MachineRegisterInfo * MRI
const TargetInstrInfo & TII
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Machine Check Debug Module
Promote Memory to Register
#define TYPED_PTR_TARGET_EXT_NAME
Definition SPIRVUtils.h:395
This class represents an incoming formal argument to a Function.
LLVM_ABI Type * getParamByRefType() const
If this is a byref argument, return its type.
LLVM_ABI bool hasByRefAttr() const
Return true if this argument has the byref attribute.
LLVM_ABI Type * getParamStructRetType() const
If this is an sret argument, return its type.
LLVM_ABI bool hasByValAttr() const
Return true if this argument has the byval attribute.
LLVM_ABI Type * getParamByValType() const
If this is a byval argument, return its type.
LLVM_ABI bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
LLVM Basic Block Representation.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Class to represent function types.
ArrayRef< Type * > params() const
Type * getReturnType() const
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
This is an important class for using LLVM in a threaded context.
Instances of this class represent a single low-level machine instruction.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
MachineInstrBundleIterator< MachineInstr > iterator
Helper class to build MachineInstr.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
size_t GetNodeRank(BasicBlock *BB) const
void partialOrderVisit(BasicBlock &Start, std::function< bool(BasicBlock *)> Op)
bool compare(const BasicBlock *LHS, const BasicBlock *RHS) const
PartialOrderingVisitor(Function &F)
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Wrapper class representing virtual and physical registers.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
unsigned getNumIntParameters() const
static LLVM_ABI TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types={}, ArrayRef< unsigned > Ints={})
Return a target extension type having the specified name and optional type and integer parameters.
unsigned getNumTypeParameters() const
StringRef getName() const
Return the name for this target extension type.
The instances of the Type class are immutable: once they are created, they are never changed.
@ TypedPointerTyID
Typed pointer used by some GPU targets.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
bool isTargetExtTy() const
Return true if this is a target extension type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
TypeID getTypeID() const
Return the type id for the type.
static LLVM_ABI TypedPointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
LLVM Value Representation.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
DomTreeBase< BasicBlock > BBDomTree
FunctionType * getOriginalFunctionType(const Function &F)
This is an optimization pass for GlobalISel generic memory operations.
void buildOpName(Register Target, const StringRef &Name, MachineIRBuilder &MIRBuilder)
bool getVacantFunctionName(Module &M, std::string &Name)
std::string getStringImm(const MachineInstr &MI, unsigned StartIndex)
int64_t getIConstValSext(Register ConstReg, const MachineRegisterInfo *MRI)
bool isTypedPointerWrapper(const TargetExtType *ExtTy)
Definition SPIRVUtils.h:401
bool isTypeFoldingSupported(unsigned Opcode)
unsigned getPointerAddressSpace(const Type *T)
Definition SPIRVUtils.h:365
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
MachineInstr * getDef(const MachineOperand &MO, const MachineRegisterInfo *MRI)
void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB)
FPDecorationId demangledPostfixToDecorationId(const std::string &S)
Definition SPIRVUtils.h:549
CallInst * buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef< Type * > Types, Value *Arg, Value *Arg2, ArrayRef< Constant * > Imms, IRBuilder<> &B)
bool matchPeeledArrayPattern(const StructType *Ty, Type *&OriginalElementType, uint64_t &TotalSize)
unsigned getArrayComponentCount(const MachineRegisterInfo *MRI, const MachineInstr *ResType)
bool sortBlocks(Function &F)
Type * toTypedFunPointer(FunctionType *FTy)
Definition SPIRVUtils.h:465
FPDecorationId
Definition SPIRVUtils.h:547
@ RTP
Definition SPIRVUtils.h:547
@ RTE
Definition SPIRVUtils.h:547
@ RTN
Definition SPIRVUtils.h:547
@ SAT
Definition SPIRVUtils.h:547
@ RTZ
Definition SPIRVUtils.h:547
SmallVector< unsigned, 1 > getSpirvLoopControlOperandsFromLoopMetadata(Loop *L)
uint64_t getIConstVal(Register ConstReg, const MachineRegisterInfo *MRI)
SmallVector< MachineInstr *, 4 > createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode, unsigned MinWC, unsigned ContinuedOpcode, ArrayRef< Register > Args, Register ReturnRegister, Register TypeID)
SPIRV::MemorySemantics::MemorySemantics getMemSemanticsForStorageClass(SPIRV::StorageClass::StorageClass SC)
constexpr unsigned storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC)
Definition SPIRVUtils.h:244
MachineBasicBlock::iterator getFirstValidInstructionInsertPoint(MachineBasicBlock &BB)
bool isNestedPointer(const Type *Ty)
MetadataAsValue * buildMD(Value *Arg)
Definition SPIRVUtils.h:511
std::string getOclOrSpirvBuiltinDemangledName(StringRef Name)
bool isTypedPointerTy(const Type *T)
Definition SPIRVUtils.h:349
bool isUntypedEquivalentToTyExt(Type *Ty1, Type *Ty2)
Definition SPIRVUtils.h:439
void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
MachineBasicBlock::iterator getOpVariableMBBIt(MachineInstr &I)
Register createVirtualRegister(SPIRVType *SpvType, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI, const MachineFunction &MF)
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
Type * getTypedPointerWrapper(Type *ElemTy, unsigned AS)
Definition SPIRVUtils.h:396
Type * reconstructFunctionType(Function *F)
Definition SPIRVUtils.h:388
void buildOpMemberDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, uint32_t Member, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
Type * toTypedPointer(Type *Ty)
Definition SPIRVUtils.h:456
bool isVector1(Type *Ty)
Definition SPIRVUtils.h:489
bool isSpecialOpaqueType(const Type *Ty)
void setRegClassType(Register Reg, SPIRVType *SpvType, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI, const MachineFunction &MF, bool Force)
bool isPointerTy(const Type *T)
Definition SPIRVUtils.h:359
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
MachineBasicBlock::iterator getInsertPtValidEnd(MachineBasicBlock *MBB)
const Type * unifyPtrType(const Type *Ty)
Definition SPIRVUtils.h:483
constexpr bool isGenericCastablePtr(SPIRV::StorageClass::StorageClass SC)
Definition SPIRVUtils.h:229
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
MachineInstr * passCopy(MachineInstr *Def, const MachineRegisterInfo *MRI)
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
std::optional< SPIRV::LinkageType::LinkageType > getSpirvLinkageTypeFor(const SPIRVSubtarget &ST, const GlobalValue &GV)
bool isEntryPoint(const Function &F)
const std::set< unsigned > & getTypeFoldingSupportedOpcodes()
SPIRV::StorageClass::StorageClass addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI)
SPIRV::Scope::Scope getMemScope(LLVMContext &Ctx, SyncScope::ID Id)
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder, const MDNode *GVarMD, const SPIRVSubtarget &ST)
std::string getStringValueFromReg(Register Reg, MachineRegisterInfo &MRI)
int64_t foldImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
Type * parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx)
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
Type * getPointeeTypeByAttr(Argument *Arg)
Definition SPIRVUtils.h:378
bool hasPointeeTypeAttr(Argument *Arg)
Definition SPIRVUtils.h:373
MachineInstr * getDefInstrMaybeConstant(Register &ConstReg, const MachineRegisterInfo *MRI)
constexpr unsigned BitWidth
bool isEquivalentTypes(Type *Ty1, Type *Ty2)
Definition SPIRVUtils.h:451
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
bool hasBuiltinTypePrefix(StringRef Name)
Type * getMDOperandAsType(const MDNode *N, unsigned I)
bool hasInitializer(const GlobalVariable *GV)
Definition SPIRVUtils.h:344
Type * applyWrappers(Type *Ty)
Definition SPIRVUtils.h:414
Type * normalizeType(Type *Ty)
Definition SPIRVUtils.h:497
bool isPointerTyOrWrapper(const Type *Ty)
Definition SPIRVUtils.h:408
bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID)
Type * getPointeeType(const Type *Ty)
Definition SPIRVUtils.h:428
PoisonValue * getNormalizedPoisonValue(Type *Ty)
Definition SPIRVUtils.h:507
void addStringImm(const StringRef &Str, MCInst &Inst)
MachineInstr * getVRegDef(MachineRegisterInfo &MRI, Register Reg)
bool isUntypedPointerTy(const Type *T)
Definition SPIRVUtils.h:354
Type * reconstitutePeeledArrayType(Type *Ty)
SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord)
Definition SPIRVUtils.h:145
static size_t computeFPFastMathDefaultInfoVecIndex(size_t BitWidth)
Definition SPIRVUtils.h:146
FPFastMathDefaultInfo()=default
bool FPFastMathDefault
Definition SPIRVUtils.h:131
bool ContractionOff
Definition SPIRVUtils.h:129
FPFastMathDefaultInfo(const Type *Ty, unsigned FastMathFlags)
Definition SPIRVUtils.h:134
const Type * Ty
Definition SPIRVUtils.h:118
bool operator==(const FPFastMathDefaultInfo &Other) const
Definition SPIRVUtils.h:136
unsigned FastMathFlags
Definition SPIRVUtils.h:119
bool SignedZeroInfNanPreserve
Definition SPIRVUtils.h:130