25#include "llvm/IR/IntrinsicsSPIRV.h"
32#define DEBUG_TYPE "spirv-prepare-globals"
38struct SPIRVPrepareGlobals :
public ModulePass {
43 return "SPIRV prepare global variables";
46 bool runOnModule(
Module &M)
override;
63 LLVM_DEBUG(
dbgs() <<
"Skipping alias whose aliasee is not a GlobalObject: "
68 if (AO->isInterposable()) {
69 LLVM_DEBUG(
dbgs() <<
"Skipping interposable aliasee: " << AO->getName()
75 <<
" with aliasee: " << AO->getName() <<
"\n");
87 for (
auto &&U :
F->users()) {
96 unsigned ID = SpecID->getZExtValue();
108 CI->setArgOperand(0, ConstantInt::get(CI->getArgOperand(0)->getType(),
ID));
118 Tmp.append(
Predicate).append(
" ").append(
utostr(SpecID)).push_back(
'\0');
125 PredSpecIDStr,
"llvm.amdgcn.feature.predicate.ids");
130bool SPIRVPrepareGlobals::runOnModule(
Module &M) {
134 Changed |= tryReplaceAliasWithAliasee(GA);
137 if (M.getTargetTriple().getVendor() !=
Triple::AMD)
144 &M, Intrinsic::spv_named_boolean_spec_constant))
145 Changed |= tryAssignPredicateSpecConstIDs(M,
F);
149char SPIRVPrepareGlobals::ID = 0;
154 "SPIRV prepare global variables",
false,
false)
158 return new SPIRVPrepareGlobals();
This file defines the StringMap class.
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true, bool ByteString=false)
This method constructs a CDS and initializes it with a text string.
This is an important base class in LLVM.
LLVM_ABI void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
const Constant * getAliasee() const
LLVM_ABI bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
static bool isDiscardableIfUnused(LinkageTypes Linkage)
Whether the definition of this global may be discarded if it is not used in its compilation unit.
@ ExternalLinkage
Externally visible function.
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.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
StringRef - Represent a constant reference to a string, i.e.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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...
std::string utostr(uint64_t X, bool isNeg=false)
ModulePass * createSPIRVPrepareGlobalsPass()
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.