summaryrefslogtreecommitdiff
path: root/tools/opt/AnalysisWrappers.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-05-27 06:13:36 +0000
committerChris Lattner <sabre@nondot.org>2004-05-27 06:13:36 +0000
commitd9572118ebd6ebf0b3ee55d5e3487b2a0b5b74f8 (patch)
treebe10646ad9fdb1698c450672978133cb7a73e549 /tools/opt/AnalysisWrappers.cpp
parent9b2a1849083284b213c16bea6edd181e9e337885 (diff)
downloadllvm-d9572118ebd6ebf0b3ee55d5e3487b2a0b5b74f8.tar.gz
llvm-d9572118ebd6ebf0b3ee55d5e3487b2a0b5b74f8.tar.bz2
llvm-d9572118ebd6ebf0b3ee55d5e3487b2a0b5b74f8.tar.xz
Add a simple pass.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13820 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/opt/AnalysisWrappers.cpp')
-rw-r--r--tools/opt/AnalysisWrappers.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/opt/AnalysisWrappers.cpp b/tools/opt/AnalysisWrappers.cpp
index aa9f03d883..8e6ee2237c 100644
--- a/tools/opt/AnalysisWrappers.cpp
+++ b/tools/opt/AnalysisWrappers.cpp
@@ -17,8 +17,10 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Analysis/InstForest.h"
+#include "llvm/Support/CallSite.h"
using namespace llvm;
@@ -38,3 +40,46 @@ namespace {
RegisterAnalysis<InstForestHelper> P1("instforest", "InstForest Printer");
}
+
+namespace {
+ /// ExternalFunctionsPassedConstants - This pass prints out call sites to
+ /// external functions that are called with constant arguments. This can be
+ /// useful when looking for standard library functions we should constant fold
+ /// or handle in alias analyses.
+ struct ExternalFunctionsPassedConstants : public Pass {
+ virtual bool run(Module &M) {
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ if (I->isExternal()) {
+ bool PrintedFn = false;
+ for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
+ UI != E; ++UI)
+ if (Instruction *User = dyn_cast<Instruction>(*UI)) {
+ CallSite CS = CallSite::get(User);
+ if (CS.getInstruction()) {
+ for (CallSite::arg_iterator AI = CS.arg_begin(),
+ E = CS.arg_end(); AI != E; ++AI)
+ if (isa<Constant>(*AI)) {
+ if (!PrintedFn) {
+ std::cerr << "Function '" << I->getName() << "':\n";
+ PrintedFn = true;
+ }
+ std::cerr << *User;
+ break;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ void print(std::ostream &OS) const {}
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+ }
+ };
+
+ RegisterAnalysis<ExternalFunctionsPassedConstants>
+ P2("externalfnconstants", "Print external fn callsites passed constants");
+}