38  bool runOnModule(
Module &M);
 
   43  Value *remapConstantVectorOrConstantAggregate(
Module *M, Function *
F,
 
   46  Value *remapConstantExpr(
Module *M, Function *
F, ConstantExpr *
C,
 
   49  typedef ValueMap<GlobalVariable *, GlobalVariable *> GVMapTy;
 
   50  typedef ValueMap<Constant *, Value *> ConstantToValueMapTy;
 
   52  ConstantToValueMapTy ConstantToValueMap;
 
   56bool GenericToNVVM::runOnModule(
Module &M) {
 
   65        !GV.getName().starts_with(
"llvm.")) {
 
   66      GlobalVariable *NewGV = 
new GlobalVariable(
 
   67          M, GV.getValueType(), GV.isConstant(), GV.getLinkage(),
 
   68          GV.hasInitializer() ? GV.getInitializer() : 
nullptr, 
"", &GV,
 
   85  for (Function &
F : M) {
 
   86    if (
F.isDeclaration()) {
 
   89    IRBuilder<> Builder(&*
F.getEntryBlock().getFirstNonPHIOrDbg());
 
   90    for (BasicBlock &BB : 
F) {
 
   91      for (Instruction &
II : BB) {
 
   92        for (
unsigned i = 0, e = 
II.getNumOperands(); i < e; ++i) {
 
   93          Value *Operand = 
II.getOperand(i);
 
  101    ConstantToValueMap.
clear();
 
  107    VM[
I->first] = 
I->second;
 
  113  for (GVMapTy::iterator 
I = GVMap.
begin(), 
E = GVMap.
end(); 
I != 
E;) {
 
  114    GlobalVariable *GV = 
I->first;
 
  115    GlobalVariable *NewGV = 
I->second;
 
  119    auto Next = std::next(
I);
 
  132  assert(GVMap.
empty() && 
"Expected it to be empty by now");
 
  137Value *GenericToNVVM::remapConstant(
Module *M, Function *
F, Constant *
C,
 
  141  ConstantToValueMapTy::iterator CTII = ConstantToValueMap.
find(
C);
 
  142  if (CTII != ConstantToValueMap.
end()) {
 
  154    if (
I != GVMap.
end()) {
 
  155      GlobalVariable *GV = 
I->second;
 
  163    NewValue = remapConstantVectorOrConstantAggregate(M, 
F, 
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);
 
  186    OperandChanged |= Operand != NewOperand;
 
  191  if (!OperandChanged) {
 
  200    for (
unsigned i = 0; i < NumOperands; ++i) {
 
  201      Value *Idx = ConstantInt::get(Type::getInt32Ty(
M->getContext()), i);
 
  205    for (
unsigned i = 0; i < NumOperands; ++i) {
 
  214Value *GenericToNVVM::remapConstantExpr(
Module *M, Function *
F, ConstantExpr *
C,
 
  216  bool OperandChanged = 
false;
 
  218  unsigned NumOperands = 
C->getNumOperands();
 
  222  for (
unsigned i = 0; i < NumOperands; ++i) {
 
  223    Value *Operand = 
C->getOperand(i);
 
  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:
 
  253                             ArrayRef(&NewOperands[1], NumOperands - 1), 
"",
 
  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 {
 
  278  GenericToNVVMLegacyPass() : ModulePass(
ID) {}
 
  280  bool runOnModule(
Module &M) 
override;
 
  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);
 
 
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.
 
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
 
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...
 
void initializeGenericToNVVMLegacyPassPass(PassRegistry &)
 
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)