1 //===- AnalysisWrappers.cpp - Wrappers around non-pass analyses -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
27 /// ExternalFunctionsPassedConstants - This pass prints out call sites to
28 /// external functions that are called with constant arguments. This can be
29 /// useful when looking for standard library functions we should constant fold
30 /// or handle in alias analyses.
31 struct ExternalFunctionsPassedConstants : public ModulePass {
32 virtual bool runOnModule(Module &M) {
33 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
34 if (I->isExternal()) {
35 bool PrintedFn = false;
36 for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
38 if (Instruction *User = dyn_cast<Instruction>(*UI)) {
39 CallSite CS = CallSite::get(User);
40 if (CS.getInstruction()) {
41 for (CallSite::arg_iterator AI = CS.arg_begin(),
42 E = CS.arg_end(); AI != E; ++AI)
43 if (isa<Constant>(*AI)) {
45 std::cerr << "Function '" << I->getName() << "':\n";
58 void print(std::ostream &OS) const {}
60 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
65 RegisterAnalysis<ExternalFunctionsPassedConstants>
66 P2("externalfnconstants", "Print external fn callsites passed constants");