LLVM 23.0.0git
BasicBlockSectionsProfileReader.cpp
Go to the documentation of this file.
1//===-- BasicBlockSectionsProfileReader.cpp -------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Implementation of the basic block sections profile reader pass. It parses
10// and stores the basic block sections profile file (which is specified via the
11// `-basic-block-sections` flag).
12//
13//===----------------------------------------------------------------------===//
14
16#include "llvm/ADT/DenseSet.h"
17#include "llvm/ADT/SmallSet.h"
20#include "llvm/ADT/StringMap.h"
21#include "llvm/ADT/StringRef.h"
23#include "llvm/Pass.h"
24#include "llvm/Support/Error.h"
28#include "llvm/Support/Path.h"
30#include <llvm/ADT/STLExtras.h>
31
32using namespace llvm;
33
36 "bbsections-profile-reader",
37 "Reads and parses a basic block sections profile.", false,
38 false)
39
41BasicBlockSectionsProfileReader::parseUniqueBBID(StringRef S) const {
43 S.split(Parts, '.');
44 if (Parts.size() > 2)
45 return createProfileParseError(Twine("unable to parse basic block id: '") +
46 S + "'");
47 unsigned long long BaseBBID;
48 if (getAsUnsignedInteger(Parts[0], 10, BaseBBID))
49 return createProfileParseError(
50 Twine("unable to parse BB id: '" + Parts[0]) +
51 "': unsigned integer expected");
52 unsigned long long CloneID = 0;
53 if (Parts.size() > 1 && getAsUnsignedInteger(Parts[1], 10, CloneID))
54 return createProfileParseError(Twine("unable to parse clone id: '") +
55 Parts[1] + "': unsigned integer expected");
56 return UniqueBBID{static_cast<unsigned>(BaseBBID),
57 static_cast<unsigned>(CloneID)};
58}
59
61 return !getClusterInfoForFunction(FuncName).empty();
62}
63
66 StringRef FuncName) const {
67 auto R = ProgramOptimizationProfile.find(getAliasName(FuncName));
68 return R != ProgramOptimizationProfile.end() ? R->second.ClusterInfo
70}
71
74 StringRef FuncName) const {
75 auto R = ProgramOptimizationProfile.find(getAliasName(FuncName));
76 return R != ProgramOptimizationProfile.end()
77 ? R->second.ClonePaths
79}
80
82 StringRef FuncName, const UniqueBBID &SrcBBID,
83 const UniqueBBID &SinkBBID) const {
84 const CFGProfile *CFG = getFunctionCFGProfile(FuncName);
85 if (CFG == nullptr)
86 return 0;
87 auto NodeIt = CFG->EdgeCounts.find(SrcBBID);
88 if (NodeIt == CFG->EdgeCounts.end())
89 return 0;
90 auto EdgeIt = NodeIt->second.find(SinkBBID);
91 if (EdgeIt == NodeIt->second.end())
92 return 0;
93 return EdgeIt->second;
94}
95
98 StringRef FuncName) const {
99 auto R = ProgramOptimizationProfile.find(getAliasName(FuncName));
100 return R != ProgramOptimizationProfile.end() ? R->second.PrefetchTargets
102}
103
106 StringRef FuncName) const {
108 ProgramOptimizationProfile.find(getAliasName(FuncName));
109 return It != ProgramOptimizationProfile.end() ? It->second.PrefetchHints
111}
112
113// Reads the version 1 basic block sections profile. Profile for each function
114// is encoded as follows:
115// m <module_name>
116// f <function_name_1> <function_name_2> ...
117// c <bb_id_1> <bb_id_2> <bb_id_3>
118// c <bb_id_4> <bb_id_5>
119// ...
120// Module name specifier (starting with 'm') is optional and allows
121// distinguishing profile for internal-linkage functions with the same name. If
122// not specified, it will apply to any function with the same name. Function
123// name specifier (starting with 'f') can specify multiple function name
124// aliases. Basic block clusters are specified by 'c' and specify the cluster of
125// basic blocks, and the internal order in which they must be placed in the same
126// section.
127// This profile can also specify cloning paths which instruct the compiler to
128// clone basic blocks along a path. The cloned blocks are then specified in the
129// cluster information.
130// The following profile lists two cloning paths (starting with 'p') for
131// function bar and places the total 9 blocks within two clusters. The first two
132// blocks of a cloning path specify the edge along which the path is cloned. For
133// instance, path 1 (1 -> 3 -> 4) instructs that 3 and 4 must be cloned along
134// the edge 1->3. Within the given clusters, each cloned block is identified by
135// "<original block id>.<clone id>". For instance, 3.1 represents the first
136// clone of block 3. Original blocks are specified just with their block ids. A
137// block cloned multiple times appears with distinct clone ids. The CFG for bar
138// is shown below before and after cloning with its final clusters labeled.
139//
140// f main
141// f bar
142// p 1 3 4 # cloning path 1
143// p 4 2 # cloning path 2
144// c 1 3.1 4.1 6 # basic block cluster 1
145// c 0 2 3 4 2.1 5 # basic block cluster 2
146// ****************************************************************************
147// function bar before and after cloning with basic block clusters shown.
148// ****************************************************************************
149// .... ..............
150// 0 -------+ : 0 :---->: 1 ---> 3.1 :
151// | | : | : :........ | :
152// v v : v : : v :
153// +--> 2 --> 5 1 ~~~~~~> +---: 2 : : 4.1: clsuter 1
154// | | | | : | : : | :
155// | v | | : v ....... : v :
156// | 3 <------+ | : 3 <--+ : : 6 :
157// | | | : | | : :....:
158// | v | : v | :
159// +--- 4 ---> 6 | : 4 | :
160// | : | | :
161// | : v | :
162// | :2.1---+ : cluster 2
163// | : | ......:
164// | : v :
165// +-->: 5 :
166// ....
167// ****************************************************************************
168// This profile can also specify prefetch targets (starting with 't') which
169// instruct the compiler to emit a prefetch symbol for the given target and
170// prefetch hints (starting with 'i') which instruct the compiler to insert a
171// prefetch hint instruction at the given site for the given target.
172//
173// A prefetch target is specified by a pair "<bbid>,<subblock_index>" where
174// bbid specifies the target basic block and subblock_index is a zero-based
175// index. Subblock 0 refers to the region at the beginning of the block up to
176// the first callsite. Subblock `i > 0` refers to the region immediately after
177// the `i`-th callsite up to the `i+1`-th callsite (or the end of the block).
178// The prefetch target is always emitted at the beginning of the subblock.
179// This is the beginning of the basic block for `i = 0` and immediately after
180// the `i`-th call for every `i > 0`.
181//
182// A prefetch hint is specified by a pair "site target", where site is
183// specified as a pair "<bbid>,<callsite_index>" similar to prefetch
184// targets, and target is specified as a triple
185// "<function_name>,<bbid>,<callsite_index>".
186//
187// Example: A basic block in function "foo" with BBID 10 and two call
188// instructions (call_A, call_B). This block is conceptually split into
189// subblocks, with the prefetch target symbol emitted at the beginning of
190// each subblock.
191//
192// +----------------------------------+
193// | __llvm_prefetch_target_foo_10_0: | <--- Subblock 0 (before call_A)
194// | Instruction 1 |
195// | Instruction 2 |
196// | call_A (Callsite 0) |
197// | __llvm_prefetch_target_foo_10_1: | <--- Subblock 1 (after call_A,
198// | | before call_B)
199// | Instruction 3 |
200// | call_B (Callsite 1) |
201// | __llvm_prefetch_target_foo_10_2: | <--- Subblock 2 (after call_B,
202// | | before call_C)
203// | Instruction 4 |
204// +----------------------------------+
205//
206// A prefetch hint specified in function "bar" as "120,1 foo,10,2" results
207// in a hint inserted after the first call in block #120 of bar targeting the
208// address immediately after the second call in block #10 of function foo.
209//
210// B
211// +----------------------------------------------------+
212// | Instruction 1 |
213// | call_C (Callsite 1) |
214// | code_prefetch __llvm_prefetch_target_foo_10 |
215// | Instruction 2 |
216// +----------------------------------------------------+
217//
218Error BasicBlockSectionsProfileReader::ReadV1Profile() {
219 auto FI = ProgramOptimizationProfile.end();
220
221 // Current cluster ID corresponding to this function.
222 unsigned CurrentCluster = 0;
223 // Current position in the current cluster.
224 unsigned CurrentPosition = 0;
225
226 // Temporary set to ensure every basic block ID appears once in the clusters
227 // of a function.
228 DenseSet<UniqueBBID> FuncBBIDs;
229
230 // Debug-info-based module filename for the current function. Empty string
231 // means no filename.
232 StringRef DIFilename;
233
234 for (; !LineIt.is_at_eof(); ++LineIt) {
235 StringRef S(*LineIt);
236 char Specifier = S[0];
237 S = S.drop_front().trim();
239 S.split(Values, ' ');
240 switch (Specifier) {
241 case '@':
242 continue;
243 case 'm': // Module name speicifer.
244 if (Values.size() != 1) {
245 return createProfileParseError(Twine("invalid module name value: '") +
246 S + "'");
247 }
248 DIFilename = sys::path::remove_leading_dotslash(Values[0]);
249 continue;
250 case 'f': { // Function names specifier.
251 bool FunctionFound = any_of(Values, [&](StringRef Alias) {
252 auto It = FunctionNameToDIFilename.find(Alias);
253 // No match if this function name is not found in this module.
254 if (It == FunctionNameToDIFilename.end())
255 return false;
256 // Return a match if debug-info-filename is not specified. Otherwise,
257 // check for equality.
258 return DIFilename.empty() || It->second == DIFilename;
259 });
260 if (!FunctionFound) {
261 // Skip the following profile by setting the profile iterator (FI) to
262 // the past-the-end element.
263 FI = ProgramOptimizationProfile.end();
264 DIFilename = "";
265 continue;
266 }
267 for (size_t i = 1; i < Values.size(); ++i)
268 FuncAliasMap.try_emplace(Values[i], Values.front());
269
270 // Prepare for parsing clusters of this function name.
271 // Start a new cluster map for this function name.
272 auto R = ProgramOptimizationProfile.try_emplace(Values.front());
273 // Report error when multiple profiles have been specified for the same
274 // function.
275 if (!R.second)
276 return createProfileParseError("duplicate profile for function '" +
277 Values.front() + "'");
278 FI = R.first;
279 CurrentCluster = 0;
280 FuncBBIDs.clear();
281 // We won't need DIFilename anymore. Clean it up to avoid its application
282 // on the next function.
283 DIFilename = "";
284 continue;
285 }
286 case 'c': // Basic block cluster specifier.
287 // Skip the profile when we the profile iterator (FI) refers to the
288 // past-the-end element.
289 if (FI == ProgramOptimizationProfile.end())
290 continue;
291 // Reset current cluster position.
292 CurrentPosition = 0;
293 for (auto BasicBlockIDStr : Values) {
294 auto BasicBlockID = parseUniqueBBID(BasicBlockIDStr);
295 if (!BasicBlockID)
296 return BasicBlockID.takeError();
297 if (!FuncBBIDs.insert(*BasicBlockID).second)
298 return createProfileParseError(
299 Twine("duplicate basic block id found '") + BasicBlockIDStr +
300 "'");
301
302 FI->second.ClusterInfo.emplace_back(BBClusterInfo{
303 *std::move(BasicBlockID), CurrentCluster, CurrentPosition++});
304 }
305 CurrentCluster++;
306 continue;
307 case 'p': { // Basic block cloning path specifier.
308 // Skip the profile when we the profile iterator (FI) refers to the
309 // past-the-end element.
310 if (FI == ProgramOptimizationProfile.end())
311 continue;
312 SmallSet<unsigned, 5> BBsInPath;
313 FI->second.ClonePaths.push_back({});
314 for (size_t I = 0; I < Values.size(); ++I) {
315 auto BaseBBIDStr = Values[I];
316 unsigned long long BaseBBID = 0;
317 if (getAsUnsignedInteger(BaseBBIDStr, 10, BaseBBID))
318 return createProfileParseError(Twine("unsigned integer expected: '") +
319 BaseBBIDStr + "'");
320 if (I != 0 && !BBsInPath.insert(BaseBBID).second)
321 return createProfileParseError(
322 Twine("duplicate cloned block in path: '") + BaseBBIDStr + "'");
323 FI->second.ClonePaths.back().push_back(BaseBBID);
324 }
325 continue;
326 }
327 case 'g': { // CFG profile specifier.
328 // Skip the profile when we the profile iterator (FI) refers to the
329 // past-the-end element.
330 if (FI == ProgramOptimizationProfile.end())
331 continue;
332 // For each node, its CFG profile is encoded as
333 // <src>:<count>,<sink_1>:<count_1>,<sink_2>:<count_2>,...
334 for (auto BasicBlockEdgeProfile : Values) {
335 if (BasicBlockEdgeProfile.empty())
336 continue;
337 SmallVector<StringRef, 4> NodeEdgeCounts;
338 BasicBlockEdgeProfile.split(NodeEdgeCounts, ',');
339 UniqueBBID SrcBBID;
340 for (size_t i = 0; i < NodeEdgeCounts.size(); ++i) {
341 auto [BBIDStr, CountStr] = NodeEdgeCounts[i].split(':');
342 auto BBID = parseUniqueBBID(BBIDStr);
343 if (!BBID)
344 return BBID.takeError();
345 unsigned long long Count = 0;
346 if (getAsUnsignedInteger(CountStr, 10, Count))
347 return createProfileParseError(
348 Twine("unsigned integer expected: '") + CountStr + "'");
349 if (i == 0) {
350 // The first element represents the source and its total count.
351 FI->second.CFG.NodeCounts[SrcBBID = *BBID] = Count;
352 continue;
353 }
354 FI->second.CFG.EdgeCounts[SrcBBID][*BBID] = Count;
355 }
356 }
357 continue;
358 }
359 case 'h': { // Basic block hash secifier.
360 // Skip the profile when the profile iterator (FI) refers to the
361 // past-the-end element.
362 if (FI == ProgramOptimizationProfile.end())
363 continue;
364 for (auto BBIDHashStr : Values) {
365 auto [BBIDStr, HashStr] = BBIDHashStr.split(':');
366 unsigned long long BBID = 0, Hash = 0;
367 if (getAsUnsignedInteger(BBIDStr, 10, BBID))
368 return createProfileParseError(Twine("unsigned integer expected: '") +
369 BBIDStr + "'");
370 if (getAsUnsignedInteger(HashStr, 16, Hash))
371 return createProfileParseError(
372 Twine("unsigned integer expected in hex format: '") + HashStr +
373 "'");
374 FI->second.CFG.BBHashes[BBID] = Hash;
375 }
376 continue;
377 }
378 case 't': { // Callsite target specifier.
379 // Skip the profile when we the profile iterator (FI) refers to the
380 // past-the-end element.
381 if (FI == ProgramOptimizationProfile.end())
382 continue;
383 SmallVector<StringRef, 2> PrefetchTargetStr;
384 Values[0].split(PrefetchTargetStr, ',');
385 if (PrefetchTargetStr.size() != 2)
386 return createProfileParseError(Twine("Callsite target expected: ") +
387 Values[0]);
388 auto TargetBBID = parseUniqueBBID(PrefetchTargetStr[0]);
389 if (!TargetBBID)
390 return TargetBBID.takeError();
391 unsigned long long CallsiteIndex;
392 if (getAsUnsignedInteger(PrefetchTargetStr[1], 10, CallsiteIndex))
393 return createProfileParseError(Twine("signed integer expected: '") +
394 PrefetchTargetStr[1]);
395 FI->second.PrefetchTargets.push_back(
396 CallsiteID{*TargetBBID, static_cast<unsigned>(CallsiteIndex)});
397 continue;
398 }
399
400 case 'i': { // Prefetch hint specifier.
401 // Skip the profile when the profile iterator (FI) refers to the
402 // past-the-end element.
403 if (FI == ProgramOptimizationProfile.end())
404 continue;
405 if (Values.size() != 2)
406 return createProfileParseError(
407 Twine("Prefetch hint expected of format '<prefetch-site> "
408 "<prefetch-target>': " +
409 S));
410 SmallVector<StringRef, 2> PrefetchSiteStr;
411 Values[0].split(PrefetchSiteStr, ',');
412 if (PrefetchSiteStr.size() != 2)
413 return createProfileParseError(Twine("Prefetch site expected of format "
414 "'<block-id>,<callsite-id>': ") +
415 Values[0]);
416 auto SiteBBID = parseUniqueBBID(PrefetchSiteStr[0]);
417 if (!SiteBBID)
418 return SiteBBID.takeError();
419 unsigned long long SiteCallsiteIndex;
420 if (getAsUnsignedInteger(PrefetchSiteStr[1], 10, SiteCallsiteIndex))
421 return createProfileParseError(Twine("unsigned integer expected: '") +
422 PrefetchSiteStr[1]);
423
424 SmallVector<StringRef, 3> PrefetchTargetStr;
425 Values[1].split(PrefetchTargetStr, ',');
426 if (PrefetchTargetStr.size() != 3)
427 return createProfileParseError(
428 Twine("Prefetch target expected of format "
429 "'<function-name>,<block-id>,<callsite-id>': ") +
430 Values[1]);
431 auto TargetBBID = parseUniqueBBID(PrefetchTargetStr[1]);
432 if (!TargetBBID)
433 return TargetBBID.takeError();
434 unsigned long long TargetCallsiteIndex;
435 if (getAsUnsignedInteger(PrefetchTargetStr[2], 10, TargetCallsiteIndex))
436 return createProfileParseError(Twine("unsigned integer expected: '") +
437 PrefetchTargetStr[2]);
438 FI->second.PrefetchHints.push_back(PrefetchHint{
439 CallsiteID{*SiteBBID, static_cast<unsigned>(SiteCallsiteIndex)},
440 PrefetchTargetStr[0],
441 CallsiteID{*TargetBBID, static_cast<unsigned>(TargetCallsiteIndex)}});
442 continue;
443 }
444 default:
445 return createProfileParseError(Twine("invalid specifier: '") +
446 Twine(Specifier) + "'");
447 }
448 llvm_unreachable("should not break from this switch statement");
449 }
450 return Error::success();
451}
452
453Error BasicBlockSectionsProfileReader::ReadV0Profile() {
454 auto FI = ProgramOptimizationProfile.end();
455 // Current cluster ID corresponding to this function.
456 unsigned CurrentCluster = 0;
457 // Current position in the current cluster.
458 unsigned CurrentPosition = 0;
459
460 // Temporary set to ensure every basic block ID appears once in the clusters
461 // of a function.
462 SmallSet<unsigned, 4> FuncBBIDs;
463
464 for (; !LineIt.is_at_eof(); ++LineIt) {
465 StringRef S(*LineIt);
466 if (S[0] == '@')
467 continue;
468 // Check for the leading "!"
469 if (!S.consume_front("!") || S.empty())
470 break;
471 // Check for second "!" which indicates a cluster of basic blocks.
472 if (S.consume_front("!")) {
473 // Skip the profile when we the profile iterator (FI) refers to the
474 // past-the-end element.
475 if (FI == ProgramOptimizationProfile.end())
476 continue;
478 S.split(BBIDs, ' ');
479 // Reset current cluster position.
480 CurrentPosition = 0;
481 for (auto BBIDStr : BBIDs) {
482 unsigned long long BBID;
483 if (getAsUnsignedInteger(BBIDStr, 10, BBID))
484 return createProfileParseError(Twine("unsigned integer expected: '") +
485 BBIDStr + "'");
486 if (!FuncBBIDs.insert(BBID).second)
487 return createProfileParseError(
488 Twine("duplicate basic block id found '") + BBIDStr + "'");
489
490 FI->second.ClusterInfo.emplace_back(
491 BBClusterInfo({{static_cast<unsigned>(BBID), 0},
492 CurrentCluster,
493 CurrentPosition++}));
494 }
495 CurrentCluster++;
496 } else {
497 // This is a function name specifier. It may include a debug info filename
498 // specifier starting with `M=`.
499 auto [AliasesStr, DIFilenameStr] = S.split(' ');
500 SmallString<128> DIFilename;
501 if (DIFilenameStr.starts_with("M=")) {
502 DIFilename =
503 sys::path::remove_leading_dotslash(DIFilenameStr.substr(2));
504 if (DIFilename.empty())
505 return createProfileParseError("empty module name specifier");
506 } else if (!DIFilenameStr.empty()) {
507 return createProfileParseError("unknown string found: '" +
508 DIFilenameStr + "'");
509 }
510 // Function aliases are separated using '/'. We use the first function
511 // name for the cluster info mapping and delegate all other aliases to
512 // this one.
514 AliasesStr.split(Aliases, '/');
515 bool FunctionFound = any_of(Aliases, [&](StringRef Alias) {
516 auto It = FunctionNameToDIFilename.find(Alias);
517 // No match if this function name is not found in this module.
518 if (It == FunctionNameToDIFilename.end())
519 return false;
520 // Return a match if debug-info-filename is not specified. Otherwise,
521 // check for equality.
522 return DIFilename.empty() || It->second == DIFilename;
523 });
524 if (!FunctionFound) {
525 // Skip the following profile by setting the profile iterator (FI) to
526 // the past-the-end element.
527 FI = ProgramOptimizationProfile.end();
528 continue;
529 }
530 for (size_t i = 1; i < Aliases.size(); ++i)
531 FuncAliasMap.try_emplace(Aliases[i], Aliases.front());
532
533 // Prepare for parsing clusters of this function name.
534 // Start a new cluster map for this function name.
535 auto R = ProgramOptimizationProfile.try_emplace(Aliases.front());
536 // Report error when multiple profiles have been specified for the same
537 // function.
538 if (!R.second)
539 return createProfileParseError("duplicate profile for function '" +
540 Aliases.front() + "'");
541 FI = R.first;
542 CurrentCluster = 0;
543 FuncBBIDs.clear();
544 }
545 }
546 return Error::success();
547}
548
549// Basic Block Sections can be enabled for a subset of machine basic blocks.
550// This is done by passing a file containing names of functions for which basic
551// block sections are desired. Additionally, machine basic block ids of the
552// functions can also be specified for a finer granularity. Moreover, a cluster
553// of basic blocks could be assigned to the same section.
554// Optionally, a debug-info filename can be specified for each function to allow
555// distinguishing internal-linkage functions of the same name.
556// A file with basic block sections for all of function main and three blocks
557// for function foo (of which 1 and 2 are placed in a cluster) looks like this:
558// (Profile for function foo is only loaded when its debug-info filename
559// matches 'path/to/foo_file.cc').
560// ----------------------------
561// list.txt:
562// !main
563// !foo M=path/to/foo_file.cc
564// !!1 2
565// !!4
566Error BasicBlockSectionsProfileReader::ReadProfile() {
567 assert(MBuf);
568
569 unsigned long long Version = 0;
570 StringRef FirstLine(*LineIt);
571 if (FirstLine.consume_front("v")) {
572 if (getAsUnsignedInteger(FirstLine, 10, Version)) {
573 return createProfileParseError(Twine("version number expected: '") +
574 FirstLine + "'");
575 }
576 if (Version > 1) {
577 return createProfileParseError(Twine("invalid profile version: ") +
578 Twine(Version));
579 }
580 ++LineIt;
581 }
582
583 switch (Version) {
584 case 0:
585 // TODO: Deprecate V0 once V1 is fully integrated downstream.
586 return ReadV0Profile();
587 case 1:
588 return ReadV1Profile();
589 default:
590 llvm_unreachable("Invalid profile version.");
591 }
592}
593
595 if (!BBSPR.MBuf)
596 return false;
597 // Get the function name to debug info filename mapping.
598 BBSPR.FunctionNameToDIFilename.clear();
599 for (const Function &F : M) {
600 SmallString<128> DIFilename;
601 if (F.isDeclaration())
602 continue;
603 DISubprogram *Subprogram = F.getSubprogram();
604 if (Subprogram) {
605 llvm::DICompileUnit *CU = Subprogram->getUnit();
606 if (CU)
607 DIFilename = sys::path::remove_leading_dotslash(CU->getFilename());
608 }
609 [[maybe_unused]] bool inserted =
610 BBSPR.FunctionNameToDIFilename.try_emplace(F.getName(), DIFilename)
611 .second;
612 assert(inserted);
613 }
614 if (auto Err = BBSPR.ReadProfile())
615 report_fatal_error(std::move(Err));
616 return false;
617}
618
620
626
628 StringRef FuncName) const {
629 return BBSPR.isFunctionHot(FuncName);
630}
631
634 StringRef FuncName) const {
635 return BBSPR.getClusterInfoForFunction(FuncName);
636}
637
640 StringRef FuncName) const {
641 return BBSPR.getClonePathsForFunction(FuncName);
642}
643
644const CFGProfile *
646 StringRef FuncName) const {
647 return BBSPR.getFunctionCFGProfile(FuncName);
648}
649
651 StringRef FuncName, const UniqueBBID &SrcBBID,
652 const UniqueBBID &SinkBBID) const {
653 return BBSPR.getEdgeCount(FuncName, SrcBBID, SinkBBID);
654}
655
658 StringRef FuncName) const {
659 return BBSPR.getPrefetchTargetsForFunction(FuncName);
660}
661
664 StringRef FuncName) const {
665 return BBSPR.getPrefetchHintsForFunction(FuncName);
666}
667
672
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file defines the DenseSet and SmallDenseSet classes.
Flatten the CFG
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
Result run(Function &F, FunctionAnalysisManager &AM)
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
SmallVector< SmallVector< unsigned > > getClonePathsForFunction(StringRef FuncName) const
SmallVector< BBClusterInfo > getClusterInfoForFunction(StringRef FuncName) const
SmallVector< CallsiteID > getPrefetchTargetsForFunction(StringRef FuncName) const
const CFGProfile * getFunctionCFGProfile(StringRef FuncName) const
uint64_t getEdgeCount(StringRef FuncName, const UniqueBBID &SrcBBID, const UniqueBBID &DestBBID) const
SmallVector< PrefetchHint > getPrefetchHintsForFunction(StringRef FuncName) const
SmallVector< PrefetchHint > getPrefetchHintsForFunction(StringRef FuncName) const
bool isFunctionHot(StringRef FuncName) const
SmallVector< SmallVector< unsigned > > getClonePathsForFunction(StringRef FuncName) const
const CFGProfile * getFunctionCFGProfile(StringRef FuncName) const
SmallVector< CallsiteID > getPrefetchTargetsForFunction(StringRef FuncName) const
uint64_t getEdgeCount(StringRef FuncName, const UniqueBBID &SrcBBID, const UniqueBBID &DestBBID) const
SmallVector< BBClusterInfo > getClusterInfoForFunction(StringRef FuncName) const
Subprogram description. Uses SubclassData1.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition Pass.h:285
This interface provides simple read-only access to a block of memory, and provides simple methods for...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:184
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMapIterBase< ValueTy, true > const_iterator
Definition StringMap.h:220
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:730
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:140
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:202
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI StringRef remove_leading_dotslash(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Remove redundant leading "./" pieces and consecutive separators.
This is an optimization pass for GlobalISel generic memory operations.
ImmutablePass * createBasicBlockSectionsProfileReaderWrapperPass(const MemoryBuffer *Buf)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1746
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:334
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29