Skip to content

Commit 8ac920d

Browse files
committed
Everything else.
1 parent 790f779 commit 8ac920d

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

build-release/prefetch-profile.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct BBClusterInfo {
4444

4545
struct BBPosition {
4646
UniqueBBID BBID;
47-
unsigned BBOffset;
47+
unsigned CallsiteIndex;
4848
};
4949

5050
struct PrefetchHint {
@@ -62,7 +62,7 @@ struct FunctionPathAndClusterInfo {
6262
// determines the `UniqueBBID::CloneID` of the cloned blocks in that path.
6363
SmallVector<SmallVector<unsigned>> ClonePaths;
6464
SmallVector<PrefetchHint> PrefetchHints;
65-
DenseSet<BBPosition> PrefetchTargets;
65+
SmallVector<BBPosition> PrefetchTargets;
6666
// Node counts for each basic block.
6767
DenseMap<UniqueBBID, uint64_t> NodeCounts;
6868
// Edge counts for each edge.
@@ -73,27 +73,6 @@ struct FunctionPathAndClusterInfo {
7373
DenseMap<unsigned, uint64_t> BBHashes;
7474
};
7575

76-
// Provides DenseMapInfo BBPosition.
77-
template <> struct DenseMapInfo<BBPosition> {
78-
static inline BBPosition getEmptyKey() {
79-
return {DenseMapInfo<UniqueBBID>::getEmptyKey(),
80-
DenseMapInfo<unsigned>::getEmptyKey()};
81-
}
82-
static inline BBPosition getTombstoneKey() {
83-
return BBPosition{DenseMapInfo<UniqueBBID>::getTombstoneKey(),
84-
DenseMapInfo<unsigned>::getTombstoneKey()};
85-
}
86-
static unsigned getHashValue(const BBPosition &Val) {
87-
std::pair<unsigned, unsigned> PairVal = std::make_pair(
88-
DenseMapInfo<UniqueBBID>::getHashValue(Val.BBID), Val.BBOffset);
89-
return DenseMapInfo<std::pair<unsigned, unsigned>>::getHashValue(PairVal);
90-
}
91-
static bool isEqual(const BBPosition &LHS, const BBPosition &RHS) {
92-
return DenseMapInfo<UniqueBBID>::isEqual(LHS.BBID, RHS.BBID) &&
93-
DenseMapInfo<unsigned>::isEqual(LHS.BBOffset, RHS.BBOffset);
94-
}
95-
};
96-
9776
class BasicBlockSectionsProfileReader {
9877
public:
9978
friend class BasicBlockSectionsProfileReaderWrapperPass;
@@ -123,7 +102,7 @@ class BasicBlockSectionsProfileReader {
123102
SmallVector<PrefetchHint>
124103
getPrefetchHintsForFunction(StringRef FuncName) const;
125104

126-
DenseSet<BBPosition> getPrefetchTargetsForFunction(StringRef FuncName) const;
105+
DenseMap<UniqueBBID, SmallVector<unsigned>> getPrefetchTargetsForFunction(StringRef FuncName) const;
127106

128107
private:
129108
StringRef getAliasName(StringRef FuncName) const {
@@ -236,7 +215,7 @@ class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
236215
SmallVector<PrefetchHint>
237216
getPrefetchHintsForFunction(StringRef FuncName) const;
238217

239-
DenseSet<BBPosition> getPrefetchTargetsForFunction(StringRef FuncName) const;
218+
DenseMap<UniqueBBID, SmallVector<unsigned>> getPrefetchTargetsForFunction(StringRef FuncName) const;
240219

241220
// Initializes the FunctionNameToDIFilename map for the current module and
242221
// then reads the profile for the matching functions.

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
485485
AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
486486
if (EmitBBHash)
487487
AU.addRequired<MachineBlockHashInfo>();
488+
AU.addUsedIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>();
488489
}
489490

490491
bool AsmPrinter::doInitialization(Module &M) {
@@ -1987,7 +1988,16 @@ void AsmPrinter::emitFunctionBody() {
19871988

19881989
FunctionCallGraphInfo FuncCGInfo;
19891990
const auto &CallSitesInfoMap = MF->getCallSitesInfo();
1990-
for (auto &MBB : *MF) {
1991+
DenseMap<UniqueBBID, SmallVector<unsigned>> FunctionPrefetchTargets;
1992+
if (auto *BBSPRPass =
1993+
getAnalysisIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>()) {
1994+
FunctionPrefetchTargets = BBSPRPass->getBBSPR().getPrefetchTargetsForFunction(MF->getName());
1995+
}
1996+
1997+
for (auto &MBB : *MF) {
1998+
1999+
SmallVector<unsigned> BBPrefetchTargets;
2000+
= FunctionPrefetchTargets.lookup(MBB.g);
19912001
int NextPrefetchTargetIndex = MBB.getPrefetchTargets().empty() ? -1 : 0;
19922002
// Print a label for the basic block.
19932003
emitBasicBlockStart(MBB);

llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ BasicBlockSectionsProfileReader::getPrefetchHintsForFunction(
9999
return ProgramPathAndClusterInfo.lookup(getAliasName(FuncName)).PrefetchHints;
100100
}
101101

102-
DenseSet<BBPosition>
102+
SmallVector<BBPosition>
103103
BasicBlockSectionsProfileReader::getPrefetchTargetsForFunction(
104104
StringRef FuncName) const {
105105
return ProgramPathAndClusterInfo.lookup(getAliasName(FuncName))
@@ -333,11 +333,11 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
333333
auto TargetBBID = parseUniqueBBID(PrefetchTargetStr[0]);
334334
if (!TargetBBID)
335335
return TargetBBID.takeError();
336-
unsigned long long TargetBBOffset;
337-
if (getAsUnsignedInteger(PrefetchTargetStr[1], 10, TargetBBOffset))
336+
unsigned long long TargetCallsiteIndex;
337+
if (getAsUnsignedInteger(PrefetchTargetStr[1], 10, TargetCallsiteIndex))
338338
return createProfileParseError(Twine("unsigned integer expected: '") +
339339
PrefetchTargetStr[1]);
340-
FI->second.PrefetchTargets.insert(BBPosition{*TargetBBID, static_cast<unsigned>(TargetBBOffset)});
340+
FI->second.PrefetchTargets.push_back(BBPosition{*TargetBBID, static_cast<unsigned>(TargetCallsiteIndex)});
341341
continue;
342342
}
343343
default:
@@ -552,7 +552,7 @@ BasicBlockSectionsProfileReaderWrapperPass::getPrefetchHintsForFunction(
552552
return BBSPR.getPrefetchHintsForFunction(FuncName);
553553
}
554554

555-
DenseSet<BBPosition>
555+
SmallVector<BBPosition>
556556
BasicBlockSectionsProfileReaderWrapperPass::getPrefetchTargetsForFunction(
557557
StringRef FuncName) const {
558558
return BBSPR.getPrefetchTargetsForFunction(FuncName);

0 commit comments

Comments
 (0)