Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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: 9 additions & 1 deletion llvm/include/llvm/IR/OptBisect.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef LLVM_IR_OPTBISECT_H
#define LLVM_IR_OPTBISECT_H

#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Compiler.h"
Expand Down Expand Up @@ -67,7 +68,13 @@ class LLVM_ABI OptBisect : public OptPassGate {
StringRef IRDescription) const override;

/// isEnabled() should return true before calling shouldRunPass().
bool isEnabled() const override { return BisectLimit != Disabled; }
bool isEnabled() const override {
return BisectLimit != Disabled || !BisectSkipNumbers.empty();
}

/// Add pass at index SkipNumber to the list of passes to skip
/// during bisection.
void addSkip(int SkipNumber) { BisectSkipNumbers.insert(SkipNumber); }

/// Set the new optimization limit and reset the counter. Passing
/// OptBisect::Disabled disables the limiting.
Expand All @@ -81,6 +88,7 @@ class LLVM_ABI OptBisect : public OptPassGate {
private:
int BisectLimit = Disabled;
mutable int LastBisectNum = 0;
SmallSet<int, 4> BisectSkipNumbers;
};

/// This class implements a mechanism to disable passes and individual
Expand Down
9 changes: 8 additions & 1 deletion llvm/lib/IR/OptBisect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
}),
cl::desc("Maximum optimization to perform"));

static cl::opt<int> OptBisectSkip(
"opt-bisect-skip", cl::Hidden, cl::init(OptBisect::Disabled), cl::Optional,
cl::cb<void, int>([](int PassNum) { getOptBisector().addSkip(PassNum); }),
cl::desc("Skip pass at the given index in the optimization pipeline"));

static cl::opt<bool> OptBisectVerbose(
"opt-bisect-verbose",
cl::desc("Show verbose output when opt-bisect-limit is set"), cl::Hidden,
Expand Down Expand Up @@ -66,7 +71,9 @@ bool OptBisect::shouldRunPass(StringRef PassName,
assert(isEnabled());

int CurBisectNum = ++LastBisectNum;
bool ShouldRun = (BisectLimit == -1 || CurBisectNum <= BisectLimit);
bool ShouldRun = (BisectLimit == -1 || BisectLimit == Disabled ||
CurBisectNum <= BisectLimit) &&
!BisectSkipNumbers.contains(CurBisectNum);
if (OptBisectVerbose)
printPassMessage(PassName, CurBisectNum, IRDescription, ShouldRun);
return ShouldRun;
Expand Down
15 changes: 15 additions & 0 deletions llvm/test/Other/opt-bisect-skip.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; Test that verifies functionality for -opt-bisect-skip

; RUN: opt -O1 -opt-bisect-skip=3 -opt-bisect-skip=7 %s 2>&1 | FileCheck %s --check-prefix=CHECK-DISABLE-PASS
; CHECK-DISABLE-PASS: BISECT: running pass (1) annotation2metadata on [module]
; CHECK-DISABLE-PASS: BISECT: running pass (2) forceattrs on [module]
; CHECK-DISABLE-PASS: BISECT: NOT running pass (3) inferattrs on [module]
; CHECK-DISABLE-PASS: BISECT: running pass (4) lower-expect on foo
; CHECK-DISABLE-PASS: BISECT: running pass (5) simplifycfg on foo
; CHECK-DISABLE-PASS: BISECT: running pass (6) sroa on foo
; CHECK-DISABLE-PASS: BISECT: NOT running pass (7) early-cse on foo
; CHECK-DISABLE-PASS: BISECT: running pass (8) openmp-opt on [module]

define void @foo() {
ret void
}