Skip to content

Commit

Permalink
Work-in-progress support for GCC 5
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmalcolm committed May 6, 2015
1 parent 4254ccb commit 4376e71
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 58 deletions.
8 changes: 6 additions & 2 deletions gcc-c-api/gcc-callgraph.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2012, 2013 David Malcolm <dmalcolm@redhat.com>
Copyright 2012, 2013 Red Hat, Inc.
Copyright 2012, 2013, 2015 David Malcolm <dmalcolm@redhat.com>
Copyright 2012, 2013, 2015 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
Expand All @@ -21,6 +21,10 @@
#include "tree.h"
#include "cgraph.h"
#include "ggc.h"
#include "tree-ssa-alias.h"
#include "basic-block.h"
#include "gimple-expr.h"
#include "gimple.h"

/***********************************************************
gcc_cgraph_node
Expand Down
8 changes: 6 additions & 2 deletions gcc-c-api/gcc-cfg.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2012, 2013 David Malcolm <dmalcolm@redhat.com>
Copyright 2012, 2013 Red Hat, Inc.
Copyright 2012, 2013, 2015 David Malcolm <dmalcolm@redhat.com>
Copyright 2012, 2013, 2015 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
Expand Down Expand Up @@ -247,7 +247,11 @@ gcc_cfg_block_for_each_rtl_insn (gcc_cfg_block block,
void *user_data),
void *user_data)
{
#if (GCC_VERSION >= 5000)
rtx_insn *insn;
#else
rtx insn;
#endif

if (!(block.inner->flags & BB_RTL))
{
Expand Down
19 changes: 17 additions & 2 deletions gcc-c-api/gcc-common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2012 David Malcolm <dmalcolm@redhat.com>
Copyright 2012 Red Hat, Inc.
Copyright 2012, 2015 David Malcolm <dmalcolm@redhat.com>
Copyright 2012, 2015 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
Expand Down Expand Up @@ -33,3 +33,18 @@
#define GCC_IMPLEMENT_PUBLIC_API(RETURN_TYPE) RETURN_TYPE
#define GCC_IMPLEMENT_PRIVATE_API(RETURN_TYPE) RETURN_TYPE

#if (GCC_VERSION >= 5000)
#define AS_A_GASM(STMT) (as_a <gasm *> (STMT))
#define AS_A_GCOND(STMT) (as_a <gcond *> (STMT))
#define AS_A_GLABEL(STMT) (as_a <glabel *> (STMT))
#define AS_A_GPHI(STMT) (as_a <gphi *> (STMT))
#define AS_A_GSWITCH(STMT) (as_a <gswitch *> (STMT))
#define AS_A_GRETURN(STMT) (as_a <greturn *> (STMT))
#else
#define AS_A_GASM(STMT) (STMT)
#define AS_A_GCOND(STMT) (STMT)
#define AS_A_GLABEL(STMT) (STMT)
#define AS_A_GPHI(STMT) (STMT)
#define AS_A_GSWITCH(STMT) (STMT)
#define AS_A_GRETURN(STMT) (STMT)
#endif
30 changes: 18 additions & 12 deletions gcc-c-api/gcc-gimple.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2012, 2013 David Malcolm <dmalcolm@redhat.com>
Copyright 2012, 2013 Red Hat, Inc.
Copyright 2012, 2013, 2015 David Malcolm <dmalcolm@redhat.com>
Copyright 2012, 2013, 2015 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
Expand Down Expand Up @@ -108,10 +108,10 @@ GCC_IMPLEMENT_PUBLIC_API (gcc_tree) gcc_gimple_get_expr_type (gcc_gimple stmt)
/***************************************************************************
gcc_gimple_asm
**************************************************************************/
GCC_IMPLEMENT_PUBLIC_API (const char *)
GCC_IMPLEMENT_PUBLIC_API (const char *)
gcc_gimple_asm_get_string (gcc_gimple_asm stmt)
{
return gimple_asm_string (stmt.inner);
return gimple_asm_string (AS_A_GASM (stmt.inner));
}

/***************************************************************************
Expand Down Expand Up @@ -172,10 +172,11 @@ gcc_gimple_call_for_each_arg (gcc_gimple_call stmt,
/***************************************************************************
gcc_gimple_return
**************************************************************************/
GCC_IMPLEMENT_PUBLIC_API (gcc_tree)
GCC_IMPLEMENT_PUBLIC_API (gcc_tree)
gcc_gimple_return_get_retval (gcc_gimple_return stmt)
{
return gcc_private_make_tree (gimple_return_retval (stmt.inner));
return gcc_private_make_tree
(gimple_return_retval (AS_A_GRETURN (stmt.inner)));
}

/***************************************************************************
Expand All @@ -196,13 +197,15 @@ gcc_gimple_cond_get_rhs (gcc_gimple_cond stmt)
GCC_IMPLEMENT_PUBLIC_API (gcc_tree)
gcc_gimple_cond_get_true_label (gcc_gimple_cond stmt)
{
return gcc_private_make_tree (gimple_cond_true_label (stmt.inner));
return gcc_private_make_tree (gimple_cond_true_label
(AS_A_GCOND (stmt.inner)));
}

GCC_IMPLEMENT_PUBLIC_API (gcc_tree)
gcc_gimple_cond_get_false_label (gcc_gimple_cond stmt)
{
return gcc_private_make_tree (gimple_cond_false_label (stmt.inner));
return gcc_private_make_tree (gimple_cond_false_label
(AS_A_GCOND (stmt.inner)));
}

/***************************************************************************
Expand Down Expand Up @@ -244,7 +247,8 @@ gcc_gimple_phi_for_each_edges (gcc_gimple_phi phi,
GCC_IMPLEMENT_PUBLIC_API (gcc_tree)
gcc_gimple_switch_get_indexvar (gcc_gimple_switch stmt)
{
return gcc_private_make_tree (gimple_switch_index (stmt.inner));
return gcc_private_make_tree (gimple_switch_index
(AS_A_GSWITCH (stmt.inner)));
}

GCC_IMPLEMENT_PUBLIC_API (bool)
Expand All @@ -253,14 +257,14 @@ gcc_gimple_switch_for_each_label (gcc_gimple_switch stmt,
void *user_data),
void *user_data)
{
unsigned num_labels = gimple_switch_num_labels (stmt.inner);
unsigned num_labels = gimple_switch_num_labels (AS_A_GSWITCH (stmt.inner));
unsigned i;

for (i = 0; i < num_labels; i++)
{
if (cb
(gcc_private_make_case_label_expr
(gimple_switch_label (stmt.inner, i)), user_data))
(gimple_switch_label (AS_A_GSWITCH (stmt.inner), i)), user_data))
{
return true;
}
Expand All @@ -274,7 +278,9 @@ gcc_gimple_switch_for_each_label (gcc_gimple_switch stmt,
GCC_IMPLEMENT_PUBLIC_API(gcc_label_decl)
gcc_gimple_label_get_label(gcc_gimple_label stmt)
{
return gcc_tree_as_gcc_label_decl (gcc_private_make_tree (gimple_label_label (stmt.inner)));
return gcc_tree_as_gcc_label_decl
(gcc_private_make_tree (gimple_label_label
(AS_A_GLABEL (stmt.inner))));
}

/*
Expand Down
8 changes: 6 additions & 2 deletions gcc-python-callgraph.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2011, 2012 David Malcolm <dmalcolm@redhat.com>
Copyright 2011, 2012 Red Hat, Inc.
Copyright 2011, 2012, 2015 David Malcolm <dmalcolm@redhat.com>
Copyright 2011, 2012, 2015 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
Expand Down Expand Up @@ -174,7 +174,11 @@ PyGcc_get_callgraph_nodes(PyObject *self, PyObject *args)
/* For debugging, see GCC's dump of things: */
if (0) {
fprintf(stderr, "----------------BEGIN----------------\n");
#if (GCC_VERSION >= 5000)
cgraph_node::dump_cgraph (stderr);
#else
dump_cgraph (stderr);
#endif
fprintf(stderr, "---------------- END ----------------\n");
}

Expand Down
6 changes: 3 additions & 3 deletions gcc-python-gimple.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2011, 2012, 2013 David Malcolm <dmalcolm@redhat.com>
Copyright 2011, 2012, 2013 Red Hat, Inc.
Copyright 2011-2013, 2015 David Malcolm <dmalcolm@redhat.com>
Copyright 2011-2013, 2015 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
Expand Down Expand Up @@ -358,7 +358,7 @@ PyGccGimplePhi_get_args(struct PyGccGimple *self, void *closure)

for (i = 0 ; i < num_args; i++) {
tree arg_def = gimple_phi_arg_def(self->stmt.inner, i);
edge arg_edge = gimple_phi_arg_edge(self->stmt.inner, i);
edge arg_edge = gimple_phi_arg_edge(AS_A_GPHI(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&",
Expand Down
45 changes: 29 additions & 16 deletions gcc-python-pass.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2011, 2012, 2013 David Malcolm <dmalcolm@redhat.com>
Copyright 2011, 2012, 2013 Red Hat, Inc.
Copyright 2011-2013, 2015 David Malcolm <dmalcolm@redhat.com>
Copyright 2011-2013, 2015 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
Expand Down Expand Up @@ -42,7 +42,7 @@
*/
static PyObject *pass_wrapper_cache = NULL;

static bool impl_gate(void)
static bool impl_gate(function *fun)
{
PyObject *pass_obj;
PyObject *cfun_obj = NULL;
Expand Down Expand Up @@ -72,8 +72,9 @@ static bool impl_gate(void)
return true;
}

/* Supply the current function, if any */
if (cfun) {
/* Supply the function, if any */
if (fun) {
assert (fun == cfun);
gcc_function cf = gcc_get_current_function();

/* Temporarily override input_location to the top of the function: */
Expand Down Expand Up @@ -106,7 +107,7 @@ static bool impl_gate(void)
return result;
}

static unsigned int impl_execute(void)
static unsigned int impl_execute(function *fun)
{
PyObject *pass_obj;
PyObject *cfun_obj = NULL;
Expand All @@ -117,8 +118,8 @@ static unsigned int impl_execute(void)
pass_obj = PyGccPass_New(current_pass);
assert(pass_obj); /* we own a ref at this point */

/* Supply the current function, if any */
if (cfun) {
if (fun) {
assert (fun == cfun);
gcc_function cf = gcc_get_current_function();

/* Temporarily override input_location to the top of the function: */
Expand Down Expand Up @@ -182,6 +183,20 @@ static unsigned int impl_execute(void)
GCC 4.9 converted passes to a C++ class hierarchy, with methods for gate
and execute.
*/

#if (GCC_VERSION >= 5000)
/* GCC 5 added a "fun" param to the "gate" and "execute" vfuncs of
pass opt_pass. */
# define PASS_DECLARE_GATE_AND_EXECUTE \
bool gate (function *fun) { return impl_gate(fun); } \
unsigned int execute (function *fun) { return impl_execute(fun); }
#else
/* ...whereas in GCC 4.9 they took no params, with cfun being implied. */
# define PASS_DECLARE_GATE_AND_EXECUTE \
bool gate () { return impl_gate(cfun); } \
unsigned int execute () { return impl_execute(cfun); }
#endif /* #if (GCC_VERSION >= 5000) */

class PyGccGimplePass : public gimple_opt_pass
{
public:
Expand All @@ -190,8 +205,7 @@ class PyGccGimplePass : public gimple_opt_pass
{
}

bool gate () { return impl_gate(); }
unsigned int execute () { return impl_execute(); }
PASS_DECLARE_GATE_AND_EXECUTE
opt_pass *clone() {return this; }
};

Expand All @@ -203,8 +217,7 @@ class PyGccRtlPass : public rtl_opt_pass
{
}

bool gate () { return impl_gate(); }
unsigned int execute () { return impl_execute(); }
PASS_DECLARE_GATE_AND_EXECUTE
opt_pass *clone() {return this; }
};

Expand All @@ -225,8 +238,7 @@ class PyGccIpaPass : public ipa_opt_pass_d
{
}

bool gate () { return impl_gate(); }
unsigned int execute () { return impl_execute(); }
PASS_DECLARE_GATE_AND_EXECUTE
opt_pass *clone() {return this; }
};

Expand All @@ -238,8 +250,7 @@ class PyGccSimpleIpaPass : public simple_ipa_opt_pass
{
}

bool gate () { return impl_gate(); }
unsigned int execute () { return impl_execute(); }
PASS_DECLARE_GATE_AND_EXECUTE
opt_pass *clone() {return this; }
};

Expand Down Expand Up @@ -272,8 +283,10 @@ do_pass_init(PyObject *s, PyObject *args, PyObject *kwargs,
memset(&pass_data, 0, sizeof(pass_data));
pass_data.type = pass_type;
pass_data.name = PyGcc_strdup(name);
#if (GCC_VERSION < 5000)
pass_data.has_gate = true;
pass_data.has_execute = true;
#endif
switch (pass_type) {
case GIMPLE_PASS:
pass = new PyGccGimplePass (pass_data, g);
Expand Down
6 changes: 4 additions & 2 deletions gcc-python-rtl.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2011, 2012, 2013 David Malcolm <dmalcolm@redhat.com>
Copyright 2011, 2012, 2013 Red Hat, Inc.
Copyright 2011-2013, 2015 David Malcolm <dmalcolm@redhat.com>
Copyright 2011-2013, 2015 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
Expand All @@ -24,6 +24,7 @@
#include "rtl.h"
#include "gcc-c-api/gcc-rtl.h"

#if (GCC_VERSION < 5000)
PyObject *
PyGccRtl_get_location(struct PyGccRtl *self, void *closure)
{
Expand All @@ -38,6 +39,7 @@ PyGccRtl_get_location(struct PyGccRtl *self, void *closure)
Py_RETURN_NONE;
#endif
}
#endif

PyObject *
get_operand_as_object(const_rtx in_rtx, int idx, char fmt)
Expand Down
17 changes: 15 additions & 2 deletions gcc-python-tree.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2011, 2012, 2013 David Malcolm <dmalcolm@redhat.com>
Copyright 2011, 2012, 2013 Red Hat, Inc.
Copyright 2011-2015 David Malcolm <dmalcolm@redhat.com>
Copyright 2011-2015 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
Expand Down Expand Up @@ -336,6 +336,19 @@ PyGccFunctionDecl_get_fullname(struct PyGccTree *self, void *closure)
return PyGccString_FromString(str);
}

PyObject *
PyGccFunctionDecl_get_callgraph_node(struct PyGccTree *self, void *closure)
{
/* cgraph_get_node became cgraph_node::get in 5.0 */
struct cgraph_node *node;
#if (GCC_VERSION >= 5000)
node = cgraph_node::get(self->t.inner);
#else
node = cgraph_get_node(self->t.inner);
#endif
return PyGccCallgraphNode_New(gcc_private_make_cgraph_node(node));
}

PyObject *
PyGccArrayRef_repr(PyObject *self)
{
Expand Down
Loading

0 comments on commit 4376e71

Please sign in to comment.