29#include "llvm/IR/IntrinsicsNVPTX.h"
41#define NVVM_REFLECT_FUNCTION "__nvvm_reflect"
42#define NVVM_REFLECT_OCL_FUNCTION "__nvvm_reflect_ocl"
46#define DEBUG_TYPE "nvptx-reflect"
55 NVVMReflect() : NVVMReflect(0) {}
70 cl::desc(
"NVVM reflection, enabled by default"));
72char NVVMReflect::ID = 0;
74 "Replace occurrences of __nvvm_reflect() calls with 0/1",
false,
83 assert(
F.isDeclaration() &&
"_reflect function should not have a body");
84 assert(
F.getReturnType()->isIntegerTy() &&
85 "_reflect's return type should be integer");
121 Function *Callee = Call->getCalledFunction();
124 Callee->getIntrinsicID() != Intrinsic::nvvm_reflect))
128 assert(Call->getNumOperands() == 2 &&
129 "Wrong number of operands to __nvvm_reflect function");
133 const Value *Str = Call->getArgOperand(0);
134 if (
const CallInst *ConvCall = dyn_cast<CallInst>(Str)) {
136 Str = ConvCall->getArgOperand(0);
140 Str = Str->stripPointerCasts();
141 assert(isa<Constant>(Str) &&
142 "Format of __nvvm_reflect function not recognized");
144 const Value *Operand = cast<Constant>(Str)->getOperand(0);
145 if (
const GlobalVariable *GV = dyn_cast<GlobalVariable>(Operand)) {
148 assert(GV->hasInitializer() &&
149 "Format of _reflect function not recognized");
150 const Constant *Initializer = GV->getInitializer();
151 Operand = Initializer;
154 assert(isa<ConstantDataSequential>(Operand) &&
155 "Format of _reflect function not recognized");
156 assert(cast<ConstantDataSequential>(Operand)->isCString() &&
157 "Format of _reflect function not recognized");
159 StringRef ReflectArg = cast<ConstantDataSequential>(Operand)->getAsString();
160 ReflectArg = ReflectArg.
substr(0, ReflectArg.
size() - 1);
164 if (ReflectArg ==
"__CUDA_FTZ") {
168 if (
auto *Flag = mdconst::extract_or_null<ConstantInt>(
169 F.getParent()->getModuleFlag(
"nvvm-reflect-ftz")))
170 ReflectVal = Flag->getSExtValue();
171 }
else if (ReflectArg ==
"__CUDA_ARCH") {
179 I->eraseFromParent();
184bool NVVMReflect::runOnFunction(
Function &
F) {
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Select target instructions out of generic instructions
Module.h This file contains the declarations for the Module class.
#define NVVM_REFLECT_OCL_FUNCTION
#define NVVM_REFLECT_FUNCTION
static cl::opt< bool > NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true), cl::Hidden, cl::desc("NVVM reflection, enabled by default"))
SmallVector< Instruction *, 4 > ToRemove
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
A container for analyses that lazily runs them and caches their results.
This class represents a function call, abstracting a target machine's calling convention.
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.
This is an important base class in LLVM.
FunctionPass class - This class is used to implement most global optimizations.
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
constexpr size_t size() const
size - Get the string size.
LLVM Value Representation.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createNVVMReflectPass(unsigned int SmVersion)
void initializeNVVMReflectPass(PassRegistry &)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)