[PATCH] D33618: [PartialInlining] Reduce function outlining overhead

Wei Mi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 28 17:33:09 PDT 2017


wmi added inline comments.


================
Comment at: lib/Transforms/Utils/CodeExtractor.cpp:146-167
+  for (BasicBlock *BB : Blocks) {
+    for (Instruction &II : *BB) {
+      IntrinsicInst *LifeStart = dyn_cast<IntrinsicInst>(&II);
+      if (!LifeStart)
+        continue;
+      if (LifeStart->getIntrinsicID() != Intrinsic::lifetime_start)
+        continue;
----------------
Here it requires lifetime.start and lifetime.end are in the blocks to be extracted.
I guess there are also many cases for which we have lifetime.start appear in entry block and lifetime.end appear in return block, and the actual uses of the alloca object are all in the blocks to be extracted. For those cases, we can sink the lifetime.start and lifetime.end together into the extracted func. To do that, we may need to start from alloca instructions in non-extracted blocks instead of lifetime.start in extracted blocks. Since the number of non-extracted blocks will be smaller than extracted blocks, so I guess it will be more efficient?    

%%%
This is the small case I try:

class A {
public:
  void memfunc();
};
int cond;

void foo() {
  A a;
  if (cond)
    return;
  a.memfunc();
  return;
}

void goo() {
  foo();
}

The IR of foo:
define void @_Z3foov() local_unnamed_addr #0 {
entry:
  %a = alloca %class.A, align 1
  %0 = getelementptr inbounds %class.A, %class.A* %a, i64 0, i32 0
  call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %0) #3
  %1 = load i32, i32* @cond, align 4, !tbaa !2
  %tobool = icmp eq i32 %1, 0
  br i1 %tobool, label %if.end, label %cleanup

if.end: 
  call void @_ZN1A7memfuncEv(%class.A* nonnull %a) #3
  br label %cleanup

cleanup: 
  call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull %0) #3
  ret void
}
%%%

For the testcase, the lifetime.start and lifetime.end are not in the blocks to be extracted, but it is beneficial to have the alloca sinked.



https://reviews.llvm.org/D33618





More information about the llvm-commits mailing list