For PR872:
authorReid Spencer <rspencer@reidspencer.com>
Fri, 18 Aug 2006 06:34:30 +0000 (06:34 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Fri, 18 Aug 2006 06:34:30 +0000 (06:34 +0000)
Shrinkify LLVM's footprint by removing the analyze tool and moving its
functionality into the opt tool. THis eliminates one of the largest tools
from LLVM and doesn't make opt much bigger because it already included
most of the analysis passes.  To get the old analyze functionality pass
the -analyze option to opt. Note that the integeration here is dead
simple. The "main" of analyze was just copied to opt and invoked if the
-analyze option was given. There may be opportunities for further
integration such as removing the distinction between transform passes
and analysis passes.

To use the analysis functionality, if you previously did this:
  analyze $FNAME -domset -disable-verify
you would now do this:
  opt -analyze $FNAME -domset -disable-verify
Pretty simple.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29762 91177308-0d34-0410-b5e6-96231b3b80d8

41 files changed:
test/Analysis/DSGraph/2003-06-29-IncompleteTDPass.ll
test/Analysis/DSGraph/2003-06-29-NodeCollapsing2.ll
test/Analysis/DSGraph/2003-06-30-TopDownResolve.ll
test/Analysis/DSGraph/2003-07-01-FieldCollapse.ll
test/Analysis/DSGraph/2003-07-16-ConstantExprCollapse.ll
test/Analysis/DSGraph/2003-11-02-NodeCollapsing.ll
test/Analysis/DSGraph/2004-02-13-memcpy.ll
test/Analysis/DSGraph/2005-03-22-IncompleteGlobal.ll
test/Analysis/DSGraph/2006-03-27-LinkedCollapsed.ll
test/Analysis/DSGraph/2006-04-13-ZeroArrayStruct.ll
test/Analysis/DSGraph/2006-04-25-ZeroArrayStructUse.ll
test/Analysis/DSGraph/FunctionPointerTable-const.ll
test/Analysis/DSGraph/GlobalsGraphFuncPtr.ll
test/Analysis/DSGraph/HardBUCase.ll
test/Analysis/DSGraph/PhysicalSubtyping.ll
test/Analysis/DSGraph/SCCSimpleExample.ll
test/Analysis/DSGraph/constant_globals.ll
test/Analysis/DSGraph/strcpy.ll
test/Analysis/Dominators/2003-05-12-UnreachableCode.ll
test/Analysis/LoopInfo/2003-05-15-NestingProblem.ll
test/Transforms/DSAnalysis/arraymerge.ll
test/Transforms/DSAnalysis/arraytest.ll
test/Transforms/DSAnalysis/badcases.ll
test/Transforms/DSAnalysis/basictest.ll
test/Transforms/DSAnalysis/fieldmerge.ll
test/Transforms/DSAnalysis/goodcases.ll
test/Transforms/DSAnalysis/indcalltest.ll
test/Transforms/DSAnalysis/misctests.ll
test/Transforms/DSAnalysis/physicalsubtype.ll
test/Transforms/DSAnalysis/recursion.ll
test/Transforms/DSAnalysis/simplest-test.ll
test/Transforms/DSAnalysis/simpletest.ll
test/Transforms/DSAnalysis/structpadding.ll
tools/Makefile
tools/analyze/AnalysisWrappers.cpp [deleted file]
tools/analyze/GraphPrinters.cpp [deleted file]
tools/analyze/Makefile [deleted file]
tools/analyze/PrintSCC.cpp [deleted file]
tools/analyze/analyze.cpp [deleted file]
tools/opt/Makefile
tools/opt/opt.cpp

index 0c462e1e6ea10ecdc2bacc0faf210cebddbfa83c..4b919c1a57bfbb0603add969c7bc41b4e9125229 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: analyze %s -datastructure-gc -dsgc-dspass=td -dsgc-check-flags=Ptr:HR
+; RUN: opt -analyze %s -datastructure-gc -dsgc-dspass=td -dsgc-check-flags=Ptr:HR
 
 
 
index 99aae03adf6b8f6e77a2f6968732b626f44276a4..f357694d7a259472e7071abaf3afe277b446895c 100644 (file)
@@ -1,7 +1,7 @@
 ; This is the same testcase as 2003-06-29-NodeCollapsing2.ll, but it uses the 
 ; graph checker.
 ;
-; RUN: analyze %s -datastructure-gc -dsgc-abort-if-any-collapsed
+; RUN: opt -analyze %s -datastructure-gc -dsgc-abort-if-any-collapsed
 ;
 %T = type { int}
 
index 6622eb2ea3e808d9b974a339062f079eab8f1e36..f0cd849a4a1a11bb44b43b2cca468ae40e22a0d3 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: analyze %s -datastructure-gc -dsgc-dspass=td -dsgc-check-flags=X:GM
+; RUN: opt -analyze %s -datastructure-gc -dsgc-dspass=td -dsgc-check-flags=X:GM
 
 %G = internal global int 5
 
index 3f1893ba03bcec3be2a71ba78f549544df13cdbd..58ddc46d49d3ef16cfaf35c8714e6b4754065ebf 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: analyze %s -datastructure-gc -dsgc-abort-if-any-collapsed
+; RUN: opt -analyze %s -datastructure-gc -dsgc-abort-if-any-collapsed
 
 %X = internal global { int, short, short } { int 1, short 2, short 3 }
 
index aec1e99fd8b886ef0fd9a0801e1cfe6f42895994..38e57b888c6efc6e87a2430459dc26dab5bf4c03 100644 (file)
@@ -1,6 +1,6 @@
 ; This should cause the global node to collapse!!
 ; XFAIL: *
-; RUN: analyze %s -datastructure-gc --dsgc-check-flags=test:GAU
+; RUN: opt -analyze %s -datastructure-gc --dsgc-check-flags=test:GAU
 
 %Tree = type { int, %Tree*, %Tree* }
 %T5 = external global %Tree
index 37f5038cd4408d3a9b3d217cc8ff33cb28dfe2e2..3a58e057a7fcec2ac88e4e9b4f96f52062058045 100644 (file)
@@ -1,7 +1,7 @@
 ; This is the same testcase as 2003-06-29-NodeCollapsing2.ll, but it uses the 
 ; graph checker.
 ;
-; RUN: analyze %s -datastructure-gc -dsgc-abort-if-any-collapsed
+; RUN: opt -analyze %s -datastructure-gc -dsgc-abort-if-any-collapsed
 ;
 
 %S = type { double, int }
index 105709f12ecc68d0dd1698b37e65364c4a6d0928..3b06bae73c66d8e16a643f0ce0d9338a1f5ac333 100644 (file)
@@ -1,5 +1,5 @@
-; RUN: analyze %s -datastructure-gc -dsgc-check-flags=Xn:SMR
-; RUN: analyze %s -datastructure-gc -dsgc-check-flags=X:SMR
+; RUN: opt -analyze %s -datastructure-gc -dsgc-check-flags=Xn:SMR
+; RUN: opt -analyze %s -datastructure-gc -dsgc-check-flags=X:SMR
 
 declare void %llvm.memcpy.i32(sbyte*, sbyte*, uint, uint)
 declare void %llvm.memmove.i32(sbyte*, sbyte*, uint, uint)
index 0af1efab27f891dd33a6ffce9c46e54ad488d4fc..1d3240217af7bed2916b0f80081e4ef000c7c3d5 100644 (file)
@@ -1,5 +1,5 @@
-; RUN: analyze %s -datastructure-gc  -dsgc-check-flags=G:GIM -dsgc-dspass=bu &&\
-; RUN: analyze %s -datastructure-gc  -dsgc-check-flags=G:GIM -dsgc-dspass=td
+; RUN: opt -analyze %s -datastructure-gc  -dsgc-check-flags=G:GIM -dsgc-dspass=bu &&\
+; RUN: opt -analyze %s -datastructure-gc  -dsgc-check-flags=G:GIM -dsgc-dspass=td
 
 %S = type { double, int }
 
index 06af9063233806a149a668bc0009b755b45ff340..ce1ebb920270f4d25931b8048b184108904a9e25 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | analyze -datastructure
+; RUN: llvm-as < %s | opt -analyze -datastructure
 
 target endian = little
 target pointersize = 32
index c12bb9e837953a2dce8bd08e7521c04e74300ead..0fa6ba8d8f3c0020e74bfd2fc72706e346368dcf 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | analyze -datastructure
+; RUN: llvm-as < %s | opt -analyze -datastructure
 
 ; ModuleID = 'bug3.bc'
 target endian = little
index b8238f06dd344a7ce906219d29f885e3d7a4addd..aa41920252fc13fbaa19c90c40638e93333e44f1 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: analyze %s -datastructure-gc -dsgc-check-flags=x:IA
+; RUN: opt -analyze %s -datastructure-gc -dsgc-check-flags=x:IA
 
 ; ModuleID = 'bug3.bc'
 target endian = little
index 76c226570f5650d974d664e5d0a4bba81564fba8..4031a09fb2328eda2565b5b0fcd4543a5ef8681f 100644 (file)
@@ -1,7 +1,7 @@
 ; FIXME: this should be SHM for bu, but change it for now since besides incompleteness
 ;        this is working
-; RUN: analyze %s -datastructure-gc -dsgc-dspass=bu -dsgc-check-flags=Y:SHIM && \
-; RUN: analyze %s -datastructure-gc -dsgc-dspass=td -dsgc-check-flags=P1:SHM,P2:SHM
+; RUN: opt -analyze %s -datastructure-gc -dsgc-dspass=bu -dsgc-check-flags=Y:SHIM && \
+; RUN: opt -analyze %s -datastructure-gc -dsgc-dspass=td -dsgc-check-flags=P1:SHM,P2:SHM
 
 %G = internal constant [2 x int*(int*)*] [ 
   int*(int*)* %callee1, int*(int*)* %callee2
index 99ac4734d4247a89174e592b953f2b5fdde20a19..ea5c04e4c037b362f4f1b3071f25d658ca9061af 100644 (file)
@@ -5,7 +5,7 @@
 ; -- globals in GG pointed to by latter should be marked I, but not other nodes
 ;
 ; FIXME: KnownPtr should be just S.
-; RUN: analyze %s -datastructure-gc -dsgc-check-flags=KnownPtr:SI,UnknownPtr:SI -dsgc-dspass=bu
+; RUN: opt -analyze %s -datastructure-gc -dsgc-check-flags=KnownPtr:SI,UnknownPtr:SI -dsgc-dspass=bu
 
 %Z = internal global int 0
 %X = internal global int 0
index 6d9aa055a9207a90c9b77a486d1837f1eabc3577..318b4f28b9e5e026fe71e2137210d259790678e4 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: analyze %s -budatastructure -dont-print-ds
+; RUN: opt -analyze %s -budatastructure -dont-print-ds
 
 %MidFnTy = type void (\2*)
 
index d9ac454522f67f2870dc8d2373142d5b76a9fc5b..59575484a43a74eca13cb35cb9f4110104718d4f 100644 (file)
@@ -1,6 +1,6 @@
 ; Test to check for support for "physical subtyping"
 ;
-; RUN: analyze %s -datastructure-gc -dsgc-abort-if-any-collapsed
+; RUN: opt -analyze %s -datastructure-gc -dsgc-abort-if-any-collapsed
 ;
 %S = type { int }
 %T = type { int, float, double }
index 3c71c3461c3c550763adc744a415386f299baa21..825c5797455b214044ac590335f762ae02124ba4 100644 (file)
@@ -1,5 +1,5 @@
 
-; RUN: analyze %s -datastructure-gc --dsgc-abort-if-merged=Y,BVal
+; RUN: opt -analyze %s -datastructure-gc --dsgc-abort-if-merged=Y,BVal
 
 implementation
 
index f42aec91e5d21692d147d4c7a6726f18ce9e9edb..2473d1dd831864b746ed41397a16567d04ffd88c 100644 (file)
@@ -1,5 +1,5 @@
 ; FIXME: A should just be SM
-; RUN: analyze %s -datastructure-gc -dsgc-dspass=bu -dsgc-check-flags=A:SIM
+; RUN: opt -analyze %s -datastructure-gc -dsgc-dspass=bu -dsgc-check-flags=A:SIM
 ; Constant globals should not mark stuff incomplete.  This should allow the 
 ; bu pass to resolve the indirect call immediately in "test", allowing %A to
 ; be marked complete and the store to happen.
index 7cb201198794327ceb3b3610df8826b3058aa322..ae936d32a7d77f89e5b9c2e42e0ea18da59efa5e 100644 (file)
@@ -3,7 +3,7 @@
 ; has no defined way to check for this, so DSA can know that strcpy doesn't
 ; require merging the input arguments.
 
-; RUN: analyze %s -datastructure-gc --dsgc-abort-if-merged=A,B --dsgc-check-flags=A:ASM,B:ASR --dsgc-dspass=bu
+; RUN: opt -analyze %s -datastructure-gc --dsgc-abort-if-merged=A,B --dsgc-check-flags=A:ASM,B:ASR --dsgc-dspass=bu
 
 implementation
 
index e1e71cdc94b2092096ebe8e00ed741b1e2a41633..d781eb5374256ef530728c698061a81ce676a634 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: analyze %s -domset -disable-verify
+; RUN: opt -analyze %s -domset -disable-verify
 ;
 int %re_match_2() {
 ENTRY:
index 4feee420dd559ccd1d85dbfb40ac2171f1941da6..96099a8da9740cf7940a1893a4a71f2758f7b904 100644 (file)
@@ -1,7 +1,7 @@
 ; This testcase was incorrectly computing that the loopentry.7 loop was
 ; not a child of the loopentry.6 loop.
 ;
-; RUN: analyze %s -loops | grep "^            Loop Containing:  %loopentry.7"
+; RUN: opt -analyze %s -loops | grep "^            Loop Containing:  %loopentry.7"
 
 void %getAndMoveToFrontDecode() {              ; No predecessors!
        br label %endif.2
index c4ac718c1c2d3c8622d205e466746aac2ce366b3..30f458308e7b15236d3c83c3522b6f0a118eda67 100644 (file)
@@ -2,7 +2,7 @@
 ; folded completely away if possible.  This is a very common case, so it should
 ; be efficient.
 ;
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 ;
 implementation
 
index 521bd630e354fb471c65275ea4d04db83812353a..bb6c4c148e06c39712574ddf300e5d50408b15ab 100644 (file)
@@ -1,5 +1,5 @@
 ;
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 %crazy = type [2 x { [2 x sbyte], short } ]
 
 implementation
index b841b6e8d85010325402e1cfe8b9e52992e93d41..a977f23bb57147eba636d2d97cc20a8b249000a8 100644 (file)
@@ -1,6 +1,6 @@
 ; This file contains a list of situations where node folding should happen...
 ;
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 
 implementation
 
index 615e0219cf1d0289c90d46650bf7b97b01b21963..a3583a1475cefd4945a2e07a554cc12aa91e74e2 100644 (file)
@@ -1,6 +1,6 @@
 ; very simple test
 ;
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 
 implementation
 
index 4dcefb7f3b4d78f54d44b6ab7dc94a323cdf3203..a754d06643612e764ad117e6fdbd890301041531 100644 (file)
@@ -1,5 +1,5 @@
 ;
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 
 %str = type { int*, int* }
 
index 1d545b3965e1362597d83ac3eb30e5248afdc2c7..f6d9ff9fa285d265e12045d1609e087df5f7abee 100644 (file)
@@ -1,6 +1,6 @@
 ; This file contains a list of cases where node folding should NOT happen
 ;
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 ;
 
 implementation
index 16cb6bea18f390463f0f968f0db29d2f3b34aa0b..1ec92d30d74f1f0d7d015b13cfdb5ba5369f9a6c 100644 (file)
@@ -1,5 +1,5 @@
 ;
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 
 %G = global int 2              ; <int*> [#uses=1]
 %H = global int* null
index 29c7079ac53f1da77b37b7af351dcb2a31c89a07..acdbabf8362e23d5edcb16b7f9a2cc214f49a552 100644 (file)
@@ -1,5 +1,5 @@
 ;
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 
 int* %test1(int *%A) {
        %R = getelementptr int* %A, long 1
index 2beb3eca6bcce9fe7dc20082c02de74f8eac973e..26fa511f40db7cc0ae2934a888038897767f4bc2 100644 (file)
@@ -1,6 +1,6 @@
 ; A test for "physical subtyping" used in some C programs...
 ;
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 ;
 %ST = type { int, int* }            ; "Subtype"
 %DT = type { int, int*, int }       ; "derived type"
index 6acdd24853a811a6a1f074593bd6e3ac97617101..da075cd9c37a41bd6d6ee23f01d113e9f094827d 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 
 implementation   ; Functions:
 
index b75740396647eda5649ceda8881cbbe3ed2e6322..b398c28546768a593bd2b17f6cd118eeac0e9ad0 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 
 void %foo(int* %X) {
        store int 4, int* %X
index 298aa836710bd96ddd530a63bf2db0ff028d5a9b..80b94335d3d9b863d3a058e733f188684179ceeb 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 
 implementation
 
index 693c9888b98e542e1268da9fe4a57856cebec989..5b3c8b86a4db5e081aefe9b18a04ad761fb4cdfc 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: analyze %s -tddatastructure
+; RUN: opt -analyze %s -tddatastructure
 
 %str = type { int, int* }
 
index 99e73960ac377963a4eddcc5135bba5074b67980..649c655be9ff4b0e548a9fb8039cc15be6301b39 100644 (file)
@@ -9,8 +9,7 @@
 
 LEVEL := ..
 PARALLEL_DIRS := llvm-config llvm-as llvm-dis opt gccas llc llvm-link lli gccld\
-                 llvm-stub analyze llvm-extract llvm-nm llvm-prof llvm-ar \
-                llvm-ranlib llvm-bcanalyzer llvmc llvm-ld llvm-db bugpoint \
-                 llvm2cpp
+                 llvm-stub llvm-extract llvm-nm llvm-prof llvm-ar llvm-ranlib \
+                llvm-bcanalyzer llvmc llvm-ld llvm-db bugpoint llvm2cpp
 
 include $(LEVEL)/Makefile.common
diff --git a/tools/analyze/AnalysisWrappers.cpp b/tools/analyze/AnalysisWrappers.cpp
deleted file mode 100644 (file)
index b371d50..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-//===- AnalysisWrappers.cpp - Wrappers around non-pass analyses -----------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// 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.
-//
-// These classes are separated out of analyze.cpp so that it is more clear which
-// code is the integral part of the analyze tool, and which part of the code is
-// just making it so more passes are available.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Module.h"
-#include "llvm/Pass.h"
-#include "llvm/Support/CallSite.h"
-#include "llvm/Analysis/CallGraph.h"
-#include <iostream>
-using namespace llvm;
-
-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.
-  struct ExternalFunctionsPassedConstants : public ModulePass {
-    virtual bool runOnModule(Module &M) {
-      for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
-        if (I->isExternal()) {
-          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)
-                  if (isa<Constant>(*AI)) {
-                    if (!PrintedFn) {
-                      std::cerr << "Function '" << I->getName() << "':\n";
-                      PrintedFn = true;
-                    }
-                    std::cerr << *User;
-                    break;
-                  }
-              }
-            }
-        }
-
-      return false;
-    }
-
-    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.setPreservesAll();
-    }
-  };
-
-  RegisterAnalysis<ExternalFunctionsPassedConstants>
-  P1("externalfnconstants", "Print external fn callsites passed constants");
-  
-  struct CallGraphPrinter : public ModulePass {
-    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.setPreservesAll();
-      AU.addRequired<CallGraph>();
-    }
-    virtual bool runOnModule(Module &M) { return false; }
-
-    virtual void print(std::ostream &OS, const Module *M) const {
-      getAnalysis<CallGraph>().print(OS, M);
-    }
-  };
-  
-  RegisterAnalysis<CallGraphPrinter>
-    P2("callgraph", "Print a call graph");
-}
diff --git a/tools/analyze/GraphPrinters.cpp b/tools/analyze/GraphPrinters.cpp
deleted file mode 100644 (file)
index 8826cd2..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-//===- GraphPrinters.cpp - DOT printers for various graph types -----------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines several printers for various different types of graphs used
-// by the LLVM infrastructure.  It uses the generic graph interface to convert
-// the graph into a .dot graph.  These graphs can then be processed with the
-// "dot" tool to convert them to postscript or some other suitable format.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/GraphWriter.h"
-#include "llvm/Pass.h"
-#include "llvm/Value.h"
-#include "llvm/Analysis/CallGraph.h"
-#include <fstream>
-using namespace llvm;
-
-template<typename GraphType>
-static void WriteGraphToFile(std::ostream &O, const std::string &GraphName,
-                             const GraphType &GT) {
-  std::string Filename = GraphName + ".dot";
-  O << "Writing '" << Filename << "'...";
-  std::ofstream F(Filename.c_str());
-
-  if (F.good())
-    WriteGraph(F, GT);
-  else
-    O << "  error opening file for writing!";
-  O << "\n";
-}
-
-
-//===----------------------------------------------------------------------===//
-//                              Call Graph Printer
-//===----------------------------------------------------------------------===//
-
-namespace llvm {
-  template<>
-  struct DOTGraphTraits<CallGraph*> : public DefaultDOTGraphTraits {
-    static std::string getGraphName(CallGraph *F) {
-      return "Call Graph";
-    }
-
-    static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
-      if (Node->getFunction())
-        return ((Value*)Node->getFunction())->getName();
-      else
-        return "Indirect call node";
-    }
-  };
-}
-
-
-namespace {
-  struct CallGraphPrinter : public ModulePass {
-    virtual bool runOnModule(Module &M) {
-      WriteGraphToFile(std::cerr, "callgraph", &getAnalysis<CallGraph>());
-      return false;
-    }
-
-    void print(std::ostream &OS) const {}
-
-    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.addRequired<CallGraph>();
-      AU.setPreservesAll();
-    }
-  };
-
-  RegisterAnalysis<CallGraphPrinter> P2("print-callgraph",
-                                        "Print Call Graph to 'dot' file");
-}
diff --git a/tools/analyze/Makefile b/tools/analyze/Makefile
deleted file mode 100644 (file)
index e3885a9..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-##===- tools/analyze/Makefile ------------------------------*- Makefile -*-===##
-# 
-#                     The LLVM Compiler Infrastructure
-#
-# This file was developed by the LLVM research group and is distributed under
-# the University of Illinois Open Source License. See LICENSE.TXT for details.
-# 
-##===----------------------------------------------------------------------===##
-LEVEL = ../..
-TOOLNAME = analyze
-USEDLIBS = LLVMAsmParser.a LLVMBCReader.a LLVMAnalysis.a LLVMipa.a \
-           LLVMDataStructure \
-          LLVMScalarOpts.a LLVMTransforms.a LLVMTarget.a LLVMScalarOpts.a \
-          LLVMTransformUtils.a LLVMCore.a LLVMSupport.a LLVMbzip2.a LLVMSystem.a
-REQUIRES_EH := 1
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/analyze/PrintSCC.cpp b/tools/analyze/PrintSCC.cpp
deleted file mode 100644 (file)
index c0adf5c..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-//===- PrintSCC.cpp - Enumerate SCCs in some key graphs -------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file provides passes to print out SCCs in a CFG or a CallGraph.
-// Normally, you would not use these passes; instead, you would use the
-// scc_iterator directly to enumerate SCCs and process them in some way.  These
-// passes serve three purposes:
-//
-// (1) As a reference for how to use the scc_iterator.
-// (2) To print out the SCCs for a CFG or a CallGraph:
-//       analyze -cfgscc            to print the SCCs in each CFG of a module.
-//       analyze -cfgscc -stats     to print the #SCCs and the maximum SCC size.
-//       analyze -cfgscc -debug > /dev/null to watch the algorithm in action.
-//
-//     and similarly:
-//       analyze -callscc [-stats] [-debug] to print SCCs in the CallGraph
-//
-// (3) To test the scc_iterator.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Pass.h"
-#include "llvm/Module.h"
-#include "llvm/Analysis/CallGraph.h"
-#include "llvm/Support/CFG.h"
-#include "llvm/ADT/SCCIterator.h"
-#include <iostream>
-using namespace llvm;
-
-namespace {
-  struct CFGSCC : public FunctionPass {
-    bool runOnFunction(Function& func);
-
-    void print(std::ostream &O, const Module* = 0) const { }
-
-    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.setPreservesAll();
-    }
-  };
-
-  struct CallGraphSCC : public ModulePass {
-    // run - Print out SCCs in the call graph for the specified module.
-    bool runOnModule(Module &M);
-
-    void print(std::ostream &O, const Module* = 0) const { }
-
-    // getAnalysisUsage - This pass requires the CallGraph.
-    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.setPreservesAll();
-      AU.addRequired<CallGraph>();
-    }
-  };
-
-  RegisterAnalysis<CFGSCC>
-  Y("cfgscc", "Print SCCs of each function CFG");
-
-  RegisterAnalysis<CallGraphSCC>
-  Z("callscc", "Print SCCs of the Call Graph");
-}
-
-bool CFGSCC::runOnFunction(Function &F) {
-  unsigned sccNum = 0;
-  std::cout << "SCCs for Function " << F.getName() << " in PostOrder:";
-  for (scc_iterator<Function*> SCCI = scc_begin(&F),
-         E = scc_end(&F); SCCI != E; ++SCCI) {
-    std::vector<BasicBlock*> &nextSCC = *SCCI;
-    std::cout << "\nSCC #" << ++sccNum << " : ";
-    for (std::vector<BasicBlock*>::const_iterator I = nextSCC.begin(),
-           E = nextSCC.end(); I != E; ++I)
-      std::cout << (*I)->getName() << ", ";
-    if (nextSCC.size() == 1 && SCCI.hasLoop())
-      std::cout << " (Has self-loop).";
-  }
-  std::cout << "\n";
-
-  return true;
-}
-
-
-// run - Print out SCCs in the call graph for the specified module.
-bool CallGraphSCC::runOnModule(Module &M) {
-  CallGraphNode* rootNode = getAnalysis<CallGraph>().getRoot();
-  unsigned sccNum = 0;
-  std::cout << "SCCs for the program in PostOrder:";
-  for (scc_iterator<CallGraphNode*> SCCI = scc_begin(rootNode),
-         E = scc_end(rootNode); SCCI != E; ++SCCI) {
-    const std::vector<CallGraphNode*> &nextSCC = *SCCI;
-    std::cout << "\nSCC #" << ++sccNum << " : ";
-    for (std::vector<CallGraphNode*>::const_iterator I = nextSCC.begin(),
-           E = nextSCC.end(); I != E; ++I)
-      std::cout << ((*I)->getFunction() ? (*I)->getFunction()->getName()
-                    : std::string("Indirect CallGraph node")) << ", ";
-    if (nextSCC.size() == 1 && SCCI.hasLoop())
-      std::cout << " (Has self-loop).";
-  }
-  std::cout << "\n";
-
-  return true;
-}
diff --git a/tools/analyze/analyze.cpp b/tools/analyze/analyze.cpp
deleted file mode 100644 (file)
index e6b2be5..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-//===- analyze.cpp - The LLVM analyze utility -----------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This utility is designed to print out the results of running various analysis
-// passes on a program.  This is useful for understanding a program, or for
-// debugging an analysis pass.
-//
-//  analyze --help           - Output information about command line switches
-//  analyze --quiet          - Do not print analysis name before output
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Module.h"
-#include "llvm/PassManager.h"
-#include "llvm/Bytecode/Reader.h"
-#include "llvm/Assembly/Parser.h"
-#include "llvm/Analysis/Verifier.h"
-#include "llvm/Analysis/LinkAllAnalyses.h"
-#include "llvm/Target/TargetData.h"
-#include "llvm/Support/PassNameParser.h"
-#include "llvm/System/Signals.h"
-#include "llvm/Support/PluginLoader.h"
-#include "llvm/Support/Timer.h"
-#include "llvm/LinkAllVMCore.h"
-#include <algorithm>
-
-using namespace llvm;
-
-namespace {
-  cl::opt<std::string>
-  InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"),
-                cl::value_desc("filename"));
-
-  cl::opt<bool> Quiet("q", cl::desc("Don't print analysis pass names"));
-  cl::alias    QuietA("quiet", cl::desc("Alias for -q"),
-                      cl::aliasopt(Quiet));
-
-  cl::opt<bool> NoVerify("disable-verify", cl::Hidden,
-                         cl::desc("Do not verify input module"));
-
-  // The AnalysesList is automatically populated with registered Passes by the
-  // PassNameParser.
-  //
-  cl::list<const PassInfo*, bool, FilteredPassNameParser<PassInfo::Analysis> >
-  AnalysesList(cl::desc("Analyses available:"));
-
-  Timer BytecodeLoadTimer("Bytecode Loader");
-}
-
-struct ModulePassPrinter : public ModulePass {
-  const PassInfo *PassToPrint;
-  ModulePassPrinter(const PassInfo *PI) : PassToPrint(PI) {}
-
-  virtual bool runOnModule(Module &M) {
-    if (!Quiet) {
-      std::cout << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
-      getAnalysisID<Pass>(PassToPrint).print(std::cout, &M);
-    }
-
-    // Get and print pass...
-    return false;
-  }
-
-  virtual const char *getPassName() const { return "'Pass' Printer"; }
-
-  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.addRequiredID(PassToPrint);
-    AU.setPreservesAll();
-  }
-};
-
-struct FunctionPassPrinter : public FunctionPass {
-  const PassInfo *PassToPrint;
-  FunctionPassPrinter(const PassInfo *PI) : PassToPrint(PI) {}
-
-  virtual bool runOnFunction(Function &F) {
-    if (!Quiet) {
-      std::cout << "Printing analysis '" << PassToPrint->getPassName()
-               << "' for function '" << F.getName() << "':\n";
-    }
-    // Get and print pass...
-    getAnalysisID<Pass>(PassToPrint).print(std::cout, F.getParent());
-    return false;
-  }
-
-  virtual const char *getPassName() const { return "FunctionPass Printer"; }
-
-  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.addRequiredID(PassToPrint);
-    AU.setPreservesAll();
-  }
-};
-
-struct BasicBlockPassPrinter : public BasicBlockPass {
-  const PassInfo *PassToPrint;
-  BasicBlockPassPrinter(const PassInfo *PI) : PassToPrint(PI) {}
-
-  virtual bool runOnBasicBlock(BasicBlock &BB) {
-    if (!Quiet) {
-      std::cout << "Printing Analysis info for BasicBlock '" << BB.getName()
-               << "': Pass " << PassToPrint->getPassName() << ":\n";
-    }
-
-    // Get and print pass...
-    getAnalysisID<Pass>(PassToPrint).print(std::cout, BB.getParent()->getParent());
-    return false;
-  }
-
-  virtual const char *getPassName() const { return "BasicBlockPass Printer"; }
-
-  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.addRequiredID(PassToPrint);
-    AU.setPreservesAll();
-  }
-};
-
-
-
-int main(int argc, char **argv) {
-  try {
-    cl::ParseCommandLineOptions(argc, argv, " llvm analysis printer tool\n");
-    sys::PrintStackTraceOnErrorSignal();
-
-    Module *CurMod = 0;
-    try {
-#if 0
-      TimeRegion RegionTimer(BytecodeLoadTimer);
-#endif
-      CurMod = ParseBytecodeFile(InputFilename);
-      if (!CurMod && !(CurMod = ParseAssemblyFile(InputFilename))){
-        std::cerr << argv[0] << ": input file didn't read correctly.\n";
-        return 1;
-      }
-    } catch (const ParseException &E) {
-      std::cerr << argv[0] << ": " << E.getMessage() << "\n";
-      return 1;
-    }
-
-    // Create a PassManager to hold and optimize the collection of passes we are
-    // about to build...
-    //
-    PassManager Passes;
-
-    // Add an appropriate TargetData instance for this module...
-    Passes.add(new TargetData(CurMod));
-
-    // Make sure the input LLVM is well formed.
-    if (!NoVerify)
-      Passes.add(createVerifierPass());
-
-    // Create a new optimization pass for each one specified on the command line
-    for (unsigned i = 0; i < AnalysesList.size(); ++i) {
-      const PassInfo *Analysis = AnalysesList[i];
-
-      if (Analysis->getNormalCtor()) {
-        Pass *P = Analysis->getNormalCtor()();
-        Passes.add(P);
-
-        if (BasicBlockPass *BBP = dynamic_cast<BasicBlockPass*>(P))
-          Passes.add(new BasicBlockPassPrinter(Analysis));
-        else if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P))
-          Passes.add(new FunctionPassPrinter(Analysis));
-        else
-          Passes.add(new ModulePassPrinter(Analysis));
-
-      } else
-        std::cerr << argv[0] << ": cannot create pass: "
-                  << Analysis->getPassName() << "\n";
-    }
-
-    Passes.run(*CurMod);
-
-    delete CurMod;
-    return 0;
-
-  } catch (const std::string& msg) {
-    std::cerr << argv[0] << ": " << msg << "\n";
-  } catch (...) {
-    std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
-  }
-  return 1;
-}
index f310639c08b29fc4c4026c816a3400bcc4c92c33..9e4cddfa976b119a478c33384002281572090cc5 100644 (file)
@@ -10,9 +10,9 @@ LEVEL = ../..
 TOOLNAME = opt
 REQUIRES_EH := 1
 
-USEDLIBS = LLVMBCReader.a LLVMBCWriter.a LLVMInstrumentation.a \
-          LLVMScalarOpts.a LLVMipo.a LLVMipa.a LLVMDataStructure LLVMTransforms.a \
-          LLVMTarget.a LLVMTransformUtils.a LLVMAnalysis.a LLVMCore.a LLVMSupport.a \
-          LLVMbzip2.a LLVMSystem.a 
+USEDLIBS = LLVMAsmParser.a LLVMBCReader.a LLVMBCWriter.a LLVMInstrumentation.a \
+          LLVMScalarOpts.a LLVMipo.a LLVMipa.a LLVMDataStructure \
+          LLVMTransforms.a LLVMTarget.a LLVMTransformUtils.a LLVMAnalysis.a \
+          LLVMCore.a LLVMSupport.a LLVMbzip2.a LLVMSystem.a 
 
 include $(LEVEL)/Makefile.common
index 096506ff39295dc19fd70fd45759f40dbd4c4081..b67892bb34a8aa2ff2b306ee0f9b1d6b06c70d51 100644 (file)
@@ -8,11 +8,12 @@
 //===----------------------------------------------------------------------===//
 //
 // Optimizations may be specified an arbitrary number of times on the command
-// line, they are run in the order specified.
+// line, They are run in the order specified.
 //
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Module.h"
+#include "llvm/Assembly/Parser.h"
 #include "llvm/PassManager.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Bytecode/WriteBytecodePass.h"
@@ -24,6 +25,8 @@
 #include "llvm/System/Signals.h"
 #include "llvm/Support/PluginLoader.h"
 #include "llvm/Support/SystemUtils.h"
+#include "llvm/Support/Timer.h"
+#include "llvm/Analysis/LinkAllAnalyses.h"
 #include "llvm/Transforms/LinkAllPasses.h"
 #include "llvm/LinkAllVMCore.h"
 #include <fstream>
@@ -43,7 +46,8 @@ OptimizationList(cl::desc("Optimizations available:"));
 // Other command line options...
 //
 static cl::opt<std::string>
-InputFilename(cl::Positional, cl::desc("<input bytecode>"), cl::init("-"));
+InputFilename(cl::Positional, cl::desc("<input bytecode file>"), 
+    cl::init("-"), cl::value_desc("filename"));
 
 static cl::opt<std::string>
 OutputFilename("o", cl::desc("Override output filename"),
@@ -68,6 +72,91 @@ Quiet("q", cl::desc("Obsolete option"), cl::Hidden);
 static cl::alias
 QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet));
 
+static cl::opt<bool>
+AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization"));
+
+// The AnalysesList is automatically populated with registered Passes by the
+// PassNameParser.
+static 
+  cl::list<const PassInfo*, bool, FilteredPassNameParser<PassInfo::Analysis> >
+  AnalysesList(cl::desc("Analyses available:"));
+
+static Timer BytecodeLoadTimer("Bytecode Loader");
+
+// ---------- Define Printers for module and function passes ------------
+namespace {
+
+struct ModulePassPrinter : public ModulePass {
+  const PassInfo *PassToPrint;
+  ModulePassPrinter(const PassInfo *PI) : PassToPrint(PI) {}
+
+  virtual bool runOnModule(Module &M) {
+    if (!Quiet) {
+      std::cout << "Printing analysis '" << PassToPrint->getPassName() 
+                << "':\n";
+      getAnalysisID<Pass>(PassToPrint).print(std::cout, &M);
+    }
+
+    // Get and print pass...
+    return false;
+  }
+
+  virtual const char *getPassName() const { return "'Pass' Printer"; }
+
+  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+    AU.addRequiredID(PassToPrint);
+    AU.setPreservesAll();
+  }
+};
+
+struct FunctionPassPrinter : public FunctionPass {
+  const PassInfo *PassToPrint;
+  FunctionPassPrinter(const PassInfo *PI) : PassToPrint(PI) {}
+
+  virtual bool runOnFunction(Function &F) {
+    if (!Quiet) {
+      std::cout << "Printing analysis '" << PassToPrint->getPassName()
+               << "' for function '" << F.getName() << "':\n";
+    }
+    // Get and print pass...
+    getAnalysisID<Pass>(PassToPrint).print(std::cout, F.getParent());
+    return false;
+  }
+
+  virtual const char *getPassName() const { return "FunctionPass Printer"; }
+
+  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+    AU.addRequiredID(PassToPrint);
+    AU.setPreservesAll();
+  }
+};
+
+struct BasicBlockPassPrinter : public BasicBlockPass {
+  const PassInfo *PassToPrint;
+  BasicBlockPassPrinter(const PassInfo *PI) : PassToPrint(PI) {}
+
+  virtual bool runOnBasicBlock(BasicBlock &BB) {
+    if (!Quiet) {
+      std::cout << "Printing Analysis info for BasicBlock '" << BB.getName()
+               << "': Pass " << PassToPrint->getPassName() << ":\n";
+    }
+
+    // Get and print pass...
+    getAnalysisID<Pass>(PassToPrint).print(
+      std::cout, BB.getParent()->getParent());
+    return false;
+  }
+
+  virtual const char *getPassName() const { return "BasicBlockPass Printer"; }
+
+  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+    AU.addRequiredID(PassToPrint);
+    AU.setPreservesAll();
+  }
+};
+
+} // anonymous namespace
+
 
 //===----------------------------------------------------------------------===//
 // main for opt
@@ -75,9 +164,63 @@ QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet));
 int main(int argc, char **argv) {
   try {
     cl::ParseCommandLineOptions(argc, argv,
-                                " llvm .bc -> .bc modular optimizer\n");
+      " llvm .bc -> .bc modular optimizer and analysis printer \n");
     sys::PrintStackTraceOnErrorSignal();
 
+    if (AnalyzeOnly) {
+      Module *CurMod = 0;
+      try {
+#if 0
+        TimeRegion RegionTimer(BytecodeLoadTimer);
+#endif
+        CurMod = ParseBytecodeFile(InputFilename);
+        if (!CurMod && !(CurMod = ParseAssemblyFile(InputFilename))){
+          std::cerr << argv[0] << ": input file didn't read correctly.\n";
+          return 1;
+        }
+      } catch (const ParseException &E) {
+        std::cerr << argv[0] << ": " << E.getMessage() << "\n";
+        return 1;
+      }
+
+      // Create a PassManager to hold and optimize the collection of passes we 
+      // are about to build...
+      PassManager Passes;
+
+      // Add an appropriate TargetData instance for this module...
+      Passes.add(new TargetData(CurMod));
+
+      // Make sure the input LLVM is well formed.
+      if (!NoVerify)
+        Passes.add(createVerifierPass());
+
+      // Create a new optimization pass for each one specified on the 
+      // command line
+      for (unsigned i = 0; i < AnalysesList.size(); ++i) {
+        const PassInfo *Analysis = AnalysesList[i];
+
+        if (Analysis->getNormalCtor()) {
+          Pass *P = Analysis->getNormalCtor()();
+          Passes.add(P);
+
+          if (BasicBlockPass *BBP = dynamic_cast<BasicBlockPass*>(P))
+            Passes.add(new BasicBlockPassPrinter(Analysis));
+          else if (FunctionPass *FP = dynamic_cast<FunctionPass*>(P))
+            Passes.add(new FunctionPassPrinter(Analysis));
+          else
+            Passes.add(new ModulePassPrinter(Analysis));
+
+        } else
+          std::cerr << argv[0] << ": cannot create pass: "
+                    << Analysis->getPassName() << "\n";
+      }
+
+      Passes.run(*CurMod);
+
+      delete CurMod;
+      return 0;
+    }
+
     // Allocate a full target machine description only if necessary...
     // FIXME: The choice of target should be controllable on the command line.
     std::auto_ptr<TargetMachine> target;
@@ -169,6 +312,7 @@ int main(int argc, char **argv) {
     Passes.run(*M.get());
 
     return 0;
+
   } catch (const std::string& msg) {
     std::cerr << argv[0] << ": " << msg << "\n";
   } catch (...) {