44 bool runOnModule(
Module &M)
override;
63 ConstantToValueMapTy ConstantToValueMap;
72 GenericToNVVM,
"generic-to-nvvm",
73 "Ensure that the global variables are in the global address space",
false,
108 if (
I->isDeclaration()) {
111 IRBuilder<> Builder(
I->getEntryBlock().getFirstNonPHIOrDbg());
116 for (
unsigned i = 0, e = II->getNumOperands(); i < e; ++i) {
117 Value *Operand = II->getOperand(i);
118 if (isa<Constant>(Operand)) {
120 i, remapConstant(&M,
I, cast<Constant>(Operand), Builder));
125 ConstantToValueMap.clear();
130 for (
auto I = GVMap.begin(), E = GVMap.end();
I != E; ++
I)
131 VM[
I->first] =
I->second;
136 E = M.named_metadata_end();
138 remapNamedMDNode(VM,
I);
145 for (GVMapTy::iterator
I = GVMap.begin(), E = GVMap.end();
I != E;) {
151 auto Next = std::next(
I);
164 assert(GVMap.empty() &&
"Expected it to be empty by now");
173 Value *CVTA =
nullptr;
191 M, Intrinsic::nvvm_ptr_global_to_gen, ParamTypes);
192 CVTA = Builder.
CreateCall(CVTAFunction, CVTA,
"cvta");
205 M, Intrinsic::nvvm_ptr_global_to_gen, ParamTypes);
206 CVTA = Builder.
CreateCall(CVTAFunction, GV,
"cvta");
216 ConstantToValueMapTy::iterator CTII = ConstantToValueMap.find(C);
217 if (CTII != ConstantToValueMap.end()) {
222 if (isa<GlobalVariable>(C)) {
231 GVMapTy::iterator
I = GVMap.find(cast<GlobalVariable>(C));
232 if (I != GVMap.end()) {
233 NewValue = getOrInsertCVTA(M, F, I->second, Builder);
235 }
else if (isa<ConstantVector>(C) || isa<ConstantArray>(C) ||
236 isa<ConstantStruct>(C)) {
240 NewValue = remapConstantVectorOrConstantAggregate(M, F, C, Builder);
241 }
else if (isa<ConstantExpr>(C)) {
245 NewValue = remapConstantExpr(M, F, cast<ConstantExpr>(C), Builder);
248 ConstantToValueMap[C] = NewValue;
252 Value *GenericToNVVM::remapConstantVectorOrConstantAggregate(
254 bool OperandChanged =
false;
260 for (
unsigned i = 0; i < NumOperands; ++i) {
262 Value *NewOperand = remapConstant(M, F, cast<Constant>(Operand), Builder);
263 OperandChanged |= Operand != NewOperand;
268 if (!OperandChanged) {
276 if (isa<ConstantVector>(C)) {
277 for (
unsigned i = 0; i < NumOperands; ++i) {
282 for (
unsigned i = 0; i < NumOperands; ++i) {
293 bool OperandChanged =
false;
299 for (
unsigned i = 0; i < NumOperands; ++i) {
301 Value *NewOperand = remapConstant(M, F, cast<Constant>(Operand), Builder);
302 OperandChanged |= Operand != NewOperand;
307 if (!OperandChanged) {
315 case Instruction::ICmp:
318 NewOperands[0], NewOperands[1]);
319 case Instruction::FCmp:
321 assert(
false &&
"Address space conversion should have no effect "
322 "on float point CompareConstantExpr (fcmp)!");
327 case Instruction::InsertElement:
331 case Instruction::ShuffleVector:
335 case Instruction::ExtractValue:
338 case Instruction::InsertValue:
342 case Instruction::GetElementPtr:
344 return cast<GEPOperator>(C)->isInBounds()
346 cast<GEPOperator>(C)->getSourceElementType(),
350 cast<GEPOperator>(C)->getSourceElementType(),
355 return Builder.
CreateSelect(NewOperands[0], NewOperands[1], NewOperands[2]);
360 NewOperands[0], NewOperands[1]);
367 assert(
false &&
"GenericToNVVM encountered an unsupported ConstantExpr");
374 bool OperandChanged =
false;
380 for (
unsigned i = 0; i < NumOperands; ++i) {
383 OperandChanged |= Operand != NewOperand;
388 if (!OperandChanged) {
395 E = NewOperands.
end();
Value * CreateGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
void push_back(const T &Elt)
LinkageTypes getLinkage() const
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
A Module instance is used to store all the information related to an LLVM module. ...
unsigned getNumOperands() const
void addOperand(MDNode *M)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
INITIALIZE_PASS(GenericToNVVM,"generic-to-nvvm","Ensure that the global variables are in the global address space", false, false) bool GenericToNVVM
bool isSurface(const llvm::Value &)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
ModulePass * createGenericToNVVMPass()
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
StringRef getName() const
Return a constant reference to the value's name.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
void setName(const Twine &Name)
Change the name of the value.
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
void eraseFromParent() override
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
bool isInteger() const
isInteger - Return true if this is an integer, or a vector integer type.
ConstantExpr - a constant value that is initialized with an expression using other constant values...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Type * getElementType() const
PointerType - Class to represent pointers.
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.
Metadata * MapMetadata(const Metadata *MD, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Represent the analysis usage information of a pass.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
MDNode * getOperand(unsigned i) const
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
Value * getOperand(unsigned i) const
unsigned getPredicate() const
getPredicate - Return the ICMP or FCMP predicate value.
ArrayRef< unsigned > getIndices() const
getIndices - Assert that this is an insertvalue or exactvalue expression and return the list of indic...
EVT - Extended Value Type.
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
void initializeGenericToNVVMPass(PassRegistry &)
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="")
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
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.
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...
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="")
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
bool isSampler(const llvm::Value &)
ThreadLocalMode getThreadLocalMode() const
PointerType * getType() const
Global values are always pointers.
static IntegerType * getInt32Ty(LLVMContext &C)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
getEVT - Return the value type corresponding to the specified type.
void copyAttributesFrom(const GlobalValue *Src) override
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
NamedMDListType::iterator named_metadata_iterator
The named metadata iterators.
bool isFloatingPoint() const
isFloatingPoint - Return true if this is a FP, or a vector FP type.
bool isTexture(const llvm::Value &)
LLVM Value Representation.
unsigned getNumOperands() const
void dropAllReferences()
Remove all uses and clear node vector.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static IntegerType * getInt8Ty(LLVMContext &C)
LLVMContext & getContext() const
Get the global data context.