Skip to content

Commit d12e45a

Browse files
authored
[BOLT][NFC] Split out DomTree construction from BF::calculateLoopInfo (#87181)
1 parent ea92b1f commit d12e45a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "bolt/Core/BinaryBasicBlock.h"
2929
#include "bolt/Core/BinaryContext.h"
30+
#include "bolt/Core/BinaryDomTree.h"
3031
#include "bolt/Core/BinaryLoop.h"
3132
#include "bolt/Core/BinarySection.h"
3233
#include "bolt/Core/DebugData.h"
@@ -266,6 +267,7 @@ class BinaryFunction {
266267
BinaryContext &BC;
267268

268269
std::unique_ptr<BinaryLoopInfo> BLI;
270+
std::unique_ptr<BinaryDominatorTree> BDT;
269271

270272
/// All labels in the function that are referenced via relocations from
271273
/// data objects. Typically these are jump table destinations and computed
@@ -838,6 +840,14 @@ class BinaryFunction {
838840
/// stats.
839841
void calculateMacroOpFusionStats();
840842

843+
/// Returns if BinaryDominatorTree has been constructed for this function.
844+
bool hasDomTree() const { return BDT != nullptr; }
845+
846+
BinaryDominatorTree &getDomTree() { return *BDT.get(); }
847+
848+
/// Constructs DomTree for this function.
849+
void constructDomTree();
850+
841851
/// Returns if loop detection has been run for this function.
842852
bool hasLoopInfo() const { return BLI != nullptr; }
843853

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "bolt/Core/BinaryFunction.h"
1414
#include "bolt/Core/BinaryBasicBlock.h"
15-
#include "bolt/Core/BinaryDomTree.h"
1615
#include "bolt/Core/DynoStats.h"
1716
#include "bolt/Core/HashUtilities.h"
1817
#include "bolt/Core/MCPlusBuilder.h"
@@ -4076,12 +4075,17 @@ BinaryFunction::~BinaryFunction() {
40764075
delete BB;
40774076
}
40784077

4078+
void BinaryFunction::constructDomTree() {
4079+
BDT.reset(new BinaryDominatorTree);
4080+
BDT->recalculate(*this);
4081+
}
4082+
40794083
void BinaryFunction::calculateLoopInfo() {
4084+
if (!hasDomTree())
4085+
constructDomTree();
40804086
// Discover loops.
4081-
BinaryDominatorTree DomTree;
4082-
DomTree.recalculate(*this);
40834087
BLI.reset(new BinaryLoopInfo());
4084-
BLI->analyze(DomTree);
4088+
BLI->analyze(getDomTree());
40854089

40864090
// Traverse discovered loops and add depth and profile information.
40874091
std::stack<BinaryLoop *> St;

0 commit comments

Comments
 (0)