44 virtual bool runOnModule(
Module &M);
65 ConstantToValueMapTy ConstantToValueMap;
74 GenericToNVVM,
"generic-to-nvvm",
75 "Ensure that the global variables are in the global address space",
false,
109 if (
I->isDeclaration()) {
112 IRBuilder<> Builder(
I->getEntryBlock().getFirstNonPHIOrDbg());
117 for (
unsigned i = 0, e = II->getNumOperands(); i < e; ++i) {
118 Value *Operand = II->getOperand(i);
119 if (isa<Constant>(Operand)) {
121 i, remapConstant(&M,
I, cast<Constant>(Operand), Builder));
126 ConstantToValueMap.clear();
132 E = M.named_metadata_end();
134 remapNamedMDNode(&M,
I);
141 for (GVMapTy::iterator
I = GVMap.begin(), E = GVMap.end();
I != E;) {
151 Use &U = (UI++).getUse();
187 CVTA = Builder.
CreateCall(CVTAFunction, CVTA,
"cvta");
201 CVTA = Builder.
CreateCall(CVTAFunction, GV,
"cvta");
211 ConstantToValueMapTy::iterator CTII = ConstantToValueMap.find(C);
212 if (CTII != ConstantToValueMap.end()) {
217 if (isa<GlobalVariable>(C)) {
226 GVMapTy::iterator
I = GVMap.find(cast<GlobalVariable>(C));
227 if (I != GVMap.end()) {
228 NewValue = getOrInsertCVTA(M, F, I->second, Builder);
230 }
else if (isa<ConstantVector>(C) || isa<ConstantArray>(C) ||
231 isa<ConstantStruct>(C)) {
235 NewValue = remapConstantVectorOrConstantAggregate(M, F, C, Builder);
236 }
else if (isa<ConstantExpr>(C)) {
240 NewValue = remapConstantExpr(M, F, cast<ConstantExpr>(C), Builder);
243 ConstantToValueMap[
C] = NewValue;
247 Value *GenericToNVVM::remapConstantVectorOrConstantAggregate(
249 bool OperandChanged =
false;
255 for (
unsigned i = 0; i < NumOperands; ++i) {
257 Value *NewOperand = remapConstant(M, F, cast<Constant>(Operand), Builder);
258 OperandChanged |= Operand != NewOperand;
263 if (!OperandChanged) {
271 if (isa<ConstantVector>(C)) {
272 for (
unsigned i = 0; i < NumOperands; ++i) {
277 for (
unsigned i = 0; i < NumOperands; ++i) {
288 bool OperandChanged =
false;
294 for (
unsigned i = 0; i < NumOperands; ++i) {
296 Value *NewOperand = remapConstant(M, F, cast<Constant>(Operand), Builder);
297 OperandChanged |= Operand != NewOperand;
302 if (!OperandChanged) {
310 case Instruction::ICmp:
313 NewOperands[0], NewOperands[1]);
314 case Instruction::FCmp:
316 assert(
false &&
"Address space conversion should have no effect "
317 "on float point CompareConstantExpr (fcmp)!");
322 case Instruction::InsertElement:
326 case Instruction::ShuffleVector:
330 case Instruction::ExtractValue:
333 case Instruction::InsertValue:
337 case Instruction::GetElementPtr:
339 return cast<GEPOperator>(
C)->isInBounds()
348 return Builder.
CreateSelect(NewOperands[0], NewOperands[1], NewOperands[2]);
353 NewOperands[0], NewOperands[1]);
360 assert(
false &&
"GenericToNVVM encountered an unsupported ConstantExpr");
367 bool OperandChanged =
false;
373 for (
unsigned i = 0; i < NumOperands; ++i) {
375 MDNode *NewOperand = remapMDNode(M, Operand);
376 OperandChanged |= Operand != NewOperand;
381 if (!OperandChanged) {
388 E = NewOperands.
end();
396 bool OperandChanged =
false;
402 for (
unsigned i = 0; i < NumOperands; ++i) {
404 Value *NewOperand = Operand;
406 if (isa<GlobalVariable>(Operand)) {
407 GVMapTy::iterator I = GVMap.find(cast<GlobalVariable>(Operand));
408 if (I != GVMap.end()) {
409 NewOperand = I->second;
410 if (++i < NumOperands) {
417 I->second->getType()->getAddressSpace());
420 }
else if (isa<MDNode>(Operand)) {
421 NewOperand = remapMDNode(M, cast<MDNode>(Operand));
424 OperandChanged |= Operand != NewOperand;
429 if (!OperandChanged) {
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="")
ThreadLocalMode getThreadLocalMode() const
The main container class for the LLVM Intermediate Representation.
unsigned getNumOperands() const
unsigned getNumOperands() const
getNumOperands - Return number of MDNode operands.
void addOperand(MDNode *M)
addOperand - Add metadata operand.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
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 &)
MDNode - a tuple of other values.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
ModulePass * createGenericToNVVMPass()
const Constant * getInitializer() const
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
static MDNode * get(LLVMContext &Context, ArrayRef< Value * > Vals)
Value * CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, const Twine &Name="")
StringRef getName() const
Value * getOperand(unsigned i) const LLVM_READONLY
getOperand - Return specified operand.
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)
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
ID
LLVM Calling Convention Representation.
bool isInteger() const
isInteger - Return true if this is an integer, or a vector integer type.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Type * getElementType() const
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="")
LLVM Constant Representation.
virtual void eraseFromParent()
MDNode * getOperand(unsigned i) const
getOperand - Return specified operand.
Value * getOperand(unsigned i) const
unsigned getPredicate() const
ArrayRef< unsigned > getIndices() const
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
static UndefValue * get(Type *T)
void initializeGenericToNVVMPass(PassRegistry &)
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast 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="")
void copyAttributesFrom(const GlobalValue *Src)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
bool hasInitializer() const
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="")
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
PointerType * getType() const
getType - Global values are always pointers.
static IntegerType * getInt32Ty(LLVMContext &C)
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
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 &)
void removeDeadConstantUsers() const
LLVM Value Representation.
CallInst * CreateCall(Value *Callee, const Twine &Name="")
unsigned getNumOperands() const
getNumOperands - Return the number of NamedMDNode operands.
void dropAllReferences()
dropAllReferences - Remove all uses and clear node vector.
static IntegerType * getInt8Ty(LLVMContext &C)
LLVMContext & getContext() const