13#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
14#define LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
25#include <unordered_map>
26#include <unordered_set>
32class MachineInstrBuilder;
33class MachineIRBuilder;
34class MachineRegisterInfo;
39class SPIRVGlobalRegistry;
73 std::unordered_set<BasicBlock *> Queued = {};
74 std::queue<BasicBlock *> ToVisit = {};
78 size_t TraversalIndex;
81 using BlockToOrderInfoMap = std::unordered_map<BasicBlock *, OrderInfo>;
82 BlockToOrderInfoMap BlockToOrder;
83 std::vector<BasicBlock *> Order = {};
86 std::unordered_set<BasicBlock *> getReachableFrom(
BasicBlock *Start);
122 std::vector<Value *> &Args);
139 SPIRV::Decoration::Decoration Dec,
140 const std::vector<uint32_t> &DecArgs,
143 SPIRV::Decoration::Decoration Dec,
144 const std::vector<uint32_t> &DecArgs,
165 case SPIRV::StorageClass::Function:
167 case SPIRV::StorageClass::CrossWorkgroup:
169 case SPIRV::StorageClass::UniformConstant:
171 case SPIRV::StorageClass::Workgroup:
173 case SPIRV::StorageClass::Generic:
175 case SPIRV::StorageClass::DeviceOnlyINTEL:
177 case SPIRV::StorageClass::HostOnlyINTEL:
179 case SPIRV::StorageClass::Input:
181 case SPIRV::StorageClass::Output:
183 case SPIRV::StorageClass::CodeSectionINTEL:
185 case SPIRV::StorageClass::Private:
193SPIRV::StorageClass::StorageClass
196SPIRV::MemorySemantics::MemorySemantics
207 const MachineRegisterInfo *
MRI);
263 Type *SubT =
T->getScalarType();
265 ? cast<PointerType>(SubT)->getAddressSpace()
266 : cast<TypedPointerType>(SubT)->getAddressSpace();
287 for (
unsigned i = 0; i <
F->arg_size(); ++i)
292#define TYPED_PTR_TARGET_EXT_NAME "spirv.$TypedPointerType"
306 if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty))
312 if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty)) {
315 ExtTy->getIntParameter(0));
316 }
else if (
auto *VecTy = dyn_cast<VectorType>(Ty)) {
317 Type *ElemTy = VecTy->getElementType();
319 if (NewElemTy != ElemTy)
327 if (
auto PType = dyn_cast<TypedPointerType>(Ty))
328 return PType->getElementType();
329 else if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty))
331 return ExtTy->getTypeParameter(0);
339 if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty2))
341 ExtTy->getTypeParameter(0) ==
343 ExtTy->getIntParameter(0) == cast<PointerType>(Ty1)->getAddressSpace())
365 bool IsUntypedPtr =
false;
372 if (!IsUntypedPtr &&
RetTy == OrigRetTy)
381 if (
auto FTy = dyn_cast<FunctionType>(Ty))
388#define SPIRV_BACKEND_SERVICE_FUN_NAME "__spirv_backend_service_fun"
392 MachineIRBuilder &MIRBuilder,
bool Force =
false);
412 static std::unordered_map<std::string, FPDecorationId> Mapping = {
418 auto It = Mapping.find(S);
unsigned const MachineRegisterInfo * MRI
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const HexagonInstrInfo * TII
Promote Memory to Register
#define TYPED_PTR_TARGET_EXT_NAME
Class for arbitrary precision integers.
This class represents an incoming formal argument to a Function.
Type * getParamByRefType() const
If this is a byref argument, return its type.
bool hasByRefAttr() const
Return true if this argument has the byref attribute.
Type * getParamStructRetType() const
If this is an sret argument, return its type.
bool hasByValAttr() const
Return true if this argument has the byval attribute.
Type * getParamByValType() const
If this is a byval argument, return its type.
bool hasStructRetAttr() const
Return true if this argument has the sret attribute.
LLVM Basic Block Representation.
This class represents an Operation in the Expression.
Core dominator tree base class.
Class to represent function types.
ArrayRef< Type * > params() const
Type * getReturnType() const
static 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 provides a uniform API for creating instructions and inserting them into a basic block: either a...
Instances of this class represent a single low-level machine instruction.
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
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 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.
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
@ TypedPointerTyID
Typed pointer used by some GPU targets.
bool isTargetExtTy() const
Return true if this is a target extension type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static IntegerType * getInt8Ty(LLVMContext &C)
TypeID getTypeID() const
Return the type id for the type.
static TypedPointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
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)
bool isTypedPointerWrapper(const TargetExtType *ExtTy)
unsigned getPointerAddressSpace(const Type *T)
void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB)
FPDecorationId demangledPostfixToDecorationId(const std::string &S)
bool sortBlocks(Function &F)
Type * toTypedFunPointer(FunctionType *FTy)
uint64_t getIConstVal(Register ConstReg, const MachineRegisterInfo *MRI)
SPIRV::MemorySemantics::MemorySemantics getMemSemanticsForStorageClass(SPIRV::StorageClass::StorageClass SC)
constexpr unsigned storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC)
bool isNestedPointer(const Type *Ty)
std::string getOclOrSpirvBuiltinDemangledName(StringRef Name)
bool isTypedPointerTy(const Type *T)
bool isUntypedEquivalentToTyExt(Type *Ty1, Type *Ty2)
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)
Type * getTypedPointerWrapper(Type *ElemTy, unsigned AS)
Type * reconstructFunctionType(Function *F)
Type * toTypedPointer(Type *Ty)
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)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
MachineBasicBlock::iterator getInsertPtValidEnd(MachineBasicBlock *MBB)
const Type * unifyPtrType(const Type *Ty)
bool isEntryPoint(const Function &F)
SPIRV::StorageClass::StorageClass addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI)
AtomicOrdering
Atomic ordering for LLVM's memory model.
SPIRV::Scope::Scope getMemScope(LLVMContext &Ctx, SyncScope::ID Id)
Type * parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx)
Type * getPointeeTypeByAttr(Argument *Arg)
bool hasPointeeTypeAttr(Argument *Arg)
MachineInstr * getDefInstrMaybeConstant(Register &ConstReg, const MachineRegisterInfo *MRI)
bool isEquivalentTypes(Type *Ty1, Type *Ty2)
bool hasBuiltinTypePrefix(StringRef Name)
Type * getMDOperandAsType(const MDNode *N, unsigned I)
bool hasInitializer(const GlobalVariable *GV)
Type * applyWrappers(Type *Ty)
bool isPointerTyOrWrapper(const Type *Ty)
bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID)
Type * getPointeeType(const Type *Ty)
void addStringImm(const StringRef &Str, MCInst &Inst)
MachineInstr * getVRegDef(MachineRegisterInfo &MRI, Register Reg)
void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder, const MDNode *GVarMD)
bool isUntypedPointerTy(const Type *T)
SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord)