//===----------------------------------------------------------------------===//
#include "AMDGPU.h"
-#include "llvm/Analysis/Passes.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/Passes.h"
#include "llvm/IR/Function.h"
-#include "llvm/InstVisitor.h"
-#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstVisitor.h"
using namespace llvm;
FunctionType *TexSign;
FunctionType *TexQSign;
- void getAdjustementFromTextureTarget(unsigned TextureType, bool hasLOD,
- unsigned SrcSelect[4], unsigned CT[4],
- bool &useShadowVariant) {
+ void getAdjustmentFromTextureTarget(unsigned TextureType, bool hasLOD,
+ unsigned SrcSelect[4], unsigned CT[4],
+ bool &useShadowVariant) {
enum TextureTypes {
TEXTURE_1D = 1,
TEXTURE_2D,
switch (TextureType) {
case 0:
+ useShadowVariant = false;
return;
case TEXTURE_RECT:
case TEXTURE_1D:
}
if (TextureType == TEXTURE_CUBE_ARRAY ||
- TextureType == TEXTURE_SHADOWCUBE_ARRAY) {
+ TextureType == TEXTURE_SHADOWCUBE_ARRAY)
CT[2] = 0;
- }
if (TextureType == TEXTURE_1D_ARRAY ||
TextureType == TEXTURE_SHADOW1D_ARRAY) {
TextureType == TEXTURE_SHADOW2D ||
TextureType == TEXTURE_SHADOWRECT ||
TextureType == TEXTURE_SHADOW1D_ARRAY) &&
- !(hasLOD && useShadowVariant)) {
+ !(hasLOD && useShadowVariant))
SrcSelect[3] = 2;
- }
}
void ReplaceCallInst(CallInst &I, FunctionType *FT, const char *Name,
};
bool useShadowVariant;
- getAdjustementFromTextureTarget(TextureType, hasLOD, SrcSelect, CT,
- useShadowVariant);
+ getAdjustmentFromTextureTarget(TextureType, hasLOD, SrcSelect, CT,
+ useShadowVariant);
ReplaceCallInst(I, FT, useShadowVariant?ShadowInt:VanillaInt, SrcSelect,
Offset, ResourceId, SamplerId, CT, Coord);
};
bool useShadowVariant;
- getAdjustementFromTextureTarget(TextureType, false, SrcSelect, CT,
- useShadowVariant);
+ getAdjustmentFromTextureTarget(TextureType, false, SrcSelect, CT,
+ useShadowVariant);
ReplaceCallInst(I, TexQSign, "llvm.R600.txf", SrcSelect,
Offset, ResourceId, SamplerId, CT, Coord);
}
void visitCallInst(CallInst &I) {
- if (I.getCalledFunction()->getName() == "llvm.AMDGPU.tex")
+ if (!I.getCalledFunction())
+ return;
+
+ StringRef Name = I.getCalledFunction()->getName();
+ if (Name == "llvm.AMDGPU.tex") {
ReplaceTexIntrinsic(I, false, TexSign, "llvm.R600.tex", "llvm.R600.texc");
- if (I.getCalledFunction()->getName() == "llvm.AMDGPU.txl")
+ return;
+ }
+ if (Name == "llvm.AMDGPU.txl") {
ReplaceTexIntrinsic(I, true, TexSign, "llvm.R600.txl", "llvm.R600.txlc");
- if (I.getCalledFunction()->getName() == "llvm.AMDGPU.txb")
+ return;
+ }
+ if (Name == "llvm.AMDGPU.txb") {
ReplaceTexIntrinsic(I, true, TexSign, "llvm.R600.txb", "llvm.R600.txbc");
- if (I.getCalledFunction()->getName() == "llvm.AMDGPU.txf")
+ return;
+ }
+ if (Name == "llvm.AMDGPU.txf") {
ReplaceTXF(I);
- if (I.getCalledFunction()->getName() == "llvm.AMDGPU.txq")
+ return;
+ }
+ if (Name == "llvm.AMDGPU.txq") {
ReplaceTexIntrinsic(I, false, TexQSign, "llvm.R600.txq", "llvm.R600.txq");
- if (I.getCalledFunction()->getName() == "llvm.AMDGPU.ddx")
+ return;
+ }
+ if (Name == "llvm.AMDGPU.ddx") {
ReplaceTexIntrinsic(I, false, TexSign, "llvm.R600.ddx", "llvm.R600.ddx");
- if (I.getCalledFunction()->getName() == "llvm.AMDGPU.ddy")
+ return;
+ }
+ if (Name == "llvm.AMDGPU.ddy") {
ReplaceTexIntrinsic(I, false, TexSign, "llvm.R600.ddy", "llvm.R600.ddy");
+ return;
+ }
}
};