[llvm-commits] CVS: llvm/lib/Transforms/Utils/InlineFunction.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Jan 13 11:15:26 PST 2006



Changes in directory llvm/lib/Transforms/Utils:

InlineFunction.cpp updated: 1.37 -> 1.38
---
Log message:

Use the ClonedCodeInfo object to avoid scans of the inlined code when
it doesn't contain any calls.  This is a fairly common case for C++ code,
so it will probably speed up the inliner marginally in these cases.


---
Diffs of the changes:  (+67 -62)

 InlineFunction.cpp |  129 +++++++++++++++++++++++++++--------------------------
 1 files changed, 67 insertions(+), 62 deletions(-)


Index: llvm/lib/Transforms/Utils/InlineFunction.cpp
diff -u llvm/lib/Transforms/Utils/InlineFunction.cpp:1.37 llvm/lib/Transforms/Utils/InlineFunction.cpp:1.38
--- llvm/lib/Transforms/Utils/InlineFunction.cpp:1.37	Fri Jan 13 13:05:59 2006
+++ llvm/lib/Transforms/Utils/InlineFunction.cpp	Fri Jan 13 13:15:15 2006
@@ -51,70 +51,75 @@
   // The inlined code is currently at the end of the function, scan from the
   // start of the inlined code to its end, checking for stuff we need to
   // rewrite.
-  for (Function::iterator BB = FirstNewBlock, E = Caller->end();
-       BB != E; ++BB) {
-    for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ) {
-      Instruction *I = BBI++;
-      
-      // We only need to check for function calls: inlined invoke instructions
-      // require no special handling.
-      if (!isa<CallInst>(I)) continue;
-      CallInst *CI = cast<CallInst>(I);
-
-      // If this is an intrinsic function call, do not convert it to an invoke.
-      if (CI->getCalledFunction() &&
-          CI->getCalledFunction()->getIntrinsicID())
-        continue;
-      
-      // Convert this function call into an invoke instruction.
-      // First, split the basic block.
-      BasicBlock *Split = BB->splitBasicBlock(CI, CI->getName()+".noexc");
-      
-      // Next, create the new invoke instruction, inserting it at the end
-      // of the old basic block.
-      InvokeInst *II =
-        new InvokeInst(CI->getCalledValue(), Split, InvokeDest,
-                       std::vector<Value*>(CI->op_begin()+1, CI->op_end()),
-                       CI->getName(), BB->getTerminator());
-      II->setCallingConv(CI->getCallingConv());
-      
-      // Make sure that anything using the call now uses the invoke!
-      CI->replaceAllUsesWith(II);
-      
-      // Delete the unconditional branch inserted by splitBasicBlock
-      BB->getInstList().pop_back();
-      Split->getInstList().pop_front();  // Delete the original call
-      
-      // Update any PHI nodes in the exceptional block to indicate that
-      // there is now a new entry in them.
-      unsigned i = 0;
-      for (BasicBlock::iterator I = InvokeDest->begin();
-           isa<PHINode>(I); ++I, ++i) {
-        PHINode *PN = cast<PHINode>(I);
-        PN->addIncoming(InvokeDestPHIValues[i], BB);
+  if (InlinedCodeInfo.ContainsCalls || InlinedCodeInfo.ContainsUnwinds) {
+    for (Function::iterator BB = FirstNewBlock, E = Caller->end();
+         BB != E; ++BB) {
+      if (InlinedCodeInfo.ContainsCalls) {
+        for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ){
+          Instruction *I = BBI++;
+          
+          // We only need to check for function calls: inlined invoke
+          // instructions require no special handling.
+          if (!isa<CallInst>(I)) continue;
+          CallInst *CI = cast<CallInst>(I);
+
+          // If this is an intrinsic function call, don't convert it to an
+          // invoke.
+          if (CI->getCalledFunction() &&
+              CI->getCalledFunction()->getIntrinsicID())
+            continue;
+          
+          // Convert this function call into an invoke instruction.
+          // First, split the basic block.
+          BasicBlock *Split = BB->splitBasicBlock(CI, CI->getName()+".noexc");
+          
+          // Next, create the new invoke instruction, inserting it at the end
+          // of the old basic block.
+          InvokeInst *II =
+            new InvokeInst(CI->getCalledValue(), Split, InvokeDest,
+                           std::vector<Value*>(CI->op_begin()+1, CI->op_end()),
+                           CI->getName(), BB->getTerminator());
+          II->setCallingConv(CI->getCallingConv());
+          
+          // Make sure that anything using the call now uses the invoke!
+          CI->replaceAllUsesWith(II);
+          
+          // Delete the unconditional branch inserted by splitBasicBlock
+          BB->getInstList().pop_back();
+          Split->getInstList().pop_front();  // Delete the original call
+          
+          // Update any PHI nodes in the exceptional block to indicate that
+          // there is now a new entry in them.
+          unsigned i = 0;
+          for (BasicBlock::iterator I = InvokeDest->begin();
+               isa<PHINode>(I); ++I, ++i) {
+            PHINode *PN = cast<PHINode>(I);
+            PN->addIncoming(InvokeDestPHIValues[i], BB);
+          }
+            
+          // This basic block is now complete, start scanning the next one.
+          break;
+        }
       }
-        
-      // This basic block is now complete, start scanning the next one.
-      break;
-    }
-    
-    if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) {
-      // An UnwindInst requires special handling when it gets inlined into an
-      // invoke site.  Once this happens, we know that the unwind would cause
-      // a control transfer to the invoke exception destination, so we can
-      // transform it into a direct branch to the exception destination.
-      new BranchInst(InvokeDest, UI);
-      
-      // Delete the unwind instruction!
-      UI->getParent()->getInstList().pop_back();
       
-      // Update any PHI nodes in the exceptional block to indicate that
-      // there is now a new entry in them.
-      unsigned i = 0;
-      for (BasicBlock::iterator I = InvokeDest->begin();
-           isa<PHINode>(I); ++I, ++i) {
-        PHINode *PN = cast<PHINode>(I);
-        PN->addIncoming(InvokeDestPHIValues[i], BB);
+      if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) {
+        // An UnwindInst requires special handling when it gets inlined into an
+        // invoke site.  Once this happens, we know that the unwind would cause
+        // a control transfer to the invoke exception destination, so we can
+        // transform it into a direct branch to the exception destination.
+        new BranchInst(InvokeDest, UI);
+        
+        // Delete the unwind instruction!
+        UI->getParent()->getInstList().pop_back();
+        
+        // Update any PHI nodes in the exceptional block to indicate that
+        // there is now a new entry in them.
+        unsigned i = 0;
+        for (BasicBlock::iterator I = InvokeDest->begin();
+             isa<PHINode>(I); ++I, ++i) {
+          PHINode *PN = cast<PHINode>(I);
+          PN->addIncoming(InvokeDestPHIValues[i], BB);
+        }
       }
     }
   }






More information about the llvm-commits mailing list