41 #define NVVM_REFLECT_FUNCTION "__nvvm_reflect" 45 #define DEBUG_TYPE "nvptx-reflect" 53 unsigned int SmVersion;
54 NVVMReflect() : NVVMReflect(0) {}
55 explicit NVVMReflect(
unsigned int Sm) :
FunctionPass(ID), SmVersion(Sm) {
64 return new NVVMReflect(SmVersion);
69 cl::desc(
"NVVM reflection, enabled by default"));
73 "Replace occurrences of __nvvm_reflect() calls with 0/1",
false,
77 if (!NVVMReflectEnabled)
81 assert(F.isDeclaration() &&
"_reflect function should not have a body");
82 assert(F.getReturnType()->isIntegerTy() &&
83 "_reflect's return type should be integer");
126 "Wrong number of operands to __nvvm_reflect function");
131 if (
const CallInst *ConvCall = dyn_cast<CallInst>(Str)) {
133 Str = ConvCall->getArgOperand(0);
135 assert(isa<ConstantExpr>(Str) &&
136 "Format of __nvvm__reflect function not recognized");
140 assert(isa<Constant>(Sym) &&
141 "Format of __nvvm_reflect function not recognized");
143 const Value *Operand = cast<Constant>(Sym)->getOperand(0);
144 if (
const GlobalVariable *GV = dyn_cast<GlobalVariable>(Operand)) {
147 assert(GV->hasInitializer() &&
148 "Format of _reflect function not recognized");
149 const Constant *Initializer = GV->getInitializer();
150 Operand = Initializer;
153 assert(isa<ConstantDataSequential>(Operand) &&
154 "Format of _reflect function not recognized");
155 assert(cast<ConstantDataSequential>(Operand)->isCString() &&
156 "Format of _reflect function not recognized");
158 StringRef ReflectArg = cast<ConstantDataSequential>(Operand)->getAsString();
159 ReflectArg = ReflectArg.
substr(0, ReflectArg.
size() - 1);
163 if (ReflectArg ==
"__CUDA_FTZ") {
167 if (
auto *
Flag = mdconst::extract_or_null<ConstantInt>(
168 F.getParent()->getModuleFlag(
"nvvm-reflect-ftz")))
169 ReflectVal =
Flag->getSExtValue();
170 }
else if (ReflectArg ==
"__CUDA_ARCH") {
171 ReflectVal = SmVersion * 10;
178 I->eraseFromParent();
180 return ToRemove.size() > 0;
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
void push_back(const T &Elt)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
This class represents a function call, abstracting a target machine's calling convention.
FunctionPass * createNVVMReflectPass(unsigned int SmVersion)
Value * getArgOperand(unsigned i) const
static cl::opt< bool > NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true), cl::Hidden, cl::desc("NVVM reflection, enabled by default"))
A constant value that is initialized with an expression using other constant values.
Type * getType() const
All values are typed, get the type of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
amdgpu Simplify well known AMD library false Value * Callee
Value * getOperand(unsigned i) const
Flag
These should be considered private to the implementation of the MCInstrDesc class.
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
void initializeNVVMReflectPass(PassRegistry &)
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
#define NVVM_REFLECT_FUNCTION
FunctionPass class - This class is used to implement most global optimizations.
INITIALIZE_PASS(NVVMReflect, "nvvm-reflect", "Replace occurrences of __nvvm_reflect() calls with 0/1", false, false) bool NVVMReflect
unsigned getNumOperands() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
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.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
StringRef getName() const
Return a constant reference to the value's name.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
StringRef - Represent a constant reference to a string, i.e.
inst_range instructions(Function *F)
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...