Update makefile for more accurate deps
authorChris Lattner <sabre@nondot.org>
Fri, 20 Jul 2001 19:16:29 +0000 (19:16 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 20 Jul 2001 19:16:29 +0000 (19:16 +0000)
Include support to print out Expression types

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

tools/analyze/Makefile
tools/analyze/analyze.cpp

index d624faff811f8baa12c55eb9c4ba89ffba3e2254..b33d40bd6909fbc85c057d6d3b92f694f13a238a 100644 (file)
@@ -5,6 +5,8 @@ all:: analyze
 clean ::
        rm -f analyze
 
-analyze : $(ObjectsG) Debug/.dir Depend/.dir
+LIBDEPS =  ../../lib/Optimizations/Debug/libopt.a  ../../lib/Analysis/Debug/libanalysis.a
+
+analyze : $(ObjectsG) Debug/.dir Depend/.dir $(LIBDEPS)
        $(LinkG) -o $@ $(ObjectsG) -lopt -lasmparser \
-                                  -lbcreader -lvmcore -lasmwriter -lanalysis
+                                  -lbcreader -lvmcore -lasmwriter -lanalysis -lopt
index 76de37515bc68c9b31c57f0d0906eade936160e5..e305052ffec61786b706de266405eb49a75162fc 100644 (file)
@@ -11,7 +11,9 @@
 //===------------------------------------------------------------------------===
 
 #include <iostream>
+#include "llvm/Instruction.h"
 #include "llvm/Module.h"
+#include "llvm/Method.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Assembly/Parser.h"
 #include "llvm/Tools/CommandLine.h"
@@ -19,6 +21,7 @@
 
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Analysis/IntervalPartition.h"
+#include "llvm/Analysis/Expressions.h"
 
 static void PrintMethod(Method *M) {
   cout << M;
@@ -28,6 +31,34 @@ static void PrintIntervalPartition(Method *M) {
   cout << cfg::IntervalPartition(M);
 }
 
+static void PrintClassifiedExprs(Method *M) {
+  cout << "Classified expressions for: " << M->getName() << endl;
+  Method::inst_iterator I = M->inst_begin(), E = M->inst_end();
+  for (; I != E; ++I) {
+    cout << *I;
+
+    if ((*I)->getType() == Type::VoidTy) continue;
+    ExprAnalysisResult R = ClassifyExpression(*I);
+    if (R.Var == *I) continue;  // Doesn't tell us anything
+
+    cout << "\t\tExpr =";
+    switch (R.ExprType) {
+    case ExprAnalysisResult::ScaledLinear:
+      WriteAsOperand(cout, (Value*)R.Scale) << " *";
+      // fall through
+    case ExprAnalysisResult::Linear:
+      WriteAsOperand(cout, R.Var);
+      if (R.Offset == 0) break;
+      else cout << " +";
+      // fall through
+    case ExprAnalysisResult::Constant:
+      if (R.Offset) WriteAsOperand(cout, (Value*)R.Offset); else cout << " 0";
+      break;
+    }
+    cout << endl << endl;
+  }
+}
+
 
 static void PrintDominatorSets(Method *M) {
   cout << cfg::DominatorSet(M);
@@ -61,6 +92,7 @@ struct {
 } AnTable[] = {
   { "-print"          , "Print each Method"       , PrintMethod },
   { "-intervals"      , "Interval Partition"      , PrintIntervalPartition },
+  { "-exprclassify"   , "Classify Expressions"    , PrintClassifiedExprs },
 
   { "-domset"         , "Dominator Sets"          , PrintDominatorSets },
   { "-idom"           , "Immediate Dominators"    , PrintImmediateDominators },
@@ -102,8 +134,9 @@ int main(int argc, char **argv) {
   // Loop over all of the methods in the module...
   for (Module::iterator I = C->begin(), E = C->end(); I != E; ++I) {
     Method *M = *I;
+    if (M->isExternal()) continue;
 
-    // Loop over all of the optimizations to be run...
+    // Loop over all of the analyses to be run...
     for (int i = 1; i < argc; i++) {
       if (argv[i] == 0) continue;
       unsigned j;