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
4242*/
4343static 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+
185200class PyGccGimplePass : public gimple_opt_pass
186201{
187202public :
@@ -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 );
0 commit comments