73 "disable-nvptx-favor-non-generic",
75 cl::desc(
"Do not convert generic address space usage "
76 "to non-generic address space usage"),
81 class NVPTXFavorNonGenericAddrSpaces :
public FunctionPass {
90 bool optimizeMemoryInstruction(
Instruction *
I,
unsigned Idx);
104 Value *hoistAddrSpaceCastFrom(
Value *V,
int Depth = 0);
118 "Remove unnecessary non-generic-to-generic addrspacecasts",
123 static
bool isEliminableAddrSpaceCast(
Value *V) {
126 if (Cast ==
nullptr || Cast->
getOpcode() != Instruction::AddrSpaceCast)
145 Value *NVPTXFavorNonGenericAddrSpaces::hoistAddrSpaceCastFromGEP(
149 if (NewOperand ==
nullptr)
153 assert(isEliminableAddrSpaceCast(NewOperand));
154 Operator *Cast = cast<Operator>(NewOperand);
158 if (
Instruction *GEPI = dyn_cast<Instruction>(GEP)) {
183 Value *NVPTXFavorNonGenericAddrSpaces::hoistAddrSpaceCastFromBitCast(
185 Value *NewOperand = hoistAddrSpaceCastFrom(BC->
getOperand(0), Depth + 1);
186 if (NewOperand ==
nullptr)
190 assert(isEliminableAddrSpaceCast(NewOperand));
191 Operator *Cast = cast<Operator>(NewOperand);
199 Type *TypeOfNewCast =
203 if (
BitCastInst *BCI = dyn_cast<BitCastInst>(BC)) {
220 Value *NVPTXFavorNonGenericAddrSpaces::hoistAddrSpaceCastFrom(
Value *V,
223 if (isEliminableAddrSpaceCast(V))
228 if (Depth >= MaxDepth)
235 return hoistAddrSpaceCastFromGEP(GEP, Depth);
238 return hoistAddrSpaceCastFromBitCast(BC, Depth);
243 bool NVPTXFavorNonGenericAddrSpaces::optimizeMemoryInstruction(
Instruction *
MI,
246 if (NewOperand ==
nullptr)
259 assert(isEliminableAddrSpaceCast(NewOperand));
265 bool NVPTXFavorNonGenericAddrSpaces::runOnFunction(
Function &
F) {
269 bool Changed =
false;
272 if (isa<LoadInst>(
I)) {
274 Changed |= optimizeMemoryInstruction(
I, 0);
275 }
else if (isa<StoreInst>(
I)) {
277 Changed |= optimizeMemoryInstruction(
I, 1);
285 return new NVPTXFavorNonGenericAddrSpaces();
Type * getSourceElementType() const
FunctionPass * createNVPTXFavorNonGenericAddrSpacesPass()
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static cl::opt< bool > DisableFavorNonGeneric("disable-nvptx-favor-non-generic", cl::init(false), cl::desc("Do not convert generic address space usage ""to non-generic address space usage"), cl::Hidden)
Type * getPointerElementType() const
This class represents a conversion between pointers from one address space to another.
void setIsInBounds(bool b=true)
setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
void initializeNVPTXFavorNonGenericAddrSpacesPass(PassRegistry &)
This class represents a no-op cast from one type to another.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
void takeName(Value *V)
Transfer the name from V to this value.
Type * getElementType() const
PointerType - Class to represent pointers.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
initializer< Ty > init(const Ty &Val)
The instances of the Type class are immutable: once they are created, they are never changed...
INITIALIZE_PASS(NVPTXFavorNonGenericAddrSpaces,"nvptx-favor-non-generic","Remove unnecessary non-generic-to-generic addrspacecasts", false, false) static bool isEliminableAddrSpaceCast(Value *V)
This is an important base class in LLVM.
Value * getPointerOperand()
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
This is a utility class that provides an abstraction for the common functionality between Instruction...
Type * getType() const
All values are typed, get the type of this value.
void setOperand(unsigned i, Value *Val)
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
LLVM Value Representation.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...