34 bool runOnModule(
Module &M);
39 Value *remapConstantVectorOrConstantAggregate(
Module *M, Function *
F,
42 Value *remapConstantExpr(
Module *M, Function *
F, ConstantExpr *
C,
45 typedef ValueMap<GlobalVariable *, GlobalVariable *> GVMapTy;
46 typedef ValueMap<Constant *, Value *> ConstantToValueMapTy;
48 ConstantToValueMapTy ConstantToValueMap;
52bool GenericToNVVM::runOnModule(
Module &M) {
61 !GV.getName().starts_with(
"llvm.")) {
62 GlobalVariable *NewGV =
new GlobalVariable(
63 M, GV.getValueType(), GV.isConstant(), GV.getLinkage(),
64 GV.hasInitializer() ? GV.getInitializer() :
nullptr,
"", &GV,
81 for (Function &
F : M) {
82 if (
F.isDeclaration()) {
85 IRBuilder<> Builder(&*
F.getEntryBlock().getFirstNonPHIOrDbg());
86 for (BasicBlock &BB :
F) {
87 for (Instruction &
II : BB) {
88 for (
unsigned i = 0, e =
II.getNumOperands(); i < e; ++i) {
89 Value *Operand =
II.getOperand(i);
97 ConstantToValueMap.
clear();
103 VM[
I->first] =
I->second;
109 for (GVMapTy::iterator
I = GVMap.
begin(),
E = GVMap.
end();
I !=
E;) {
110 GlobalVariable *GV =
I->first;
111 GlobalVariable *NewGV =
I->second;
115 auto Next = std::next(
I);
128 assert(GVMap.
empty() &&
"Expected it to be empty by now");
133Value *GenericToNVVM::remapConstant(
Module *M, Function *
F, Constant *
C,
137 ConstantToValueMapTy::iterator CTII = ConstantToValueMap.
find(
C);
138 if (CTII != ConstantToValueMap.
end()) {
150 if (
I != GVMap.
end()) {
151 GlobalVariable *GV =
I->second;
159 NewValue = remapConstantVectorOrConstantAggregate(M,
F,
C, Builder);
167 ConstantToValueMap[
C] = NewValue;
171Value *GenericToNVVM::remapConstantVectorOrConstantAggregate(
173 bool OperandChanged =
false;
175 unsigned NumOperands =
C->getNumOperands();
179 for (
unsigned i = 0; i < NumOperands; ++i) {
180 Value *Operand =
C->getOperand(i);
182 OperandChanged |= Operand != NewOperand;
187 if (!OperandChanged) {
196 for (
unsigned i = 0; i < NumOperands; ++i) {
197 Value *Idx = ConstantInt::get(Type::getInt32Ty(
M->getContext()), i);
201 for (
unsigned i = 0; i < NumOperands; ++i) {
210Value *GenericToNVVM::remapConstantExpr(
Module *M, Function *
F, ConstantExpr *
C,
212 bool OperandChanged =
false;
214 unsigned NumOperands =
C->getNumOperands();
218 for (
unsigned i = 0; i < NumOperands; ++i) {
219 Value *Operand =
C->getOperand(i);
221 OperandChanged |= Operand != NewOperand;
226 if (!OperandChanged) {
232 unsigned Opcode =
C->getOpcode();
234 case Instruction::ExtractElement:
237 case Instruction::InsertElement:
241 case Instruction::ShuffleVector:
245 case Instruction::GetElementPtr:
249 ArrayRef(&NewOperands[1], NumOperands - 1),
"",
251 case Instruction::Select:
253 return Builder.
CreateSelect(NewOperands[0], NewOperands[1], NewOperands[2]);
258 NewOperands[0], NewOperands[1]);
263 NewOperands[0],
C->getType());
270class GenericToNVVMLegacyPass :
public ModulePass {
274 GenericToNVVMLegacyPass() : ModulePass(
ID) {}
276 bool runOnModule(
Module &M)
override;
280char GenericToNVVMLegacyPass::ID = 0;
283 return new GenericToNVVMLegacyPass();
287 GenericToNVVMLegacyPass,
"generic-to-nvvm",
288 "Ensure that the global variables are in the global address space",
false,
291bool GenericToNVVMLegacyPass::runOnModule(
Module &M) {
292 return GenericToNVVM().runOnModule(M);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static LLVM_ABI Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
LLVM_ABI void copyMetadata(const GlobalObject *Src, unsigned Offset)
Copy metadata from Src, adjusting offsets by Offset.
PointerType * getType() const
Global values are always pointers.
LLVM_ABI void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
LLVM_ABI 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="")
LLVM_ABI 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="")
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI 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)
iterator find(const KeyT &Val)
bool erase(const KeyT &Val)
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI 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.
FunctionAddr VTableAddr Value
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...
bool isSampler(const Value &V)
bool isSurface(const Value &V)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
FunctionAddr VTableAddr Next
ArrayRef(const T &OneElt) -> ArrayRef< T >
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool isTexture(const Value &V)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)