26 class R600TextureIntrinsicsReplacer :
38 void getAdjustmentFromTextureTarget(
unsigned TextureType,
bool hasLOD,
39 unsigned SrcSelect[4],
unsigned CT[4],
40 bool &useShadowVariant) {
52 TEXTURE_SHADOW1D_ARRAY,
53 TEXTURE_SHADOW2D_ARRAY,
56 TEXTURE_2D_ARRAY_MSAA,
58 TEXTURE_SHADOWCUBE_ARRAY
61 switch (TextureType) {
63 useShadowVariant =
false;
70 case TEXTURE_1D_ARRAY:
71 case TEXTURE_2D_ARRAY:
72 case TEXTURE_CUBE_ARRAY:
74 case TEXTURE_2D_ARRAY_MSAA:
75 useShadowVariant =
false;
77 case TEXTURE_SHADOW1D:
78 case TEXTURE_SHADOW2D:
79 case TEXTURE_SHADOWRECT:
80 case TEXTURE_SHADOW1D_ARRAY:
81 case TEXTURE_SHADOW2D_ARRAY:
82 case TEXTURE_SHADOWCUBE:
83 case TEXTURE_SHADOWCUBE_ARRAY:
84 useShadowVariant =
true;
90 if (TextureType == TEXTURE_RECT ||
91 TextureType == TEXTURE_SHADOWRECT) {
96 if (TextureType == TEXTURE_CUBE_ARRAY ||
97 TextureType == TEXTURE_SHADOWCUBE_ARRAY)
100 if (TextureType == TEXTURE_1D_ARRAY ||
101 TextureType == TEXTURE_SHADOW1D_ARRAY) {
102 if (hasLOD && useShadowVariant) {
108 }
else if (TextureType == TEXTURE_2D_ARRAY ||
109 TextureType == TEXTURE_SHADOW2D_ARRAY) {
113 if ((TextureType == TEXTURE_SHADOW1D ||
114 TextureType == TEXTURE_SHADOW2D ||
115 TextureType == TEXTURE_SHADOWRECT ||
116 TextureType == TEXTURE_SHADOW1D_ARRAY) &&
117 !(hasLOD && useShadowVariant))
122 unsigned SrcSelect[4],
Value *Offset[3],
Value *Resource,
123 Value *Sampler,
unsigned CT[4],
Value *Coord) {
132 Value *SwizzledCoord =
133 Builder.CreateShuffleVector(Coord, Coord, SwizzleMask);
158 const char *VanillaInt,
159 const char *ShadowInt) {
164 unsigned TextureType =
167 unsigned SrcSelect[4] = { 0, 1, 2, 3 };
168 unsigned CT[4] = {1, 1, 1, 1};
174 bool useShadowVariant;
176 getAdjustmentFromTextureTarget(TextureType, hasLOD, SrcSelect, CT,
179 ReplaceCallInst(I, FT, useShadowVariant?ShadowInt:VanillaInt, SrcSelect,
180 Offset, ResourceId, SamplerId, CT, Coord);
188 unsigned TextureType =
191 unsigned SrcSelect[4] = { 0, 1, 2, 3 };
192 unsigned CT[4] = {1, 1, 1, 1};
198 bool useShadowVariant;
200 getAdjustmentFromTextureTarget(TextureType,
false, SrcSelect, CT,
203 ReplaceCallInst(I, TexQSign,
"llvm.R600.txf", SrcSelect,
204 Offset, ResourceId, SamplerId, CT, Coord);
208 R600TextureIntrinsicsReplacer():
212 bool doInitialization(
Module &M)
override {
232 Type *ArgsQType[] = {
248 bool runOnFunction(
Function &F)
override {
253 const char *getPassName()
const override {
254 return "R600 Texture Intrinsics Replacer";
265 if (Name ==
"llvm.AMDGPU.tex") {
266 ReplaceTexIntrinsic(I,
false, TexSign,
"llvm.R600.tex",
"llvm.R600.texc");
269 if (Name ==
"llvm.AMDGPU.txl") {
270 ReplaceTexIntrinsic(I,
true, TexSign,
"llvm.R600.txl",
"llvm.R600.txlc");
273 if (Name ==
"llvm.AMDGPU.txb") {
274 ReplaceTexIntrinsic(I,
true, TexSign,
"llvm.R600.txb",
"llvm.R600.txbc");
277 if (Name ==
"llvm.AMDGPU.txf") {
281 if (Name ==
"llvm.AMDGPU.txq") {
282 ReplaceTexIntrinsic(I,
false, TexQSign,
"llvm.R600.txq",
"llvm.R600.txq");
285 if (Name ==
"llvm.AMDGPU.ddx") {
286 ReplaceTexIntrinsic(I,
false, TexSign,
"llvm.R600.ddx",
"llvm.R600.ddx");
289 if (Name ==
"llvm.AMDGPU.ddy") {
290 ReplaceTexIntrinsic(I,
false, TexSign,
"llvm.R600.ddy",
"llvm.R600.ddy");
302 return new R600TextureIntrinsicsReplacer();
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
Base class for instruction visitors.
A Module instance is used to store all the information related to an LLVM module. ...
CallInst - This class represents a function call, abstracting a target machine's calling convention...
Externally visible function.
StringRef getName() const
Return a constant reference to the value's name.
FunctionPass * createR600TextureIntrinsicsReplacer()
static Type * getFloatTy(LLVMContext &C)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static Constant * get(ArrayRef< Constant * > V)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Function does not access memory.
void addFnAttr(Attribute::AttrKind N)
Add function attributes to this function.
FunctionType - Class to represent function types.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
FunctionType::get - This static method is the primary way of constructing a FunctionType.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
This is an important base class in LLVM.
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Function * getCalledFunction() const
getCalledFunction - Return the function called, or null if this is an indirect function invocation...
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
static IntegerType * getInt32Ty(LLVMContext &C)
LLVM Value Representation.
static VectorType * get(Type *ElementType, unsigned NumElements)
VectorType::get - This static method is the primary way to construct an VectorType.
StringRef - Represent a constant reference to a string, i.e.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
LLVMContext & getContext() const
Get the global data context.