38 bool runOnModule(
Module &M);
52 ConstantToValueMapTy ConstantToValueMap;
56bool GenericToNVVM::runOnModule(
Module &M) {
65 !GV.getName().starts_with(
"llvm.")) {
67 M, GV.getValueType(), GV.isConstant(), GV.getLinkage(),
68 GV.hasInitializer() ? GV.getInitializer() :
nullptr,
"", &GV,
86 if (
F.isDeclaration()) {
89 IRBuilder<> Builder(
F.getEntryBlock().getFirstNonPHIOrDbg());
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()) {
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) {
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::ExtractElement:
242 case Instruction::InsertElement:
246 case Instruction::ShuffleVector:
250 case Instruction::GetElementPtr:
252 return Builder.
CreateGEP(cast<GEPOperator>(
C)->getSourceElementType(),
254 ArrayRef(&NewOperands[1], NumOperands - 1),
"",
255 cast<GEPOperator>(
C)->isInBounds());
256 case Instruction::Select:
258 return Builder.
CreateSelect(NewOperands[0], NewOperands[1], NewOperands[2]);
263 NewOperands[0], NewOperands[1]);
268 NewOperands[0],
C->getType());
275class GenericToNVVMLegacyPass :
public ModulePass {
285char GenericToNVVMLegacyPass::ID = 0;
288 return new GenericToNVVMLegacyPass();
292 GenericToNVVMLegacyPass,
"generic-to-nvvm",
293 "Ensure that the global variables are in the global address space",
false,
296bool GenericToNVVMLegacyPass::runOnModule(
Module &M) {
297 return GenericToNVVM().runOnModule(M);
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.
uint64_t IntrinsicInst * II
#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.
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.
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.
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
Value * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
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.
@ C
The default llvm calling convention, compatible with C.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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 isSampler(const Value &V)
bool isSurface(const Value &V)
bool isTexture(const Value &V)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)