38 bool runOnModule(
Module &M);
52 ConstantToValueMapTy ConstantToValueMap;
56bool GenericToNVVM::runOnModule(
Module &M) {
65 !GV.getName().startswith(
"llvm.")) {
67 M, GV.getValueType(), GV.isConstant(), GV.getLinkage(),
68 GV.hasInitializer() ? GV.getInitializer() :
nullptr,
"", &GV,
86 if (
F.isDeclaration()) {
92 for (
unsigned i = 0, e = II.getNumOperands(); i < e; ++i) {
93 Value *Operand = II.getOperand(i);
94 if (isa<Constant>(Operand)) {
96 i, remapConstant(&M, &
F, cast<Constant>(Operand), Builder));
101 ConstantToValueMap.clear();
106 for (
auto I = GVMap.begin(),
E = GVMap.end();
I !=
E; ++
I)
107 VM[
I->first] =
I->second;
113 for (GVMapTy::iterator
I = GVMap.begin(),
E = GVMap.end();
I !=
E;) {
119 auto Next = std::next(
I);
132 assert(GVMap.empty() &&
"Expected it to be empty by now");
141 ConstantToValueMapTy::iterator CTII = ConstantToValueMap.find(
C);
142 if (CTII != ConstantToValueMap.end()) {
147 if (isa<GlobalVariable>(
C)) {
153 GVMapTy::iterator
I = GVMap.find(cast<GlobalVariable>(
C));
154 if (
I != GVMap.end()) {
156 NewValue =
Builder.CreateAddrSpaceCast(
160 }
else if (isa<ConstantAggregate>(
C)) {
164 NewValue = remapConstantVectorOrConstantAggregate(M,
F,
C, Builder);
165 }
else if (isa<ConstantExpr>(
C)) {
169 NewValue = remapConstantExpr(M,
F, cast<ConstantExpr>(
C), Builder);
172 ConstantToValueMap[
C] = NewValue;
176Value *GenericToNVVM::remapConstantVectorOrConstantAggregate(
178 bool OperandChanged =
false;
180 unsigned NumOperands =
C->getNumOperands();
184 for (
unsigned i = 0; i < NumOperands; ++i) {
185 Value *Operand =
C->getOperand(i);
186 Value *NewOperand = remapConstant(M,
F, cast<Constant>(Operand), Builder);
187 OperandChanged |= Operand != NewOperand;
192 if (!OperandChanged) {
200 if (isa<ConstantVector>(
C)) {
201 for (
unsigned i = 0; i < NumOperands; ++i) {
203 NewValue =
Builder.CreateInsertElement(NewValue, NewOperands[i],
Idx);
206 for (
unsigned i = 0; i < NumOperands; ++i) {
217 bool OperandChanged =
false;
219 unsigned NumOperands =
C->getNumOperands();
223 for (
unsigned i = 0; i < NumOperands; ++i) {
224 Value *Operand =
C->getOperand(i);
225 Value *NewOperand = remapConstant(M,
F, cast<Constant>(Operand), Builder);
226 OperandChanged |= Operand != NewOperand;
231 if (!OperandChanged) {
237 unsigned Opcode =
C->getOpcode();
239 case Instruction::ICmp:
242 NewOperands[0], NewOperands[1]);
243 case Instruction::FCmp:
246 "on float point CompareConstantExpr (fcmp)!");
247 case Instruction::ExtractElement:
249 return Builder.CreateExtractElement(NewOperands[0], NewOperands[1]);
250 case Instruction::InsertElement:
252 return Builder.CreateInsertElement(NewOperands[0], NewOperands[1],
254 case Instruction::ShuffleVector:
256 return Builder.CreateShuffleVector(NewOperands[0], NewOperands[1],
258 case Instruction::GetElementPtr:
260 return Builder.CreateGEP(cast<GEPOperator>(
C)->getSourceElementType(),
262 ArrayRef(&NewOperands[1], NumOperands - 1),
"",
263 cast<GEPOperator>(
C)->isInBounds());
264 case Instruction::Select:
266 return Builder.CreateSelect(NewOperands[0], NewOperands[1], NewOperands[2]);
271 NewOperands[0], NewOperands[1]);
276 NewOperands[0],
C->getType());
283class GenericToNVVMLegacyPass :
public ModulePass {
293char GenericToNVVMLegacyPass::ID = 0;
296 return new GenericToNVVMLegacyPass();
300 GenericToNVVMLegacyPass,
"generic-to-nvvm",
301 "Ensure that the global variables are in the global address space",
false,
304bool GenericToNVVMLegacyPass::runOnModule(
Module &M) {
305 return GenericToNVVM().runOnModule(M);
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A container for analyses that lazily runs them and caches their results.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
A constant value that is initialized with an expression using other constant values.
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
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.
This is an important base class in LLVM.
void copyMetadata(const GlobalObject *Src, unsigned Offset)
Copy metadata from Src, adjusting offsets by Offset.
PointerType * getType() const
Global values are always pointers.
Type * getValueType() const
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static IntegerType * getInt32Ty(LLVMContext &C)
LLVM Value Representation.
void setName(const Twine &Name)
Change the name of the value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
StringRef getName() const
Return a constant reference to the value's name.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
ModulePass * createGenericToNVVMLegacyPass()
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
void initializeGenericToNVVMLegacyPassPass(PassRegistry &)
bool isSurface(const Value &val)
bool isTexture(const Value &val)
bool isSampler(const Value &val)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)