LLVM: lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

22

23#define DEBUG_TYPE "amdgpu-mc-resource-usage"

24

25using namespace llvm;

26

28 MCContext &OutContext, bool IsLocal) {

29 auto GOCS = [FuncName, &OutContext, IsLocal](StringRef Suffix) {

34 };

35 switch (RIK) {

37 return GOCS(".num_vgpr");

39 return GOCS(".num_agpr");

41 return GOCS(".numbered_sgpr");

43 return GOCS(".num_named_barrier");

45 return GOCS(".private_seg_size");

47 return GOCS(".uses_vcc");

49 return GOCS(".uses_flat_scratch");

51 return GOCS(".has_dyn_sized_stack");

53 return GOCS(".has_recursion");

55 return GOCS(".has_indirect_call");

56 }

58}

59

65

66void MCResourceInfo::assignMaxRegs(MCContext &OutContext) {

67

72

73 auto assignMaxRegSym = [&OutContext](MCSymbol *Sym, int32_t RegCount) {

76 };

77

78 assignMaxRegSym(MaxVGPRSym, MaxVGPR);

79 assignMaxRegSym(MaxAGPRSym, MaxAGPR);

80 assignMaxRegSym(MaxSGPRSym, MaxSGPR);

81 assignMaxRegSym(MaxNamedBarrierSym, MaxNamedBarrier);

82}

83

85

87 assert(!Finalized && "Cannot finalize ResourceInfo again.");

88 Finalized = true;

89 assignMaxRegs(OutContext);

90}

91

95

99

103

107

108

109

110

111

112

113

114

115const MCExpr *MCResourceInfo::flattenedCycleMax(MCSymbol *RecSym,

116 ResourceInfoKind RIK,

120 int64_t Maximum = 0;

121

124

125 while (!WorkList.empty()) {

127 switch (CurExpr->getKind()) {

128 default: {

129

130

131

132

135 << ": Recursion in unexpected sub-expression, using "

136 "module maximum\n");

137 switch (RIK) {

138 default:

139 break;

142 OutContext);

143 break;

146 OutContext);

147 break;

150 OutContext);

151 break;

152 }

153 }

154 break;

155 }

158 Maximum = std::max(Maximum, Val);

159 break;

160 }

166 if (Seen.insert(SymVal).second)

168 }

169 break;

170 }

174 for (auto &Arg : TargetExpr->getArgs())

176 }

177 break;

178 }

179 }

180 }

181

183 << ": Using flattened max: << " << Maximum << '\n');

184

186}

187

188void MCResourceInfo::assignResourceInfoExpr(

192 const TargetMachine &TM = MF.getTarget();

195 const MCConstantExpr *LocalConstExpr =

197 const MCExpr *SymVal = LocalConstExpr;

200 << LocalValue << " as function local usage\n");

201 if (!Callees.empty()) {

203 SmallPtrSet<const Function *, 8> Seen;

204 ArgExprs.push_back(LocalConstExpr);

205

206 for (const Function *Callee : Callees) {

207 if (!Seen.insert(Callee).second)

208 continue;

209

210 bool IsCalleeLocal = Callee->hasLocalLinkage();

213 getSymbol(CalleeFnSym->getName(), RIK, OutContext, IsCalleeLocal);

214

215

216

221 << CalleeValSym->getName() << " as callee\n");

223 } else {

225 << ": Recursion found, attempt flattening of cycle "

226 "for resource usage\n");

227

228

229

230 switch (RIK) {

231 default:

232 break;

236 ArgExprs.push_back(flattenedCycleMax(CalleeValSym, RIK, OutContext));

237 break;

241 break;

242 }

243 }

244 }

245 if (ArgExprs.size() > 1)

247 }

249}

250

255

261

267 }

268

271

272 LLVM_DEBUG(dbgs() << "MCResUse: Gathering resource information for "

273 << FnSym->getName() << '\n');

275 if (!FRI.Callees.empty()) {

276 dbgs() << "MCResUse: Callees:\n";

279 dbgs() << "MCResUse: " << CalleeFnSym->getName() << '\n';

280 }

281 }

282 });

283

284 auto SetMaxReg = [&](MCSymbol *MaxSym, int32_t numRegs,

288 FRI.Callees, OutContext);

289 } else {

297 << ": Indirect callee within, using module maximum\n");

298 }

299 };

300

306

307 {

308

309

316 << " for indirect/recursive callees within\n");

319 }

320

324 if (!Seen.insert(Callee).second)

325 continue;

326 if (!Callee->isDeclaration()) {

327 bool IsCalleeLocal = Callee->hasLocalLinkage();

331 IsCalleeLocal);

332

333

334

339 << CalleeValSym->getName() << " as callee\n");

341 }

342 }

343 }

344 const MCExpr *localConstExpr =

348 << " as function local usage\n");

349 if (!ArgExprs.empty()) {

352 localConstExpr =

354 }

356 }

357

358 auto SetToLocal = [&](int64_t LocalValue, ResourceInfoKind RIK) {

361 dbgs() << "MCResUse: " << Sym->getName() << ": Adding " << LocalValue

362 << ", no further propagation as indirect callee found within\n");

364 };

365

380 } else {

387 }

388}

389

399

401 bool hasXnack,

411 hasXnack, Ctx),

412 Ctx);

413}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

MC infrastructure to propagate the function level resource usage info.

AMDGPU target specific MCExpr operations.

ArrayRef< const MCExpr * > getArgs() const

static const AMDGPUMCExpr * createMax(ArrayRef< const MCExpr * > Args, MCContext &Ctx)

static const AMDGPUMCExpr * createTotalNumVGPR(const MCExpr *NumAGPR, const MCExpr *NumVGPR, MCContext &Ctx)

static const AMDGPUMCExpr * create(VariantKind Kind, ArrayRef< const MCExpr * > Args, MCContext &Ctx)

static const AMDGPUMCExpr * createExtraSGPRs(const MCExpr *VCCUsed, const MCExpr *FlatScrUsed, bool XNACKUsed, MCContext &Ctx)

Allow delayed MCExpr resolve of ExtraSGPRs (in case VCCUsed or FlatScrUsed are unresolvable but neede...

VariantKind getKind() const

static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *E)

CallingConv::ID getCallingConv() const

getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...

bool hasLocalLinkage() const

StringRef getPrivateGlobalPrefix() const

static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())

static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)

Context object for machine code objects.

const MCAsmInfo * getAsmInfo() const

LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)

Lookup the symbol inside with the specified Name.

Base class for the full range of assembler expressions which are needed for parsing.

@ Constant

Constant expressions.

@ SymbolRef

References to labels and assigned expressions.

@ Target

Target specific expression.

MCSymbol * getMaxNamedBarrierSymbol(MCContext &OutContext)

Definition AMDGPUMCResourceInfo.cpp:104

void addMaxSGPRCandidate(int32_t candidate)

MCSymbol * getMaxSGPRSymbol(MCContext &OutContext)

Definition AMDGPUMCResourceInfo.cpp:100

const MCExpr * getSymRefExpr(StringRef FuncName, ResourceInfoKind RIK, MCContext &Ctx, bool IsLocal)

Definition AMDGPUMCResourceInfo.cpp:60

void addMaxNamedBarrierCandidate(int32_t candidate)

MCSymbol * getMaxAGPRSymbol(MCContext &OutContext)

Definition AMDGPUMCResourceInfo.cpp:96

const MCExpr * createTotalNumVGPRs(const MachineFunction &MF, MCContext &Ctx)

Definition AMDGPUMCResourceInfo.cpp:390

void finalize(MCContext &OutContext)

Definition AMDGPUMCResourceInfo.cpp:86

MCSymbol * getSymbol(StringRef FuncName, ResourceInfoKind RIK, MCContext &OutContext, bool IsLocal)

Definition AMDGPUMCResourceInfo.cpp:27

void reset()

Definition AMDGPUMCResourceInfo.cpp:84

void addMaxAGPRCandidate(int32_t candidate)

MCSymbol * getMaxVGPRSymbol(MCContext &OutContext)

Definition AMDGPUMCResourceInfo.cpp:92

const MCExpr * createTotalNumSGPRs(const MachineFunction &MF, bool hasXnack, MCContext &Ctx)

Definition AMDGPUMCResourceInfo.cpp:400

void addMaxVGPRCandidate(int32_t candidate)

void gatherResourceInfo(const MachineFunction &MF, const AMDGPUResourceUsageAnalysisWrapperPass::FunctionResourceInfo &FRI, MCContext &OutContext)

AMDGPUResourceUsageAnalysis gathers resource usage on a per-function granularity.

Definition AMDGPUMCResourceInfo.cpp:251

const MCSymbol & getSymbol() const

static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...

StringRef getName() const

getName - Get the symbol name.

bool isVariable() const

isVariable - Check if this is a variable symbol.

LLVM_ABI void setVariableValue(const MCExpr *Value)

const MCExpr * getVariableValue() const

Get the expression of the variable symbol.

Function & getFunction()

Return the LLVM function that this machine code represents.

const TargetMachine & getTarget() const

getTarget - Return the target machine this machine code is compiled with

std::pair< iterator, bool > insert(PtrType Ptr)

Inserts Ptr if and only if there is no element in the container equal to Ptr.

SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

void push_back(const T &Elt)

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.

Primary interface to the complete machine description for the target machine.

MCSymbol * getSymbol(const GlobalValue *GV) const

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

LLVM_READNONE constexpr bool isEntryFunctionCC(CallingConv::ID CC)

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

class LLVM_GSL_OWNER SmallVector

Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

bool HasDynamicallySizedStack

uint64_t PrivateSegmentSize

SmallVector< const Function *, 16 > Callees

uint64_t CalleeSegmentSize

AMDGPUResourceUsageAnalysisImpl::SIFunctionResourceInfo FunctionResourceInfo