Skip to content

[Instrumentation] Support MachineFunction in OptNoneInstrumentation #115471

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
Nov 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
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/FinalizeISel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace llvm {
class FinalizeISelPass : public PassInfoMixin<FinalizeISelPass> {
public:
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &);
static bool isRequired() { return true; }
};

} // namespace llvm
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/LocalStackSlotAllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class LocalStackSlotAllocationPass
: public PassInfoMixin<LocalStackSlotAllocationPass> {
public:
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &);
static bool isRequired() { return true; }
};

} // namespace llvm
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/MIRPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PrintMIRPreparePass : public PassInfoMixin<PrintMIRPreparePass> {
public:
PrintMIRPreparePass(raw_ostream &OS = errs()) : OS(OS) {}
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM);
static bool isRequired() { return true; }
};

class PrintMIRPass : public PassInfoMixin<PrintMIRPass> {
Expand All @@ -40,6 +41,7 @@ class PrintMIRPass : public PassInfoMixin<PrintMIRPass> {
PrintMIRPass(raw_ostream &OS = errs()) : OS(OS) {}
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
static bool isRequired() { return true; }
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is essentially a concept? This needs something to document it in the base class?

};

/// Print LLVM IR using the MIR serialization format to the given output stream.
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/MachineVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MachineVerifierPass : public PassInfoMixin<MachineVerifierPass> {
: Banner(Banner) {}
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
static bool isRequired() { return true; }
};

} // namespace llvm
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/PHIElimination.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PHIEliminationPass : public PassInfoMixin<PHIEliminationPass> {
public:
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
static bool isRequired() { return true; }
};

} // namespace llvm
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/RegAllocFast.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class RegAllocFastPass : public PassInfoMixin<RegAllocFastPass> {

void printPipeline(raw_ostream &OS,
function_ref<StringRef(StringRef)> MapClassName2PassName);

static bool isRequired() { return true; }
};

} // namespace llvm
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/SelectionDAGISel.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ class SelectionDAGISelPass : public PassInfoMixin<SelectionDAGISelPass> {
public:
PreservedAnalyses run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM);
static bool isRequired() { return true; }
};
}

Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/CodeGen/EarlyIfConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,6 @@ bool EarlyIfConverter::run(MachineFunction &MF) {
PreservedAnalyses
EarlyIfConverterPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
if (MF.getFunction().hasOptNone())
return PreservedAnalyses::all();

MachineDominatorTree &MDT = MFAM.getResult<MachineDominatorTreeAnalysis>(MF);
MachineLoopInfo &LI = MFAM.getResult<MachineLoopAnalysis>(MF);
MachineTraceMetrics &MTM = MFAM.getResult<MachineTraceMetricsAnalysis>(MF);
Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/CodeGen/MachineCSE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,9 +957,6 @@ PreservedAnalyses MachineCSEPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
MFPropsModifier _(*this, MF);

if (MF.getFunction().hasOptNone())
return PreservedAnalyses::all();

MachineDominatorTree &MDT = MFAM.getResult<MachineDominatorTreeAnalysis>(MF);
MachineBlockFrequencyInfo &MBFI =
MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);
Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/CodeGen/MachineLICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,9 +1763,6 @@ bool MachineLICMImpl::isTgtHotterThanSrc(MachineBasicBlock *SrcBlock,
template <typename DerivedT, bool PreRegAlloc>
PreservedAnalyses MachineLICMBasePass<DerivedT, PreRegAlloc>::run(
MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) {
if (MF.getFunction().hasOptNone())
return PreservedAnalyses::all();

bool Changed = MachineLICMImpl(PreRegAlloc, nullptr, &MFAM).run(MF);
if (!Changed)
return PreservedAnalyses::all();
Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/CodeGen/OptimizePHIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ INITIALIZE_PASS(OptimizePHIsLegacy, DEBUG_TYPE,

PreservedAnalyses OptimizePHIsPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
if (MF.getFunction().hasOptNone())
return PreservedAnalyses::all();

OptimizePHIs OP;
if (!OP.run(MF))
return PreservedAnalyses::all();
Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/CodeGen/StackColoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,9 +1193,6 @@ bool StackColoringLegacy::runOnMachineFunction(MachineFunction &MF) {

PreservedAnalyses StackColoringPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
if (MF.getFunction().hasOptNone())
return PreservedAnalyses::all();

StackColoring SC(&MFAM.getResult<SlotIndexesAnalysis>(MF));
if (SC.run(MF))
return PreservedAnalyses::none();
Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/CodeGen/TailDuplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ PreservedAnalyses TailDuplicatePassBase<DerivedT, PreRegAlloc>::run(
MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) {
MFPropsModifier _(static_cast<DerivedT &>(*this), MF);

if (MF.getFunction().hasOptNone())
return PreservedAnalyses::all();

auto *MBPI = &MFAM.getResult<MachineBranchProbabilityAnalysis>(MF);
auto *PSI = MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF)
.getCachedResult<ProfileSummaryAnalysis>(
Expand Down
16 changes: 9 additions & 7 deletions llvm/lib/Passes/StandardInstrumentations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,14 +1048,16 @@ void OptNoneInstrumentation::registerCallbacks(
}

bool OptNoneInstrumentation::shouldRun(StringRef PassID, Any IR) {
const auto *F = unwrapIR<Function>(IR);
if (!F) {
if (const auto *L = unwrapIR<Loop>(IR))
F = L->getHeader()->getParent();
}
bool ShouldRun = !(F && F->hasOptNone());
bool ShouldRun = true;
if (const auto *F = unwrapIR<Function>(IR))
ShouldRun = !F->hasOptNone();
else if (const auto *L = unwrapIR<Loop>(IR))
ShouldRun = !L->getHeader()->getParent()->hasOptNone();
else if (const auto *MF = unwrapIR<MachineFunction>(IR))
ShouldRun = !MF->getFunction().hasOptNone();

if (!ShouldRun && DebugLogging) {
errs() << "Skipping pass " << PassID << " on " << F->getName()
errs() << "Skipping pass " << PassID << " on " << getIRName(IR)
<< " due to optnone attribute\n";
}
return ShouldRun;
Expand Down
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/X86/optnone.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# RUN: llc -passes=machine-cse -debug-pass-manager %s -o - 2>&1 | FileCheck %s

# CHECK: Skipping pass MachineCSEPass on test_optnone due to optnone attribute
# CHECK: Running pass: MachineCSEPass on test_opt
--- |
define void @test_optnone() noinline optnone { ret void }
define void @test_opt() { ret void }
...
---
name: test_optnone
body: |
bb.0:
RET64
...
---
name: test_opt
body: |
bb.0:
RET64
...
Loading