Silence -Wunused-variable in release builds.
[llvm/stm8.git] / tools / opt / AnalysisWrappers.cpp
bloba2b57bb3e1151783ea6eac88a9c64e820da111a0
1 //===- AnalysisWrappers.cpp - Wrappers around non-pass analyses -----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines pass wrappers around LLVM analyses that don't make sense to
11 // be passes. It provides a nice standard pass interface to these classes so
12 // that they can be printed out by analyze.
14 // These classes are separated out of analyze.cpp so that it is more clear which
15 // code is the integral part of the analyze tool, and which part of the code is
16 // just making it so more passes are available.
18 //===----------------------------------------------------------------------===//
20 #include "llvm/Module.h"
21 #include "llvm/Pass.h"
22 #include "llvm/Support/CallSite.h"
23 #include "llvm/Analysis/CallGraph.h"
24 #include "llvm/Support/raw_ostream.h"
25 using namespace llvm;
27 namespace {
28 /// ExternalFunctionsPassedConstants - This pass prints out call sites to
29 /// external functions that are called with constant arguments. This can be
30 /// useful when looking for standard library functions we should constant fold
31 /// or handle in alias analyses.
32 struct ExternalFunctionsPassedConstants : public ModulePass {
33 static char ID; // Pass ID, replacement for typeid
34 ExternalFunctionsPassedConstants() : ModulePass(ID) {}
35 virtual bool runOnModule(Module &M) {
36 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
37 if (!I->isDeclaration()) continue;
39 bool PrintedFn = false;
40 for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
41 UI != E; ++UI) {
42 Instruction *User = dyn_cast<Instruction>(*UI);
43 if (!User) continue;
45 CallSite CS(cast<Value>(User));
46 if (!CS) continue;
48 for (CallSite::arg_iterator AI = CS.arg_begin(),
49 E = CS.arg_end(); AI != E; ++AI) {
50 if (!isa<Constant>(*AI)) continue;
52 if (!PrintedFn) {
53 errs() << "Function '" << I->getName() << "':\n";
54 PrintedFn = true;
56 errs() << *User;
57 break;
62 return false;
65 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
66 AU.setPreservesAll();
71 char ExternalFunctionsPassedConstants::ID = 0;
72 static RegisterPass<ExternalFunctionsPassedConstants>
73 P1("print-externalfnconstants",
74 "Print external fn callsites passed constants");
76 namespace {
77 struct CallGraphPrinter : public ModulePass {
78 static char ID; // Pass ID, replacement for typeid
79 CallGraphPrinter() : ModulePass(ID) {}
81 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
82 AU.setPreservesAll();
83 AU.addRequiredTransitive<CallGraph>();
85 virtual bool runOnModule(Module &M) {
86 getAnalysis<CallGraph>().print(errs(), &M);
87 return false;
92 char CallGraphPrinter::ID = 0;
93 static RegisterPass<CallGraphPrinter>
94 P2("print-callgraph", "Print a call graph");