[llvm] da9bcda - [llvm][NFC] Inliner.cpp: ensure InlineHistory ID is always initialized;

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 15:30:54 PDT 2020


Author: Mircea Trofin
Date: 2020-04-10T15:28:53-07:00
New Revision: da9bcdaad9b603de4f0eea4509c38f30b1f4dc36

URL: https://github.com/llvm/llvm-project/commit/da9bcdaad9b603de4f0eea4509c38f30b1f4dc36
DIFF: https://github.com/llvm/llvm-project/commit/da9bcdaad9b603de4f0eea4509c38f30b1f4dc36.diff

LOG: [llvm][NFC] Inliner.cpp: ensure InlineHistory ID is always initialized;

Summary:
The inline history is associated with a call site. There are two locations
we fetch inline history. In one, we fetch it together with the call
site. In the other, we initialize it under certain conditions, use it
later under same conditions (different if check), and otherwise is
uninitialized. Although currently there is no uninitialized use, the
code is more challenging to maintain correctly, than if the value were
always initialized.

Changed to the upfront initialization pattern already present in this
file.

Reviewers: davidxl, dblaikie

Subscribers: eraman, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77877

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/Inliner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp
index b2824797b974..6a4e1197bf8e 100644
--- a/llvm/lib/Transforms/IPO/Inliner.cpp
+++ b/llvm/lib/Transforms/IPO/Inliner.cpp
@@ -613,7 +613,9 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
     // calls to become direct calls.
     // CallSites may be modified inside so ranged for loop can not be used.
     for (unsigned CSi = 0; CSi != CallSites.size(); ++CSi) {
-      CallBase &CS = *CallSites[CSi].first;
+      auto &P = CallSites[CSi];
+      CallBase &CS = *P.first;
+      const int InlineHistoryID = P.second;
 
       Function *Caller = CS.getCaller();
       Function *Callee = CS.getCalledFunction();
@@ -622,19 +624,14 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
       if (!Callee || Callee->isDeclaration())
         continue;
 
-      Instruction *Instr = &CS;
+      bool IsTriviallyDead = isInstructionTriviallyDead(&CS, &GetTLI(*Caller));
 
-      bool IsTriviallyDead =
-          isInstructionTriviallyDead(Instr, &GetTLI(*Caller));
-
-      int InlineHistoryID;
       if (!IsTriviallyDead) {
         // If this call site was obtained by inlining another function, verify
         // that the include path for the function did not include the callee
         // itself.  If so, we'd be recursively inlining the same function,
         // which would provide the same callsites, which would cause us to
         // infinitely inline.
-        InlineHistoryID = CallSites[CSi].second;
         if (InlineHistoryID != -1 &&
             inlineHistoryIncludes(Callee, InlineHistoryID, InlineHistory)) {
           setInlineRemark(CS, "recursive");
@@ -667,11 +664,11 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
       // size.  This happens because IPSCCP propagates the result out of the
       // call and then we're left with the dead call.
       if (IsTriviallyDead) {
-        LLVM_DEBUG(dbgs() << "    -> Deleting dead call: " << *Instr << "\n");
+        LLVM_DEBUG(dbgs() << "    -> Deleting dead call: " << CS << "\n");
         // Update the call graph by deleting the edge from Callee to Caller.
         setInlineRemark(CS, "trivially dead");
         CG[Caller]->removeCallEdgeFor(CS);
-        Instr->eraseFromParent();
+        CS.eraseFromParent();
         ++NumCallsDeleted;
       } else {
         // Get DebugLoc to report. CS will be invalid after Inliner.
@@ -1039,9 +1036,9 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
     // call graph and prepare the context of that new caller.
     bool DidInline = false;
     for (; I < (int)Calls.size() && Calls[I].first->getCaller() == &F; ++I) {
-      int InlineHistoryID;
-      CallBase *CS = nullptr;
-      std::tie(CS, InlineHistoryID) = Calls[I];
+      auto &P = Calls[I];
+      CallBase *CS = P.first;
+      const int InlineHistoryID = P.second;
       Function &Callee = *CS->getCalledFunction();
 
       if (InlineHistoryID != -1 &&


        


More information about the llvm-commits mailing list