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 {
|
2007-05-02 21:39:20 +00:00
|
|
|
static const char ID; // Pass ID, replacement for typeid
|
2007-05-01 21:15:47 +00:00
|
|
|
ExternalFunctionsPassedConstants() : ModulePass((intptr_t)&ID) {}
|
2004-09-20 04:48:05 +00:00
|
|
|
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)
|
2007-01-30 20:08:39 +00:00
|
|
|
if (I->isDeclaration()) {
|
2004-05-27 06:13:36 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-05-02 21:39:20 +00:00
|
|
|
const char ExternalFunctionsPassedConstants::ID = 0;
|
2006-08-27 22:30:17 +00:00
|
|
|
RegisterPass<ExternalFunctionsPassedConstants>
|
2005-12-22 19:26:06 +00:00
|
|
|
P1("externalfnconstants", "Print external fn callsites passed constants");
|
|
|
|
|
|
|
|
struct CallGraphPrinter : public ModulePass {
|
2007-05-02 21:39:20 +00:00
|
|
|
static const char ID; // Pass ID, replacement for typeid
|
2007-05-01 21:15:47 +00:00
|
|
|
CallGraphPrinter() : ModulePass((intptr_t)&ID) {}
|
|
|
|
|
2005-12-22 19:26:06 +00:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
2006-12-05 19:43:42 +00:00
|
|
|
AU.addRequiredTransitive<CallGraph>();
|
2005-12-22 19:26:06 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-05-02 21:39:20 +00:00
|
|
|
const char CallGraphPrinter::ID = 0;
|
2006-08-27 22:30:17 +00:00
|
|
|
RegisterPass<CallGraphPrinter>
|
2005-12-22 19:26:06 +00:00
|
|
|
P2("callgraph", "Print a call graph");
|
2004-05-27 06:13:36 +00:00
|
|
|
}
|