43 bool runOnModule(
Module &M)
override;
59 ConstantToValueMapTy ConstantToValueMap;
68 GenericToNVVM,
"generic-to-nvvm",
69 "Ensure that the global variables are in the global address space",
false,
104 if (
I->isDeclaration()) {
107 IRBuilder<> Builder(
I->getEntryBlock().getFirstNonPHIOrDbg());
112 for (
unsigned i = 0, e = II->getNumOperands(); i < e; ++i) {
113 Value *Operand = II->getOperand(i);
114 if (isa<Constant>(Operand)) {
116 i, remapConstant(&M, &*
I, cast<Constant>(Operand), Builder));
121 ConstantToValueMap.clear();
126 for (
auto I = GVMap.begin(),
E = GVMap.end();
I !=
E; ++
I)
127 VM[
I->first] =
I->second;
133 for (GVMapTy::iterator
I = GVMap.begin(),
E = GVMap.end();
I !=
E;) {
139 auto Next = std::next(
I);
152 assert(GVMap.empty() &&
"Expected it to be empty by now");
161 ConstantToValueMapTy::iterator CTII = ConstantToValueMap.find(C);
162 if (CTII != ConstantToValueMap.end()) {
167 if (isa<GlobalVariable>(C)) {
173 GVMapTy::iterator
I = GVMap.find(cast<GlobalVariable>(C));
174 if (I != GVMap.end()) {
180 }
else if (isa<ConstantAggregate>(C)) {
184 NewValue = remapConstantVectorOrConstantAggregate(M, F, C, Builder);
185 }
else if (isa<ConstantExpr>(C)) {
189 NewValue = remapConstantExpr(M, F, cast<ConstantExpr>(C), Builder);
192 ConstantToValueMap[
C] = NewValue;
196 Value *GenericToNVVM::remapConstantVectorOrConstantAggregate(
198 bool OperandChanged =
false;
204 for (
unsigned i = 0; i < NumOperands; ++i) {
206 Value *NewOperand = remapConstant(M, F, cast<Constant>(Operand), Builder);
207 OperandChanged |= Operand != NewOperand;
212 if (!OperandChanged) {
220 if (isa<ConstantVector>(C)) {
221 for (
unsigned i = 0; i < NumOperands; ++i) {
226 for (
unsigned i = 0; i < NumOperands; ++i) {
237 bool OperandChanged =
false;
243 for (
unsigned i = 0; i < NumOperands; ++i) {
245 Value *NewOperand = remapConstant(M, F, cast<Constant>(Operand), Builder);
246 OperandChanged |= Operand != NewOperand;
251 if (!OperandChanged) {
259 case Instruction::ICmp:
262 NewOperands[0], NewOperands[1]);
263 case Instruction::FCmp:
266 "on float point CompareConstantExpr (fcmp)!");
267 case Instruction::ExtractElement:
270 case Instruction::InsertElement:
274 case Instruction::ShuffleVector:
278 case Instruction::ExtractValue:
281 case Instruction::InsertValue:
285 case Instruction::GetElementPtr:
287 return cast<GEPOperator>(
C)->isInBounds()
289 cast<GEPOperator>(C)->getSourceElementType(),
293 cast<GEPOperator>(C)->getSourceElementType(),
298 return Builder.
CreateSelect(NewOperands[0], NewOperands[1], NewOperands[2]);
303 NewOperands[0], NewOperands[1]);
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
ThreadLocalMode getThreadLocalMode() const
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
unsigned getOpcode() const
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 * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
bool isTexture(const Value &val)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
ModulePass * createGenericToNVVMPass()
unsigned getPredicate() const
Return the ICMP or FCMP predicate value.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
LLVMContext & getContext() const
Get the global data context.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
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.
INITIALIZE_PASS(GenericToNVVM, "generic-to-nvvm", "Ensure that the global variables are in the global address space", false, false) bool GenericToNVVM
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
A constant value that is initialized with an expression using other constant values.
Type * getType() const
All values are typed, get the type of this value.
bool isSurface(const Value &val)
LinkageTypes getLinkage() const
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool isSampler(const Value &val)
Value * getOperand(unsigned i) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Represent the analysis usage information of a pass.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
void initializeGenericToNVVMPass(PassRegistry &)
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Value * CreateGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
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.
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
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.
static IntegerType * getInt32Ty(LLVMContext &C)
StringRef getName() const
Return a constant reference to the value's name.
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Type * getValueType() const
ArrayRef< unsigned > getIndices() const
Assert that this is an insertvalue or exactvalue expression and return the list of indices...
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
bool hasInitializer() const
Definitions have initializers, declarations don't.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
PointerType * getType() const
Global values are always pointers.