[llvm-commits] [poolalloc] r58019 - in /poolalloc/trunk: lib/AssistDS/ lib/AssistDS/FuncSpec.cpp lib/AssistDS/IndCloner.cpp lib/AssistDS/Makefile lib/DSA/StdLibPass.cpp lib/Makefile test/TEST.poolalloc.Makefile
Andrew Lenharth
alenhar2 at cs.uiuc.edu
Wed Oct 22 18:15:05 PDT 2008
Author: alenhar2
Date: Wed Oct 22 20:15:04 2008
New Revision: 58019
URL: http://llvm.org/viewvc/llvm-project?rev=58019&view=rev
Log:
Some random helper passes for DSA (esp TD)
Added:
poolalloc/trunk/lib/AssistDS/
poolalloc/trunk/lib/AssistDS/FuncSpec.cpp
poolalloc/trunk/lib/AssistDS/IndCloner.cpp
poolalloc/trunk/lib/AssistDS/Makefile
Modified:
poolalloc/trunk/lib/DSA/StdLibPass.cpp
poolalloc/trunk/lib/Makefile
poolalloc/trunk/test/TEST.poolalloc.Makefile
Added: poolalloc/trunk/lib/AssistDS/FuncSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/FuncSpec.cpp?rev=58019&view=auto
==============================================================================
--- poolalloc/trunk/lib/AssistDS/FuncSpec.cpp (added)
+++ poolalloc/trunk/lib/AssistDS/FuncSpec.cpp Wed Oct 22 20:15:04 2008
@@ -0,0 +1,87 @@
+//===-- FuncSpec.cpp - Clone Functions With Constant Function Ptr Args ----===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "funcspec"
+
+#include "llvm/Instructions.h"
+#include "llvm/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Transforms/Utils/Cloning.h"
+#include "llvm/ADT/Statistic.h"
+#include <set>
+#include <map>
+#include <vector>
+
+using namespace llvm;
+
+STATISTIC(numCloned, "Number of Functions Cloned");
+STATISTIC(numReplaced, "Number of Calls Replaced");
+
+namespace {
+ class FuncSpec : public ModulePass {
+ public:
+ static char ID;
+ FuncSpec() : ModulePass(&ID) {}
+ bool runOnModule(Module& M) {
+ std::map<CallInst*, std::vector<std::pair<unsigned, Constant*> > > cloneSites;
+ std::map<std::pair<Function*, std::vector<std::pair<unsigned, Constant*> > >, Function* > toClone;
+
+ for (Module::iterator I = M.begin(); I != M.end(); ++I)
+ if (!I->isDeclaration() && !I->mayBeOverridden()) {
+ std::vector<unsigned> FPArgs;
+ for (Function::arg_iterator ii = I->arg_begin(), ee = I->arg_end();
+ ii != ee; ++ii)
+ if (const PointerType* Ty = dyn_cast<PointerType>(ii->getType())) {
+ if (isa<FunctionType>(Ty->getElementType())) {
+ FPArgs.push_back(ii->getArgNo());
+ cerr << "Eligable: " << I->getName() << "\n";
+ }
+ } else if (isa<FunctionType>(ii->getType())) {
+ FPArgs.push_back(ii->getArgNo());
+ cerr << "Eligable: " << I->getName() << "\n";
+ }
+ for(Value::use_iterator ui = I->use_begin(), ue = I->use_end();
+ ui != ue; ++ui)
+ if (CallInst* CI = dyn_cast<CallInst>(ui)) {
+ std::vector<std::pair<unsigned, Constant*> > Consts;
+ for (unsigned x = 0; x < FPArgs.size(); ++x)
+ if (Constant* C = dyn_cast<Constant>(ui->getOperand(x + 1))) {
+ Consts.push_back(std::make_pair(x, C));
+ CI->dump();
+ }
+ if (!Consts.empty()) {
+ cloneSites[CI] = Consts;
+ toClone[std::make_pair(I, Consts)] = 0;
+ }
+ }
+ }
+
+ numCloned += toClone.size();
+
+ for (std::map<std::pair<Function*, std::vector<std::pair<unsigned, Constant*> > >, Function* >::iterator I = toClone.begin(), E = toClone.end(); I != E; ++I) {
+ Function* DirectF = CloneFunction(I->first.first);
+ DirectF->setName(I->first.first->getName() + "_SPEC");
+ DirectF->setLinkage(GlobalValue::InternalLinkage);
+ I->first.first->getParent()->getFunctionList().push_back(DirectF);
+ I->second = DirectF;
+ }
+
+ for (std::map<CallInst*, std::vector<std::pair<unsigned, Constant*> > >::iterator ii = cloneSites.begin(), ee = cloneSites.end(); ii != ee; ++ii) {
+ ii->first->setOperand(0, toClone[std::make_pair(cast<Function>(ii->first->getOperand(0)), ii->second)]);
+ ++numReplaced;
+ }
+
+ return true;
+ }
+ };
+}
+
+char FuncSpec::ID = 0;
+static RegisterPass<FuncSpec>
+X("funcspec", "Specialize for Funnction Pointers");
Added: poolalloc/trunk/lib/AssistDS/IndCloner.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/IndCloner.cpp?rev=58019&view=auto
==============================================================================
--- poolalloc/trunk/lib/AssistDS/IndCloner.cpp (added)
+++ poolalloc/trunk/lib/AssistDS/IndCloner.cpp Wed Oct 22 20:15:04 2008
@@ -0,0 +1,61 @@
+//===-- IndClonder.cpp - Clone Indirect Called Functions ------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "indclone"
+
+#include "llvm/Instructions.h"
+#include "llvm/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Transforms/Utils/Cloning.h"
+#include "llvm/ADT/Statistic.h"
+#include <set>
+
+using namespace llvm;
+
+STATISTIC(numCloned, "Number of Functions Cloned");
+STATISTIC(numReplaced, "Number of Calls Replaced");
+
+namespace {
+ class IndClone : public ModulePass {
+ public:
+ static char ID;
+ IndClone() : ModulePass(&ID) {}
+ bool runOnModule(Module& M) {
+ std::set<Function*> toClone;
+ for (Module::iterator I = M.begin(); I != M.end(); ++I)
+ if (!I->isDeclaration() && !I->mayBeOverridden())
+ for(Value::use_iterator ui = I->use_begin(), ue = I->use_end();
+ ui != ue; ++ui)
+ if (!isa<CallInst>(ui)) {
+ toClone.insert(I);
+ }
+ numCloned += toClone.size();
+ for (std::set<Function*>::iterator I = toClone.begin(),
+ E = toClone.end(); I != E; ++I) {
+ Function* DirectF = CloneFunction(*I);
+ DirectF->setName((*I)->getName() + "_DIRECT");
+ DirectF->setLinkage(GlobalValue::InternalLinkage);
+ (*I)->getParent()->getFunctionList().push_back(DirectF);
+ for(Value::use_iterator ui = (*I)->use_begin(), ue = (*I)->use_end();
+ ui != ue; ++ui)
+ if (CallInst* CI = dyn_cast<CallInst>(ui))
+ if (CI->getOperand(0) == *I) {
+ ++numReplaced;
+ CI->setOperand(0, DirectF);
+ }
+ }
+
+ return true;
+ }
+ };
+}
+
+char IndClone::ID = 0;
+static RegisterPass<IndClone>
+X("indclone", "Indirect call cloning");
Added: poolalloc/trunk/lib/AssistDS/Makefile
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/Makefile?rev=58019&view=auto
==============================================================================
--- poolalloc/trunk/lib/AssistDS/Makefile (added)
+++ poolalloc/trunk/lib/AssistDS/Makefile Wed Oct 22 20:15:04 2008
@@ -0,0 +1,16 @@
+##===- lib/AssistDS/Makefile -------------------------------*- Makefile -*-===##
+#
+# 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.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+SHARED_LIBRARY=1
+LIBRARYNAME = AssistDS
+
+include $(LEVEL)/Makefile.common
+
+CFlags += -Wno-deprecated
Modified: poolalloc/trunk/lib/DSA/StdLibPass.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/StdLibPass.cpp?rev=58019&r1=58018&r2=58019&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/StdLibPass.cpp (original)
+++ poolalloc/trunk/lib/DSA/StdLibPass.cpp Wed Oct 22 20:15:04 2008
@@ -195,6 +195,24 @@
if (!I->isDeclaration())
getOrCreateGraph(&*I);
+ //Trust the readnone annotation
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ if (I->isDeclaration() && I->doesNotAccessMemory() && !isa<PointerType>(I->getReturnType()))
+ eraseCallsTo(I);
+
+ //Useless external
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ if (I->isDeclaration() && !I->isVarArg() && !isa<PointerType>(I->getReturnType())) {
+ bool hasPtr = false;
+ for (Function::arg_iterator ii = I->arg_begin(), ee = I->arg_end(); ii != ee; ++ii)
+ if (isa<PointerType>(ii->getType())) {
+ hasPtr = true;
+ break;
+ }
+ if (!hasPtr)
+ eraseCallsTo(I);
+ }
+
//Functions we handle by summary
for (int x = 0; recFuncs[x].name; ++x)
@@ -247,15 +265,7 @@
Node->foldNodeCompletely();
}
}
- for (Value::use_iterator ii = F->use_begin(), ee = F->use_end();
- ii != ee; ++ii)
- if (CallInst* CI = dyn_cast<CallInst>(ii))
- if (CI->getOperand(0) == F) {
- DSGraph* Graph = getDSGraph(*CI->getParent()->getParent());
- //delete the call
- DOUT << "Removing " << F->getName() << " from " << CI->getParent()->getParent()->getName() << "\n";
- Graph->removeFunctionCalls(*F);
- }
+ eraseCallsTo(F);
}
return false;
Modified: poolalloc/trunk/lib/Makefile
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/Makefile?rev=58019&r1=58018&r2=58019&view=diff
==============================================================================
--- poolalloc/trunk/lib/Makefile (original)
+++ poolalloc/trunk/lib/Makefile Wed Oct 22 20:15:04 2008
@@ -6,6 +6,6 @@
#
# List all of the subdirectories that we will compile.
#
-DIRS=DSA PoolAllocate
+DIRS=DSA PoolAllocate AssistDS
include $(LEVEL)/Makefile.common
Modified: poolalloc/trunk/test/TEST.poolalloc.Makefile
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/test/TEST.poolalloc.Makefile?rev=58019&r1=58018&r2=58019&view=diff
==============================================================================
--- poolalloc/trunk/test/TEST.poolalloc.Makefile (original)
+++ poolalloc/trunk/test/TEST.poolalloc.Makefile Wed Oct 22 20:15:04 2008
@@ -27,6 +27,7 @@
# Pool allocator pass shared object
PA_SO := $(PADIR)/Debug/lib/libpoolalloc$(SHLIBEXT)
DSA_SO := $(PADIR)/Debug/lib/libLLVMDataStructure$(SHLIBEXT)
+ASSIST_SO := $(PADIR)/Debug/lib/libAssistDS$(SHLIBEXT)
# Pool allocator runtime library
#PA_RT := $(PADIR)/Debug/lib/libpoolalloc_fl_rt.bc
@@ -49,8 +50,8 @@
-$(LLVMLD) -link-as-library $< $(PA_PRE_RT) -o $@
$(PROGRAMS_TO_TEST:%=Output/%.base.bc): \
-Output/%.base.bc: Output/%.temp.bc $(LOPT)
- -$(LOPT) -instnamer -internalize -globaldce $< -f -o $@
+Output/%.base.bc: Output/%.temp.bc $(LOPT) $(ASSIST_SO)
+ -$(LOPT) -load $(ASSIST_SO) -instnamer -internalize -indclone -funcspec -ipsccp -deadargelim -instcombine -globaldce -stats $< -f -o $@
# This rule runs the pool allocator on the .base.bc file to produce a new .bc
# file
More information about the llvm-commits
mailing list