[llvm] r290562 - [PM] Move the collection of call sites to a more appropriate place

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 26 17:24:51 PST 2016


Author: chandlerc
Date: Mon Dec 26 19:24:50 2016
New Revision: 290562

URL: http://llvm.org/viewvc/llvm-project?rev=290562&view=rev
Log:
[PM] Move the collection of call sites to a more appropriate place
inside of `InlineFunction`. Prior to this, call instructions are
specifically being rewritten and replaced within the inlined region,
invalidating some of the call sites.

Several of these regions are using the same technique to walk the
inlined region so this seems clearly safe up to this point.

I've also added a short circuit to the scan for call sites based on what
other code is doing.

With this, the most common crash I've found in the new inliner code is
fixed. I've turned it on for another test case that covers this
scenario.

I'll make my way through most of the other inliner test cases
just to get some easy coverage next.

Modified:
    llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
    llvm/trunk/test/Transforms/Inline/inline_invoke.ll

Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=290562&r1=290561&r2=290562&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Mon Dec 26 19:24:50 2016
@@ -1644,16 +1644,8 @@ bool llvm::InlineFunction(CallSite CS, I
     }
 
     // Update the callgraph if requested.
-    if (IFI.CG) {
+    if (IFI.CG)
       UpdateCallGraphAfterInlining(CS, FirstNewBlock, VMap, IFI);
-    } else {
-      // Otherwise just collect the raw call sites that were inlined.
-      for (BasicBlock &NewBB :
-           make_range(FirstNewBlock->getIterator(), Caller->end()))
-        for (Instruction &I : NewBB)
-          if (auto CS = CallSite(&I))
-            IFI.InlinedCallSites.push_back(CS);
-    }
 
     // For 'nodebug' functions, the associated DISubprogram is always null.
     // Conservatively avoid propagating the callsite debug location to
@@ -2018,6 +2010,20 @@ bool llvm::InlineFunction(CallSite CS, I
     std::swap(Returns, NormalReturns);
   }
 
+  // Now that all of the transforms on the inlined code have taken place but
+  // before we splice the inlined code into the CFG and lose track of which
+  // blocks were actually inlined, collect the call sites. We only do this if
+  // call graph updates weren't requested, as those provide value handle based
+  // tracking of inlined call sites instead.
+  if (InlinedFunctionInfo.ContainsCalls && !IFI.CG) {
+    // Otherwise just collect the raw call sites that were inlined.
+    for (BasicBlock &NewBB :
+         make_range(FirstNewBlock->getIterator(), Caller->end()))
+      for (Instruction &I : NewBB)
+        if (auto CS = CallSite(&I))
+          IFI.InlinedCallSites.push_back(CS);
+  }
+
   // If we cloned in _exactly one_ basic block, and if that block ends in a
   // return instruction, we splice the body of the inlined callee directly into
   // the calling basic block.

Modified: llvm/trunk/test/Transforms/Inline/inline_invoke.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/inline_invoke.ll?rev=290562&r1=290561&r2=290562&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Inline/inline_invoke.ll (original)
+++ llvm/trunk/test/Transforms/Inline/inline_invoke.ll Mon Dec 26 19:24:50 2016
@@ -1,4 +1,5 @@
 ; RUN: opt < %s -inline -S | FileCheck %s
+; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s
 
 ; Test that the inliner correctly handles inlining into invoke sites
 ; by appending selectors and forwarding _Unwind_Resume directly to the




More information about the llvm-commits mailing list