Skip to content

Commit 93183a4

Browse files
committed
Revert D104028 "[llvm][Inliner] Add an optional PriorityInlineOrder"
1 parent de92287 commit 93183a4

File tree

5 files changed

+24
-203
lines changed

5 files changed

+24
-203
lines changed

llvm/lib/Transforms/IPO/Inliner.cpp

Lines changed: 17 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ static cl::opt<std::string> CGSCCInlineReplayFile(
9999
"by inlining from cgscc inline remarks."),
100100
cl::Hidden);
101101

102-
static cl::opt<bool> InlineEnablePriorityOrder(
103-
"inline-enable-priority-order", cl::Hidden, cl::init(false),
104-
cl::desc("Enable the priority inline order for the inliner"));
105-
106102
LegacyInlinerBase::LegacyInlinerBase(char &ID) : CallGraphSCCPass(ID) {}
107103

108104
LegacyInlinerBase::LegacyInlinerBase(char &ID, bool InsertLifetime)
@@ -677,17 +673,16 @@ InlinerPass::getAdvisor(const ModuleAnalysisManagerCGSCCProxy::Result &MAM,
677673
template <typename T> class InlineOrder {
678674
public:
679675
using reference = T &;
680-
using const_reference = const T &;
681676

682677
virtual ~InlineOrder() {}
683678

684679
virtual size_t size() = 0;
685680

686681
virtual void push(const T &Elt) = 0;
687682

688-
virtual T pop() = 0;
683+
virtual void pop() = 0;
689684

690-
virtual const_reference front() = 0;
685+
virtual reference front() = 0;
691686

692687
virtual void erase_if(function_ref<bool(T)> Pred) = 0;
693688

@@ -697,19 +692,18 @@ template <typename T> class InlineOrder {
697692
template <typename T, typename Container = SmallVector<T, 16>>
698693
class DefaultInlineOrder : public InlineOrder<T> {
699694
using reference = T &;
700-
using const_reference = const T &;
701695

702696
public:
703697
size_t size() override { return Calls.size() - FirstIndex; }
704698

705699
void push(const T &Elt) override { Calls.push_back(Elt); }
706700

707-
T pop() override {
701+
void pop() override {
708702
assert(size() > 0);
709-
return Calls[FirstIndex++];
703+
FirstIndex++;
710704
}
711705

712-
const_reference front() override {
706+
reference front() override {
713707
assert(size() > 0);
714708
return Calls[FirstIndex];
715709
}
@@ -724,57 +718,6 @@ class DefaultInlineOrder : public InlineOrder<T> {
724718
size_t FirstIndex = 0;
725719
};
726720

727-
class PriorityInlineOrder : public InlineOrder<std::pair<CallBase *, int>> {
728-
using T = std::pair<CallBase *, int>;
729-
using reference = T &;
730-
using const_reference = const T &;
731-
732-
static bool cmp(const T &P1, const T &P2) { return P1.second > P2.second; }
733-
734-
int evaluate(CallBase *CB) {
735-
Function *Callee = CB->getCalledFunction();
736-
return (int)Callee->getInstructionCount();
737-
}
738-
739-
public:
740-
size_t size() override { return Heap.size(); }
741-
742-
void push(const T &Elt) override {
743-
CallBase *CB = Elt.first;
744-
const int InlineHistoryID = Elt.second;
745-
const int Goodness = evaluate(CB);
746-
747-
Heap.push_back({CB, Goodness});
748-
std::push_heap(Heap.begin(), Heap.end(), cmp);
749-
InlineHistoryMap[CB] = InlineHistoryID;
750-
}
751-
752-
T pop() override {
753-
assert(size() > 0);
754-
CallBase *CB = Heap.front().first;
755-
T Result = std::make_pair(CB, InlineHistoryMap[CB]);
756-
InlineHistoryMap.erase(CB);
757-
std::pop_heap(Heap.begin(), Heap.end(), cmp);
758-
Heap.pop_back();
759-
return Result;
760-
}
761-
762-
const_reference front() override {
763-
assert(size() > 0);
764-
CallBase *CB = Heap.front().first;
765-
return *InlineHistoryMap.find(CB);
766-
}
767-
768-
void erase_if(function_ref<bool(T)> Pred) override {
769-
Heap.erase(std::remove_if(Heap.begin(), Heap.end(), Pred), Heap.end());
770-
std::make_heap(Heap.begin(), Heap.end(), cmp);
771-
}
772-
773-
private:
774-
SmallVector<T, 16> Heap;
775-
DenseMap<CallBase *, int> InlineHistoryMap;
776-
};
777-
778721
PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
779722
CGSCCAnalysisManager &AM, LazyCallGraph &CG,
780723
CGSCCUpdateResult &UR) {
@@ -797,8 +740,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
797740

798741
// We use a single common worklist for calls across the entire SCC. We
799742
// process these in-order and append new calls introduced during inlining to
800-
// the end. The PriorityInlineOrder is optional here, in which the smaller
801-
// callee would have a higher priority to inline.
743+
// the end.
802744
//
803745
// Note that this particular order of processing is actually critical to
804746
// avoid very bad behaviors. Consider *highly connected* call graphs where
@@ -820,12 +762,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
820762
// this model, but it is uniformly spread across all the functions in the SCC
821763
// and eventually they all become too large to inline, rather than
822764
// incrementally maknig a single function grow in a super linear fashion.
823-
std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>> Calls;
824-
if (InlineEnablePriorityOrder)
825-
Calls = std::make_unique<PriorityInlineOrder>();
826-
else
827-
Calls = std::make_unique<DefaultInlineOrder<std::pair<CallBase *, int>>>();
828-
assert(Calls != nullptr && "Expected an initialized InlineOrder");
765+
DefaultInlineOrder<std::pair<CallBase *, int>> Calls;
829766

830767
// Populate the initial list of calls in this SCC.
831768
for (auto &N : InitialC) {
@@ -840,7 +777,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
840777
if (auto *CB = dyn_cast<CallBase>(&I))
841778
if (Function *Callee = CB->getCalledFunction()) {
842779
if (!Callee->isDeclaration())
843-
Calls->push({CB, -1});
780+
Calls.push({CB, -1});
844781
else if (!isa<IntrinsicInst>(I)) {
845782
using namespace ore;
846783
setInlineRemark(*CB, "unavailable definition");
@@ -854,7 +791,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
854791
}
855792
}
856793
}
857-
if (Calls->empty())
794+
if (Calls.empty())
858795
return PreservedAnalyses::all();
859796

860797
// Capture updatable variable for the current SCC.
@@ -876,15 +813,15 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
876813
SmallVector<Function *, 4> DeadFunctions;
877814

878815
// Loop forward over all of the calls.
879-
while (!Calls->empty()) {
816+
while (!Calls.empty()) {
880817
// We expect the calls to typically be batched with sequences of calls that
881818
// have the same caller, so we first set up some shared infrastructure for
882819
// this caller. We also do any pruning we can at this layer on the caller
883820
// alone.
884-
Function &F = *Calls->front().first->getCaller();
821+
Function &F = *Calls.front().first->getCaller();
885822
LazyCallGraph::Node &N = *CG.lookup(F);
886823
if (CG.lookupSCC(N) != C) {
887-
Calls->pop();
824+
Calls.pop();
888825
continue;
889826
}
890827

@@ -900,8 +837,9 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
900837
// We bail out as soon as the caller has to change so we can update the
901838
// call graph and prepare the context of that new caller.
902839
bool DidInline = false;
903-
while (!Calls->empty() && Calls->front().first->getCaller() == &F) {
904-
auto P = Calls->pop();
840+
while (!Calls.empty() && Calls.front().first->getCaller() == &F) {
841+
auto &P = Calls.front();
842+
Calls.pop();
905843
CallBase *CB = P.first;
906844
const int InlineHistoryID = P.second;
907845
Function &Callee = *CB->getCalledFunction();
@@ -971,7 +909,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
971909
}
972910
if (NewCallee)
973911
if (!NewCallee->isDeclaration())
974-
Calls->push({ICB, NewHistoryID});
912+
Calls.push({ICB, NewHistoryID});
975913
}
976914
}
977915

@@ -988,7 +926,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
988926
// made dead by this operation on other functions).
989927
Callee.removeDeadConstantUsers();
990928
if (Callee.use_empty() && !CG.isLibFunction(Callee)) {
991-
Calls->erase_if([&](const std::pair<CallBase *, int> &Call) {
929+
Calls.erase_if([&](const std::pair<CallBase *, int> &Call) {
992930
return Call.first->getCaller() == &Callee;
993931
});
994932
// Clear the body and queue the function itself for deletion when we

llvm/test/Transforms/Inline/inline_call.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
; Check the optimizer doesn't crash at inlining the function top and all of its callees are inlined.
22
; RUN: opt < %s -O3 -S | FileCheck %s
3-
; RUN: opt < %s -O3 -inline-enable-priority-order=true -S | FileCheck %s
43

54
define dso_local void (...)* @second(i8** %p) {
65
entry:

llvm/test/Transforms/Inline/inline_invoke.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
; RUN: opt < %s -inline -S | FileCheck %s
22
; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s
3-
; RUN: opt < %s -passes='cgscc(inline)' -inline-enable-priority-order=true -S | FileCheck %s
43

54
; Test that the inliner correctly handles inlining into invoke sites
65
; by appending selectors and forwarding _Unwind_Resume directly to the

llvm/test/Transforms/Inline/last-callsite.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
; RUN: opt < %s -passes='cgscc(inline)' -inline-threshold=0 -S | FileCheck %s
2-
; RUN: opt < %s -passes='cgscc(inline)' -inline-threshold=0 -inline-enable-priority-order=true -S | FileCheck %s
32

43
; The 'test1_' prefixed functions test the basic 'last callsite' inline
54
; threshold adjustment where we specifically inline the last call site of an

0 commit comments

Comments
 (0)