28#define DEBUG_TYPE "kernel-info"
41 bool ExternalNotKernel =
false;
54 int64_t AllocasDyn = 0;
55 int64_t AllocasStaticSizeSum = 0;
58 int64_t DirectCalls = 0;
59 int64_t IndirectCalls = 0;
63 int64_t DirectCallsToDefinedFunctions = 0;
66 int64_t InlineAssemblyCalls = 0;
72 unsigned FlatAddrspace;
75 int64_t FlatAddrspaceAccesses = 0;
84 if (
auto *SubProgram =
F->getSubprogram()) {
85 if (SubProgram->isArtificial())
87 Name = SubProgram->getName();
92 V->printAsOperand(OS,
false, M);
96 R <<
"'" << Name <<
"'";
109 bool Artificial =
false;
115 Artificial = DVR.
Variable->isArtificial();
127 R <<
"alloca ('" << ValName <<
"') ";
128 if (!DbgName.
empty())
129 R <<
"for '" << DbgName <<
"' ";
131 R <<
"without debug info ";
134 R <<
"static size of " <<
itostr(StaticSize) <<
" bytes";
148 R <<
", " << CallKind <<
", callee is ";
162 R <<
", '" <<
II->getCalledFunction()->getName() <<
"' call";
170 R <<
" ('" << Name <<
"')";
172 R <<
" accesses memory in flat address space";
177void KernelInfo::updateForBB(
const BasicBlock &BB,
181 const DataLayout &
DL =
M.getDataLayout();
182 for (
const Instruction &
I : BB) {
185 TypeSize::ScalarTy StaticSize = 0;
186 if (std::optional<TypeSize>
Size = Alloca->getAllocationSize(
DL)) {
187 StaticSize =
Size->getFixedValue();
189 (TypeSize::ScalarTy)std::numeric_limits<int64_t>::max());
190 AllocasStaticSizeSum += StaticSize;
198 SmallString<40> CallKind;
199 SmallString<40> RemarkKind;
202 CallKind +=
"indirect";
203 RemarkKind +=
"Indirect";
206 CallKind +=
"direct";
207 RemarkKind +=
"Direct";
211 CallKind +=
" invoke";
212 RemarkKind +=
"Invoke";
215 RemarkKind +=
"Call";
219 if (!
Callee->isIntrinsic() && !
Callee->isDeclaration()) {
220 ++DirectCallsToDefinedFunctions;
221 CallKind +=
" to defined function";
222 RemarkKind +=
"ToDefinedFunction";
225 ++InlineAssemblyCalls;
226 CallKind +=
" to inline assembly";
227 RemarkKind +=
"ToInlineAssembly";
232 if (
MI->getDestAddressSpace() == FlatAddrspace) {
233 ++FlatAddrspaceAccesses;
235 }
else if (
const AnyMemTransferInst *MT =
237 if (MT->getSourceAddressSpace() == FlatAddrspace) {
238 ++FlatAddrspaceAccesses;
244 if (
Load->getPointerAddressSpace() == FlatAddrspace) {
245 ++FlatAddrspaceAccesses;
249 if (
Store->getPointerAddressSpace() == FlatAddrspace) {
250 ++FlatAddrspaceAccesses;
254 if (At->getPointerAddressSpace() == FlatAddrspace) {
255 ++FlatAddrspaceAccesses;
259 if (At->getPointerAddressSpace() == FlatAddrspace) {
260 ++FlatAddrspaceAccesses;
280 if (!
F.hasFnAttribute(Name))
282 return F.getFnAttributeAsParsedInteger(Name);
288 TargetTransformInfo &TheTTI =
FAM.
getResult<TargetIRAnalysis>(
F);
292 KI.ExternalNotKernel =
F.hasExternalLinkage() && !
F.hasKernelCallingConv();
293 for (StringRef Name : {
"omp_target_num_teams",
"omp_target_thread_limit"}) {
295 KI.LaunchBounds.push_back({
Name, *Val});
299 auto &ORE =
FAM.
getResult<OptimizationRemarkEmitterAnalysis>(
F);
300 for (
const auto &BB :
F)
301 KI.updateForBB(BB, ORE);
303#define REMARK_PROPERTY(PROP_NAME) \
304 remarkProperty(ORE, F, #PROP_NAME, KI.PROP_NAME)
306 for (
auto LB : KI.LaunchBounds)
317#undef REMARK_PROPERTY
323 if (
F.getContext().getDiagHandlerPtr()->isPassedOptRemarkEnabled(
DEBUG_TYPE))
324 KernelInfo::emitKernelInfo(
F, AM, TM);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
static void remarkCall(OptimizationRemarkEmitter &ORE, const Function &Caller, const CallBase &Call, StringRef CallKind, StringRef RemarkKind)
static void remarkAlloca(OptimizationRemarkEmitter &ORE, const Function &Caller, const AllocaInst &Alloca, TypeSize::ScalarTy StaticSize)
static std::optional< int64_t > parseFnAttrAsInteger(Function &F, StringRef Name)
static void remarkProperty(OptimizationRemarkEmitter &ORE, const Function &F, StringRef Name, int64_t Value)
static void remarkFlatAddrspaceAccess(OptimizationRemarkEmitter &ORE, const Function &Caller, const Instruction &Inst)
#define REMARK_PROPERTY(PROP_NAME)
static void identifyCallee(OptimizationRemark &R, const Module *M, const Value *V, StringRef Kind="")
static void identifyFunction(OptimizationRemark &R, const Function &F)
Machine Check Debug Module
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
This file defines the SmallString class.
an instruction to allocate memory on the stack
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
const Function * getParent() const
Return the enclosing method, or null if none.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isInlineAsm() const
Check if this call is an inline asm statement.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
LLVM_ABI bool isIndirectCall() const
Return true if the callsite is an indirect call.
StringRef getName() const
DebugLoc getDebugLoc() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
DbgRecordParamRef< DILocalVariable > Variable
DILocalVariable * getVariable() const
const char * getOpcodeName() const
A wrapper class for inspecting calls to intrinsic functions.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
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 all()
Construct a special preserved set that preserves all passes.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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 bool empty() const
empty - Check if the string is empty.
Primary interface to the complete machine description for the target machine.
bool isVoidTy() const
Return true if this is 'void'.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
const ParentTy * getParent() const
A raw_ostream that writes to an SmallVector or SmallString.
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.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI TinyPtrVector< DbgVariableRecord * > findDVRDeclares(Value *V)
Finds dbg.declare records declaring local variables as living in the memory that 'V' points to.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
std::string itostr(int64_t X)