2002-07-30 05:24:10 +08:00
|
|
|
//===- AnalysisWrappers.cpp - Wrappers around non-pass analyses -----------===//
|
2005-04-22 08:00:37 +08:00
|
|
|
//
|
2003-10-21 01:47:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:44:31 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 08:00:37 +08:00
|
|
|
//
|
2003-10-21 01:47:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-07-30 05:24:10 +08: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-15 01:20:40 +08:00
|
|
|
// These classes are separated out of analyze.cpp so that it is more clear which
|
2002-07-30 05:24:10 +08: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 14:13:36 +08:00
|
|
|
#include "llvm/Module.h"
|
2004-04-03 04:56:33 +08:00
|
|
|
#include "llvm/Pass.h"
|
2004-05-27 14:13:36 +08:00
|
|
|
#include "llvm/Support/CallSite.h"
|
2005-12-23 03:26:06 +08:00
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
2004-07-04 20:20:55 +08:00
|
|
|
#include <iostream>
|
2003-11-12 06:41:34 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2004-05-27 14:13:36 +08: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 12:48:05 +08:00
|
|
|
struct ExternalFunctionsPassedConstants : public ModulePass {
|
2007-05-03 09:11:54 +08:00
|
|
|
static char ID; // Pass ID, replacement for typeid
|
2009-02-18 13:09:16 +08:00
|
|
|
ExternalFunctionsPassedConstants() : ModulePass(&ID) {}
|
2004-09-20 12:48:05 +08:00
|
|
|
virtual bool runOnModule(Module &M) {
|
2004-05-27 14:13:36 +08:00
|
|
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
2007-01-31 04:08:39 +08:00
|
|
|
if (I->isDeclaration()) {
|
2004-05-27 14:13:36 +08: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 08:44:14 +08:00
|
|
|
if (isa<Constant>(*AI)) {
|
2004-05-27 14:13:36 +08: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 09:11:54 +08:00
|
|
|
char ExternalFunctionsPassedConstants::ID = 0;
|
2006-08-28 06:30:17 +08:00
|
|
|
RegisterPass<ExternalFunctionsPassedConstants>
|
2008-09-23 20:47:39 +08:00
|
|
|
P1("print-externalfnconstants",
|
|
|
|
"Print external fn callsites passed constants");
|
2008-09-19 15:57:09 +08:00
|
|
|
|
2005-12-23 03:26:06 +08:00
|
|
|
struct CallGraphPrinter : public ModulePass {
|
2007-05-03 09:11:54 +08:00
|
|
|
static char ID; // Pass ID, replacement for typeid
|
2009-02-18 13:09:16 +08:00
|
|
|
CallGraphPrinter() : ModulePass(&ID) {}
|
2007-05-02 05:15:47 +08:00
|
|
|
|
2005-12-23 03:26:06 +08:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
2006-12-06 03:43:42 +08:00
|
|
|
AU.addRequiredTransitive<CallGraph>();
|
2005-12-23 03:26:06 +08:00
|
|
|
}
|
2008-09-19 15:57:09 +08:00
|
|
|
virtual bool runOnModule(Module &M) {
|
|
|
|
getAnalysis<CallGraph>().print(std::cerr, &M);
|
|
|
|
return false;
|
2005-12-23 03:26:06 +08:00
|
|
|
}
|
|
|
|
};
|
2008-09-19 15:57:09 +08:00
|
|
|
|
2007-05-03 09:11:54 +08:00
|
|
|
char CallGraphPrinter::ID = 0;
|
2006-08-28 06:30:17 +08:00
|
|
|
RegisterPass<CallGraphPrinter>
|
2008-09-23 20:47:39 +08:00
|
|
|
P2("print-callgraph", "Print a call graph");
|
2004-05-27 14:13:36 +08:00
|
|
|
}
|