43 bool runOnModule(
Module &M)
override;
61 ConstantToValueMapTy ConstantToValueMap;
70 GenericToNVVM,
"generic-to-nvvm",
71 "Ensure that the global variables are in the global address space",
false,
106 if (
I->isDeclaration()) {
109 IRBuilder<> Builder(
I->getEntryBlock().getFirstNonPHIOrDbg());
114 for (
unsigned i = 0, e = II->getNumOperands();
i < e; ++
i) {
115 Value *Operand = II->getOperand(
i);
116 if (isa<Constant>(Operand)) {
118 i, remapConstant(&M, &*
I, cast<Constant>(Operand), Builder));
123 ConstantToValueMap.clear();
128 for (
auto I = GVMap.begin(),
E = GVMap.end();
I !=
E; ++
I)
129 VM[
I->first] =
I->second;
135 for (GVMapTy::iterator
I = GVMap.begin(),
E = GVMap.end();
I !=
E;) {
141 auto Next = std::next(
I);
154 assert(GVMap.empty() &&
"Expected it to be empty by now");
163 Value *CVTA =
nullptr;
178 M, Intrinsic::nvvm_ptr_global_to_gen, {ResultType, DestTy});
179 CVTA = Builder.
CreateCall(CVTAFunction, CVTA,
"cvta");
192 M, Intrinsic::nvvm_ptr_global_to_gen, ParamTypes);
193 CVTA = Builder.
CreateCall(CVTAFunction, GV,
"cvta");
203 ConstantToValueMapTy::iterator CTII = ConstantToValueMap.find(C);
204 if (CTII != ConstantToValueMap.end()) {
209 if (isa<GlobalVariable>(C)) {
218 GVMapTy::iterator
I = GVMap.find(cast<GlobalVariable>(C));
219 if (I != GVMap.end()) {
220 NewValue = getOrInsertCVTA(M, F, I->second, Builder);
222 }
else if (isa<ConstantAggregate>(C)) {
226 NewValue = remapConstantVectorOrConstantAggregate(M, F, C, Builder);
227 }
else if (isa<ConstantExpr>(C)) {
231 NewValue = remapConstantExpr(M, F, cast<ConstantExpr>(C), Builder);
234 ConstantToValueMap[
C] = NewValue;
238 Value *GenericToNVVM::remapConstantVectorOrConstantAggregate(
240 bool OperandChanged =
false;
246 for (
unsigned i = 0;
i < NumOperands; ++
i) {
248 Value *NewOperand = remapConstant(M, F, cast<Constant>(Operand), Builder);
249 OperandChanged |= Operand != NewOperand;
254 if (!OperandChanged) {
262 if (isa<ConstantVector>(C)) {
263 for (
unsigned i = 0;
i < NumOperands; ++
i) {
268 for (
unsigned i = 0;
i < NumOperands; ++
i) {
279 bool OperandChanged =
false;
285 for (
unsigned i = 0;
i < NumOperands; ++
i) {
287 Value *NewOperand = remapConstant(M, F, cast<Constant>(Operand), Builder);
288 OperandChanged |= Operand != NewOperand;
293 if (!OperandChanged) {
301 case Instruction::ICmp:
304 NewOperands[0], NewOperands[1]);
305 case Instruction::FCmp:
308 "on float point CompareConstantExpr (fcmp)!");
309 case Instruction::ExtractElement:
312 case Instruction::InsertElement:
316 case Instruction::ShuffleVector:
320 case Instruction::ExtractValue:
323 case Instruction::InsertValue:
327 case Instruction::GetElementPtr:
329 return cast<GEPOperator>(
C)->isInBounds()
331 cast<GEPOperator>(C)->getSourceElementType(),
335 cast<GEPOperator>(C)->getSourceElementType(),
340 return Builder.
CreateSelect(NewOperands[0], NewOperands[1], NewOperands[2]);
345 NewOperands[0], NewOperands[1]);
void push_back(const T &Elt)
LinkageTypes getLinkage() const
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
A Module instance is used to store all the information related to an LLVM module. ...
unsigned getNumOperands() const
bool isTexture(const Value &val)
Type * getValueType() const
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
INITIALIZE_PASS(GenericToNVVM,"generic-to-nvvm","Ensure that the global variables are in the global address space", false, false) bool GenericToNVVM
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.
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
StringRef getName() const
Return a constant reference to the value's 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.
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.
A constant value that is initialized with an expression using other constant values.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
bool isSurface(const Value &val)
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.
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
bool isSampler(const Value &val)
Class to represent pointers.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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.
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)
Represent the analysis usage information of a pass.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
Value * getOperand(unsigned i) const
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
unsigned getPredicate() const
Return the ICMP or FCMP predicate value.
ArrayRef< unsigned > getIndices() const
Assert that this is an insertvalue or exactvalue expression and return the list of indices...
EVT - Extended Value Type.
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.
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.
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.
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 GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
Value * CreateGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
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...
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...
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
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...
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="")
bool isFloatingPoint() const
isFloatingPoint - Return true if this is a FP, or a vector FP type.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
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="")
static IntegerType * getInt8Ty(LLVMContext &C)
LLVMContext & getContext() const
Get the global data context.