[llvm-commits] [poolalloc] r127490 - in /poolalloc/trunk/lib/AssistDS: ArgSimplify.cpp VarArgsFunc.cpp

Arushi Aggarwal aggarwa4 at illinois.edu
Fri Mar 11 12:48:58 PST 2011


Author: aggarwa4
Date: Fri Mar 11 14:48:57 2011
New Revision: 127490

URL: http://llvm.org/viewvc/llvm-project?rev=127490&view=rev
Log:
Formatting changes.

Modified:
    poolalloc/trunk/lib/AssistDS/ArgSimplify.cpp
    poolalloc/trunk/lib/AssistDS/VarArgsFunc.cpp

Modified: poolalloc/trunk/lib/AssistDS/ArgSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/ArgSimplify.cpp?rev=127490&r1=127489&r2=127490&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/ArgSimplify.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/ArgSimplify.cpp Fri Mar 11 14:48:57 2011
@@ -6,7 +6,6 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-//===----------------------------------------------------------------------===//
 #define DEBUG_TYPE "argsimpl"
 
 #include "llvm/Instructions.h"
@@ -27,26 +26,33 @@
 
 namespace {
 
-  static void simplify(Function *I, unsigned arg_count, const Type* type) {
+  // F - Function to modify
+  // arg_count - The argument to function I that may be changed
+  // type - Declared type of the argument
+
+  static void simplify(Function *F, unsigned arg_count, const Type* type) {
 
-    for(Value::use_iterator ui = I->use_begin(), ue = I->use_end();
+    // Go through all uses of the function
+    for(Value::use_iterator ui = F->use_begin(), ue = F->use_end();
         ui != ue; ++ui) {
+
       if (Constant *C = dyn_cast<Constant>(ui)) {
         if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
           if (CE->getOpcode() == Instruction::BitCast) {
-            if(CE->getOperand(0) == I) {                    
+            if(CE->getOperand(0) == F) {                    
               for(Value::use_iterator uii = CE->use_begin(), uee = CE->use_end();
                   uii != uee; ) {
+                // check if it is ever used as a call (bitcast F to ...)()
                 if (CallInst* CI = dyn_cast<CallInst>(uii++)) {
                   if(CI->getCalledValue() == CE) {
                     // if I is ever called as a bitcasted function
-                    if(I->getReturnType() == CI->getType()){
+                    if(F->getReturnType() == CI->getType()){
                       // if the return types match.
-                      if(I->arg_size() == (CI->getNumOperands()-1)){
+                      if(F->arg_size() == (CI->getNumOperands()-1)){
                         // and the numeber of args match too
                         unsigned arg_count1 = 1;
                         bool change = true;
-                        for (Function::arg_iterator ii1 = I->arg_begin(), ee1 = I->arg_end();
+                        for (Function::arg_iterator ii1 = F->arg_begin(), ee1 = F->arg_end();
                              ii1 != ee1; ++ii1,arg_count1++) {
                           if(arg_count1 == (arg_count + 1)) {
                             if(ii1->getType() == CI->getOperand(arg_count1)->getType()){
@@ -73,7 +79,7 @@
                           const FunctionType *NewFTy = FunctionType::
                             get(CI->getType(), TP, false);
                           
-                          Module *M = I->getParent();
+                          Module *M = F->getParent();
                           Function *NewF = Function::Create(NewFTy,
                                                             GlobalValue::InternalLinkage,
                                                             "argbounce",
@@ -104,7 +110,7 @@
                               Args.push_back(ai);
                           }
                           
-                          CallInst * CallI = CallInst::Create(I,Args.begin(), 
+                          CallInst * CallI = CallInst::Create(F,Args.begin(), 
                                                               Args.end(),"", entryBB);
                           if(CallI->getType()->isVoidTy())
                             ReturnInst::Create(M->getContext(), entryBB);
@@ -124,8 +130,8 @@
         }
       }
     }
-
   }
+  
   class ArgSimplify : public ModulePass {
   public:
     static char ID;
@@ -143,12 +149,13 @@
             bool change = true;
             for(Value::use_iterator ui = ii->use_begin(), ue = ii->use_end();
                 ui != ue; ++ui) {
+              // check if the argument is used exclusively in ICmp Instructions
               if(!isa<ICmpInst>(ui)){
                 change = false;
                 break;
               }
             }
-            // if this argument is only used in CMP instructions, we can
+            // if this argument is only used in ICMP instructions, we can
             // replace it.
             if(change) {
               simplify(I, ii->getArgNo(), ii->getType()); 

Modified: poolalloc/trunk/lib/AssistDS/VarArgsFunc.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/VarArgsFunc.cpp?rev=127490&r1=127489&r2=127490&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/VarArgsFunc.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/VarArgsFunc.cpp Fri Mar 11 14:48:57 2011
@@ -42,11 +42,12 @@
               if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) 
                 if (CE->getOpcode() == Instruction::BitCast) 
                   if(CE->getOperand(0) == I) 
-                    if(const FunctionType *FTy  = dyn_cast<FunctionType>((cast<PointerType>(CE->getType()))->getElementType())) 
+                    if(const FunctionType *FTy  = dyn_cast<FunctionType>
+                       ((cast<PointerType>(CE->getType()))->getElementType())) 
                       //casting to a varargs funtion
                       if(FTy->isVarArg()) 
-                        for(Value::use_iterator uii = CE->use_begin(), uee = CE->use_end();
-                            uii != uee; ++uii) 
+                        for(Value::use_iterator uii = CE->use_begin(),
+                            uee = CE->use_end(); uii != uee; ++uii) 
                           if (CallInst* CI = dyn_cast<CallInst>(uii)) 
                             if(CI->getCalledValue() == CE) 
                                worklist.push_back(CI);





More information about the llvm-commits mailing list