[llvm-commits] [poolalloc] r130278 - in /poolalloc/trunk: include/dsa/CStdLib.h include/poolalloc/PoolAllocate.h lib/DSA/StdLibPass.cpp lib/PoolAllocate/PoolAllocate.cpp

Matthew Wala mttjwl at gmail.com
Tue Apr 26 20:13:18 PDT 2011


Author: wala1
Date: Tue Apr 26 22:13:18 2011
New Revision: 130278

URL: http://llvm.org/viewvc/llvm-project?rev=130278&view=rev
Log:
Created a new table with C string function information that will be shared
with SAFECode, and made pool allocation use this table for argument information.

Also inserted transformed C string function information to StdLibPass.


Added:
    poolalloc/trunk/include/dsa/CStdLib.h
Modified:
    poolalloc/trunk/include/poolalloc/PoolAllocate.h
    poolalloc/trunk/lib/DSA/StdLibPass.cpp
    poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp

Added: poolalloc/trunk/include/dsa/CStdLib.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/CStdLib.h?rev=130278&view=auto
==============================================================================
--- poolalloc/trunk/include/dsa/CStdLib.h (added)
+++ poolalloc/trunk/include/dsa/CStdLib.h Tue Apr 26 22:13:18 2011
@@ -0,0 +1,48 @@
+//===- CStdLib.h - CStdLib Function Information ------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Tables to hold information about transformed CStdLib functions.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CSTDLIB_H
+#define LLVM_CSTDLIB_H
+
+namespace llvm {
+
+  const struct CStdLibPoolArgCountEntry {
+    const char *function;
+    unsigned pool_argc;
+  } \
+  CStdLibPoolArgCounts[] = {
+    { "pool_strcpy",      2 },
+    { "pool_stpcpy",      2 },
+    { "pool_strncpy",     2 },
+    { "pool_strlen",      1 },
+    { "pool_strchr",      1 },
+    { "pool_strrchr",     1 },
+    { "pool_strcat",      2 },
+    { "pool_strncat",     2 },
+    { "pool_strstr",      2 },
+    { "pool_strpbrk",     2 },
+    { "pool_strcmp",      2 },
+    { "pool_strcmp",      2 },
+    { "pool_memcmp",      2 },
+    { "pool_strcasecmp",  2 },
+    { "pool_strncasecmp", 2 },
+    { "pool_strspn",      2 },
+    { "pool_strcspn",     2 },
+    { "pool_memccpy",     2 },
+    { "pool_memchr",      1 },
+    {  0,                 0 }
+  };
+
+} // End llvm namespace
+
+#endif

Modified: poolalloc/trunk/include/poolalloc/PoolAllocate.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/PoolAllocate.h?rev=130278&r1=130277&r2=130278&view=diff
==============================================================================
--- poolalloc/trunk/include/poolalloc/PoolAllocate.h (original)
+++ poolalloc/trunk/include/poolalloc/PoolAllocate.h Tue Apr 26 22:13:18 2011
@@ -210,9 +210,6 @@
   // Map a cloned function to its original function
   std::map<const Function*, Function*> CloneToOrigMap;
 
-  // Map a CStdLib function name to its pool argument count.
-  StringMap<unsigned> CStdLibPoolArgs;
-
 public:
 
   Constant *PoolInit, *PoolDestroy, *PoolAlloc, *PoolRealloc, *PoolMemAlign, *PoolThreadWrapper;
@@ -248,7 +245,6 @@
 		  lie_preserve_passes = SAFECodeEnabled ? LIE_PRESERVE_ALL : LIE_PRESERVE_DSA;
 		  dsa_pass_to_use = SAFECodeEnabled ? PASS_EQTD : PASS_BUEQ;
 
-      InitializeCStdLibPoolArgs();
       }
 
   /*TODO: finish removing the SAFECode flag*/
@@ -272,7 +268,6 @@
   		  else
   			  dsa_pass_to_use = dsa_pass_to_use_;
 
-        InitializeCStdLibPoolArgs();
         }
 
   virtual bool runOnModule(Module &M);
@@ -439,9 +434,6 @@
 
  private:
 
-  /// Initialiaze the pool argument counts.
-  void InitializeCStdLibPoolArgs();
-
   /// MicroOptimizePoolCalls - Apply any microoptimizations to calls to pool
   /// allocation function calls that we can.
   void MicroOptimizePoolCalls();

Modified: poolalloc/trunk/lib/DSA/StdLibPass.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/StdLibPass.cpp?rev=130278&r1=130277&r2=130278&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/StdLibPass.cpp (original)
+++ poolalloc/trunk/lib/DSA/StdLibPass.cpp Tue Apr 26 22:13:18 2011
@@ -74,14 +74,17 @@
   bool collapse;
 };
 
-#define NRET_NARGS  {0,0,0,0,0,0,0,0,0,0}
-#define YRET_NARGS  {1,0,0,0,0,0,0,0,0,0}
-#define NRET_YARGS  {0,1,1,1,1,1,1,1,1,1}
-#define YRET_YARGS  {1,1,1,1,1,1,1,1,1,1}
-#define NRET_NYARGS {0,0,1,1,1,1,1,1,1,1}
-#define YRET_NYARGS {1,0,1,1,1,1,1,1,1,1}
-#define NRET_YNARGS {0,1,0,0,0,0,0,0,0,0}
-#define YRET_YNARGS {1,1,0,0,0,0,0,0,0,0}
+#define NRET_NARGS    {0,0,0,0,0,0,0,0,0,0}
+#define YRET_NARGS    {1,0,0,0,0,0,0,0,0,0}
+#define NRET_YARGS    {0,1,1,1,1,1,1,1,1,1}
+#define YRET_YARGS    {1,1,1,1,1,1,1,1,1,1}
+#define NRET_NYARGS   {0,0,1,1,1,1,1,1,1,1}
+#define YRET_NYARGS   {1,0,1,1,1,1,1,1,1,1}
+#define NRET_YNARGS   {0,1,0,0,0,0,0,0,0,0}
+#define YRET_YNARGS   {1,1,0,0,0,0,0,0,0,0}
+#define YRET_NNYARGS  {1,0,0,1,1,1,1,1,1,1}
+#define NRET_NNYARGS  {0,0,0,1,1,1,1,1,1,1}
+#define YRET_NNYNARGS {1,0,0,1,0,0,0,0,0,0}
 
 const struct {
   const char* name;
@@ -262,6 +265,29 @@
   {"sc.pool_unregister", {NRET_NARGS, NRET_NARGS, NRET_NARGS, NRET_NARGS, false}},
   {"sc.pool_argvregister", {NRET_NARGS, NRET_NARGS, NRET_NARGS, NRET_NARGS, false}},
 
+  // CStdLib Runtime Checks
+  {"pool_strncpy",    {NRET_NNYARGS, YRET_NNYARGS, NRET_NARGS, YRET_NNYARGS,  true}},
+  {"pool_strcpy",     {NRET_NNYARGS, YRET_NNYARGS, NRET_NARGS, YRET_NNYARGS,  true}},
+  {"pool_stpcpy",     {NRET_NNYARGS, YRET_NNYARGS, NRET_NARGS, YRET_NNYARGS,  true}},
+  {"pool_strchr",     {NRET_NYARGS,  YRET_NARGS,   NRET_NARGS, YRET_NYARGS,   true}},
+  {"pool_strrchr",    {NRET_NYARGS,  YRET_NARGS,   NRET_NARGS, YRET_NYARGS,   true}},
+  {"pool_strcat",     {NRET_NNYARGS, YRET_NNYARGS, NRET_NARGS, YRET_NNYARGS,  true}},
+  {"pool_strncat",    {NRET_NNYARGS, YRET_NNYARGS, NRET_NARGS, YRET_NNYARGS,  true}},
+  {"pool_strstr",     {NRET_NNYARGS, YRET_NARGS,   NRET_NARGS, YRET_NNYNARGS, true}},
+  {"pool_strpbrk",    {NRET_NNYARGS, YRET_NARGS,   NRET_NARGS, YRET_NNYNARGS, true}},
+  {"pool_strspn",     {NRET_NYARGS,  YRET_NARGS,   NRET_NARGS, NRET_NARGS,    true}},
+  {"pool_strcspn",    {NRET_NYARGS,  YRET_NARGS,   NRET_NARGS, NRET_NARGS,    true}},
+  {"pool_memccpy",    {NRET_NNYARGS, YRET_NNYARGS, NRET_NARGS, YRET_NNYARGS,  true}},
+  {"pool_memchr",     {NRET_NYARGS,  YRET_NARGS,   NRET_NARGS, YRET_NYARGS,   true}},
+  {"pool_strcmp",     {NRET_NNYARGS, NRET_NARGS,   NRET_NARGS, NRET_NARGS,   false}},
+  {"pool_strncmp",    {NRET_NNYARGS, NRET_NARGS,   NRET_NARGS, NRET_NARGS,   false}},
+  {"pool_strlen",     {NRET_NYARGS,  NRET_NARGS,   NRET_NARGS, NRET_NARGS,   false}},
+  {"pool_strnlen",    {NRET_NYARGS,  NRET_NARGS,   NRET_NARGS, NRET_NARGS,   false}},
+  {"pool_memcmp",     {NRET_NNYARGS, NRET_NARGS,   NRET_NARGS, NRET_NARGS,   false}},
+  {"pool_strcasecmp", {NRET_NNYARGS, NRET_NARGS,   NRET_NARGS, NRET_NARGS,   false}},
+  {"pool_strncasecmp",{NRET_NNYARGS, NRET_NARGS,   NRET_NARGS, NRET_NARGS,   false}},
+
+
 #if 0
   {"wait",       {false, false, false, false,  true, false, false, false, false}},
 #endif

Modified: poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp?rev=130278&r1=130277&r2=130278&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Tue Apr 26 22:13:18 2011
@@ -16,6 +16,7 @@
 
 #define DEBUG_TYPE "poolalloc"
 
+#include "dsa/CStdLib.h"
 #include "dsa/DataStructure.h"
 #include "dsa/DSGraph.h"
 #include "poolalloc/Heuristic.h"
@@ -1563,42 +1564,11 @@
   }
 }
 
-// Builds the StringMap that holds information about the pool
-// argument counts of C standard library functions.
-void PoolAllocate::InitializeCStdLibPoolArgs()
-{
-  CStdLibPoolArgs.GetOrCreateValue("pool_strcpy",   2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strncpy",   2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strlen",   1);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strchr",   1);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strrchr",  1);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strcat",   2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strncat",  2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strstr",   2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strpbrk",  2);
-
-  CStdLibPoolArgs.GetOrCreateValue("pool_strcmp",  2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strncmp",   2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_memcmp",  2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strcasecmp",  2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strncasecmp",   2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strspn",  2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_strcspn",  2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_memccpy",  2);
-  CStdLibPoolArgs.GetOrCreateValue("pool_memchr",  1);
-  //CStdLibPoolArgs.GetOrCreateValue("pool_strtok",   2);
-  //CStdLibPoolArgs.GetOrCreateValue("pool_strtok_r", 2);
-  //CStdLibPoolArgs.GetOrCreateValue("pool_strspn",   2);
-  //CStdLibPoolArgs.GetOrCreateValue("pool_strcspn",  2);
-}
-
 // Return the number of initial pool arguments for the specified CStdLib
 // function, or 0 if it is not found in the table.
-unsigned PoolAllocate::getCStdLibPoolArguments(StringRef funcname)
-{
-  StringMap<unsigned>::const_iterator argc = CStdLibPoolArgs.find(funcname);
-  if (argc != CStdLibPoolArgs.end())
-    return argc->getValue();
-  else
-    return 0;
+unsigned PoolAllocate::getCStdLibPoolArguments(StringRef funcname) {
+  const CStdLibPoolArgCountEntry *entries = &CStdLibPoolArgCounts[0];
+  while (entries->function && entries->function != funcname)
+    entries++;
+  return entries->pool_argc;
 }





More information about the llvm-commits mailing list