[llvm-commits] [poolalloc] r127395 - in /poolalloc/trunk/lib/PoolAllocate: PASimple.cpp TransformFunctionBody.cpp

Matthew Wala mttjwl at gmail.com
Wed Mar 9 19:46:17 PST 2011


Author: wala1
Date: Wed Mar  9 21:46:17 2011
New Revision: 127395

URL: http://llvm.org/viewvc/llvm-project?rev=127395&view=rev
Log:
1) Added CStdLib support in simple pool allocation.
2) Updated function transforms to support more CStdLib functions.

Modified:
    poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
    poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp

Modified: poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PASimple.cpp?rev=127395&r1=127394&r2=127395&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PASimple.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PASimple.cpp Wed Mar  9 21:46:17 2011
@@ -71,22 +71,22 @@
 }
 
 //
-// Function: replacePoolArgument()
+// Function: initialPoolArguments()
 //
 // Description:
-//  This function determines if the specified function has a pool argument that
-//  should be replaced, and if so, returns the index of the argument to
-//  replace.
+//  This function determines if the specified function has inital pool arguments
+//  that should be replaced, and if so, returns the numbers of initial pool arguments
+//  to replace.
 //
 // Inputs:
 //  funcname - A reference to a string containing the name of the function.
 //
 // Return value:
-//  0 - The function does not have any pool arguments to replace.
-//  Otherwise, the index of the single pool argument to replace is returned.
+//  0 - The function does not have any initial pool arguments to replace.
+//  Otherwise, the number of initial pool arguments to replace.
 //
 static unsigned
-replacePoolArgument (const std::string & funcname) {
+initialPoolArguments(const std::string & funcname) {
   if ((funcname == "sc.lscheck") ||
       (funcname == "sc.lscheckui") ||
       (funcname == "sc.lscheckalign") ||
@@ -102,6 +102,21 @@
       (funcname == "sc.get_actual_val")) {
     return 1;
   }
+  
+  // CStdLib functions
+
+  else if ( ( funcname == "pool_strlen"  ) ||
+            ( funcname == "pool_strchr"  ) ||
+            ( funcname == "pool_strrchr" ) ) {
+    return 1;
+  }
+  else if ( ( funcname == "pool_strcpy"  ) ||
+            ( funcname == "pool_strncat" ) ||
+            ( funcname == "pool_strcat"  ) ||
+            ( funcname == "pool_strstr"  ) ||
+            ( funcname == "pool_strpbrk" ) ) {
+    return 2;
+  }
 
   return 0;
 }
@@ -447,14 +462,16 @@
 
         //
         // Transform SAFECode run-time checks.  For these calls, all we need to
-        // do is to replace the pool argument with a pointer to the global
+        // do is to replace the initial pool arguments with pointers to the global
         // pool.
         //
         if (CF) {
-          if (unsigned index = replacePoolArgument (CF->getName())) {
+          if (unsigned count = initialPoolArguments (CF->getName())) {
             Type * VoidPtrTy = PointerType::getUnqual(Int8Type);
             Value * Pool = castTo (TheGlobalPool, VoidPtrTy, "pool", ii);
-            CI->setOperand (index, Pool);
+            for (unsigned index = 1; index <= count; index++ ) {
+              CI->setOperand (index, Pool);
+            }
           }
         }
       }

Modified: poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp?rev=127395&r1=127394&r2=127395&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp Wed Mar  9 21:46:17 2011
@@ -25,7 +25,9 @@
 #include "llvm/Support/InstVisitor.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/VectorExtras.h"
+
 #include <iostream>
 using namespace llvm;
 using namespace PA;
@@ -54,6 +56,7 @@
                   std::multimap<AllocaInst*, CallInst*> &poolFrees)
       : PAInfo(P), G(g), FI(fi), 
         PoolUses(poolUses), PoolFrees(poolFrees) {
+      initializeCStdLibPoolArgcs();
     }
 
     template <typename InstType, typename SetType>
@@ -89,6 +92,23 @@
     Instruction *TransformAllocationInstr(Instruction *I, Value *Size);
     Instruction *InsertPoolFreeInstr(Value *V, Instruction *Where);
 
+    // Used for looking up CStdLib function names and their initial pool
+    // argument counts
+    StringMap<unsigned> CStdLibPoolArgcs;
+
+    // Initialize the map from CStdLib function name to initial pool
+    // argument counts.
+    void initializeCStdLibPoolArgcs() {
+      CStdLibPoolArgcs.GetOrCreateValue("pool_strcpy",  2);
+      CStdLibPoolArgcs.GetOrCreateValue("pool_strlen",  1);
+      CStdLibPoolArgcs.GetOrCreateValue("pool_strchr",  1);
+      CStdLibPoolArgcs.GetOrCreateValue("pool_strrchr", 1);
+      CStdLibPoolArgcs.GetOrCreateValue("pool_strcat",  2);
+      CStdLibPoolArgcs.GetOrCreateValue("pool_strncat", 2);
+      CStdLibPoolArgcs.GetOrCreateValue("pool_strstr",  2);
+      CStdLibPoolArgcs.GetOrCreateValue("pool_strpbrk", 2);
+    }
+
     //
     // Method: UpdateNewToOldValueMap()
     //
@@ -799,6 +819,8 @@
   Instruction *TheCall = CS.getInstruction();
   bool thread_creation_point = false;
 
+  StringMap<unsigned>::const_iterator pool_argc = CStdLibPoolArgcs.end();
+
   //
   // Get the value that is called at this call site.  Strip away any pointer
   // casts that do not change the representation of the data (i.e., are
@@ -870,10 +892,8 @@
                (CF->getName() == "sc.pool_unregister") ||
                (CF->getName() == "sc.get_actual_val")) {
       visitRuntimeCheck (CS);
-    } else if (CF->getName() == "pool_strlen") {
-      visitCStdLibCheck(CS, 1);
-    } else if (CF->getName() == "pool_strcpy") {
-      visitCStdLibCheck(CS, 2);
+    } else if ((pool_argc = CStdLibPoolArgcs.find(CF->getName())) != CStdLibPoolArgcs.end()) {
+      visitCStdLibCheck(CS, pool_argc->getValue());
     } else if (CF->getName() == "pthread_create") {
       thread_creation_point = true;
 





More information about the llvm-commits mailing list