[llvm-commits] [poolalloc] r97711 - in /poolalloc/trunk: include/dsa/EntryPointAnalysis.h lib/DSA/EntryPointAnalysis.cpp lib/PoolAllocate/EntryPointAnalysis.cpp lib/PoolAllocate/EntryPointAnalysis.h

alenhar2 at llvm.org alenhar2 at llvm.org
Wed Mar 3 17:58:06 PST 2010


Author: alenhar2
Date: Wed Mar  3 19:58:06 2010
New Revision: 97711

URL: http://llvm.org/viewvc/llvm-project?rev=97711&view=rev
Log:
Abstract entrypoint finder

Added:
    poolalloc/trunk/include/dsa/EntryPointAnalysis.h
    poolalloc/trunk/lib/DSA/EntryPointAnalysis.cpp
Removed:
    poolalloc/trunk/lib/PoolAllocate/EntryPointAnalysis.cpp
    poolalloc/trunk/lib/PoolAllocate/EntryPointAnalysis.h

Added: poolalloc/trunk/include/dsa/EntryPointAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/EntryPointAnalysis.h?rev=97711&view=auto
==============================================================================
--- poolalloc/trunk/include/dsa/EntryPointAnalysis.h (added)
+++ poolalloc/trunk/include/dsa/EntryPointAnalysis.h Wed Mar  3 19:58:06 2010
@@ -0,0 +1,53 @@
+//===-- EntryPointAnalysis.h - Entry point Finding Pass -------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a general way of finding entry points in a system.  Simple programs
+// will use the main version.  Libraries and OS kernels can have more
+// specialized versions.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ENTRYPOINTANALYSIS_H
+#define	_ENTRYPOINTANALYSIS_H
+
+namespace llvm {
+class Function;
+class Module;
+}
+
+#include <string>
+#include "llvm/Pass.h"
+
+class EntryPointAnalysis : public llvm::ModulePass {
+  std::set<std::string> names;
+  bool haveNames;
+public:
+  static char ID;
+  EntryPointAnalysis();
+  virtual ~EntryPointAnalysis();
+
+  /// print - Print out the analysis results...
+  ///
+  void print(llvm::raw_ostream &O, const llvm::Module *M) const;
+
+  bool runOnModule(llvm::Module&);
+
+  virtual void getAnalysisUsage(llvm::AnalysisUsage &Info) const;
+
+  bool isEntryPoint(const llvm::Function* F) const;
+
+  void findEntryPoints(const llvm::Module& M,
+                       std::vector<const llvm::Function*>& dest) const;
+
+};
+
+
+
+#endif	/* _ENTRYPOINTANALYSIS_H */
+

Added: poolalloc/trunk/lib/DSA/EntryPointAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/EntryPointAnalysis.cpp?rev=97711&view=auto
==============================================================================
--- poolalloc/trunk/lib/DSA/EntryPointAnalysis.cpp (added)
+++ poolalloc/trunk/lib/DSA/EntryPointAnalysis.cpp Wed Mar  3 19:58:06 2010
@@ -0,0 +1,102 @@
+//===-- EntryPointAnalysis.cpp - Entry point Finding Pass -----------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a general way of finding entry points in a system.  Simple programs
+// will use the main version.  Libraries and OS kernels can have more
+// specialized versions.  This is done as an analysis group to allow more
+// convinient opt invocations.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Pass.h"
+#include "llvm/Module.h"
+#include "llvm/Function.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormattedStream.h"
+#include "llvm/Support/Debug.h"
+
+#include <fstream>
+#include <set>
+
+#include "dsa/EntryPointAnalysis.h"
+
+using namespace llvm;
+
+static cl::opt<std::string> epaFile("epa-file",
+       cl::desc("File with entry point names")); //, cl::ReallyHidden);
+
+static void readNames(std::set<std::string>& names) {
+  std::ifstream msf(epaFile.c_str(), std::ifstream::in);
+  if (!msf.good())
+    errs() << "Failed to open file: " << epaFile << " (continuing anyway)\n";
+  while (msf.good()) {
+    std::string n;
+    msf >> n;
+    if (n.size()) {
+      names.insert(n);
+//      errs() << "Read " << n << "\n";
+    }
+  }
+}
+
+
+EntryPointAnalysis::EntryPointAnalysis() :ModulePass(&ID), haveNames(false) {
+}
+
+EntryPointAnalysis::~EntryPointAnalysis() {}
+
+void EntryPointAnalysis::findEntryPoints(const Module& M,
+                                         std::vector<const Function*>& dest) const {
+  for (Module::const_iterator ii = M.begin(), ee = M.end(); ii != ee; ++ii)
+    if (isEntryPoint(ii))
+      dest.push_back(ii);
+}
+
+void EntryPointAnalysis::print(llvm::raw_ostream& O, const Module* M) const {
+  std::vector<const Function*> d;
+  findEntryPoints(*M, d);
+  O << "EntryPoints: ";
+  bool prev = false;
+  for (std::vector<const Function*>::iterator ii = d.begin(), ee = d.end();
+       ii != ee; ++ii) {
+    O << (prev ? ", " : "") << (*ii)->getNameStr();
+    prev = true;
+  }
+  O << "\n";
+}
+
+bool EntryPointAnalysis::runOnModule(llvm::Module& M) {
+  if (epaFile.size()) {
+    haveNames = true;
+    readNames(names);
+  }
+  return false;
+}
+
+void EntryPointAnalysis::getAnalysisUsage(llvm::AnalysisUsage &AU) const {
+  AU.setPreservesAll();
+}
+
+bool EntryPointAnalysis::isEntryPoint(const llvm::Function* F) const {
+  if (haveNames) {
+    return !F->isDeclaration()
+            && F->hasExternalLinkage()
+            && F->hasName()
+            && names.find(F->getNameStr()) != names.end();
+  } else {
+    return !F->isDeclaration()
+            && F->hasExternalLinkage()
+            && F->hasName() && F->getName() == "main";
+  }
+}
+
+
+
+char EntryPointAnalysis::ID;
+static RegisterPass<EntryPointAnalysis> A("epa", "Identify EntryPoints");

Removed: poolalloc/trunk/lib/PoolAllocate/EntryPointAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/EntryPointAnalysis.cpp?rev=97710&view=auto
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/EntryPointAnalysis.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/EntryPointAnalysis.cpp (removed)
@@ -1,53 +0,0 @@
-//===-- EntryPointAnalysis.cpp - Entry point Finding Pass -----------------===//
-//
-//                     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.
-//
-//===----------------------------------------------------------------------===//
-//
-// This is a general way of finding entry points in a system.  Simple programs
-// will use the main version.  Libraries and OS kernels can have more
-// specialized versions.  This is done as an analysis group to allow more
-// convinient opt invocations.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Pass.h"
-#include "llvm/Module.h"
-#include "llvm/Function.h"
-
-#include "EntryPointAnalysis.h"
-
-using namespace llvm;
-
-EntryPointAnalysis::~EntryPointAnalysis() {}
-char EntryPointAnalysis::ID;
-
-namespace {
-
-
-static RegisterAnalysisGroup<EntryPointAnalysis> A("Entry Point Analysis");
-
-class MainEntryPointAnalysis : public ImmutablePass, public EntryPointAnalysis {
-public:
-  static char ID;
-
-  MainEntryPointAnalysis() : ImmutablePass(&ID) { }
-
-  bool isEntryPoint(const llvm::Function* F) const {
-    return !F->isDeclaration()
-            && F->hasExternalLinkage()
-            && F->hasName() && F->getName() == "main";
-  }
-};
-
-char MainEntryPointAnalysis::ID;
-RegisterPass<MainEntryPointAnalysis> B("epa_main", "Identify Main");
-RegisterAnalysisGroup<EntryPointAnalysis, true> C(B);
-
-
-
-}
-

Removed: poolalloc/trunk/lib/PoolAllocate/EntryPointAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/EntryPointAnalysis.h?rev=97710&view=auto
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/EntryPointAnalysis.h (original)
+++ poolalloc/trunk/lib/PoolAllocate/EntryPointAnalysis.h (removed)
@@ -1,35 +0,0 @@
-//===-- EntryPointAnalysis.h - Entry point Finding Pass -------------------===//
-//
-//                     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.
-//
-//===----------------------------------------------------------------------===//
-//
-// This is a general way of finding entry points in a system.  Simple programs
-// will use the main version.  Libraries and OS kernels can have more
-// specialized versions.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _ENTRYPOINTANALYSIS_H
-#define	_ENTRYPOINTANALYSIS_H
-
-namespace llvm {
-class Function;
-}
-
-class EntryPointAnalysis {
-public:
-  static char ID;
-  EntryPointAnalysis() {}
-  virtual ~EntryPointAnalysis();
-
-  virtual bool isEntryPoint(const llvm::Function* F) const = 0;
-};
-
-
-
-#endif	/* _ENTRYPOINTANALYSIS_H */
-





More information about the llvm-commits mailing list