[PATCH] Update call graph after devirtualizing returned value

Chandler Carruth chandlerc at gmail.com
Tue Jun 3 17:47:24 PDT 2014


================
Comment at: lib/Transforms/Utils/InlineFunction.cpp:521-522
@@ +520,4 @@
+  CallGraphNode *CallerNode = nullptr;
+  for (auto UI = TheCall->use_begin(), UE = TheCall->use_end();
+       UI != UE;) {
+    Use &U = *UI++;
----------------
You can just write:

  for (Use *U : TheCall->uses()) {

================
Comment at: lib/Transforms/Utils/InlineFunction.cpp:524
@@ +523,3 @@
+    Use &U = *UI++;
+    U.set(CalledF);
+    CallSite CS(U.getUser());
----------------
I don't understand why you're doing it this way.

I would just do the RAUW in the caller of this like normal, and then walk the uses after replacing them.

================
Comment at: lib/Transforms/Utils/InlineFunction.cpp:526-527
@@ +525,4 @@
+    CallSite CS(U.getUser());
+    if (!CS)
+      continue;
+    if (!CallerNode) {
----------------
So, this misses cases where the function pointer is washed through a bitcast to i8* and back to a function pointer.

If you do the RAUW first, I think you can use instsimplify and look through casts to handle all of these cases more generally. You probably will also need to walk the uses recursively to find all the transitive users through bitcasts.

================
Comment at: lib/Transforms/Utils/InlineFunction.cpp:529-531
@@ +528,5 @@
+    if (!CallerNode) {
+      // Lazily look up the caller node
+      const Function *Caller = TheCall->getParent()->getParent();
+      CallerNode = (*IFI.CG)[Caller];
+    }
----------------
Why not just pass this in?

================
Comment at: lib/Transforms/Utils/InlineFunction.cpp:533-534
@@ +532,4 @@
+    }
+    CallGraphNode *CalleeNode = IFI.CG->getOrInsertFunction(CalledF);
+    CallerNode->replaceCallEdge(CS, CS, CalleeNode);
+  }
----------------
This is a linear operation on the caller, which makes this whole thing go quadratic. Have you seen any compile time performance hits?

The entire design of the call graph makes doing this really annoying. I can't wait until we can switch to LCG....

http://reviews.llvm.org/D4012






More information about the llvm-commits mailing list