Skip to content

Commit 8eef602

Browse files
committed
Add some comments.
1 parent fbf0f84 commit 8eef602

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ struct BBClusterInfo {
4242
unsigned PositionInCluster;
4343
};
4444

45-
struct BBPosition {
45+
// Assuming a block is split into subblocks across its callsites, this struct
46+
// uniquely identifies the subblock in block `BBID` which starts from right after call number `SubblockIndex` (or
47+
// the beginning of the block if `SubblockIndex` is zero) to the call number
48+
// `SubblockIndex+1` (or the end of the block if there are are `SubblockIndex`
49+
// calls in the basic block).
50+
struct SubblockID {
4651
UniqueBBID BBID;
47-
unsigned CallsiteIndex;
52+
unsigned SubblockIndex;
4853
};
4954

5055
// This represents the raw input profile for one function.
@@ -55,7 +60,9 @@ struct FunctionPathAndClusterInfo {
5560
// the edge a -> b (a is not cloned). The index of the path in this vector
5661
// determines the `UniqueBBID::CloneID` of the cloned blocks in that path.
5762
SmallVector<SmallVector<unsigned>> ClonePaths;
58-
SmallVector<BBPosition> PrefetchTargets;
63+
// Code prefetch targets, specified by the subblock ID of which beginning must
64+
// be targetted for prefetching.
65+
SmallVector<SubblockID> PrefetchTargets;
5966
// Node counts for each basic block.
6067
DenseMap<UniqueBBID, uint64_t> NodeCounts;
6168
// Edge counts for each edge.
@@ -92,7 +99,9 @@ class BasicBlockSectionsProfileReader {
9299
uint64_t getEdgeCount(StringRef FuncName, const UniqueBBID &SrcBBID,
93100
const UniqueBBID &SinkBBID) const;
94101

95-
SmallVector<BBPosition>
102+
// Returns the prefetch targets (identified by their containing subblocks) for
103+
// function `FuncName`.
104+
SmallVector<SubblockID>
96105
getPrefetchTargetsForFunction(StringRef FuncName) const;
97106

98107
private:
@@ -204,7 +213,7 @@ class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
204213
uint64_t getEdgeCount(StringRef FuncName, const UniqueBBID &SrcBBID,
205214
const UniqueBBID &DestBBID) const;
206215

207-
SmallVector<BBPosition>
216+
SmallVector<SubblockID>
208217
getPrefetchTargetsForFunction(StringRef FuncName) const;
209218

210219
// Initializes the FunctionNameToDIFilename map for the current module and

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@
119119
#include "llvm/Support/Format.h"
120120
#include "llvm/Support/MathExtras.h"
121121
#include "llvm/Support/Path.h"
122-
#include "llvm/Support/SMLoc.h"
123122
#include "llvm/Support/VCSRevision.h"
124123
#include "llvm/Support/VirtualFileSystem.h"
125124
#include "llvm/Support/raw_ostream.h"
@@ -1982,7 +1981,6 @@ void AsmPrinter::emitFunctionBody() {
19821981

19831982
FunctionCallGraphInfo FuncCGInfo;
19841983
const auto &CallSitesInfoMap = MF->getCallSitesInfo();
1985-
19861984
for (auto &MBB : *MF) {
19871985
// Print a label for the basic block.
19881986
emitBasicBlockStart(MBB);

llvm/lib/CodeGen/InsertCodePrefetch.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- InsertCodePrefetch.cpp ---=========-----------------------------===//
1+
//===-- InsertCodePrefetch.cpp ---=========--------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,9 +7,14 @@
77
//===----------------------------------------------------------------------===//
88
//
99
/// \file
10-
/// Prefetch insertion pass implementation.
10+
/// Code Prefetch Insertion Pass.
1111
//===----------------------------------------------------------------------===//
12-
/// Prefetch insertion pass.
12+
/// This pass inserts code prefetch instructions according to the prefetch
13+
/// directives in the basic block section profile. The target of a prefetch can
14+
/// be the beginning of any dynamic basic block, that is the beginning of a
15+
/// machine basic block, or immediately after a callsite. A global symbol will
16+
/// be emitted at the position of the target so it can be addressed from the
17+
/// prefetch instruction.
1318
//===----------------------------------------------------------------------===//
1419

1520
#include "llvm/ADT/SmallVector.h"
@@ -20,15 +25,11 @@
2025
#include "llvm/CodeGen/MachineBasicBlock.h"
2126
#include "llvm/CodeGen/MachineFunction.h"
2227
#include "llvm/CodeGen/MachineFunctionPass.h"
23-
#include "llvm/CodeGen/MachineOperand.h"
2428
#include "llvm/CodeGen/Passes.h"
25-
#include "llvm/CodeGen/TargetInstrInfo.h"
2629
#include "llvm/InitializePasses.h"
27-
#include "llvm/MC/MCContext.h"
28-
#include "llvm/Target/TargetMachine.h"
2930

3031
using namespace llvm;
31-
#define DEBUG_TYPE "prefetchinsertion"
32+
#define DEBUG_TYPE "insert-code-prefetch"
3233

3334
namespace {
3435
class InsertCodePrefetch : public MachineFunctionPass {
@@ -40,13 +41,12 @@ class InsertCodePrefetch : public MachineFunctionPass {
4041
}
4142

4243
StringRef getPassName() const override {
43-
return "X86 Cide Prefetch Inserter Pass";
44+
return "Code Prefetch Inserter Pass";
4445
}
4546

4647
void getAnalysisUsage(AnalysisUsage &AU) const override;
4748

48-
/// Identify basic blocks that need separate sections and prepare to emit them
49-
/// accordingly.
49+
// Sets prefetch targets based on the bb section profile.
5050
bool runOnMachineFunction(MachineFunction &MF) override;
5151
};
5252

@@ -57,10 +57,10 @@ class InsertCodePrefetch : public MachineFunctionPass {
5757
//===----------------------------------------------------------------------===//
5858

5959
char InsertCodePrefetch::ID = 0;
60-
INITIALIZE_PASS_BEGIN(InsertCodePrefetch, DEBUG_TYPE, "Reads prefetch", true,
60+
INITIALIZE_PASS_BEGIN(InsertCodePrefetch, DEBUG_TYPE, "Code prefetch insertion", true,
6161
false)
6262
INITIALIZE_PASS_DEPENDENCY(BasicBlockSectionsProfileReaderWrapperPass)
63-
INITIALIZE_PASS_END(InsertCodePrefetch, DEBUG_TYPE, "Reads prefetch", true,
63+
INITIALIZE_PASS_END(InsertCodePrefetch, DEBUG_TYPE, "Code prefetch insertion", true,
6464
false)
6565

6666
bool InsertCodePrefetch::runOnMachineFunction(MachineFunction &MF) {

0 commit comments

Comments
 (0)