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
|
|
|
|
//
|
2007-12-29 20:44:31 +00:00
|
|
|
// This file 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-03 01:11:54 +00:00
|
|
|
static char ID; // Pass ID, replacement for typeid
|
2009-02-18 05:09:16 +00:00
|
|
|
ExternalFunctionsPassedConstants() : ModulePass(&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-03 01:11:54 +00:00
|
|
|
char ExternalFunctionsPassedConstants::ID = 0;
|
2006-08-27 22:30:17 +00:00
|
|
|
RegisterPass<ExternalFunctionsPassedConstants>
|
2008-09-23 12:47:39 +00:00
|
|
|
P1("print-externalfnconstants",
|
|
|
|
"Print external fn callsites passed constants");
|
2008-09-19 07:57:09 +00:00
|
|
|
|
2005-12-22 19:26:06 +00:00
|
|
|
struct CallGraphPrinter : public ModulePass {
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID; // Pass ID, replacement for typeid
|
2009-02-18 05:09:16 +00:00
|
|
|
CallGraphPrinter() : ModulePass(&ID) {}
|
2007-05-01 21:15:47 +00:00
|
|
|
|
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
|
|
|
}
|
2008-09-19 07:57:09 +00:00
|
|
|
virtual bool runOnModule(Module &M) {
|
|
|
|
getAnalysis<CallGraph>().print(std::cerr, &M);
|
|
|
|
return false;
|
2005-12-22 19:26:06 +00:00
|
|
|
}
|
|
|
|
};
|
2008-09-19 07:57:09 +00:00
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
char CallGraphPrinter::ID = 0;
|
2006-08-27 22:30:17 +00:00
|
|
|
RegisterPass<CallGraphPrinter>
|
2008-09-23 12:47:39 +00:00
|
|
|
P2("print-callgraph", "Print a call graph");
|
2004-05-27 06:13:36 +00:00
|
|
|
}
|