Skip to content

Commit 4376e71

Browse files
committed
Work-in-progress support for GCC 5
1 parent 4254ccb commit 4376e71

13 files changed

+141
-58
lines changed

gcc-c-api/gcc-callgraph.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2012, 2013 David Malcolm <[email protected]>
3-
Copyright 2012, 2013 Red Hat, Inc.
2+
Copyright 2012, 2013, 2015 David Malcolm <[email protected]>
3+
Copyright 2012, 2013, 2015 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -21,6 +21,10 @@
2121
#include "tree.h"
2222
#include "cgraph.h"
2323
#include "ggc.h"
24+
#include "tree-ssa-alias.h"
25+
#include "basic-block.h"
26+
#include "gimple-expr.h"
27+
#include "gimple.h"
2428

2529
/***********************************************************
2630
gcc_cgraph_node

gcc-c-api/gcc-cfg.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2012, 2013 David Malcolm <[email protected]>
3-
Copyright 2012, 2013 Red Hat, Inc.
2+
Copyright 2012, 2013, 2015 David Malcolm <[email protected]>
3+
Copyright 2012, 2013, 2015 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -247,7 +247,11 @@ gcc_cfg_block_for_each_rtl_insn (gcc_cfg_block block,
247247
void *user_data),
248248
void *user_data)
249249
{
250+
#if (GCC_VERSION >= 5000)
251+
rtx_insn *insn;
252+
#else
250253
rtx insn;
254+
#endif
251255

252256
if (!(block.inner->flags & BB_RTL))
253257
{

gcc-c-api/gcc-common.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2012 David Malcolm <[email protected]>
3-
Copyright 2012 Red Hat, Inc.
2+
Copyright 2012, 2015 David Malcolm <[email protected]>
3+
Copyright 2012, 2015 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -33,3 +33,18 @@
3333
#define GCC_IMPLEMENT_PUBLIC_API(RETURN_TYPE) RETURN_TYPE
3434
#define GCC_IMPLEMENT_PRIVATE_API(RETURN_TYPE) RETURN_TYPE
3535

36+
#if (GCC_VERSION >= 5000)
37+
#define AS_A_GASM(STMT) (as_a <gasm *> (STMT))
38+
#define AS_A_GCOND(STMT) (as_a <gcond *> (STMT))
39+
#define AS_A_GLABEL(STMT) (as_a <glabel *> (STMT))
40+
#define AS_A_GPHI(STMT) (as_a <gphi *> (STMT))
41+
#define AS_A_GSWITCH(STMT) (as_a <gswitch *> (STMT))
42+
#define AS_A_GRETURN(STMT) (as_a <greturn *> (STMT))
43+
#else
44+
#define AS_A_GASM(STMT) (STMT)
45+
#define AS_A_GCOND(STMT) (STMT)
46+
#define AS_A_GLABEL(STMT) (STMT)
47+
#define AS_A_GPHI(STMT) (STMT)
48+
#define AS_A_GSWITCH(STMT) (STMT)
49+
#define AS_A_GRETURN(STMT) (STMT)
50+
#endif

gcc-c-api/gcc-gimple.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2012, 2013 David Malcolm <[email protected]>
3-
Copyright 2012, 2013 Red Hat, Inc.
2+
Copyright 2012, 2013, 2015 David Malcolm <[email protected]>
3+
Copyright 2012, 2013, 2015 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -108,10 +108,10 @@ GCC_IMPLEMENT_PUBLIC_API (gcc_tree) gcc_gimple_get_expr_type (gcc_gimple stmt)
108108
/***************************************************************************
109109
gcc_gimple_asm
110110
**************************************************************************/
111-
GCC_IMPLEMENT_PUBLIC_API (const char *)
111+
GCC_IMPLEMENT_PUBLIC_API (const char *)
112112
gcc_gimple_asm_get_string (gcc_gimple_asm stmt)
113113
{
114-
return gimple_asm_string (stmt.inner);
114+
return gimple_asm_string (AS_A_GASM (stmt.inner));
115115
}
116116

117117
/***************************************************************************
@@ -172,10 +172,11 @@ gcc_gimple_call_for_each_arg (gcc_gimple_call stmt,
172172
/***************************************************************************
173173
gcc_gimple_return
174174
**************************************************************************/
175-
GCC_IMPLEMENT_PUBLIC_API (gcc_tree)
175+
GCC_IMPLEMENT_PUBLIC_API (gcc_tree)
176176
gcc_gimple_return_get_retval (gcc_gimple_return stmt)
177177
{
178-
return gcc_private_make_tree (gimple_return_retval (stmt.inner));
178+
return gcc_private_make_tree
179+
(gimple_return_retval (AS_A_GRETURN (stmt.inner)));
179180
}
180181

181182
/***************************************************************************
@@ -196,13 +197,15 @@ gcc_gimple_cond_get_rhs (gcc_gimple_cond stmt)
196197
GCC_IMPLEMENT_PUBLIC_API (gcc_tree)
197198
gcc_gimple_cond_get_true_label (gcc_gimple_cond stmt)
198199
{
199-
return gcc_private_make_tree (gimple_cond_true_label (stmt.inner));
200+
return gcc_private_make_tree (gimple_cond_true_label
201+
(AS_A_GCOND (stmt.inner)));
200202
}
201203

202204
GCC_IMPLEMENT_PUBLIC_API (gcc_tree)
203205
gcc_gimple_cond_get_false_label (gcc_gimple_cond stmt)
204206
{
205-
return gcc_private_make_tree (gimple_cond_false_label (stmt.inner));
207+
return gcc_private_make_tree (gimple_cond_false_label
208+
(AS_A_GCOND (stmt.inner)));
206209
}
207210

208211
/***************************************************************************
@@ -244,7 +247,8 @@ gcc_gimple_phi_for_each_edges (gcc_gimple_phi phi,
244247
GCC_IMPLEMENT_PUBLIC_API (gcc_tree)
245248
gcc_gimple_switch_get_indexvar (gcc_gimple_switch stmt)
246249
{
247-
return gcc_private_make_tree (gimple_switch_index (stmt.inner));
250+
return gcc_private_make_tree (gimple_switch_index
251+
(AS_A_GSWITCH (stmt.inner)));
248252
}
249253

250254
GCC_IMPLEMENT_PUBLIC_API (bool)
@@ -253,14 +257,14 @@ gcc_gimple_switch_for_each_label (gcc_gimple_switch stmt,
253257
void *user_data),
254258
void *user_data)
255259
{
256-
unsigned num_labels = gimple_switch_num_labels (stmt.inner);
260+
unsigned num_labels = gimple_switch_num_labels (AS_A_GSWITCH (stmt.inner));
257261
unsigned i;
258262

259263
for (i = 0; i < num_labels; i++)
260264
{
261265
if (cb
262266
(gcc_private_make_case_label_expr
263-
(gimple_switch_label (stmt.inner, i)), user_data))
267+
(gimple_switch_label (AS_A_GSWITCH (stmt.inner), i)), user_data))
264268
{
265269
return true;
266270
}
@@ -274,7 +278,9 @@ gcc_gimple_switch_for_each_label (gcc_gimple_switch stmt,
274278
GCC_IMPLEMENT_PUBLIC_API(gcc_label_decl)
275279
gcc_gimple_label_get_label(gcc_gimple_label stmt)
276280
{
277-
return gcc_tree_as_gcc_label_decl (gcc_private_make_tree (gimple_label_label (stmt.inner)));
281+
return gcc_tree_as_gcc_label_decl
282+
(gcc_private_make_tree (gimple_label_label
283+
(AS_A_GLABEL (stmt.inner))));
278284
}
279285

280286
/*

gcc-python-callgraph.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2011, 2012 David Malcolm <[email protected]>
3-
Copyright 2011, 2012 Red Hat, Inc.
2+
Copyright 2011, 2012, 2015 David Malcolm <[email protected]>
3+
Copyright 2011, 2012, 2015 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -174,7 +174,11 @@ PyGcc_get_callgraph_nodes(PyObject *self, PyObject *args)
174174
/* For debugging, see GCC's dump of things: */
175175
if (0) {
176176
fprintf(stderr, "----------------BEGIN----------------\n");
177+
#if (GCC_VERSION >= 5000)
178+
cgraph_node::dump_cgraph (stderr);
179+
#else
177180
dump_cgraph (stderr);
181+
#endif
178182
fprintf(stderr, "---------------- END ----------------\n");
179183
}
180184

gcc-python-gimple.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2011, 2012, 2013 David Malcolm <[email protected]>
3-
Copyright 2011, 2012, 2013 Red Hat, Inc.
2+
Copyright 2011-2013, 2015 David Malcolm <[email protected]>
3+
Copyright 2011-2013, 2015 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -358,7 +358,7 @@ PyGccGimplePhi_get_args(struct PyGccGimple *self, void *closure)
358358

359359
for (i = 0 ; i < num_args; i++) {
360360
tree arg_def = gimple_phi_arg_def(self->stmt.inner, i);
361-
edge arg_edge = gimple_phi_arg_edge(self->stmt.inner, i);
361+
edge arg_edge = gimple_phi_arg_edge(AS_A_GPHI(self->stmt.inner), i);
362362
/* fwiw, there's also gimple_phi_arg_has_location and gimple_phi_arg_location */
363363
PyObject *tuple_obj;
364364
tuple_obj = Py_BuildValue("O&O&",

gcc-python-pass.c

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2011, 2012, 2013 David Malcolm <[email protected]>
3-
Copyright 2011, 2012, 2013 Red Hat, Inc.
2+
Copyright 2011-2013, 2015 David Malcolm <[email protected]>
3+
Copyright 2011-2013, 2015 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -42,7 +42,7 @@
4242
*/
4343
static PyObject *pass_wrapper_cache = NULL;
4444

45-
static bool impl_gate(void)
45+
static bool impl_gate(function *fun)
4646
{
4747
PyObject *pass_obj;
4848
PyObject *cfun_obj = NULL;
@@ -72,8 +72,9 @@ static bool impl_gate(void)
7272
return true;
7373
}
7474

75-
/* Supply the current function, if any */
76-
if (cfun) {
75+
/* Supply the function, if any */
76+
if (fun) {
77+
assert (fun == cfun);
7778
gcc_function cf = gcc_get_current_function();
7879

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

109-
static unsigned int impl_execute(void)
110+
static unsigned int impl_execute(function *fun)
110111
{
111112
PyObject *pass_obj;
112113
PyObject *cfun_obj = NULL;
@@ -117,8 +118,8 @@ static unsigned int impl_execute(void)
117118
pass_obj = PyGccPass_New(current_pass);
118119
assert(pass_obj); /* we own a ref at this point */
119120

120-
/* Supply the current function, if any */
121-
if (cfun) {
121+
if (fun) {
122+
assert (fun == cfun);
122123
gcc_function cf = gcc_get_current_function();
123124

124125
/* Temporarily override input_location to the top of the function: */
@@ -182,6 +183,20 @@ static unsigned int impl_execute(void)
182183
GCC 4.9 converted passes to a C++ class hierarchy, with methods for gate
183184
and execute.
184185
*/
186+
187+
#if (GCC_VERSION >= 5000)
188+
/* GCC 5 added a "fun" param to the "gate" and "execute" vfuncs of
189+
pass opt_pass. */
190+
# define PASS_DECLARE_GATE_AND_EXECUTE \
191+
bool gate (function *fun) { return impl_gate(fun); } \
192+
unsigned int execute (function *fun) { return impl_execute(fun); }
193+
#else
194+
/* ...whereas in GCC 4.9 they took no params, with cfun being implied. */
195+
# define PASS_DECLARE_GATE_AND_EXECUTE \
196+
bool gate () { return impl_gate(cfun); } \
197+
unsigned int execute () { return impl_execute(cfun); }
198+
#endif /* #if (GCC_VERSION >= 5000) */
199+
185200
class PyGccGimplePass : public gimple_opt_pass
186201
{
187202
public:
@@ -190,8 +205,7 @@ class PyGccGimplePass : public gimple_opt_pass
190205
{
191206
}
192207

193-
bool gate () { return impl_gate(); }
194-
unsigned int execute () { return impl_execute(); }
208+
PASS_DECLARE_GATE_AND_EXECUTE
195209
opt_pass *clone() {return this; }
196210
};
197211

@@ -203,8 +217,7 @@ class PyGccRtlPass : public rtl_opt_pass
203217
{
204218
}
205219

206-
bool gate () { return impl_gate(); }
207-
unsigned int execute () { return impl_execute(); }
220+
PASS_DECLARE_GATE_AND_EXECUTE
208221
opt_pass *clone() {return this; }
209222
};
210223

@@ -225,8 +238,7 @@ class PyGccIpaPass : public ipa_opt_pass_d
225238
{
226239
}
227240

228-
bool gate () { return impl_gate(); }
229-
unsigned int execute () { return impl_execute(); }
241+
PASS_DECLARE_GATE_AND_EXECUTE
230242
opt_pass *clone() {return this; }
231243
};
232244

@@ -238,8 +250,7 @@ class PyGccSimpleIpaPass : public simple_ipa_opt_pass
238250
{
239251
}
240252

241-
bool gate () { return impl_gate(); }
242-
unsigned int execute () { return impl_execute(); }
253+
PASS_DECLARE_GATE_AND_EXECUTE
243254
opt_pass *clone() {return this; }
244255
};
245256

@@ -272,8 +283,10 @@ do_pass_init(PyObject *s, PyObject *args, PyObject *kwargs,
272283
memset(&pass_data, 0, sizeof(pass_data));
273284
pass_data.type = pass_type;
274285
pass_data.name = PyGcc_strdup(name);
286+
#if (GCC_VERSION < 5000)
275287
pass_data.has_gate = true;
276288
pass_data.has_execute = true;
289+
#endif
277290
switch (pass_type) {
278291
case GIMPLE_PASS:
279292
pass = new PyGccGimplePass (pass_data, g);

gcc-python-rtl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2011, 2012, 2013 David Malcolm <[email protected]>
3-
Copyright 2011, 2012, 2013 Red Hat, Inc.
2+
Copyright 2011-2013, 2015 David Malcolm <[email protected]>
3+
Copyright 2011-2013, 2015 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
2424
#include "rtl.h"
2525
#include "gcc-c-api/gcc-rtl.h"
2626

27+
#if (GCC_VERSION < 5000)
2728
PyObject *
2829
PyGccRtl_get_location(struct PyGccRtl *self, void *closure)
2930
{
@@ -38,6 +39,7 @@ PyGccRtl_get_location(struct PyGccRtl *self, void *closure)
3839
Py_RETURN_NONE;
3940
#endif
4041
}
42+
#endif
4143

4244
PyObject *
4345
get_operand_as_object(const_rtx in_rtx, int idx, char fmt)

gcc-python-tree.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2011, 2012, 2013 David Malcolm <[email protected]>
3-
Copyright 2011, 2012, 2013 Red Hat, Inc.
2+
Copyright 2011-2015 David Malcolm <[email protected]>
3+
Copyright 2011-2015 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -336,6 +336,19 @@ PyGccFunctionDecl_get_fullname(struct PyGccTree *self, void *closure)
336336
return PyGccString_FromString(str);
337337
}
338338

339+
PyObject *
340+
PyGccFunctionDecl_get_callgraph_node(struct PyGccTree *self, void *closure)
341+
{
342+
/* cgraph_get_node became cgraph_node::get in 5.0 */
343+
struct cgraph_node *node;
344+
#if (GCC_VERSION >= 5000)
345+
node = cgraph_node::get(self->t.inner);
346+
#else
347+
node = cgraph_get_node(self->t.inner);
348+
#endif
349+
return PyGccCallgraphNode_New(gcc_private_make_cgraph_node(node));
350+
}
351+
339352
PyObject *
340353
PyGccArrayRef_repr(PyObject *self)
341354
{

0 commit comments

Comments
 (0)