2002-07-29 21:24:10 +00:00
|
|
|
//===- AnalysisWrappers.cpp - Wrappers around non-pass analyses -----------===//
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2003-10-20 17:47:21 +00:00
|
|
|
// 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.
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2003-10-20 17:47:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-07-29 21:24:10 +00:00
|
|
|
//
|
|
|
|
// This file defines pass wrappers around LLVM analyses that don't make sense to
|
|
|
|
// be passes. It provides a nice standard pass interface to these classes so
|
|
|
|
// that they can be printed out by analyze.
|
|
|
|
//
|
2003-07-14 17:20:40 +00:00
|
|
|
// These classes are separated out of analyze.cpp so that it is more clear which
|
2002-07-29 21:24:10 +00:00
|
|
|
// code is the integral part of the analyze tool, and which part of the code is
|
|
|
|
// just making it so more passes are available.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-05-27 06:13:36 +00:00
|
|
|
#include "llvm/Module.h"
|
2004-04-02 20:56:33 +00:00
|
|
|
#include "llvm/Pass.h"
|
2004-05-27 06:13:36 +00:00
|
|
|
#include "llvm/Support/CallSite.h"
|
2005-12-22 19:26:06 +00:00
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
2004-07-04 12:20:55 +00:00
|
|
|
#include <iostream>
|
2003-11-11 22:41:34 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2004-05-27 06:13:36 +00:00
|
|
|
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.
|
2004-09-20 04:48:05 +00:00
|
|
|
struct ExternalFunctionsPassedConstants : public ModulePass {
|
|
|
|
virtual bool runOnModule(Module &M) {
|
2004-05-27 06:13:36 +00:00
|
|
|
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)
|
2004-07-18 00:44:14 +00:00
|
|
|
if (isa<Constant>(*AI)) {
|
2004-05-27 06:13:36 +00:00
|
|
|
if (!PrintedFn) {
|
|
|
|
std::cerr << "Function '" << I->getName() << "':\n";
|
|
|
|
PrintedFn = true;
|
|
|
|
}
|
|
|
|
std::cerr << *User;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
RegisterAnalysis<ExternalFunctionsPassedConstants>
|
2005-12-22 19:26:06 +00:00
|
|
|
P1("externalfnconstants", "Print external fn callsites passed constants");
|
|
|
|
|
|
|
|
struct CallGraphPrinter : public ModulePass {
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequired<CallGraph>();
|
|
|
|
}
|
|
|
|
virtual bool runOnModule(Module &M) { return false; }
|
|
|
|
|
2006-04-18 23:45:19 +00:00
|
|
|
virtual void print(std::ostream &OS, const Module *M) const {
|
2005-12-22 19:26:06 +00:00
|
|
|
getAnalysis<CallGraph>().print(OS, M);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
RegisterAnalysis<CallGraphPrinter>
|
|
|
|
P2("callgraph", "Print a call graph");
|
2004-05-27 06:13:36 +00:00
|
|
|
}
|