26#include "llvm/IR/IntrinsicsSPIRV.h"
33#define DEBUG_TYPE "spirv-prepare-globals"
39struct SPIRVPrepareGlobalsImpl {
40 bool runOnModule(
Module &M);
43struct SPIRVPrepareGlobalsLegacy :
public ModulePass {
48 return "SPIRV prepare global variables";
51 bool runOnModule(
Module &M)
override {
52 return SPIRVPrepareGlobalsImpl().runOnModule(M);
70 LLVM_DEBUG(
dbgs() <<
"Skipping alias whose aliasee is not a GlobalObject: "
75 if (AO->isInterposable()) {
76 LLVM_DEBUG(
dbgs() <<
"Skipping interposable aliasee: " << AO->getName()
82 <<
" with aliasee: " << AO->getName() <<
"\n");
94 for (
auto &&U :
F->users()) {
103 unsigned ID = SpecID->getZExtValue();
104 if (
ID != UINT32_MAX)
115 CI->setArgOperand(0, ConstantInt::get(CI->getArgOperand(0)->getType(),
ID));
125 Tmp.append(
Predicate).append(
" ").append(
utostr(SpecID)).push_back(
'\0');
132 PredSpecIDStr,
"llvm.amdgcn.feature.predicate.ids");
137bool SPIRVPrepareGlobalsImpl::runOnModule(
Module &M) {
141 Changed |= tryReplaceAliasWithAliasee(GA);
144 if (M.getTargetTriple().getVendor() !=
Triple::AMD)
151 &M, Intrinsic::spv_named_boolean_spec_constant))
152 Changed |= tryAssignPredicateSpecConstIDs(M,
F);
156char SPIRVPrepareGlobalsLegacy::ID = 0;
161 "SPIRV prepare global variables",
false,
false)
171 return new SPIRVPrepareGlobalsLegacy();
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
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.
LLVM_ABI bool isInterposable(bool CheckNoIPA=true) const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
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.
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.
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.
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.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.