[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 08:27:43 PDT 2020


mtrofin created this revision.
mtrofin added reviewers: davidxl, dblaikie.
Herald added subscribers: llvm-commits, hiraditya, eraman.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

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,10 @@
     // 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;
+      int InlineHistoryID;
+      CallBase *Instr;
+      std::tie(Instr, InlineHistoryID) = CallSites[CSi];
+      CallBase &CS = *Instr;
 
       Function *Caller = CS.getCaller();
       Function *Callee = CS.getCalledFunction();
@@ -622,19 +625,15 @@
       if (!Callee || Callee->isDeclaration())
         continue;
 
-      Instruction *Instr = &CS;
-
       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");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77877.256575.patch
Type: text/x-patch
Size: 1500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200410/913bbf60/attachment-0001.bin>


More information about the llvm-commits mailing list