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()) {
159 }
else if (isa<ConstantAggregate>(
C)) {
163 NewValue = remapConstantVectorOrConstantAggregate(M,
F,
C, Builder);
164 }
else if (isa<ConstantExpr>(
C)) {
168 NewValue = remapConstantExpr(M,
F, cast<ConstantExpr>(
C), Builder);
171 ConstantToValueMap[
C] = NewValue;
175Value *GenericToNVVM::remapConstantVectorOrConstantAggregate(
177 bool OperandChanged =
false;
179 unsigned NumOperands =
C->getNumOperands();
183 for (
unsigned i = 0; i < NumOperands; ++i) {
184 Value *Operand =
C->getOperand(i);
185 Value *NewOperand = remapConstant(M,
F, cast<Constant>(Operand), Builder);
186 OperandChanged |= Operand != NewOperand;
191 if (!OperandChanged) {
199 if (isa<ConstantVector>(
C)) {
200 for (
unsigned i = 0; i < NumOperands; ++i) {
205 for (
unsigned i = 0; i < NumOperands; ++i) {
216 bool OperandChanged =
false;
218 unsigned NumOperands =
C->getNumOperands();
222 for (
unsigned i = 0; i < NumOperands; ++i) {
223 Value *Operand =
C->getOperand(i);
224 Value *NewOperand = remapConstant(M,
F, cast<Constant>(Operand), Builder);
225 OperandChanged |= Operand != NewOperand;
230 if (!OperandChanged) {
236 unsigned Opcode =
C->getOpcode();
238 case Instruction::ExtractElement:
241 case Instruction::InsertElement:
245 case Instruction::ShuffleVector:
249 case Instruction::GetElementPtr:
251 return Builder.
CreateGEP(cast<GEPOperator>(
C)->getSourceElementType(),
253 ArrayRef(&NewOperands[1], NumOperands - 1),
"",
254 cast<GEPOperator>(
C)->isInBounds());
255 case Instruction::Select:
257 return Builder.
CreateSelect(NewOperands[0], NewOperands[1], NewOperands[2]);
262 NewOperands[0], NewOperands[1]);
267 NewOperands[0],
C->getType());
274class GenericToNVVMLegacyPass :
public ModulePass {
284char GenericToNVVMLegacyPass::ID = 0;
287 return new GenericToNVVMLegacyPass();
291 GenericToNVVMLegacyPass,
"generic-to-nvvm",
292 "Ensure that the global variables are in the global address space",
false,
295bool GenericToNVVMLegacyPass::runOnModule(
Module &M) {
296 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.
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 * CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr, FMFSource FMFSource={})
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 * 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.
LLVMContext & getContext() const
All values hold a context through their type.
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)