41 #define NVVM_REFLECT_FUNCTION "__nvvm_reflect"
45 #define DEBUG_TYPE "nvptx-reflect"
57 bool runOnFunction(
Function &)
override;
65 cl::desc(
"NVVM reflection, enabled by default"));
69 "Replace occurrences of __nvvm_reflect() calls with 0/1",
false,
77 assert(F.isDeclaration() &&
"_reflect function should not have a body");
78 assert(F.getReturnType()->isIntegerTy() &&
79 "_reflect's return type should be integer");
122 "Wrong number of operands to __nvvm_reflect function");
127 if (
const CallInst *ConvCall = dyn_cast<CallInst>(Str)) {
129 Str = ConvCall->getArgOperand(0);
131 assert(isa<ConstantExpr>(Str) &&
132 "Format of __nvvm__reflect function not recognized");
136 assert(isa<Constant>(Sym) &&
137 "Format of __nvvm_reflect function not recognized");
139 const Value *Operand = cast<Constant>(Sym)->getOperand(0);
140 if (
const GlobalVariable *GV = dyn_cast<GlobalVariable>(Operand)) {
143 assert(GV->hasInitializer() &&
144 "Format of _reflect function not recognized");
145 const Constant *Initializer = GV->getInitializer();
146 Operand = Initializer;
149 assert(isa<ConstantDataSequential>(Operand) &&
150 "Format of _reflect function not recognized");
151 assert(cast<ConstantDataSequential>(Operand)->isCString() &&
152 "Format of _reflect function not recognized");
154 StringRef ReflectArg = cast<ConstantDataSequential>(Operand)->getAsString();
155 ReflectArg = ReflectArg.
substr(0, ReflectArg.
size() - 1);
156 DEBUG(
dbgs() <<
"Arg of _reflect : " << ReflectArg <<
"\n");
159 if (ReflectArg ==
"__CUDA_FTZ") {
163 if (
auto *
Flag = mdconst::extract_or_null<ConstantInt>(
164 F.getParent()->getModuleFlag(
"nvvm-reflect-ftz")))
165 ReflectVal =
Flag->getSExtValue();
172 I->eraseFromParent();
174 return ToRemove.size() > 0;
void push_back(const T &Elt)
INITIALIZE_PASS(NVVMReflect,"nvvm-reflect","Replace occurrences of __nvvm_reflect() calls with 0/1", false, false) bool NVVMReflect
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
FunctionPass * createNVVMReflectPass()
unsigned getNumOperands() const
This class represents a function call, abstracting a target machine's calling convention.
StringRef getName() const
Return a constant reference to the value's name.
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.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
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...
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).
#define NVVM_REFLECT_FUNCTION
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) 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.
Type * getType() const
All values are typed, get the type of this value.
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.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
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.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
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...