Skip to content

Commit 360c6b4

Browse files
author
git apple-llvm automerger
committed
Merge commit 'faf521042098' from llvm.org/master into apple/main
2 parents 6bc0016 + faf5210 commit 360c6b4

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

llvm/include/llvm/Analysis/CGSCCPassManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ createCGSCCToFunctionPassAdaptor(FunctionPassT Pass) {
559559
return CGSCCToFunctionPassAdaptor<FunctionPassT>(std::move(Pass));
560560
}
561561

562+
/// Checks -abort-on-max-devirt-iterations-reached to see if we should report an
563+
/// error.
564+
void maxDevirtIterationsReached();
565+
562566
/// A helper that repeats an SCC pass each time an indirect call is refined to
563567
/// a direct call by that pass.
564568
///
@@ -711,6 +715,7 @@ class DevirtSCCRepeatedPass
711715

712716
// Otherwise, if we've already hit our max, we're done.
713717
if (Iteration >= MaxIterations) {
718+
maxDevirtIterationsReached();
714719
LLVM_DEBUG(
715720
dbgs() << "Found another devirtualization after hitting the max "
716721
"number of repetitions ("

llvm/lib/Analysis/CGSCCPassManager.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
#include "llvm/IR/PassManager.h"
2222
#include "llvm/IR/PassManagerImpl.h"
2323
#include "llvm/Support/Casting.h"
24+
#include "llvm/Support/CommandLine.h"
2425
#include "llvm/Support/Debug.h"
25-
#include "llvm/Support/raw_ostream.h"
26+
#include "llvm/Support/ErrorHandling.h"
2627
#include "llvm/Support/TimeProfiler.h"
28+
#include "llvm/Support/raw_ostream.h"
2729
#include <algorithm>
2830
#include <cassert>
2931
#include <iterator>
@@ -36,6 +38,11 @@ using namespace llvm;
3638
// template typedefs.
3739
namespace llvm {
3840

41+
static cl::opt<bool> AbortOnMaxDevirtIterationsReached(
42+
"abort-on-max-devirt-iterations-reached",
43+
cl::desc("Abort when the max iterations for devirtualization CGSCC repeat "
44+
"pass is reached"));
45+
3946
// Explicit instantiations for the core proxy templates.
4047
template class AllAnalysesOn<LazyCallGraph::SCC>;
4148
template class AnalysisManager<LazyCallGraph::SCC, LazyCallGraph &>;
@@ -362,6 +369,11 @@ static void updateNewSCCFunctionAnalyses(LazyCallGraph::SCC &C,
362369
}
363370
}
364371

372+
void llvm::maxDevirtIterationsReached() {
373+
if (AbortOnMaxDevirtIterationsReached)
374+
report_fatal_error("Max devirtualization iterations reached");
375+
}
376+
365377
/// Helper function to update both the \c CGSCCAnalysisManager \p AM and the \c
366378
/// CGSCCPassManager's \c CGSCCUpdateResult \p UR based on a range of newly
367379
/// added SCCs.

llvm/test/Other/cgscc-devirt-iteration.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
; RUN: opt -aa-pipeline=basic-aa -passes='cgscc(devirt<1>(function-attrs,function(gvn,instcombine)))' -S < %s | FileCheck %s --check-prefix=CHECK --check-prefix=AFTER --check-prefix=AFTER1
99
; RUN: opt -aa-pipeline=basic-aa -passes='cgscc(devirt<2>(function-attrs,function(gvn,instcombine)))' -S < %s | FileCheck %s --check-prefix=CHECK --check-prefix=AFTER --check-prefix=AFTER2
1010
;
11+
; RUN: not --crash opt -abort-on-max-devirt-iterations-reached -aa-pipeline=basic-aa -passes='cgscc(devirt<1>(function-attrs,function(gvn,instcombine)))' -S < %s
12+
; RUN: opt -abort-on-max-devirt-iterations-reached -aa-pipeline=basic-aa -passes='cgscc(devirt<2>(function-attrs,function(gvn,instcombine)))' -S < %s
13+
;
1114
; We also verify that the real O2 pipeline catches these cases.
1215
; RUN: opt -aa-pipeline=basic-aa -passes='default<O2>' -S < %s | FileCheck %s --check-prefix=CHECK --check-prefix=AFTER --check-prefix=AFTER2
1316

0 commit comments

Comments
 (0)