21#include "llvm/IR/IntrinsicsNVPTX.h"
30 SmallVector<Instruction*, 4> InstrToDelete;
33 NVPTXImageOptimizer();
37 StringRef getPassName()
const override {
return "NVPTX Image Optimizer"; }
40 bool replaceIsTypePSampler(Instruction &
I);
41 bool replaceIsTypePSurface(Instruction &
I);
42 bool replaceIsTypePTexture(Instruction &
I);
44 void replaceWith(Instruction *From, ConstantInt *To);
48char NVPTXImageOptimizer::ID = 0;
50NVPTXImageOptimizer::NVPTXImageOptimizer()
53bool NVPTXImageOptimizer::runOnFunction(
Function &
F) {
58 InstrToDelete.
clear();
61 for (BasicBlock &BB :
F) {
62 for (Instruction &Instr : BB) {
64 Function *CalledF = CI->getCalledFunction();
69 case Intrinsic::nvvm_istypep_sampler:
70 Changed |= replaceIsTypePSampler(Instr);
72 case Intrinsic::nvvm_istypep_surface:
73 Changed |= replaceIsTypePSurface(Instr);
75 case Intrinsic::nvvm_istypep_texture:
76 Changed |= replaceIsTypePTexture(Instr);
85 for (Instruction *
I : InstrToDelete)
91bool NVPTXImageOptimizer::replaceIsTypePSampler(Instruction &
I) {
92 Value *TexHandle = cleanupValue(
I.getOperand(0));
97 }
else if (
isImage(*TexHandle)) {
107bool NVPTXImageOptimizer::replaceIsTypePSurface(Instruction &
I) {
108 Value *TexHandle = cleanupValue(
I.getOperand(0));
126bool NVPTXImageOptimizer::replaceIsTypePTexture(Instruction &
I) {
127 Value *TexHandle = cleanupValue(
I.getOperand(0));
145void NVPTXImageOptimizer::replaceWith(Instruction *From, ConstantInt *To) {
149 for (Use &U : From->
uses()) {
151 if (BI->isUnconditional())
continue;
155 Dest = BI->getSuccessor(1);
158 Dest = BI->getSuccessor(0);
160 InstrToDelete.push_back(BI);
164 InstrToDelete.push_back(From);
167Value *NVPTXImageOptimizer::cleanupValue(
Value *V) {
169 return cleanupValue(EVI->getAggregateOperand());
175 return new NVPTXImageOptimizer();
static bool runOnFunction(Function &F, bool PostInlining)
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
FunctionPass class - This class is used to implement most global optimizations.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< use_iterator > uses()
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isImageReadWrite(const Value &V)
bool isImageReadOnly(const Value &V)
bool isImage(const Value &V)
bool isSampler(const Value &V)
FunctionPass * createNVPTXImageOptimizerPass()
bool isImageWriteOnly(const Value &V)