Skip to content

Commit

Permalink
[HEXAGON] Add basic block limit for RDF optimizations (#81071)
Browse files Browse the repository at this point in the history
Skip RDF optimizations if a function contains a number of basic blocks
that is more than a limit

---------

Co-authored-by: Yashas Andaluri <quic_yandalur@quicinc.com>
  • Loading branch information
quic-asaravan and yandalur authored Feb 9, 2024
1 parent 8e297c7 commit ac05771
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions llvm/lib/Target/Hexagon/HexagonOptAddrMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ static cl::opt<int> CodeGrowthLimit("hexagon-amode-growth-limit",
cl::Hidden, cl::init(0), cl::desc("Code growth limit for address mode "
"optimization"));

extern cl::opt<unsigned> RDFFuncBlockLimit;

namespace llvm {

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

// Perform RDF optimizations only if number of basic blocks in the
// function is less than the limit
if (MF.size() > RDFFuncBlockLimit) {
LLVM_DEBUG(dbgs() << "Skipping " << getPassName()
<< ": too many basic blocks\n");
return false;
}

bool Changed = false;
auto &HST = MF.getSubtarget<HexagonSubtarget>();
MRI = &MF.getRegInfo();
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Target/Hexagon/HexagonRDFOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ static unsigned RDFCount = 0;
static cl::opt<unsigned>
RDFLimit("hexagon-rdf-limit",
cl::init(std::numeric_limits<unsigned>::max()));

extern cl::opt<unsigned> RDFFuncBlockLimit;

static cl::opt<bool> RDFDump("hexagon-rdf-dump", cl::Hidden);
static cl::opt<bool> RDFTrackReserved("hexagon-rdf-track-reserved", cl::Hidden);

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

// Perform RDF optimizations only if number of basic blocks in the
// function is less than the limit
if (MF.size() > RDFFuncBlockLimit) {
if (RDFDump)
dbgs() << "Skipping " << getPassName() << ": too many basic blocks\n";
return false;
}

if (RDFLimit.getPosition()) {
if (RDFCount >= RDFLimit)
return false;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ static cl::opt<bool>
static cl::opt<bool> EnableRDFOpt("rdf-opt", cl::Hidden, cl::init(true),
cl::desc("Enable RDF-based optimizations"));

cl::opt<unsigned> RDFFuncBlockLimit(
"rdf-bb-limit", cl::Hidden, cl::init(1000),
cl::desc("Basic block limit for a function for RDF optimizations"));

static cl::opt<bool> DisableHardwareLoops("disable-hexagon-hwloops",
cl::Hidden, cl::desc("Disable Hardware Loops for Hexagon target"));

Expand Down

0 comments on commit ac05771

Please sign in to comment.