[llvm-commits] [poolalloc] r130263 - in /poolalloc/trunk: lib/DSA/DynCount.cpp runtime/DynCount/ runtime/DynCount/DynCount.c runtime/DynCount/Makefile
Arushi Aggarwal
aggarwa4 at illinois.edu
Tue Apr 26 17:18:51 PDT 2011
Author: aggarwa4
Date: Tue Apr 26 19:18:50 2011
New Revision: 130263
URL: http://llvm.org/viewvc/llvm-project?rev=130263&view=rev
Log:
Add the functions needed for counting number of dynamically
safe LS instructions.
Added:
poolalloc/trunk/lib/DSA/DynCount.cpp
poolalloc/trunk/runtime/DynCount/
poolalloc/trunk/runtime/DynCount/DynCount.c
poolalloc/trunk/runtime/DynCount/Makefile (with props)
Added: poolalloc/trunk/lib/DSA/DynCount.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DynCount.cpp?rev=130263&view=auto
==============================================================================
--- poolalloc/trunk/lib/DSA/DynCount.cpp (added)
+++ poolalloc/trunk/lib/DSA/DynCount.cpp Tue Apr 26 19:18:50 2011
@@ -0,0 +1,140 @@
+//===- Dyncount.cpp - Test pass for using constraints -----------*- C++ -*-===//
+//
+// The SAFECode Compiler
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a test pass which helps test the generation of formulas
+// and constraints.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Pass.h"
+#include "llvm/Module.h"
+#include "llvm/Instructions.h"
+#include "llvm/Target/TargetData.h"
+#include "dsa/TypeSafety.h"
+
+using namespace llvm;
+class Dyncount : public ModulePass {
+protected:
+ void instrumentLoad (GlobalVariable * Counter, LoadInst * LI);
+ void instrumentStore (GlobalVariable * Counter, StoreInst * SI);
+ dsa::TypeSafety<TDDataStructures> *TS;
+
+public:
+ static char ID;
+ Dyncount () : ModulePass ((intptr_t) &ID) { }
+ const char *getPassName() const {
+ return "Count safe/unsafe load/store";
+ }
+ virtual bool runOnModule (Module & M);
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.addRequired<TargetData>();
+ AU.addRequired<dsa::TypeSafety<TDDataStructures> >();
+ };
+};
+
+char Dyncount::ID = 0;
+static RegisterPass<Dyncount>
+X ("dyncount", "Instrument code to count number of Load/Stores");
+
+
+void
+Dyncount::instrumentLoad (GlobalVariable * Counter, LoadInst * LI) {
+ //
+ // Generate a load, increment, and store right before the GEP.
+ //
+ LLVMContext & Context = Counter->getParent()->getContext();
+ ConstantInt * One = ConstantInt::get (Type::getInt64Ty(Context), 1);
+ LoadInst * Value = new LoadInst (Counter, "count", LI);
+ Instruction * NewValue = BinaryOperator::Create (BinaryOperator::Add,
+ Value,
+ One,
+ "count",
+ LI);
+ new StoreInst (NewValue, Counter, LI);
+ return;
+}
+void
+Dyncount::instrumentStore (GlobalVariable * Counter, StoreInst * SI) {
+ //
+ // Generate a load, increment, and store right before the GEP.
+ //
+ LLVMContext & Context = Counter->getParent()->getContext();
+ ConstantInt * One = ConstantInt::get (Type::getInt64Ty(Context), 1);
+ LoadInst * Value = new LoadInst (Counter, "count", SI);
+ Instruction * NewValue = BinaryOperator::Create (BinaryOperator::Add,
+ Value,
+ One,
+ "count",
+ SI);
+ new StoreInst (NewValue, Counter, SI);
+ return;
+}
+
+//
+// Method: runOnModule()
+//
+// Description:
+// Entry point for this pass.
+//
+bool
+Dyncount::runOnModule (Module & M) {
+ //
+ // Create two global counters within the module.
+ //
+ TS = &getAnalysis<dsa::TypeSafety<TDDataStructures> >();
+ ConstantInt * Zero = ConstantInt::get (Type::getInt64Ty(M.getContext()), 0);
+ GlobalVariable * Total = new GlobalVariable (M,
+ Type::getInt64Ty(M.getContext()),
+ false,
+ GlobalValue::InternalLinkage,
+ Zero,
+ "Total");
+ GlobalVariable * Safe = new GlobalVariable (M,
+ Type::getInt64Ty(M.getContext()),
+ false,
+ GlobalValue::InternalLinkage,
+ Zero,
+ "Safe");
+
+ for (Module::iterator F = M.begin(); F != M.end(); ++F){
+ for (Function::iterator B = F->begin(), FE = F->end(); B != FE; ++B) {
+ for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE; I++) {
+ if(LoadInst *LI = dyn_cast<LoadInst>(I)) {
+ instrumentLoad(Total, LI);
+ if(TS->isTypeSafe(LI->getOperand(0),LI->getParent()->getParent()))
+ instrumentLoad(Safe, LI);
+
+ // check if safe
+ } else if(StoreInst *SI = dyn_cast<StoreInst>(I)) {
+ instrumentStore(Total, SI);
+ if(TS->isTypeSafe(SI->getOperand(1),SI->getParent()->getParent()))
+ instrumentStore(Safe, SI);
+ // check if safe
+ }
+ }
+ }
+ }
+
+ //
+ // Add a call to main() that will record the values on exit().
+ //
+ Function *MainFunc = M.getFunction("main") ? M.getFunction("main")
+ : M.getFunction ("MAIN__");
+
+ BasicBlock & BB = MainFunc->getEntryBlock();
+ Constant * Setup = M.getOrInsertFunction ("DYN_COUNT_setup", Type::getVoidTy(M.getContext()), Total->getType(), Safe->getType(), NULL);
+ std::vector<Value *> args;
+ args.push_back (Total);
+ args.push_back (Safe);
+ CallInst::Create (Setup, args.begin(), args.end(), "", BB.getFirstNonPHI());
+
+
+ return true;
+}
+
Added: poolalloc/trunk/runtime/DynCount/DynCount.c
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynCount/DynCount.c?rev=130263&view=auto
==============================================================================
--- poolalloc/trunk/runtime/DynCount/DynCount.c (added)
+++ poolalloc/trunk/runtime/DynCount/DynCount.c Tue Apr 26 19:18:50 2011
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+static unsigned long * Total = 0;
+static unsigned long * Safe = 0;
+
+static void
+printItAll (void) {
+ FILE * fp = fopen ("lsstats", "w");
+ fprintf (fp, "%lu Safe \n", *Safe);
+ fprintf (fp, "%lu Total \n", *Total);
+ fflush (fp);
+ fclose (fp);
+ return;
+}
+
+void
+DYN_COUNT_setup (unsigned long * total, unsigned long * safe) {
+ Total = total;
+ Safe = safe;
+ atexit (printItAll);
+ return;
+}
+
+
Added: poolalloc/trunk/runtime/DynCount/Makefile
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynCount/Makefile?rev=130263&view=auto
==============================================================================
--- poolalloc/trunk/runtime/DynCount/Makefile (added)
+++ poolalloc/trunk/runtime/DynCount/Makefile Tue Apr 26 19:18:50 2011
@@ -0,0 +1,25 @@
+LEVEL = ../..
+LIBRARYNAME=count
+BYTECODE_LIBRARY=1
+
+#
+# Build shared libraries on all platforms except Cygwin and MingW (which do
+# not support them).
+#
+ifneq ($(OS),Cygwin)
+ifneq ($(OS),MingW)
+SHARED_LIBRARY=1
+endif
+endif
+
+ifeq ($(OS),Linux)
+CXX.Flags += -march=native
+else
+CXX.Flags += -march=nocona
+endif
+
+CXX.Flags += -fno-threadsafe-statics
+include $(LEVEL)/Makefile.common
+
+# Always build optimized and debug versions
+all:: $(LIBNAME_OBJO) $(LIBNAME_OBJG)
Propchange: poolalloc/trunk/runtime/DynCount/Makefile
------------------------------------------------------------------------------
svn:executable = *
More information about the llvm-commits
mailing list