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

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 15:37:22 PDT 2020


mtrofin updated this revision to Diff 256684.
mtrofin added a comment.

const -ed a few values


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77877/new/

https://reviews.llvm.org/D77877

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


Index: llvm/lib/Transforms/IPO/Inliner.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Inliner.cpp
+++ llvm/lib/Transforms/IPO/Inliner.cpp
@@ -613,7 +613,9 @@
     // 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 @@
       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 @@
       // 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 @@
     // 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 &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77877.256684.patch
Type: text/x-patch
Size: 2735 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200410/2fc5a9aa/attachment.bin>


More information about the llvm-commits mailing list