commit 638ae5797f9658540bbdc539eb51900ea96f8d65 Author: David Malcolm dmalcolm@redhat.com Date: Thu Mar 29 21:06:05 2012 -0400
add gcc-gimple.{c|h} and gcc-rtl.{c|h}
Makefile | 2 + gcc-python-cfg.c | 166 ++++++++++++++------------- gcc-python-gimple.c | 37 +++--- gcc-python-rtl.c | 25 +++-- gcc-python.h | 10 +- generate-callgraph-c.py | 2 +- generate-gimple-c.py | 38 +++--- generate-rtl-c.py | 4 +- generate-tree-c.py | 2 +- proposed-plugin-api/gcc-cfg.c | 76 ++++++++++++- proposed-plugin-api/gcc-cfg.h | 10 +- proposed-plugin-api/gcc-gimple.c | 74 ++++++++++++ proposed-plugin-api/gcc-gimple.h | 42 +++++++ proposed-plugin-api/gcc-public-types.h | 3 + proposed-plugin-api/gcc-rtl.c | 46 ++++++++ proposed-plugin-api/gcc-rtl.h | 32 +++++ proposed-plugin-api/gcc-semiprivate-types.h | 14 ++- 17 files changed, 433 insertions(+), 150 deletions(-) --- diff --git a/Makefile b/Makefile index 08b5b86..86d24d5 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,8 @@
PLUGIN_SOURCE_FILES= \ proposed-plugin-api/gcc-cfg.c \ + proposed-plugin-api/gcc-gimple.c \ + proposed-plugin-api/gcc-rtl.c \ gcc-python.c \ gcc-python-attribute.c \ gcc-python-callbacks.c \ diff --git a/gcc-python-cfg.c b/gcc-python-cfg.c index 558e9ad..8c67e4a 100644 --- a/gcc-python-cfg.c +++ b/gcc-python-cfg.c @@ -21,6 +21,7 @@ #include "gcc-python.h" #include "gcc-python-wrappers.h" #include "proposed-plugin-api/gcc-cfg.h" +#include "proposed-plugin-api/gcc-gimple.h"
#if 1 /* Ideally we wouldn't have these includes here: */ @@ -123,86 +124,113 @@ gcc_BasicBlock_get_succs(PyGccBasicBlock *self, void *closure) return result; }
-static PyObject * -gcc_python_gimple_seq_to_list(gimple_seq seq) +static bool +append_gimple_to_list(GccGimpleI stmt, void *user_data) +{ + PyObject *result = (PyObject *)user_data; + PyObject *obj_stmt; + + obj_stmt = gcc_python_make_wrapper_gimple(stmt); + if (!obj_stmt) { + return true; + } + + if (PyList_Append(result, obj_stmt)) { + Py_DECREF(obj_stmt); + return true; + } + + /* Success: */ + Py_DECREF(obj_stmt); + return false; +} + +PyObject * +gcc_BasicBlock_get_gimple(PyGccBasicBlock *self, void *closure) { - gimple_stmt_iterator gsi; PyObject *result = NULL;
+ assert(self); + assert(self->bb.inner); + result = PyList_New(0); if (!result) { - goto error; + return NULL; }
- for (gsi = gsi_start (seq); - !gsi_end_p (gsi); - gsi_next (&gsi)) { - - gimple stmt = gsi_stmt(gsi); - PyObject *obj_stmt; + if (GccCfgBlockI_ForEachGimple(self->bb, + append_gimple_to_list, + result)) { + Py_DECREF(result); + return NULL; + }
- obj_stmt = gcc_python_make_wrapper_gimple(stmt); - if (!obj_stmt) { - goto error; - } + return result; +}
- if (PyList_Append(result, obj_stmt)) { - Py_DECREF(obj_stmt); - goto error; - } - Py_DECREF(obj_stmt); +static bool +append_gimple_phi_to_list(GccGimplePhiI stmt, void *user_data) +{ + PyObject *result = (PyObject *)user_data; + PyObject *obj_stmt;
-#if 0 - printf(" gimple: %p code: %s (%i) %s:%i num_ops=%i\n", - stmt, - gimple_code_name[gimple_code(stmt)], - gimple_code(stmt), - gimple_filename(stmt), - gimple_lineno(stmt), - gimple_num_ops(stmt)); -#endif + obj_stmt = gcc_python_make_wrapper_gimple(GccGimplePhiI_Upcast(stmt)); + if (!obj_stmt) { + return true; }
- return result; + if (PyList_Append(result, obj_stmt)) { + Py_DECREF(obj_stmt); + return true; + }
- error: - Py_XDECREF(result); - return NULL; + /* Success: */ + Py_DECREF(obj_stmt); + return false; }
- PyObject * -gcc_BasicBlock_get_gimple(PyGccBasicBlock *self, void *closure) +gcc_BasicBlock_get_phi_nodes(PyGccBasicBlock *self, void *closure) { + PyObject *result = NULL; + assert(self); assert(self->bb.inner);
- if (self->bb.inner->flags & BB_RTL) { - Py_RETURN_NONE; + result = PyList_New(0); + if (!result) { + return NULL; }
- if (NULL == self->bb.inner->il.gimple) { - Py_RETURN_NONE; + if (GccCfgBlockI_ForEachGimplePhi(self->bb, + append_gimple_phi_to_list, + result)) { + Py_DECREF(result); + return NULL; }
- return gcc_python_gimple_seq_to_list(self->bb.inner->il.gimple->seq); + return result; }
-PyObject * -gcc_BasicBlock_get_phi_nodes(PyGccBasicBlock *self, void *closure) +static bool +append_rtl_to_list(GccRtlInsnI insn, void *user_data) { - assert(self); - assert(self->bb.inner); + PyObject *result = (PyObject *)user_data; + PyObject *obj;
- if (self->bb.inner->flags & BB_RTL) { - Py_RETURN_NONE; + obj = gcc_python_make_wrapper_rtl(insn); + if (!obj) { + return true; }
- if (NULL == self->bb.inner->il.gimple) { - Py_RETURN_NONE; + if (PyList_Append(result, obj)) { + Py_DECREF(obj); + return true; }
- return gcc_python_gimple_seq_to_list(self->bb.inner->il.gimple->phi_nodes); + /* Success: */ + Py_DECREF(obj); + return false; }
PyObject * @@ -210,48 +238,22 @@ gcc_BasicBlock_get_rtl(PyGccBasicBlock *self, void *closure) { PyObject *result = NULL;
- rtx insn; - - if (!(self->bb.inner->flags & BB_RTL)) { - Py_RETURN_NONE; - } - -#if 0 - /* Debugging help: */ - { - fprintf(stderr, "--BEGIN--\n"); - FOR_BB_INSNS(self->bb, insn) { - print_rtl_single (stderr, insn); - } - fprintf(stderr, "-- END --\n"); - } -#endif + assert(self); + assert(self->bb.inner);
result = PyList_New(0); if (!result) { - goto error; + return NULL; }
- FOR_BB_INSNS(self->bb.inner, insn) { - PyObject *obj; - - obj = gcc_python_make_wrapper_rtl(insn); - if (!obj) { - goto error; - } - - if (PyList_Append(result, obj)) { - Py_DECREF(obj); - goto error; - } - Py_DECREF(obj); + if (GccCfgBlockI_ForEachRtlInsn(self->bb, + append_rtl_to_list, + result)) { + Py_DECREF(result); + return NULL; }
return result; - - error: - Py_XDECREF(result); - return NULL; }
diff --git a/gcc-python-gimple.c b/gcc-python-gimple.c index b1ffcb0..7668446 100644 --- a/gcc-python-gimple.c +++ b/gcc-python-gimple.c @@ -25,6 +25,7 @@ #include "gimple.h" #include "tree-flow.h" #include "tree-flow-inline.h" +#include "proposed-plugin-api/gcc-gimple.h"
static PyObject * do_pretty_print(struct PyGccGimple * self, int spc, int flags) @@ -36,8 +37,9 @@ do_pretty_print(struct PyGccGimple * self, int spc, int flags) }
dump_gimple_stmt(gcc_python_pretty_printer_as_pp(ppobj), - self->stmt, - spc, flags); + self->stmt.inner, + spc, flags); + result = gcc_python_pretty_printer_as_string(ppobj); if (!result) { goto error; @@ -132,7 +134,7 @@ gcc_Gimple_walk_tree(struct PyGccGimple * self, PyObject *args, PyObject *kwargs memset(&wi, 0, sizeof(wi)); wi.info = closure;
- result = walk_gimple_op (self->stmt, + result = walk_gimple_op (self->stmt.inner, gimple_walk_tree_callback, &wi); Py_XDECREF(closure->callback); @@ -153,16 +155,16 @@ gcc_Gimple_get_rhs(struct PyGccGimple *self, void *closure) PyObject * result = NULL; int i;
- assert(gimple_has_ops(self->stmt)); + assert(gimple_has_ops(self->stmt.inner));
- assert(gimple_num_ops(self->stmt) > 0); - result = PyList_New(gimple_num_ops (self->stmt) - 1); + assert(gimple_num_ops(self->stmt.inner) > 0); + result = PyList_New(gimple_num_ops (self->stmt.inner) - 1); if (!result) { goto error; }
- for (i = 1 ; i < gimple_num_ops(self->stmt); i++) { - tree t = gimple_op(self->stmt, i); + for (i = 1 ; i < gimple_num_ops(self->stmt.inner); i++) { + tree t = gimple_op(self->stmt.inner, i); PyObject *obj = gcc_python_make_wrapper_tree(t); if (!obj) { goto error; @@ -187,7 +189,7 @@ PyObject * gcc_GimpleCall_get_args(struct PyGccGimple *self, void *closure) { PyObject * result = NULL; - int num_args = gimple_call_num_args (self->stmt); + int num_args = gimple_call_num_args (self->stmt.inner); int i;
result = PyList_New(num_args); @@ -196,7 +198,7 @@ gcc_GimpleCall_get_args(struct PyGccGimple *self, void *closure) }
for (i = 0 ; i < num_args; i++) { - tree t = gimple_call_arg(self->stmt, i); + tree t = gimple_call_arg(self->stmt.inner, i); PyObject *obj = gcc_python_make_wrapper_tree(t); if (!obj) { goto error; @@ -216,7 +218,7 @@ gcc_GimplePhi_get_args(struct PyGccGimple *self, void *closure) { /* See e.g. gimple-pretty-print.c:dump_gimple_phi */ PyObject * result = NULL; - int num_args = gimple_phi_num_args (self->stmt); + int num_args = gimple_phi_num_args (self->stmt.inner); int i;
result = PyList_New(num_args); @@ -225,8 +227,8 @@ gcc_GimplePhi_get_args(struct PyGccGimple *self, void *closure) }
for (i = 0 ; i < num_args; i++) { - tree arg_def = gimple_phi_arg_def(self->stmt, i); - edge arg_edge = gimple_phi_arg_edge(self->stmt, i); + tree arg_def = gimple_phi_arg_def(self->stmt.inner, i); + edge arg_edge = gimple_phi_arg_edge(self->stmt.inner, i); /* fwiw, there's also gimple_phi_arg_has_location and gimple_phi_arg_location */ PyObject *tuple_obj; tuple_obj = Py_BuildValue("O&O&", @@ -249,7 +251,7 @@ PyObject * gcc_GimpleSwitch_get_labels(struct PyGccGimple *self, void *closure) { PyObject * result = NULL; - unsigned num_labels = gimple_switch_num_labels(self->stmt); + unsigned num_labels = gimple_switch_num_labels(self->stmt.inner); int i;
result = PyList_New(num_labels); @@ -258,7 +260,7 @@ gcc_GimpleSwitch_get_labels(struct PyGccGimple *self, void *closure) }
for (i = 0 ; i < num_labels; i++) { - tree t = gimple_switch_label(self->stmt, i); + tree t = gimple_switch_label(self->stmt.inner, i); PyObject *obj = gcc_python_make_wrapper_tree(t); if (!obj) { goto error; @@ -275,7 +277,7 @@ gcc_GimpleSwitch_get_labels(struct PyGccGimple *self, void *closure)
PyObject* -gcc_python_make_wrapper_gimple(gimple stmt) +gcc_python_make_wrapper_gimple(GccGimpleI stmt) { struct PyGccGimple *gimple_obj = NULL; PyGccWrapperTypeObject* tp; @@ -300,8 +302,7 @@ error: void wrtp_mark_for_PyGccGimple(PyGccGimple *wrapper) { - /* Mark the underlying object (recursing into its fields): */ - gt_ggc_mx_gimple_statement_d(wrapper->stmt); + GccGimpleI_MarkInUse(wrapper->stmt); }
/* diff --git a/gcc-python-rtl.c b/gcc-python-rtl.c index 0eb23ba..e499cdf 100644 --- a/gcc-python-rtl.c +++ b/gcc-python-rtl.c @@ -24,12 +24,13 @@ #include "rtl.h" #include "tree-flow.h" #include "tree-flow-inline.h" +#include "proposed-plugin-api/gcc-rtl.h"
PyObject * gcc_Rtl_get_location(struct PyGccRtl *self, void *closure) { - int locator = INSN_LOCATOR (self->insn); - if (locator && insn_file (self->insn)) { + int locator = INSN_LOCATOR (self->insn.inner); + if (locator && insn_file (self->insn.inner)) { return gcc_python_make_wrapper_location(locator_location(locator)); }
@@ -59,7 +60,8 @@ get_operand_as_object(const_rtx in_rtx, int idx, char fmt)
case 'e': /* pointer to an rtl expression */ /* Nested expression: */ - return gcc_python_make_wrapper_rtl(XEXP (in_rtx, idx)); + return gcc_python_make_wrapper_rtl( + GccPrivate_make_RtlInsnI(XEXP (in_rtx, idx)));
case 'E': case 'V': @@ -71,7 +73,8 @@ get_operand_as_object(const_rtx in_rtx, int idx, char fmt) return NULL; } for (j = 0; j < XVECLEN (in_rtx, idx); j++) { - PyObject *item = gcc_python_make_wrapper_rtl(XVECEXP (in_rtx, idx, j)); + PyObject *item = gcc_python_make_wrapper_rtl( + GccPrivate_make_RtlInsnI(XVECEXP (in_rtx, idx, j))); if (!item) { Py_DECREF(list); return NULL; @@ -117,7 +120,7 @@ get_operand_as_object(const_rtx in_rtx, int idx, char fmt) PyObject * gcc_Rtl_get_operands(struct PyGccRtl *self, void *closure) { - const int length = GET_RTX_LENGTH (GET_CODE (self->insn)); + const int length = GET_RTX_LENGTH (GET_CODE (self->insn.inner)); PyObject *result; int i; const char *format_ptr; @@ -127,9 +130,9 @@ gcc_Rtl_get_operands(struct PyGccRtl *self, void *closure) return NULL; }
- format_ptr = GET_RTX_FORMAT (GET_CODE (self->insn)); + format_ptr = GET_RTX_FORMAT (GET_CODE (self->insn.inner)); for (i = 0; i < length; i++) { - PyObject *item = get_operand_as_object(self->insn, i, *format_ptr++); + PyObject *item = get_operand_as_object(self->insn.inner, i, *format_ptr++); if (!item) { Py_DECREF(result); return NULL; @@ -163,7 +166,7 @@ gcc_Rtl_str(struct PyGccRtl * self) return PyErr_SetFromErrno(PyExc_IOError); }
- print_rtl_single (f, self->insn); + print_rtl_single (f, self->insn.inner);
fclose(f);
@@ -171,12 +174,12 @@ gcc_Rtl_str(struct PyGccRtl * self) }
PyObject* -gcc_python_make_wrapper_rtl(struct rtx_def *insn) +gcc_python_make_wrapper_rtl(GccRtlInsnI insn) { struct PyGccRtl *rtl_obj = NULL; PyGccWrapperTypeObject* tp;
- if (!insn) { + if (!insn.inner) { Py_RETURN_NONE; }
@@ -199,7 +202,7 @@ void wrtp_mark_for_PyGccRtl(PyGccRtl *wrapper) { /* Mark the underlying object (recursing into its fields): */ - gt_ggc_mx_rtx_def(wrapper->insn); + GccRtlInsnI_MarkInUse(wrapper->insn); }
/* diff --git a/gcc-python.h b/gcc-python.h index d23fb47..ff3ad4b 100644 --- a/gcc-python.h +++ b/gcc-python.h @@ -177,7 +177,7 @@ DECLARE_SIMPLE_WRAPPER(PyGccLocation, DECLARE_SIMPLE_WRAPPER(PyGccGimple, gcc_GimpleType, gimple, - gimple, stmt); + GccGimpleI, stmt);
DECLARE_SIMPLE_WRAPPER(PyGccEdge, gcc_EdgeType, @@ -212,7 +212,7 @@ DECLARE_SIMPLE_WRAPPER(PyGccParameter, DECLARE_SIMPLE_WRAPPER(PyGccRtl, gcc_RtlType, rtl, - struct rtx_def *, insn) + GccRtlInsnI, insn)
DECLARE_SIMPLE_WRAPPER(PyGccTree, gcc_TreeType, @@ -238,7 +238,8 @@ void autogenerated_function_add_types(PyObject *m); /* autogenerated-gimple.c */ int autogenerated_gimple_init_types(void); void autogenerated_gimple_add_types(PyObject *m); -PyGccWrapperTypeObject* gcc_python_autogenerated_gimple_type_for_stmt(gimple g); +PyGccWrapperTypeObject* +gcc_python_autogenerated_gimple_type_for_stmt(GccGimpleI stmt);
/* autogenerated-location.c */ int autogenerated_location_init_types(void); @@ -268,7 +269,8 @@ void autogenerated_pretty_printer_add_types(PyObject *m); /* autogenerated-rtl.c */ int autogenerated_rtl_init_types(void); void autogenerated_rtl_add_types(PyObject *m); -PyGccWrapperTypeObject * gcc_python_autogenerated_rtl_type_for_stmt(struct rtx_def *insn); +PyGccWrapperTypeObject * +gcc_python_autogenerated_rtl_type_for_stmt(GccRtlInsnI insn);
/* autogenerated-tree.c */ diff --git a/generate-callgraph-c.py b/generate-callgraph-c.py index 143ee34..870b058 100644 --- a/generate-callgraph-c.py +++ b/generate-callgraph-c.py @@ -47,7 +47,7 @@ def generate_callgraph_edge(): 'The function that is called here, as a gcc.CallgraphNode') getsettable.add_simple_getter(cu, 'call_stmt', - 'gcc_python_make_wrapper_gimple(self->edge->call_stmt)', + 'gcc_python_make_wrapper_gimple(GccPrivate_make_GimpleI(self->edge->call_stmt))', 'The gcc.GimpleCall statememt for the function call') cu.add_defn(getsettable.c_defn())
diff --git a/generate-gimple-c.py b/generate-gimple-c.py index 9643b00..4f859e1 100644 --- a/generate-gimple-c.py +++ b/generate-gimple-c.py @@ -192,13 +192,13 @@ def generate_gimple(): static PyObject * gcc_Gimple_get_location(struct PyGccGimple *self, void *closure) { - return gcc_python_make_wrapper_location(gimple_location(self->stmt)); + return gcc_python_make_wrapper_location(gimple_location(self->stmt.inner)); }
static PyObject * gcc_Gimple_get_block(struct PyGccGimple *self, void *closure) { - return gcc_python_make_wrapper_tree(gimple_block(self->stmt)); + return gcc_python_make_wrapper_tree(gimple_block(self->stmt.inner)); } """)
@@ -208,7 +208,7 @@ gcc_Gimple_get_block(struct PyGccGimple *self, void *closure) PyGetSetDef('exprtype', cu.add_simple_getter('gcc_Gimple_get_exprtype', 'PyGccGimple', - 'gcc_python_make_wrapper_tree(gimple_expr_type(self->stmt))'), + 'gcc_python_make_wrapper_tree(gimple_expr_type(self->stmt.inner))'), None, 'The type of the main expression computed by this statement, as a gcc.Tree (which might be gcc.VoidType)'), PyGetSetDef('str_no_uid', @@ -250,7 +250,7 @@ def generate_gimple_subclasses(): exprcode_getter = PyGetSetDef('exprcode', cu.add_simple_getter('gcc_Gimple_get_exprcode', 'PyGccGimple', - '(PyObject*)gcc_python_autogenerated_tree_type_for_tree_code(gimple_expr_code(self->stmt), 0)'), + '(PyObject*)gcc_python_autogenerated_tree_type_for_tree_code(gimple_expr_code(self->stmt.inner), 0)'), None, 'The kind of the expression, as an gcc.Tree subclass (the type itself, not an instance)')
@@ -266,7 +266,7 @@ def generate_gimple_subclasses(): 'PyGccGimple') getsettable.add_simple_getter(cu, 'string', - 'gcc_python_string_from_string(gimple_asm_string(self->stmt))', + 'gcc_python_string_from_string(gimple_asm_string(self->stmt.inner))', 'The inline assembler as a string') return getsettable
@@ -275,7 +275,7 @@ def generate_gimple_subclasses(): [PyGetSetDef('lhs', cu.add_simple_getter('gcc_GimpleAssign_get_lhs', 'PyGccGimple', - 'gcc_python_make_wrapper_tree(gimple_assign_lhs(self->stmt))'), + 'gcc_python_make_wrapper_tree(gimple_assign_lhs(self->stmt.inner))'), None, 'Left-hand-side of the assignment, as a gcc.Tree'), exprcode_getter, @@ -286,20 +286,20 @@ def generate_gimple_subclasses(): [PyGetSetDef('lhs', cu.add_simple_getter('gcc_GimpleCall_get_lhs', 'PyGccGimple', - 'gcc_python_make_wrapper_tree(gimple_call_lhs(self->stmt))'), + 'gcc_python_make_wrapper_tree(gimple_call_lhs(self->stmt.inner))'), None, 'Left-hand-side of the call, as a gcc.Tree'), rhs_getter, PyGetSetDef('fn', cu.add_simple_getter('gcc_GimpleCall_get_fn', 'PyGccGimple', - 'gcc_python_make_wrapper_tree(gimple_call_fn(self->stmt))'), + 'gcc_python_make_wrapper_tree(gimple_call_fn(self->stmt.inner))'), None, 'The function being called, as a gcc.Tree'), PyGetSetDef('fndecl', cu.add_simple_getter('gcc_GimpleCall_get_fndecl', 'PyGccGimple', - 'gcc_python_make_wrapper_tree(gimple_call_fndecl(self->stmt))'), + 'gcc_python_make_wrapper_tree(gimple_call_fndecl(self->stmt.inner))'), None, 'The declaration of the function being called (if any), as a gcc.Tree'), exprcode_getter, @@ -310,7 +310,7 @@ def generate_gimple_subclasses(): PyGetSetDef('noreturn', cu.add_simple_getter('gcc_GimpleCall_get_noreturn', 'PyGccGimple', - 'PyBool_FromLong(gimple_call_noreturn_p(self->stmt))'), + 'PyBool_FromLong(gimple_call_noreturn_p(self->stmt.inner))'),
None, 'Has this call been marked as not returning, as a boolean'), @@ -321,7 +321,7 @@ def generate_gimple_subclasses(): [PyGetSetDef('retval', cu.add_simple_getter('gcc_GimpleReturn_get_retval', 'PyGccGimple', - 'gcc_python_make_wrapper_tree(gimple_return_retval(self->stmt))'), + 'gcc_python_make_wrapper_tree(gimple_return_retval(self->stmt.inner))'), None, 'The return value, as a gcc.Tree'), ]) @@ -334,19 +334,19 @@ def generate_gimple_subclasses(): 'PyGccGimple') getsettable.add_simple_getter(cu, 'lhs', - 'gcc_python_make_wrapper_tree(gimple_cond_lhs(self->stmt))', + 'gcc_python_make_wrapper_tree(gimple_cond_lhs(self->stmt.inner))', None) getsettable.add_simple_getter(cu, 'rhs', - 'gcc_python_make_wrapper_tree(gimple_cond_rhs(self->stmt))', + 'gcc_python_make_wrapper_tree(gimple_cond_rhs(self->stmt.inner))', None) getsettable.add_simple_getter(cu, 'true_label', - 'gcc_python_make_wrapper_tree(gimple_cond_true_label(self->stmt))', + 'gcc_python_make_wrapper_tree(gimple_cond_true_label(self->stmt.inner))', None) getsettable.add_simple_getter(cu, 'false_label', - 'gcc_python_make_wrapper_tree(gimple_cond_false_label(self->stmt))', + 'gcc_python_make_wrapper_tree(gimple_cond_false_label(self->stmt.inner))', None) return getsettable
@@ -357,7 +357,7 @@ def generate_gimple_subclasses(): 'PyGccGimple') getsettable.add_simple_getter(cu, 'lhs', - 'gcc_python_make_wrapper_tree(gimple_phi_result(self->stmt))', + 'gcc_python_make_wrapper_tree(gimple_phi_result(self->stmt.inner))', None) getsettable.add_gsdef('args', 'gcc_GimplePhi_get_args', @@ -372,7 +372,7 @@ def generate_gimple_subclasses(): 'PyGccGimple') getsettable.add_simple_getter(cu, 'indexvar', - 'gcc_python_make_wrapper_tree(gimple_switch_index(self->stmt))', + 'gcc_python_make_wrapper_tree(gimple_switch_index(self->stmt.inner))', 'Get the index variable used by the switch statement, as a gcc.Tree') getsettable.add_gsdef('labels', 'gcc_GimpleSwitch_get_labels', @@ -430,9 +430,9 @@ def generate_gimple_code_map():
cu.add_defn(""" PyGccWrapperTypeObject* -gcc_python_autogenerated_gimple_type_for_stmt(gimple g) +gcc_python_autogenerated_gimple_type_for_stmt(GccGimpleI stmt) { - enum gimple_code code = gimple_code(g); + enum gimple_code code = gimple_code(stmt.inner);
/* printf("code:%i\n", code); */ assert(code >= 0); diff --git a/generate-rtl-c.py b/generate-rtl-c.py index 6270298..a08f6fd 100644 --- a/generate-rtl-c.py +++ b/generate-rtl-c.py @@ -159,9 +159,9 @@ def generate_rtl_code_map():
cu.add_defn(""" PyGccWrapperTypeObject* -gcc_python_autogenerated_rtl_type_for_stmt(struct rtx_def *insn) +gcc_python_autogenerated_rtl_type_for_stmt(GccRtlInsnI insn) { - enum rtx_code code = insn->code; + enum rtx_code code = insn.inner->code;
/* printf("code:%i\n", code); */ assert(code >= 0); diff --git a/generate-tree-c.py b/generate-tree-c.py index 54ffdc6..f6fc0d3 100644 --- a/generate-tree-c.py +++ b/generate-tree-c.py @@ -528,7 +528,7 @@ def generate_tree_code_classes(): 'gcc_python_make_wrapper_tree(SSA_NAME_VAR(self->t))', "The variable being referenced'") add_simple_getter('def_stmt', - 'gcc_python_make_wrapper_gimple(SSA_NAME_DEF_STMT(self->t))', + 'gcc_python_make_wrapper_gimple(GccPrivate_make_GimpleI(SSA_NAME_DEF_STMT(self->t)))', "The gcc.Gimple statement which defines this SSA name'") add_simple_getter('version', 'gcc_python_int_from_long(SSA_NAME_VERSION(self->t))', diff --git a/proposed-plugin-api/gcc-cfg.c b/proposed-plugin-api/gcc-cfg.c index 2f08d51..0e98bc3 100644 --- a/proposed-plugin-api/gcc-cfg.c +++ b/proposed-plugin-api/gcc-cfg.c @@ -29,6 +29,8 @@ #include "cgraph.h" #include "opts.h" #include "c-family/c-pragma.h" /* for parse_in */ +#include "basic-block.h" +#include "rtl.h"
/*********************************************************** GccCfgI @@ -121,21 +123,85 @@ GccCfgBlockI_ForEachSuccEdge(GccCfgBlockI block, return for_each_edge(block.inner->succs, cb, user_data); }
+ GCC_IMPLEMENT_PUBLIC_API(bool) -GccCfgBlockI_ForEachPhiNode(GccCfgBlockI block, - bool (*cb)(GccGimplePhiI phi, void *user_data), - void *user_data); +GccCfgBlockI_ForEachGimplePhi(GccCfgBlockI block, + bool (*cb)(GccGimplePhiI phi, void *user_data), + void *user_data) +{ + gimple_stmt_iterator gsi; + + if (block.inner->flags & BB_RTL) { + return false; + } + + if (NULL == block.inner->il.gimple) { + return false; + } + + for (gsi = gsi_start(block.inner->il.gimple->seq); + !gsi_end_p(gsi); + gsi_next(&gsi)) { + + gimple stmt = gsi_stmt(gsi); + if (cb(GccPrivate_make_GimplePhiI(stmt), + user_data)) { + return true; + } + } + + return false; +}
GCC_IMPLEMENT_PUBLIC_API(bool) GccCfgBlockI_ForEachGimple(GccCfgBlockI block, bool (*cb)(GccGimpleI stmt, void *user_data), - void *user_data); + void *user_data) +{ + gimple_stmt_iterator gsi; + + if (block.inner->flags & BB_RTL) { + return false; + } + + if (NULL == block.inner->il.gimple) { + return false; + } + + for (gsi = gsi_start(block.inner->il.gimple->seq); + !gsi_end_p(gsi); + gsi_next(&gsi)) { + + gimple stmt = gsi_stmt(gsi); + if (cb(GccPrivate_make_GimpleI(stmt), + user_data)) { + return true; + } + } + + return false; +}
GCC_IMPLEMENT_PUBLIC_API(bool) GccCfgBlockI_ForEachRtlInsn(GccCfgBlockI block, bool (*cb)(GccRtlInsnI insn, void *user_data), - void *user_data); + void *user_data) +{ + rtx insn;
+ if (!(block.inner->flags & BB_RTL)) { + return false; + } + + FOR_BB_INSNS(block.inner, insn) { + if (cb(GccPrivate_make_RtlInsnI(insn), + user_data)) { + return true; + } + } + + return false; +}
/*********************************************************** GccCfgEdgeI diff --git a/proposed-plugin-api/gcc-cfg.h b/proposed-plugin-api/gcc-cfg.h index 1a2a4ba..c06ab74 100644 --- a/proposed-plugin-api/gcc-cfg.h +++ b/proposed-plugin-api/gcc-cfg.h @@ -62,13 +62,13 @@ GccCfgBlockI_ForEachSuccEdge(GccCfgBlockI block, These will only exist at a certain phase of the compilation */ GCC_PUBLIC_API(bool) -GccCfgBlockI_ForEachPhiNode(GccCfgBlockI block, - bool (*cb)(GccGimplePhiI phi, void *user_data), - void *user_data); +GccCfgBlockI_ForEachGimplePhi(GccCfgBlockI block, + bool (*cb)(GccGimplePhiI phi, void *user_data), + void *user_data);
/* - Iterate over GIMPLE statements (if any); terminate if the callback returns - truth (for linear search) + Iterate over non-phi GIMPLE statements (if any); terminate if the callback + returns truth (for linear search) These will only exist at a certain phase of the compilation */ GCC_PUBLIC_API(bool) diff --git a/proposed-plugin-api/gcc-gimple.c b/proposed-plugin-api/gcc-gimple.c new file mode 100644 index 0000000..a591666 --- /dev/null +++ b/proposed-plugin-api/gcc-gimple.c @@ -0,0 +1,74 @@ +/* + Copyright 2012 David Malcolm dmalcolm@redhat.com + Copyright 2012 Red Hat, Inc. + + This is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + http://www.gnu.org/licenses/. +*/ + +#include "proposed-plugin-api/gcc-gimple.h" + +//#include "tree.h" +#include "gimple.h" +#if 0 +#include "params.h" +#include "cp/name-lookup.h" /* for global_namespace */ +#include "tree.h" +#include "function.h" +#include "diagnostic.h" +#include "cgraph.h" +#include "opts.h" +#include "c-family/c-pragma.h" /* for parse_in */ +#include "basic-block.h" +#include "rtl.h" +#endif + +#include <gcc-plugin.h> + +GCC_IMPLEMENT_PUBLIC_API(void) +GccGimpleI_MarkInUse(GccGimpleI stmt) +{ + /* Mark the underlying object (recursing into its fields): */ + gt_ggc_mx_gimple_statement_d(stmt.inner); +} + +GCC_IMPLEMENT_PRIVATE_API(struct GccGimplePhiI) +GccPrivate_make_GimplePhiI(gimple inner) +{ + struct GccGimplePhiI result; + result.inner = inner; + return result; +} + +GCC_IMPLEMENT_PRIVATE_API(struct GccGimpleI) +GccPrivate_make_GimpleI(gimple inner) +{ + struct GccGimpleI result; + result.inner = inner; + return result; +} + +GCC_IMPLEMENT_PUBLIC_API(GccGimpleI) +GccGimplePhiI_Upcast(GccGimplePhiI phi) +{ + return GccPrivate_make_GimpleI(phi.inner); +} + +/* + PEP-7 +Local variables: +c-basic-offset: 4 +indent-tabs-mode: nil +End: +*/ diff --git a/proposed-plugin-api/gcc-gimple.h b/proposed-plugin-api/gcc-gimple.h new file mode 100644 index 0000000..aff0168 --- /dev/null +++ b/proposed-plugin-api/gcc-gimple.h @@ -0,0 +1,42 @@ +/* + Copyright 2012 David Malcolm dmalcolm@redhat.com + Copyright 2012 Red Hat, Inc. + + This is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + http://www.gnu.org/licenses/. +*/ + +#include "proposed-plugin-api/gcc-common.h" + +/* Gimple statements (generic) */ +GCC_PUBLIC_API(void) +GccGimpleI_MarkInUse(GccGimpleI stmt); + +GCC_PUBLIC_API(void) +GccGimpleI_Print(GccGimpleI stmt, + GccPrinterI printer, + int spc, /* FIXME: meaning of spc! */ + int flags); /* FIXME: meaning of flags! */ + +#if 0 +GCC_PUBLIC_API(bool) +GccGimpleI_WalkTree(GccGimpleI stmt,); +#endif + + +/* Subclasses of gimple */ + +/* Gimple phi nodes */ +GCC_PUBLIC_API(GccGimpleI) +GccGimplePhiI_Upcast(GccGimplePhiI phi); diff --git a/proposed-plugin-api/gcc-public-types.h b/proposed-plugin-api/gcc-public-types.h index dcd3e91..795463d 100644 --- a/proposed-plugin-api/gcc-public-types.h +++ b/proposed-plugin-api/gcc-public-types.h @@ -34,4 +34,7 @@ typedef struct GccGimpleI GccGimpleI; /* Opaque types: RTL representation */ typedef struct GccRtlInsnI GccRtlInsnI;
+/* Opaque types: pretty-printing */ +typedef struct GccPrinterI GccPrinterI; + #endif /* INCLUDED__GCC_PUBLIC_TYPES_H */ diff --git a/proposed-plugin-api/gcc-rtl.c b/proposed-plugin-api/gcc-rtl.c new file mode 100644 index 0000000..c7a15bf --- /dev/null +++ b/proposed-plugin-api/gcc-rtl.c @@ -0,0 +1,46 @@ +/* + Copyright 2012 David Malcolm dmalcolm@redhat.com + Copyright 2012 Red Hat, Inc. + + This is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + http://www.gnu.org/licenses/. +*/ + +#include "proposed-plugin-api/gcc-rtl.h" + +#include <gcc-plugin.h> +#include "tree.h" +#include "rtl.h" + +GCC_IMPLEMENT_PUBLIC_API(void) +GccRtlInsnI_MarkInUse(GccRtlInsnI insn) +{ + gt_ggc_mx_rtx_def(insn.inner); +} + +GCC_IMPLEMENT_PRIVATE_API(struct GccRtlInsnI) +GccPrivate_make_RtlInsnI(struct rtx_def *inner) +{ + struct GccRtlInsnI result; + result.inner = inner; + return result; +} + +/* + PEP-7 +Local variables: +c-basic-offset: 4 +indent-tabs-mode: nil +End: +*/ diff --git a/proposed-plugin-api/gcc-rtl.h b/proposed-plugin-api/gcc-rtl.h new file mode 100644 index 0000000..3ecc223 --- /dev/null +++ b/proposed-plugin-api/gcc-rtl.h @@ -0,0 +1,32 @@ +/* + Copyright 2012 David Malcolm dmalcolm@redhat.com + Copyright 2012 Red Hat, Inc. + + This is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + http://www.gnu.org/licenses/. +*/ + +/* FIXME: rationalize these headers */ +#include <Python.h> +#include "proposed-plugin-api/gcc-common.h" +#include "gcc-python.h" +#include "gcc-python-wrappers.h" +#include "gcc-python-compat.h" +#include "rtl.h" +#include "tree-flow.h" +#include "tree-flow-inline.h" + +/* RTL instructions */ +GCC_PUBLIC_API(void) +GccRtlInsnI_MarkInUse(GccRtlInsnI insn); diff --git a/proposed-plugin-api/gcc-semiprivate-types.h b/proposed-plugin-api/gcc-semiprivate-types.h index fb36a8f..f0b7474 100644 --- a/proposed-plugin-api/gcc-semiprivate-types.h +++ b/proposed-plugin-api/gcc-semiprivate-types.h @@ -56,17 +56,27 @@ GCC_PRIVATE_API(struct GccCfgEdgeI) GccPrivate_make_CfgEdgeI(edge inner);
-#if 0 /* Semiprivate types: GIMPLE representation */ struct GccGimplePhiI { + gimple inner; };
+GCC_PRIVATE_API(struct GccGimplePhiI) +GccPrivate_make_GimplePhiI(gimple inner); + struct GccGimpleI { + gimple inner; };
+GCC_PRIVATE_API(struct GccGimpleI) +GccPrivate_make_GimpleI(gimple inner); + /* Semiprivate types: RTL representation */ struct GccRtlInsnI { + struct rtx_def *inner; }; -#endif + +GCC_PRIVATE_API(struct GccRtlInsnI) +GccPrivate_make_RtlInsnI(struct rtx_def *inner);
#endif /* INCLUDED__GCC_SEMIPRIVATE_TYPES_H */
gcc-python-plugin-commits@lists.stg.fedorahosted.org