13#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
14#define LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
77 std::queue<BasicBlock *> ToVisit;
81 size_t TraversalIndex;
85 BlockToOrderInfoMap BlockToOrder;
86 std::vector<BasicBlock *> Order;
148 :
public SmallVector<SPIRV::FPFastMathDefaultInfo, 3> {
161 "Unreachable code in computeFPFastMathDefaultInfoVecIndex");
179void addStringImm(
const StringRef &Str, MachineInstrBuilder &MIB);
181 std::vector<Value *> &Args);
185std::string
getStringImm(
const MachineInstr &
MI,
unsigned StartIndex);
192void addNumImm(
const APInt &Imm, MachineInstrBuilder &MIB);
196 MachineIRBuilder &MIRBuilder);
198 const SPIRVInstrInfo &
TII);
202 SPIRV::Decoration::Decoration Dec,
203 ArrayRef<uint32_t> DecArgs, StringRef StrImm =
"");
205 SPIRV::Decoration::Decoration Dec,
206 ArrayRef<uint32_t> DecArgs, StringRef StrImm =
"");
210 SPIRV::Decoration::Decoration Dec,
uint32_t Member,
211 ArrayRef<uint32_t> DecArgs, StringRef StrImm =
"");
213 const SPIRVInstrInfo &
TII,
214 SPIRV::Decoration::Decoration Dec,
uint32_t Member,
215 ArrayRef<uint32_t> DecArgs, StringRef StrImm =
"");
219 const MDNode *GVarMD,
const SPIRVSubtarget &ST);
233 case SPIRV::StorageClass::Workgroup:
234 case SPIRV::StorageClass::CrossWorkgroup:
235 case SPIRV::StorageClass::Function:
236 case SPIRV::StorageClass::CodeSectionINTEL:
249 case SPIRV::StorageClass::Function:
251 case SPIRV::StorageClass::CrossWorkgroup:
253 case SPIRV::StorageClass::UniformConstant:
255 case SPIRV::StorageClass::Workgroup:
257 case SPIRV::StorageClass::Generic:
259 case SPIRV::StorageClass::DeviceOnlyINTEL:
261 case SPIRV::StorageClass::HostOnlyINTEL:
263 case SPIRV::StorageClass::Input:
265 case SPIRV::StorageClass::Output:
267 case SPIRV::StorageClass::CodeSectionINTEL:
269 case SPIRV::StorageClass::Private:
271 case SPIRV::StorageClass::StorageBuffer:
273 case SPIRV::StorageClass::Uniform:
275 case SPIRV::StorageClass::PushConstant:
283SPIRV::StorageClass::StorageClass
286SPIRV::MemorySemantics::MemorySemantics
289SPIRV::MemorySemantics::MemorySemantics
getMemSemantics(AtomicOrdering Ord);
297 const MachineRegisterInfo *MRI);
341 const DenseMap<BasicBlock *, ConstantInt *> &TargetToValue);
390 Type *SubT =
T->getScalarType();
412#define TYPED_PTR_TARGET_EXT_NAME "spirv.$TypedPointerType"
435 ExtTy->getIntParameter(0));
437 Type *ElemTy = VecTy->getElementType();
439 if (NewElemTy != ElemTy)
448 return PType->getElementType();
451 return ExtTy->getTypeParameter(0);
461 ExtTy->getTypeParameter(0) ==
485 bool IsUntypedPtr =
false;
492 if (!IsUntypedPtr && RetTy == OrigRetTy)
508 return FVTy && FVTy->getNumElements() == 1;
516 if (!FVTy || FVTy->getNumElements() != 1)
540#define SPIRV_BACKEND_SERVICE_FUN_NAME "__spirv_backend_service_fun"
541#define SPIRV_WAS_AVAILABLE_EXTERNALLY_ATTR "spv.was-available-externally"
546 MachineIRBuilder &MIRBuilder,
547 SPIRV::AccessQualifier::AccessQualifier AccessQual,
548 bool EmitIR,
bool Force =
false);
550 SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI,
551 const MachineFunction &MF,
bool Force =
false);
553 MachineRegisterInfo *MRI,
554 const MachineFunction &MF);
556 MachineIRBuilder &MIRBuilder);
558 const Type *Ty, SPIRVGlobalRegistry *GR, MachineIRBuilder &MIRBuilder,
559 SPIRV::AccessQualifier::AccessQualifier AccessQual,
bool EmitIR);
573 auto It = Mapping.
find(S);
577SmallVector<MachineInstr *, 4>
579 unsigned MinWC,
unsigned ContinuedOpcode,
589SmallVector<unsigned, 1>
593MachineInstr *
passCopy(MachineInstr *Def,
const MachineRegisterInfo *MRI);
594MachineInstr *
getDef(
const MachineOperand &MO,
const MachineRegisterInfo *MRI);
595MachineInstr *
getImm(
const MachineOperand &MO,
const MachineRegisterInfo *MRI);
596int64_t
foldImm(
const MachineOperand &MO,
const MachineRegisterInfo *MRI);
598 const MachineInstr *ResType);
600std::optional<SPIRV::LinkageType::LinkageType>
This file defines the StringMap class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseMap class.
const HexagonInstrInfo * TII
Machine Check Debug Module
Promote Memory to Register
#define TYPED_PTR_TARGET_EXT_NAME
This file defines the SmallPtrSet class.
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.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
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.
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.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
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.
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)
StringRef getOriginalAsmConstraints(const CallBase &CB)
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)
MachineBasicBlock::iterator getOpVariableMBBIt(MachineFunction &MF)
int64_t getIConstValSext(Register ConstReg, const MachineRegisterInfo *MRI)
bool isTypedPointerWrapper(const TargetExtType *ExtTy)
bool isTypeFoldingSupported(unsigned Opcode)
unsigned getPointerAddressSpace(const Type *T)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - 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)
CallInst * buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef< Type * > Types, Value *Arg, Value *Arg2, ArrayRef< Constant * > Imms, IRBuilder<> &B)
bool isUntypedPointerVectorTy(const Type *T)
bool matchPeeledArrayPattern(const StructType *Ty, Type *&OriginalElementType, uint64_t &TotalSize)
Register createVirtualRegister(SPIRVTypeInst SpvType, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI, const MachineFunction &MF)
unsigned getArrayComponentCount(const MachineRegisterInfo *MRI, const MachineInstr *ResType)
bool sortBlocks(Function &F)
Type * toTypedFunPointer(FunctionType *FTy)
AllocaInst * createVariable(Function &F, Type *Type)
void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, ArrayRef< uint32_t > DecArgs, StringRef StrImm)
bool isa_and_nonnull(const Y &Val)
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)
bool isNestedPointer(const Type *Ty)
Function * getOrCreateBackendServiceFunction(Module &M)
MetadataAsValue * buildMD(Value *Arg)
std::string getOclOrSpirvBuiltinDemangledName(StringRef Name)
bool isTypedPointerTy(const Type *T)
bool isUntypedEquivalentToTyExt(Type *Ty1, Type *Ty2)
SmallVector< unsigned, 1 > getSpirvLoopControlOperandsFromLoopMetadata(MDNode *LoopMD)
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
Type * getTypedPointerWrapper(Type *ElemTy, unsigned AS)
Type * toTypedPointer(Type *Ty)
bool isSpecialOpaqueType(const Type *Ty)
bool isPointerTy(const Type *T)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
void setRegClassType(Register Reg, SPIRVTypeInst SpvType, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI, const MachineFunction &MF, bool Force)
MachineBasicBlock::iterator getInsertPtValidEnd(MachineBasicBlock *MBB)
const Type * unifyPtrType(const Type *Ty)
constexpr bool isGenericCastablePtr(SPIRV::StorageClass::StorageClass SC)
MachineInstr * passCopy(MachineInstr *Def, const MachineRegisterInfo *MRI)
bool isa(const From &Val)
isa<X> - 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)
bool hasPointeeTypeAttr(Argument *Arg)
MachineInstr * getDefInstrMaybeConstant(Register &ConstReg, const MachineRegisterInfo *MRI)
constexpr unsigned BitWidth
Value * createExitVariable(BasicBlock *BB, const DenseMap< BasicBlock *, ConstantInt * > &TargetToValue)
bool isEquivalentTypes(Type *Ty1, Type *Ty2)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool hasBuiltinTypePrefix(StringRef Name)
Type * getMDOperandAsType(const MDNode *N, unsigned I)
void buildOpMemberDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, uint32_t Member, ArrayRef< uint32_t > DecArgs, StringRef StrImm)
bool hasInitializer(const GlobalVariable *GV)
Type * applyWrappers(Type *Ty)
Type * normalizeType(Type *Ty)
bool isPointerTyOrWrapper(const Type *Ty)
bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID)
Type * getPointeeType(const Type *Ty)
PoisonValue * getNormalizedPoisonValue(Type *Ty)
void addStringImm(const StringRef &Str, MCInst &Inst)
MachineInstr * getVRegDef(MachineRegisterInfo &MRI, Register Reg)
bool isUntypedPointerTy(const Type *T)
Type * reconstitutePeeledArrayType(Type *Ty)
SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord)
static size_t computeFPFastMathDefaultInfoVecIndex(size_t BitWidth)
FPFastMathDefaultInfo()=default
FPFastMathDefaultInfo(const Type *Ty, unsigned FastMathFlags)
bool operator==(const FPFastMathDefaultInfo &Other) const
bool SignedZeroInfNanPreserve