@@ -99,10 +99,6 @@ static cl::opt<std::string> CGSCCInlineReplayFile(
99
99
" by inlining from cgscc inline remarks." ),
100
100
cl::Hidden);
101
101
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
-
106
102
LegacyInlinerBase::LegacyInlinerBase (char &ID) : CallGraphSCCPass(ID) {}
107
103
108
104
LegacyInlinerBase::LegacyInlinerBase (char &ID, bool InsertLifetime)
@@ -677,17 +673,16 @@ InlinerPass::getAdvisor(const ModuleAnalysisManagerCGSCCProxy::Result &MAM,
677
673
template <typename T> class InlineOrder {
678
674
public:
679
675
using reference = T &;
680
- using const_reference = const T &;
681
676
682
677
virtual ~InlineOrder () {}
683
678
684
679
virtual size_t size () = 0;
685
680
686
681
virtual void push (const T &Elt) = 0;
687
682
688
- virtual T pop () = 0;
683
+ virtual void pop () = 0;
689
684
690
- virtual const_reference front () = 0;
685
+ virtual reference front () = 0;
691
686
692
687
virtual void erase_if (function_ref<bool (T)> Pred) = 0;
693
688
@@ -697,19 +692,18 @@ template <typename T> class InlineOrder {
697
692
template <typename T, typename Container = SmallVector<T, 16 >>
698
693
class DefaultInlineOrder : public InlineOrder <T> {
699
694
using reference = T &;
700
- using const_reference = const T &;
701
695
702
696
public:
703
697
size_t size () override { return Calls.size () - FirstIndex; }
704
698
705
699
void push (const T &Elt) override { Calls.push_back (Elt); }
706
700
707
- T pop () override {
701
+ void pop () override {
708
702
assert (size () > 0 );
709
- return Calls[ FirstIndex++] ;
703
+ FirstIndex++;
710
704
}
711
705
712
- const_reference front () override {
706
+ reference front () override {
713
707
assert (size () > 0 );
714
708
return Calls[FirstIndex];
715
709
}
@@ -724,57 +718,6 @@ class DefaultInlineOrder : public InlineOrder<T> {
724
718
size_t FirstIndex = 0 ;
725
719
};
726
720
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
-
778
721
PreservedAnalyses InlinerPass::run (LazyCallGraph::SCC &InitialC,
779
722
CGSCCAnalysisManager &AM, LazyCallGraph &CG,
780
723
CGSCCUpdateResult &UR) {
@@ -797,8 +740,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
797
740
798
741
// We use a single common worklist for calls across the entire SCC. We
799
742
// 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.
802
744
//
803
745
// Note that this particular order of processing is actually critical to
804
746
// avoid very bad behaviors. Consider *highly connected* call graphs where
@@ -820,12 +762,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
820
762
// this model, but it is uniformly spread across all the functions in the SCC
821
763
// and eventually they all become too large to inline, rather than
822
764
// 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;
829
766
830
767
// Populate the initial list of calls in this SCC.
831
768
for (auto &N : InitialC) {
@@ -840,7 +777,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
840
777
if (auto *CB = dyn_cast<CallBase>(&I))
841
778
if (Function *Callee = CB->getCalledFunction ()) {
842
779
if (!Callee->isDeclaration ())
843
- Calls-> push ({CB, -1 });
780
+ Calls. push ({CB, -1 });
844
781
else if (!isa<IntrinsicInst>(I)) {
845
782
using namespace ore ;
846
783
setInlineRemark (*CB, " unavailable definition" );
@@ -854,7 +791,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
854
791
}
855
792
}
856
793
}
857
- if (Calls-> empty ())
794
+ if (Calls. empty ())
858
795
return PreservedAnalyses::all ();
859
796
860
797
// Capture updatable variable for the current SCC.
@@ -876,15 +813,15 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
876
813
SmallVector<Function *, 4 > DeadFunctions;
877
814
878
815
// Loop forward over all of the calls.
879
- while (!Calls-> empty ()) {
816
+ while (!Calls. empty ()) {
880
817
// We expect the calls to typically be batched with sequences of calls that
881
818
// have the same caller, so we first set up some shared infrastructure for
882
819
// this caller. We also do any pruning we can at this layer on the caller
883
820
// alone.
884
- Function &F = *Calls-> front ().first ->getCaller ();
821
+ Function &F = *Calls. front ().first ->getCaller ();
885
822
LazyCallGraph::Node &N = *CG.lookup (F);
886
823
if (CG.lookupSCC (N) != C) {
887
- Calls-> pop ();
824
+ Calls. pop ();
888
825
continue ;
889
826
}
890
827
@@ -900,8 +837,9 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
900
837
// We bail out as soon as the caller has to change so we can update the
901
838
// call graph and prepare the context of that new caller.
902
839
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 ();
905
843
CallBase *CB = P.first ;
906
844
const int InlineHistoryID = P.second ;
907
845
Function &Callee = *CB->getCalledFunction ();
@@ -971,7 +909,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
971
909
}
972
910
if (NewCallee)
973
911
if (!NewCallee->isDeclaration ())
974
- Calls-> push ({ICB, NewHistoryID});
912
+ Calls. push ({ICB, NewHistoryID});
975
913
}
976
914
}
977
915
@@ -988,7 +926,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
988
926
// made dead by this operation on other functions).
989
927
Callee.removeDeadConstantUsers ();
990
928
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) {
992
930
return Call.first ->getCaller () == &Callee;
993
931
});
994
932
// Clear the body and queue the function itself for deletion when we
0 commit comments