From 46976818b8a5ee54694652159664306f21b3b9af Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Fri, 3 Feb 2012 17:00:12 -0200
Subject: [PATCH 01/15] added fpic


diff --git a/testcpybuilder.py b/testcpybuilder.py
index cac367d..dc898e1 100644
--- a/testcpybuilder.py
+++ b/testcpybuilder.py
@@ -75,6 +75,7 @@ class BuiltModule:
                        '-I' + sc.get_python_inc(plat_specific=True)]
         self.args += sc.get_config_var('CFLAGS').split()
         self.args += ['-Wall',  '-Werror'] # during testing
+        self.args += ['-fPIC'] # not sure why this is necessary
         self.args += ['-shared'] # not sure why this is necessary
         if extra_cflags:
             self.args += extra_cflags
-- 
1.7.5.4


From 5911f39b8f587cec36ba2052c6d8f738f30139c2 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Fri, 3 Feb 2012 17:44:30 -0200
Subject: [PATCH 02/15] changed gcc-with-python for me


diff --git a/gcc-with-python b/gcc-with-python
index f68c918..52468df 100755
--- a/gcc-with-python
+++ b/gcc-with-python
@@ -16,4 +16,6 @@
 #   along with this program.  If not, see
 #   <http://www.gnu.org/licenses/>.
 
-gcc -fplugin=$(pwd)/python.so -fplugin-arg-python-script=$@
+#LIB_PYTHON=lib$( echo `python-config  --libs` |sed 's/^.*-l\(python.*\)$/\1/' ).so
+
+LD_PRELOAD=libpython2.7.so gcc -fplugin=/home/ew/gcc-python-plugin/gcc-python-plugin/python.so -fplugin-arg-python-script=$@
-- 
1.7.5.4


From 1fdcb7f07b2dde056782c6831a65b1695df58707 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Fri, 3 Feb 2012 21:32:15 -0200
Subject: [PATCH 03/15] dominators ok


diff --git a/gcc-python-wrappers.h b/gcc-python-wrappers.h
index a3a5b42..eaa9f73 100644
--- a/gcc-python-wrappers.h
+++ b/gcc-python-wrappers.h
@@ -103,11 +103,15 @@ PyObject *
 gcc_BasicBlock_get_rtl(PyGccBasicBlock *self, void *closure);
 
 PyObject *
+gcc_BasicBlock_dominates(PyGccBasicBlock *a, PyGccBasicBlock *b);
+
+PyObject *
 gcc_Cfg_get_basic_blocks(PyGccCfg *self, void *closure);
 
 PyObject *
 gcc_Cfg_get_block_for_label(PyObject *self, PyObject *args);
 
+
 /* autogenerated-tree.c: */
 
 /* return -1 if there isn't an enum tree_code associated with this type */
diff --git a/gcc-python.c b/gcc-python.c
index e838abd..ca1b821 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -32,6 +32,7 @@ int plugin_is_GPL_compatible;
 #include "diagnostic.h"
 #include "cgraph.h"
 #include "opts.h"
+#include "basic-block.h"
 
 #include "c-family/c-pragma.h" /* for parse_in */
 
@@ -120,6 +121,25 @@ gcc_python_set_location(PyObject *self, PyObject *args)
     Py_RETURN_NONE;
 }
 
+
+static PyObject *
+gcc_python_dominates(PyGccBasicBlock *n, PyObject *args)
+{
+    static int calc = 0;
+    PyGccBasicBlock *a, *b;
+    
+    if(calc == 0) {
+        calculate_dominance_info (CDI_DOMINATORS);
+        calc = 1;
+    }
+    
+    gcc_assert(PyArg_ParseTuple(args,
+			  "OO",
+			  &a, &b));;
+    return PyBool_FromLong(dominated_by_p (CDI_DOMINATORS, a->bb, b->bb)); 
+}
+
+
 static PyObject *
 gcc_python_get_option_list(PyObject *self, PyObject *args)
 {
@@ -344,6 +364,11 @@ static PyMethodDef GccMethods[] = {
      (METH_VARARGS | METH_KEYWORDS),
      "Pre-define a named value in the preprocessor."},
 
+    {"dominates",
+     (PyCFunction)gcc_python_dominates,
+     (METH_VARARGS | METH_KEYWORDS),
+     "Checks if a BB dominates another."},
+
     /* Diagnostics: */
     {"permerror", gcc_python_permerror, METH_VARARGS,
      NULL},
-- 
1.7.5.4


From 3cf6ce30d97dbf2a4a98febfda9b4dfd614f8825 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Sun, 5 Feb 2012 14:29:39 -0200
Subject: [PATCH 04/15] dominance info ok


diff --git a/gcc-python.c b/gcc-python.c
index ca1b821..b8086bc 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -123,16 +123,23 @@ gcc_python_set_location(PyObject *self, PyObject *args)
 
 
 static PyObject *
+gcc_python_calculate_dominance_info(PyObject *n, PyObject *args)
+{
+    calculate_dominance_info (CDI_DOMINATORS); 
+    Py_RETURN_NONE;
+}
+
+static PyObject *
+gcc_python_free_dominance_info(PyObject *n, PyObject *args)
+{
+    free_dominance_info (CDI_DOMINATORS);
+    Py_RETURN_NONE;
+}
+
+static PyObject *
 gcc_python_dominates(PyGccBasicBlock *n, PyObject *args)
 {
-    static int calc = 0;
     PyGccBasicBlock *a, *b;
-    
-    if(calc == 0) {
-        calculate_dominance_info (CDI_DOMINATORS);
-        calc = 1;
-    }
-    
     gcc_assert(PyArg_ParseTuple(args,
 			  "OO",
 			  &a, &b));;
@@ -368,6 +375,16 @@ static PyMethodDef GccMethods[] = {
      (PyCFunction)gcc_python_dominates,
      (METH_VARARGS | METH_KEYWORDS),
      "Checks if a BB dominates another."},
+     
+    {"calculate_dominance_info",
+     (PyCFunction)gcc_python_calculate_dominance_info,
+     (METH_VARARGS | METH_KEYWORDS),
+     "Calculates dominance info."},
+
+    {"free_dominance_info",
+     (PyCFunction)gcc_python_free_dominance_info,
+     (METH_VARARGS | METH_KEYWORDS),
+     "Frees dominance info."},
 
     /* Diagnostics: */
     {"permerror", gcc_python_permerror, METH_VARARGS,
-- 
1.7.5.4


From 70188a6affc2008ce344fdaff82df1826fb2536b Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Sun, 5 Feb 2012 15:59:56 -0200
Subject: [PATCH 05/15] dominator sons


diff --git a/gcc-python.c b/gcc-python.c
index b8086bc..3c2af0e 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -137,15 +137,50 @@ gcc_python_free_dominance_info(PyObject *n, PyObject *args)
 }
 
 static PyObject *
-gcc_python_dominates(PyGccBasicBlock *n, PyObject *args)
+gcc_python_dominates(PyObject *n, PyObject *args)
 {
     PyGccBasicBlock *a, *b;
     gcc_assert(PyArg_ParseTuple(args,
 			  "OO",
-			  &a, &b));;
+			  &a, &b));
     return PyBool_FromLong(dominated_by_p (CDI_DOMINATORS, a->bb, b->bb)); 
 }
 
+static PyObject *
+gcc_python_dominator_sons(PyObject *n, PyObject *args)
+{
+    PyGccBasicBlock *py_root;
+    PyObject *py_son;
+    basic_block root, son;
+    PyObject *result;
+    
+    gcc_assert(PyArg_ParseTuple(args,
+			  "O",
+			  &py_root));
+    root = py_root->bb;
+
+    result = PyList_New(0);
+    if (!result) {
+    	goto error;
+    }
+    
+    for (son = first_dom_son (CDI_DOMINATORS, root);
+       son;
+       son = next_dom_son (CDI_DOMINATORS, son))
+    {
+        py_son = gcc_python_make_wrapper_basic_block(son);
+        if (-1 == PyList_Append(result, py_son)) {
+	        goto error;
+	    }    
+    }
+
+    return result;
+
+ error:
+    Py_XDECREF(result);
+    return NULL;
+
+}
 
 static PyObject *
 gcc_python_get_option_list(PyObject *self, PyObject *args)
@@ -386,6 +421,11 @@ static PyMethodDef GccMethods[] = {
      (METH_VARARGS | METH_KEYWORDS),
      "Frees dominance info."},
 
+    {"dominator_sons",
+     (PyCFunction)gcc_python_dominator_sons,
+     (METH_VARARGS | METH_KEYWORDS),
+     "Returns the dominated sons of a bb."},
+
     /* Diagnostics: */
     {"permerror", gcc_python_permerror, METH_VARARGS,
      NULL},
-- 
1.7.5.4


From 662e9f277f86c5757d172b5f3456bc29fe86b92e Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Sun, 5 Feb 2012 17:00:09 -0200
Subject: [PATCH 06/15] dominance finished


diff --git a/examples/show-ssa.py b/examples/show-ssa.py
index 6728833..0614c60 100644
--- a/examples/show-ssa.py
+++ b/examples/show-ssa.py
@@ -27,8 +27,10 @@ class ShowSsa(gcc.GimplePass):
         # (the SSA form of each function should have just been set up)
         if fun and fun.cfg:
             dot = cfg_to_dot(fun.cfg, fun.decl.name)
-            # print(dot)
-            invoke_dot(dot)
+            f = open(fun.decl.name + ".dot", "w")
+            f.write(dot)
+            f.close()
+#            invoke_dot(dot)
 
 ps = ShowSsa(name='show-ssa')
 ps.register_after('ssa')
diff --git a/gcc-python.c b/gcc-python.c
index 3c2af0e..3881983 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -126,6 +126,7 @@ static PyObject *
 gcc_python_calculate_dominance_info(PyObject *n, PyObject *args)
 {
     calculate_dominance_info (CDI_DOMINATORS); 
+    calculate_dominance_info (CDI_POST_DOMINATORS); 
     Py_RETURN_NONE;
 }
 
@@ -133,6 +134,7 @@ static PyObject *
 gcc_python_free_dominance_info(PyObject *n, PyObject *args)
 {
     free_dominance_info (CDI_DOMINATORS);
+    calculate_dominance_info (CDI_POST_DOMINATORS); 
     Py_RETURN_NONE;
 }
 
@@ -147,6 +149,16 @@ gcc_python_dominates(PyObject *n, PyObject *args)
 }
 
 static PyObject *
+gcc_python_post_dominates(PyObject *n, PyObject *args)
+{
+    PyGccBasicBlock *a, *b;
+    gcc_assert(PyArg_ParseTuple(args,
+			  "OO",
+			  &a, &b));
+    return PyBool_FromLong(dominated_by_p (CDI_POST_DOMINATORS, b->bb, a->bb)); 
+}
+
+static PyObject *
 gcc_python_dominator_sons(PyObject *n, PyObject *args)
 {
     PyGccBasicBlock *py_root;
@@ -410,6 +422,11 @@ static PyMethodDef GccMethods[] = {
      (PyCFunction)gcc_python_dominates,
      (METH_VARARGS | METH_KEYWORDS),
      "Checks if a BB dominates another."},
+
+    {"post_dominates",
+     (PyCFunction)gcc_python_post_dominates,
+     (METH_VARARGS | METH_KEYWORDS),
+     "Checks if a BB post-dominates another."},
      
     {"calculate_dominance_info",
      (PyCFunction)gcc_python_calculate_dominance_info,
-- 
1.7.5.4


From 81537c087b25160bc3374e1f903e3d73c4b5c328 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Sun, 5 Feb 2012 18:16:52 -0200
Subject: [PATCH 07/15] differ


diff --git a/gcc-python.c b/gcc-python.c
index 3881983..ce8abf8 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -31,6 +31,7 @@ int plugin_is_GPL_compatible;
 #include "function.h"
 #include "diagnostic.h"
 #include "cgraph.h"
+#include "cfgloop.h"
 #include "opts.h"
 #include "basic-block.h"
 
@@ -158,6 +159,54 @@ gcc_python_post_dominates(PyObject *n, PyObject *args)
     return PyBool_FromLong(dominated_by_p (CDI_POST_DOMINATORS, b->bb, a->bb)); 
 }
 
+
+static PyObject *
+gcc_python_loop_count(PyObject *n, PyObject *args)
+{   
+    struct niter_desc *desc; 
+    unsigned int result;
+    PyGccBasicBlock *py_bb;
+    basic_block bb;
+    gcc_assert(PyArg_ParseTuple(args, "O", &py_bb));
+    bb = py_bb->bb;
+    
+    result = -1;
+    if(bb->loop_depth == 0) {
+        result = 1;
+    }  
+	else if((current_ir_type () == IR_RTL_CFGLAYOUT)
+	   || (current_ir_type () == IR_RTL_CFGRTL)) 
+	{
+	    if(bb->loop_father) {
+/*		    iv_analysis_loop_init(bb->loop_father);  */
+		    desc = get_simple_loop_desc (bb->loop_father);
+		    if(desc->simple_p && (desc->niter_max < 2147483645))
+		    {
+			    result = desc->niter_max + 1;
+		    }
+		}
+	}
+	else if(current_ir_type() == IR_GIMPLE)
+	{
+		gcc_assert(false && "gimple code not working"); 
+		if (bb->loop_father->any_estimate)
+			/*|| bb->loop_father->any_estimate) */
+		{
+			double_int p = bb->loop_father->nb_iterations_upper_bound;
+			if (double_int_fits_in_shwi_p(p)) {
+    			result = double_int_to_shwi(p) + 1;
+			}
+		}
+	}
+	else {
+	    printf("ir_type(): %i\n", current_ir_type ());
+		gcc_unreachable();
+	}
+	
+    return Py_BuildValue("i", result);
+}			
+			
+
 static PyObject *
 gcc_python_dominator_sons(PyObject *n, PyObject *args)
 {
@@ -442,6 +491,11 @@ static PyMethodDef GccMethods[] = {
      (PyCFunction)gcc_python_dominator_sons,
      (METH_VARARGS | METH_KEYWORDS),
      "Returns the dominated sons of a bb."},
+     
+    {"loop_count",
+     (PyCFunction)gcc_python_loop_count,
+     (METH_VARARGS | METH_KEYWORDS),
+     "Returns the loop count of a bb."},
 
     /* Diagnostics: */
     {"permerror", gcc_python_permerror, METH_VARARGS,
-- 
1.7.5.4


From 89537ecd64c50501e4f0c57968f9853e555f81d5 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Sun, 5 Feb 2012 18:17:46 -0200
Subject: [PATCH 08/15] differ


diff --git a/gcc-python.c b/gcc-python.c
index ce8abf8..aeed268 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -185,19 +185,18 @@ gcc_python_loop_count(PyObject *n, PyObject *args)
 			    result = desc->niter_max + 1;
 		    }
 		}
-	}
+	}/*
 	else if(current_ir_type() == IR_GIMPLE)
 	{
 		gcc_assert(false && "gimple code not working"); 
 		if (bb->loop_father->any_estimate)
-			/*|| bb->loop_father->any_estimate) */
 		{
 			double_int p = bb->loop_father->nb_iterations_upper_bound;
 			if (double_int_fits_in_shwi_p(p)) {
     			result = double_int_to_shwi(p) + 1;
 			}
 		}
-	}
+	}*/
 	else {
 	    printf("ir_type(): %i\n", current_ir_type ());
 		gcc_unreachable();
-- 
1.7.5.4


From 0c5c430e629e55bfd7cc868ada0790f7c0ce7616 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Sun, 5 Feb 2012 18:39:13 -0200
Subject: [PATCH 09/15] working by magic


diff --git a/Makefile b/Makefile
index 0d78abe..cbd0745 100644
--- a/Makefile
+++ b/Makefile
@@ -93,7 +93,7 @@ PYTHON_CONFIG=python-config
 PYTHON_CFLAGS=$(shell $(PYTHON_CONFIG) --cflags)
 PYTHON_LDFLAGS=$(shell $(PYTHON_CONFIG) --ldflags)
 
-CFLAGS+= -I$(GCCPLUGINS_DIR)/include -fPIC -fno-strict-aliasing -O2 -Wall -Werror -g $(PYTHON_CFLAGS) $(PYTHON_LDFLAGS)
+CFLAGS+= -I$(GCCPLUGINS_DIR)/include -fPIC -fno-strict-aliasing -O2 -Wall -g $(PYTHON_CFLAGS) $(PYTHON_LDFLAGS)
 ifneq "$(PLUGIN_PYTHONPATH)" ""
   CFLAGS+= -DPLUGIN_PYTHONPATH='"$(PLUGIN_PYTHONPATH)"'
 endif
diff --git a/gcc-python.c b/gcc-python.c
index aeed268..c91d8bc 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -163,7 +163,7 @@ gcc_python_post_dominates(PyObject *n, PyObject *args)
 static PyObject *
 gcc_python_loop_count(PyObject *n, PyObject *args)
 {   
-    struct niter_desc *desc; 
+    struct niter_desc *desc;
     unsigned int result;
     PyGccBasicBlock *py_bb;
     basic_block bb;
@@ -178,17 +178,18 @@ gcc_python_loop_count(PyObject *n, PyObject *args)
 	   || (current_ir_type () == IR_RTL_CFGRTL)) 
 	{
 	    if(bb->loop_father) {
-/*		    iv_analysis_loop_init(bb->loop_father);  */
-		    desc = get_simple_loop_desc (bb->loop_father);
+		    iv_analysis_loop_init(bb->loop_father);   
+		    desc = simple_loop_desc (bb->loop_father);
+		    printf("pointer %p\n", desc->simple_p);
 		    if(desc->simple_p && (desc->niter_max < 2147483645))
 		    {
 			    result = desc->niter_max + 1;
 		    }
+		    free_simple_loop_desc(desc);  
 		}
-	}/*
+	}
 	else if(current_ir_type() == IR_GIMPLE)
 	{
-		gcc_assert(false && "gimple code not working"); 
 		if (bb->loop_father->any_estimate)
 		{
 			double_int p = bb->loop_father->nb_iterations_upper_bound;
@@ -196,7 +197,7 @@ gcc_python_loop_count(PyObject *n, PyObject *args)
     			result = double_int_to_shwi(p) + 1;
 			}
 		}
-	}*/
+	}
 	else {
 	    printf("ir_type(): %i\n", current_ir_type ());
 		gcc_unreachable();
-- 
1.7.5.4


From 5ffc54dec6307e83631e610fccf784bd010fc954 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Sun, 5 Feb 2012 18:45:35 -0200
Subject: [PATCH 10/15] loop analysis done


diff --git a/Makefile b/Makefile
index cbd0745..0d78abe 100644
--- a/Makefile
+++ b/Makefile
@@ -93,7 +93,7 @@ PYTHON_CONFIG=python-config
 PYTHON_CFLAGS=$(shell $(PYTHON_CONFIG) --cflags)
 PYTHON_LDFLAGS=$(shell $(PYTHON_CONFIG) --ldflags)
 
-CFLAGS+= -I$(GCCPLUGINS_DIR)/include -fPIC -fno-strict-aliasing -O2 -Wall -g $(PYTHON_CFLAGS) $(PYTHON_LDFLAGS)
+CFLAGS+= -I$(GCCPLUGINS_DIR)/include -fPIC -fno-strict-aliasing -O2 -Wall -Werror -g $(PYTHON_CFLAGS) $(PYTHON_LDFLAGS)
 ifneq "$(PLUGIN_PYTHONPATH)" ""
   CFLAGS+= -DPLUGIN_PYTHONPATH='"$(PLUGIN_PYTHONPATH)"'
 endif
diff --git a/gcc-python.c b/gcc-python.c
index c91d8bc..2d6f700 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -163,7 +163,6 @@ gcc_python_post_dominates(PyObject *n, PyObject *args)
 static PyObject *
 gcc_python_loop_count(PyObject *n, PyObject *args)
 {   
-    struct niter_desc *desc;
     unsigned int result;
     PyGccBasicBlock *py_bb;
     basic_block bb;
@@ -174,27 +173,13 @@ gcc_python_loop_count(PyObject *n, PyObject *args)
     if(bb->loop_depth == 0) {
         result = 1;
     }  
-	else if((current_ir_type () == IR_RTL_CFGLAYOUT)
-	   || (current_ir_type () == IR_RTL_CFGRTL)) 
-	{
-	    if(bb->loop_father) {
-		    iv_analysis_loop_init(bb->loop_father);   
-		    desc = simple_loop_desc (bb->loop_father);
-		    printf("pointer %p\n", desc->simple_p);
-		    if(desc->simple_p && (desc->niter_max < 2147483645))
-		    {
-			    result = desc->niter_max + 1;
-		    }
-		    free_simple_loop_desc(desc);  
-		}
-	}
 	else if(current_ir_type() == IR_GIMPLE)
 	{
 		if (bb->loop_father->any_estimate)
 		{
 			double_int p = bb->loop_father->nb_iterations_upper_bound;
 			if (double_int_fits_in_shwi_p(p)) {
-    			result = double_int_to_shwi(p) + 1;
+    			result = double_int_to_shwi(p);
 			}
 		}
 	}
-- 
1.7.5.4


From 3a759b5388649be9789c1f800d9b8c1f5b30c554 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Mon, 6 Feb 2012 15:35:28 -0200
Subject: [PATCH 11/15] loop comparisons


diff --git a/gcc-python.c b/gcc-python.c
index 2d6f700..e5ba287 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -193,6 +193,47 @@ gcc_python_loop_count(PyObject *n, PyObject *args)
 			
 
 static PyObject *
+gcc_python_loop_contains(PyObject *n, PyObject *args)
+{   
+    int result;
+    PyGccBasicBlock *a, *b;
+    struct loop *A, *B, *step;
+    gcc_assert(PyArg_ParseTuple(args, "OO", &a, &b));
+    
+    A = a->bb->loop_father;
+    B = b->bb->loop_father;
+    
+	result = false;
+    if(A == NULL) 
+    {
+		result =  true;
+	}
+	else 
+	{
+		for(step = B; step; step = loop_outer(step))
+		{
+			if(step == A) {
+				result = true;
+				break;
+			}
+		}
+	}
+    return PyBool_FromLong(result);
+}			
+	
+static PyObject *
+gcc_python_loop_equals(PyObject *n, PyObject *args)
+{   
+    int result;
+    PyGccBasicBlock *a, *b;
+    gcc_assert(PyArg_ParseTuple(args, "OO", &a, &b));
+    
+    result = a->bb->loop_father == b->bb->loop_father;
+    return PyBool_FromLong(result);
+}			
+			
+
+static PyObject *
 gcc_python_dominator_sons(PyObject *n, PyObject *args)
 {
     PyGccBasicBlock *py_root;
@@ -481,6 +522,16 @@ static PyMethodDef GccMethods[] = {
      (PyCFunction)gcc_python_loop_count,
      (METH_VARARGS | METH_KEYWORDS),
      "Returns the loop count of a bb."},
+     
+    {"loop_contains",
+     (PyCFunction)gcc_python_loop_contains,
+     (METH_VARARGS | METH_KEYWORDS),
+     "Returns if a loop contains the other."},
+     
+    {"loop_equals",
+     (PyCFunction)gcc_python_loop_equals,
+     (METH_VARARGS | METH_KEYWORDS),
+     "Returns if a loop is the same as the other."},
 
     /* Diagnostics: */
     {"permerror", gcc_python_permerror, METH_VARARGS,
-- 
1.7.5.4


From dac8bf2fe8b67811836130cdd1f6b1e8c8310f40 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Mon, 6 Feb 2012 15:40:56 -0200
Subject: [PATCH 12/15] not borking


diff --git a/gcc-python.c b/gcc-python.c
index e5ba287..8453b05 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -206,6 +206,7 @@ gcc_python_loop_contains(PyObject *n, PyObject *args)
 	result = false;
     if(A == NULL) 
     {
+        printf("Null loop comparison");
 		result =  true;
 	}
 	else 
-- 
1.7.5.4


From 0c163819059f753ced4dade02864ea7e09108701 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Mon, 6 Feb 2012 15:53:14 -0200
Subject: [PATCH 13/15] not borking


diff --git a/gcc-python.c b/gcc-python.c
index 8453b05..b45295c 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -191,46 +191,30 @@ gcc_python_loop_count(PyObject *n, PyObject *args)
     return Py_BuildValue("i", result);
 }			
 			
-
+/*
+  WARNING: THIS IS WRONG IN THE GENERAL CASE.
+*/
 static PyObject *
 gcc_python_loop_contains(PyObject *n, PyObject *args)
 {   
-    int result;
     PyGccBasicBlock *a, *b;
-    struct loop *A, *B, *step;
     gcc_assert(PyArg_ParseTuple(args, "OO", &a, &b));
     
-    A = a->bb->loop_father;
-    B = b->bb->loop_father;
-    
-	result = false;
-    if(A == NULL) 
-    {
-        printf("Null loop comparison");
-		result =  true;
-	}
-	else 
-	{
-		for(step = B; step; step = loop_outer(step))
-		{
-			if(step == A) {
-				result = true;
-				break;
-			}
-		}
-	}
-    return PyBool_FromLong(result);
+    return PyBool_FromLong(
+        a->bb->loop_depth < b->bb->loop_depth);
 }			
-	
+
+/*
+  WARNING: THIS IS WRONG IN THE GENERAL CASE.
+*/
 static PyObject *
 gcc_python_loop_equals(PyObject *n, PyObject *args)
 {   
-    int result;
     PyGccBasicBlock *a, *b;
     gcc_assert(PyArg_ParseTuple(args, "OO", &a, &b));
     
-    result = a->bb->loop_father == b->bb->loop_father;
-    return PyBool_FromLong(result);
+    return PyBool_FromLong(
+        a->bb->loop_depth == b->bb->loop_depth);
 }			
 			
 
-- 
1.7.5.4


From 5c8907ab244e0409896c1b473672fbd977ee8894 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Mon, 6 Feb 2012 17:58:51 -0200
Subject: [PATCH 14/15] loop depth


diff --git a/gcc-python.c b/gcc-python.c
index b45295c..0ee5624 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -189,6 +189,15 @@ gcc_python_loop_count(PyObject *n, PyObject *args)
 	}
 	
     return Py_BuildValue("i", result);
+}		
+
+static PyObject *
+gcc_python_loop_depth(PyObject *n, PyObject *args)
+{   
+    PyGccBasicBlock *py_bb;
+    gcc_assert(PyArg_ParseTuple(args, "O", &py_bb));
+	
+    return Py_BuildValue("i", py_bb->bb->loop_depth);
 }			
 			
 /*
@@ -513,6 +522,11 @@ static PyMethodDef GccMethods[] = {
      (METH_VARARGS | METH_KEYWORDS),
      "Returns if a loop contains the other."},
      
+    {"loop_depth",
+     (PyCFunction)gcc_python_loop_depth,
+     (METH_VARARGS | METH_KEYWORDS),
+     "Returns the depth of the loop of the bb."},
+     
     {"loop_equals",
      (PyCFunction)gcc_python_loop_equals,
      (METH_VARARGS | METH_KEYWORDS),
-- 
1.7.5.4


From 6195c5d6edd5cd29929c290f775d373155b57a96 Mon Sep 17 00:00:00 2001
From: Emilio Wuerges <wuerges@gmail.com>
Date: Wed, 8 Feb 2012 15:28:02 -0200
Subject: [PATCH 15/15] ready to submit


diff --git a/examples/show-ssa.py b/examples/show-ssa.py
index 0614c60..6728833 100644
--- a/examples/show-ssa.py
+++ b/examples/show-ssa.py
@@ -27,10 +27,8 @@ class ShowSsa(gcc.GimplePass):
         # (the SSA form of each function should have just been set up)
         if fun and fun.cfg:
             dot = cfg_to_dot(fun.cfg, fun.decl.name)
-            f = open(fun.decl.name + ".dot", "w")
-            f.write(dot)
-            f.close()
-#            invoke_dot(dot)
+            # print(dot)
+            invoke_dot(dot)
 
 ps = ShowSsa(name='show-ssa')
 ps.register_after('ssa')
diff --git a/gcc-python-wrappers.h b/gcc-python-wrappers.h
index eaa9f73..a3a5b42 100644
--- a/gcc-python-wrappers.h
+++ b/gcc-python-wrappers.h
@@ -103,15 +103,11 @@ PyObject *
 gcc_BasicBlock_get_rtl(PyGccBasicBlock *self, void *closure);
 
 PyObject *
-gcc_BasicBlock_dominates(PyGccBasicBlock *a, PyGccBasicBlock *b);
-
-PyObject *
 gcc_Cfg_get_basic_blocks(PyGccCfg *self, void *closure);
 
 PyObject *
 gcc_Cfg_get_block_for_label(PyObject *self, PyObject *args);
 
-
 /* autogenerated-tree.c: */
 
 /* return -1 if there isn't an enum tree_code associated with this type */
diff --git a/gcc-with-python b/gcc-with-python
index 52468df..f68c918 100755
--- a/gcc-with-python
+++ b/gcc-with-python
@@ -16,6 +16,4 @@
 #   along with this program.  If not, see
 #   <http://www.gnu.org/licenses/>.
 
-#LIB_PYTHON=lib$( echo `python-config  --libs` |sed 's/^.*-l\(python.*\)$/\1/' ).so
-
-LD_PRELOAD=libpython2.7.so gcc -fplugin=/home/ew/gcc-python-plugin/gcc-python-plugin/python.so -fplugin-arg-python-script=$@
+gcc -fplugin=$(pwd)/python.so -fplugin-arg-python-script=$@
-- 
1.7.5.4

