[llvm] [BOLT][NFC] Split out DomTree construction from BF::calculateLoopInfo (PR #87181)
Amir Ayupov via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 30 22:04:02 PDT 2024
https://github.com/aaupov created https://github.com/llvm/llvm-project/pull/87181
None
>From 3a4ecaed388d0345119680b637a3ecdba4b5f37d Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Sat, 30 Mar 2024 20:09:36 -0700
Subject: [PATCH] [BOLT][NFC] Split out DomTree construction from
BF::calculateLoopInfo
---
bolt/include/bolt/Core/BinaryFunction.h | 10 ++++++++++
bolt/lib/Core/BinaryFunction.cpp | 12 ++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index c170fa6397cc92..fd3eb2d87128b3 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -27,6 +27,7 @@
#include "bolt/Core/BinaryBasicBlock.h"
#include "bolt/Core/BinaryContext.h"
+#include "bolt/Core/BinaryDomTree.h"
#include "bolt/Core/BinaryLoop.h"
#include "bolt/Core/BinarySection.h"
#include "bolt/Core/DebugData.h"
@@ -266,6 +267,7 @@ class BinaryFunction {
BinaryContext &BC;
std::unique_ptr<BinaryLoopInfo> BLI;
+ std::unique_ptr<BinaryDominatorTree> BDT;
/// All labels in the function that are referenced via relocations from
/// data objects. Typically these are jump table destinations and computed
@@ -838,6 +840,14 @@ class BinaryFunction {
/// stats.
void calculateMacroOpFusionStats();
+ /// Returns if BinaryDominatorTree has been constructed for this function.
+ bool hasDomTree() const { return BDT != nullptr; }
+
+ BinaryDominatorTree &getDomTree() { return *BDT.get(); }
+
+ /// Constructs DomTree for this function.
+ void constructDomTree();
+
/// Returns if loop detection has been run for this function.
bool hasLoopInfo() const { return BLI != nullptr; }
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index c9e037c225dd41..24f21cb39329d4 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -12,7 +12,6 @@
#include "bolt/Core/BinaryFunction.h"
#include "bolt/Core/BinaryBasicBlock.h"
-#include "bolt/Core/BinaryDomTree.h"
#include "bolt/Core/DynoStats.h"
#include "bolt/Core/HashUtilities.h"
#include "bolt/Core/MCPlusBuilder.h"
@@ -4076,12 +4075,17 @@ BinaryFunction::~BinaryFunction() {
delete BB;
}
+void BinaryFunction::constructDomTree() {
+ BDT.reset(new BinaryDominatorTree);
+ BDT->recalculate(*this);
+}
+
void BinaryFunction::calculateLoopInfo() {
+ if (!hasDomTree())
+ constructDomTree();
// Discover loops.
- BinaryDominatorTree DomTree;
- DomTree.recalculate(*this);
BLI.reset(new BinaryLoopInfo());
- BLI->analyze(DomTree);
+ BLI->analyze(getDomTree());
// Traverse discovered loops and add depth and profile information.
std::stack<BinaryLoop *> St;
More information about the llvm-commits
mailing list