13#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
14#define LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
24#include <unordered_set>
30class MachineInstrBuilder;
31class MachineIRBuilder;
32class MachineRegisterInfo;
37class SPIRVGlobalRegistry;
71 std::unordered_set<BasicBlock *> Queued = {};
72 std::queue<BasicBlock *> ToVisit = {};
76 size_t TraversalIndex;
79 using BlockToOrderInfoMap = std::unordered_map<BasicBlock *, OrderInfo>;
80 BlockToOrderInfoMap BlockToOrder;
81 std::vector<BasicBlock *> Order = {};
84 std::unordered_set<BasicBlock *> getReachableFrom(
BasicBlock *Start);
120 std::vector<Value *> &Args);
137 SPIRV::Decoration::Decoration Dec,
138 const std::vector<uint32_t> &DecArgs,
141 SPIRV::Decoration::Decoration Dec,
142 const std::vector<uint32_t> &DecArgs,
163 case SPIRV::StorageClass::Function:
165 case SPIRV::StorageClass::CrossWorkgroup:
167 case SPIRV::StorageClass::UniformConstant:
169 case SPIRV::StorageClass::Workgroup:
171 case SPIRV::StorageClass::Generic:
173 case SPIRV::StorageClass::DeviceOnlyINTEL:
175 case SPIRV::StorageClass::HostOnlyINTEL:
177 case SPIRV::StorageClass::Input:
179 case SPIRV::StorageClass::Output:
181 case SPIRV::StorageClass::CodeSectionINTEL:
183 case SPIRV::StorageClass::Private:
191SPIRV::StorageClass::StorageClass
194SPIRV::MemorySemantics::MemorySemantics
205 const MachineRegisterInfo *
MRI);
257 Type *SubT =
T->getScalarType();
259 ? cast<PointerType>(SubT)->getAddressSpace()
260 : cast<TypedPointerType>(SubT)->getAddressSpace();
281 for (
unsigned i = 0; i <
F->arg_size(); ++i)
286#define TYPED_PTR_TARGET_EXT_NAME "spirv.$TypedPointerType"
300 if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty))
306 if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty)) {
309 ExtTy->getIntParameter(0));
310 }
else if (
auto *VecTy = dyn_cast<VectorType>(Ty)) {
311 Type *ElemTy = VecTy->getElementType();
313 if (NewElemTy != ElemTy)
321 if (
auto PType = dyn_cast<TypedPointerType>(Ty))
322 return PType->getElementType();
323 else if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty))
325 return ExtTy->getTypeParameter(0);
333 if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty2))
335 ExtTy->getTypeParameter(0) ==
337 ExtTy->getIntParameter(0) == cast<PointerType>(Ty1)->getAddressSpace())
359 bool IsUntypedPtr =
false;
366 if (!IsUntypedPtr &&
RetTy == OrigRetTy)
375 if (
auto FTy = dyn_cast<FunctionType>(Ty))
382#define SPIRV_BACKEND_SERVICE_FUN_NAME "__spirv_backend_service_fun"
386 MachineIRBuilder &MIRBuilder,
bool Force =
false);
406 static std::unordered_map<std::string, FPDecorationId> Mapping = {
412 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.
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)
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)