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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-04 18:44:52 +08:00
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
2014-03-04 19:01:28 +08:00
|
|
|
#include "llvm/IR/CallSite.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2004-04-03 04:56:33 +08:00
|
|
|
#include "llvm/Pass.h"
|
2009-07-16 00:35:29 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
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
|
2010-08-07 02:33:48 +08:00
|
|
|
ExternalFunctionsPassedConstants() : ModulePass(ID) {}
|
2014-03-08 16:27:28 +08:00
|
|
|
bool runOnModule(Module &M) override {
|
2009-08-23 14:03:38 +08:00
|
|
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
|
|
|
if (!I->isDeclaration()) continue;
|
2014-01-20 23:47:15 +08:00
|
|
|
|
2009-08-23 14:03:38 +08:00
|
|
|
bool PrintedFn = false;
|
2014-03-09 11:16:01 +08:00
|
|
|
for (User *U : I->users()) {
|
|
|
|
Instruction *UI = dyn_cast<Instruction>(U);
|
|
|
|
if (!UI) continue;
|
2014-01-20 23:47:15 +08:00
|
|
|
|
2014-03-09 11:16:01 +08:00
|
|
|
CallSite CS(cast<Value>(UI));
|
2010-07-29 06:50:26 +08:00
|
|
|
if (!CS) continue;
|
2014-01-20 23:47:15 +08:00
|
|
|
|
2009-08-23 14:03:38 +08:00
|
|
|
for (CallSite::arg_iterator AI = CS.arg_begin(),
|
|
|
|
E = CS.arg_end(); AI != E; ++AI) {
|
|
|
|
if (!isa<Constant>(*AI)) continue;
|
|
|
|
|
|
|
|
if (!PrintedFn) {
|
|
|
|
errs() << "Function '" << I->getName() << "':\n";
|
|
|
|
PrintedFn = true;
|
2004-05-27 14:13:36 +08:00
|
|
|
}
|
2014-03-09 11:16:01 +08:00
|
|
|
errs() << *UI;
|
2009-08-23 14:03:38 +08:00
|
|
|
break;
|
|
|
|
}
|
2004-05-27 14:13:36 +08:00
|
|
|
}
|
2009-08-23 14:03:38 +08:00
|
|
|
}
|
2004-05-27 14:13:36 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-08 16:27:28 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2004-05-27 14:13:36 +08:00
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
};
|
2010-08-20 08:56:16 +08:00
|
|
|
}
|
2004-05-27 14:13:36 +08:00
|
|
|
|
2010-08-20 08:56:16 +08:00
|
|
|
char ExternalFunctionsPassedConstants::ID = 0;
|
|
|
|
static RegisterPass<ExternalFunctionsPassedConstants>
|
2008-09-23 20:47:39 +08:00
|
|
|
P1("print-externalfnconstants",
|
|
|
|
"Print external fn callsites passed constants");
|