Go to the documentation of this file.
30 #include "llvm/IR/IntrinsicsNVPTX.h"
42 #define NVVM_REFLECT_FUNCTION "__nvvm_reflect"
46 #define DEBUG_TYPE "nvptx-reflect"
55 NVVMReflect() : NVVMReflect(0) {}
70 cl::desc(
"NVVM reflection, enabled by default"));
74 "Replace occurrences of __nvvm_reflect() calls with 0/1",
false,
82 assert(
F.isDeclaration() &&
"_reflect function should not have a body");
83 assert(
F.getReturnType()->isIntegerTy() &&
84 "_reflect's return type should be integer");
122 Callee->getIntrinsicID() != Intrinsic::nvvm_reflect))
126 assert(Call->getNumOperands() == 2 &&
127 "Wrong number of operands to __nvvm_reflect function");
131 const Value *Str = Call->getArgOperand(0);
132 if (
const CallInst *ConvCall = dyn_cast<CallInst>(Str)) {
134 Str = ConvCall->getArgOperand(0);
138 Str = Str->stripPointerCasts();
139 assert(isa<Constant>(Str) &&
140 "Format of __nvvm_reflect function not recognized");
142 const Value *Operand = cast<Constant>(Str)->getOperand(0);
143 if (
const GlobalVariable *GV = dyn_cast<GlobalVariable>(Operand)) {
146 assert(GV->hasInitializer() &&
147 "Format of _reflect function not recognized");
148 const Constant *Initializer = GV->getInitializer();
149 Operand = Initializer;
152 assert(isa<ConstantDataSequential>(Operand) &&
153 "Format of _reflect function not recognized");
154 assert(cast<ConstantDataSequential>(Operand)->isCString() &&
155 "Format of _reflect function not recognized");
157 StringRef ReflectArg = cast<ConstantDataSequential>(Operand)->getAsString();
158 ReflectArg = ReflectArg.
substr(0, ReflectArg.
size() - 1);
162 if (ReflectArg ==
"__CUDA_FTZ") {
166 if (
auto *
Flag = mdconst::extract_or_null<ConstantInt>(
167 F.getParent()->getModuleFlag(
"nvvm-reflect-ftz")))
168 ReflectVal =
Flag->getSExtValue();
169 }
else if (ReflectArg ==
"__CUDA_ARCH") {
177 I->eraseFromParent();
A set of analyses that are preserved following a run of a transformation pass.
This is an optimization pass for GlobalISel generic memory operations.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
#define NVVM_REFLECT_FUNCTION
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Flag
These should be considered private to the implementation of the MCInstrDesc class.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
static cl::opt< bool > NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true), cl::Hidden, cl::desc("NVVM reflection, enabled by default"))
inst_range instructions(Function *F)
This is an important base class in LLVM.
FunctionPass * createNVVMReflectPass(unsigned int SmVersion)
initializer< Ty > init(const Ty &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
void initializeNVVMReflectPass(PassRegistry &)
amdgpu Simplify well known AMD library false FunctionCallee Callee
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
static bool runOnFunction(Function &F, bool PostInlining)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
SmallVector< Instruction *, 4 > ToRemove
INITIALIZE_PASS(NVVMReflect, "nvvm-reflect", "Replace occurrences of __nvvm_reflect() calls with 0/1", false, false) static bool runNVVMReflect(Function &F
A container for analyses that lazily runs them and caches their results.
FunctionPass class - This class is used to implement most global optimizations.
This class represents a function call, abstracting a target machine's calling convention.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM Value Representation.