Skip to content

[HEXAGON] Add basic block limit for RDF optimizations #81071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this message is here, it might be useful/interesting to show what the number and limit are.

<< ": 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