Skip to content

[LLVM] Change ModulePass::skipModule to take a const reference #146168

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 1 commit into from
Jun 30, 2025
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
12 changes: 6 additions & 6 deletions llvm/include/llvm/IR/OptBisect.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class OptPassGate {

/// IRDescription is a textual description of the IR unit the pass is running
/// over.
virtual bool shouldRunPass(const StringRef PassName,
StringRef IRDescription) {
virtual bool shouldRunPass(StringRef PassName,
StringRef IRDescription) const {
return true;
}

Expand Down Expand Up @@ -62,8 +62,8 @@ class LLVM_ABI OptBisect : public OptPassGate {
/// Most passes should not call this routine directly. Instead, it is called
/// through helper routines provided by the base classes of the pass. For
/// instance, function passes should call FunctionPass::skipFunction().
bool shouldRunPass(const StringRef PassName,
StringRef IRDescription) override;
bool shouldRunPass(StringRef PassName,
StringRef IRDescription) const override;

/// isEnabled() should return true before calling shouldRunPass().
bool isEnabled() const override { return BisectLimit != Disabled; }
Expand All @@ -75,11 +75,11 @@ class LLVM_ABI OptBisect : public OptPassGate {
LastBisectNum = 0;
}

static const int Disabled = std::numeric_limits<int>::max();
static constexpr int Disabled = std::numeric_limits<int>::max();

private:
int BisectLimit = Disabled;
int LastBisectNum = 0;
mutable int LastBisectNum = 0;
};

/// Singleton instance of the OptBisect class, so multiple pass managers don't
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class LLVM_ABI ModulePass : public Pass {
protected:
/// Optional passes call this function to check whether the pass should be
/// skipped. This is the case when optimization bisect is over the limit.
bool skipModule(Module &M) const;
bool skipModule(const Module &M) const;
};

//===----------------------------------------------------------------------===//
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/LoopPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ bool LoopPass::skipLoop(const Loop *L) const {
if (!F)
return false;
// Check the opt bisect limit.
OptPassGate &Gate = F->getContext().getOptPassGate();
const OptPassGate &Gate = F->getContext().getOptPassGate();
if (Gate.isEnabled() &&
!Gate.shouldRunPass(this->getPassName(), getDescription(*L)))
return true;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/RegionPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static std::string getDescription(const Region &R) {

bool RegionPass::skipRegion(Region &R) const {
Function &F = *R.getEntry()->getParent();
OptPassGate &Gate = F.getContext().getOptPassGate();
const OptPassGate &Gate = F.getContext().getOptPassGate();
if (Gate.isEnabled() &&
!Gate.shouldRunPass(this->getPassName(), getDescription(R)))
return true;
Expand Down
14 changes: 6 additions & 8 deletions llvm/lib/IR/OptBisect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ static cl::opt<bool> OptBisectVerbose(
cl::desc("Show verbose output when opt-bisect-limit is set"), cl::Hidden,
cl::init(true), cl::Optional);

static void printPassMessage(const StringRef &Name, int PassNum,
StringRef TargetDesc, bool Running) {
static void printPassMessage(StringRef Name, int PassNum, StringRef TargetDesc,
bool Running) {
StringRef Status = Running ? "" : "NOT ";
errs() << "BISECT: " << Status << "running pass "
<< "(" << PassNum << ") " << Name << " on " << TargetDesc << "\n";
errs() << "BISECT: " << Status << "running pass (" << PassNum << ") " << Name
<< " on " << TargetDesc << '\n';
}

bool OptBisect::shouldRunPass(const StringRef PassName,
StringRef IRDescription) {
bool OptBisect::shouldRunPass(StringRef PassName,
StringRef IRDescription) const {
assert(isEnabled());

int CurBisectNum = ++LastBisectNum;
Expand All @@ -55,6 +55,4 @@ bool OptBisect::shouldRunPass(const StringRef PassName,
return ShouldRun;
}

const int OptBisect::Disabled;

OptPassGate &llvm::getGlobalPassGate() { return getOptBisector(); }
4 changes: 2 additions & 2 deletions llvm/lib/IR/Pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ static std::string getDescription(const Module &M) {
return "module (" + M.getName().str() + ")";
}

bool ModulePass::skipModule(Module &M) const {
OptPassGate &Gate = M.getContext().getOptPassGate();
bool ModulePass::skipModule(const Module &M) const {
const OptPassGate &Gate = M.getContext().getOptPassGate();
return Gate.isEnabled() &&
!Gate.shouldRunPass(this->getPassName(), getDescription(M));
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Passes/StandardInstrumentations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ bool OptPassGateInstrumentation::shouldRun(StringRef PassName, Any IR) {

void OptPassGateInstrumentation::registerCallbacks(
PassInstrumentationCallbacks &PIC) {
OptPassGate &PassGate = Context.getOptPassGate();
const OptPassGate &PassGate = Context.getOptPassGate();
if (!PassGate.isEnabled())
return;

Expand Down
3 changes: 2 additions & 1 deletion llvm/unittests/IR/LegacyPassManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ namespace llvm {
struct CustomOptPassGate : public OptPassGate {
bool Skip;
CustomOptPassGate(bool Skip) : Skip(Skip) { }
bool shouldRunPass(const StringRef PassName, StringRef IRDescription) override {
bool shouldRunPass(StringRef PassName,
StringRef IRDescription) const override {
return !Skip;
}
bool isEnabled() const override { return true; }
Expand Down
Loading