Skip to content

Commit ac05771

Browse files
[HEXAGON] Add basic block limit for RDF optimizations (#81071)
Skip RDF optimizations if a function contains a number of basic blocks that is more than a limit --------- Co-authored-by: Yashas Andaluri <[email protected]>
1 parent 8e297c7 commit ac05771

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

llvm/lib/Target/Hexagon/HexagonOptAddrMode.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ static cl::opt<int> CodeGrowthLimit("hexagon-amode-growth-limit",
4747
cl::Hidden, cl::init(0), cl::desc("Code growth limit for address mode "
4848
"optimization"));
4949

50+
extern cl::opt<unsigned> RDFFuncBlockLimit;
51+
5052
namespace llvm {
5153

5254
FunctionPass *createHexagonOptAddrMode();
@@ -856,6 +858,14 @@ bool HexagonOptAddrMode::runOnMachineFunction(MachineFunction &MF) {
856858
if (skipFunction(MF.getFunction()))
857859
return false;
858860

861+
// Perform RDF optimizations only if number of basic blocks in the
862+
// function is less than the limit
863+
if (MF.size() > RDFFuncBlockLimit) {
864+
LLVM_DEBUG(dbgs() << "Skipping " << getPassName()
865+
<< ": too many basic blocks\n");
866+
return false;
867+
}
868+
859869
bool Changed = false;
860870
auto &HST = MF.getSubtarget<HexagonSubtarget>();
861871
MRI = &MF.getRegInfo();

llvm/lib/Target/Hexagon/HexagonRDFOpt.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ static unsigned RDFCount = 0;
5050
static cl::opt<unsigned>
5151
RDFLimit("hexagon-rdf-limit",
5252
cl::init(std::numeric_limits<unsigned>::max()));
53+
54+
extern cl::opt<unsigned> RDFFuncBlockLimit;
55+
5356
static cl::opt<bool> RDFDump("hexagon-rdf-dump", cl::Hidden);
5457
static cl::opt<bool> RDFTrackReserved("hexagon-rdf-track-reserved", cl::Hidden);
5558

@@ -285,6 +288,14 @@ bool HexagonRDFOpt::runOnMachineFunction(MachineFunction &MF) {
285288
if (skipFunction(MF.getFunction()))
286289
return false;
287290

291+
// Perform RDF optimizations only if number of basic blocks in the
292+
// function is less than the limit
293+
if (MF.size() > RDFFuncBlockLimit) {
294+
if (RDFDump)
295+
dbgs() << "Skipping " << getPassName() << ": too many basic blocks\n";
296+
return false;
297+
}
298+
288299
if (RDFLimit.getPosition()) {
289300
if (RDFCount >= RDFLimit)
290301
return false;

llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ static cl::opt<bool>
3939
static cl::opt<bool> EnableRDFOpt("rdf-opt", cl::Hidden, cl::init(true),
4040
cl::desc("Enable RDF-based optimizations"));
4141

42+
cl::opt<unsigned> RDFFuncBlockLimit(
43+
"rdf-bb-limit", cl::Hidden, cl::init(1000),
44+
cl::desc("Basic block limit for a function for RDF optimizations"));
45+
4246
static cl::opt<bool> DisableHardwareLoops("disable-hexagon-hwloops",
4347
cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target"));
4448

0 commit comments

Comments
 (0)