bles? (Dataflow analysis, aka DFA). This flag was removed in GCC 4.8 “*referenced_vars” (none) gcc.PROP_ssa Is the GIMPLE in SSA form? “ssa” “expand” gcc.PROP_no_crit_edges Have all critical edges within the CFG been split? “crited” (none) gcc.PROP_rtl Is the function now in RTL form? (rather than GIMPLE-SSA) “expand” “*clean_state” gcc.PROP_gimple_lomp Have OpenMP directives been lowered into explicit calls to the runtime library (libgomp) “omplower” “expand” gcc.PROP_cfglayout Are we reorganizing the CFG into a more efficient order? “into_cfglayout” “outof_cfglayout” gcc.PROP_gimple_lcx Have operations on complex numbers been lowered to scalar operations? “cplxlower” “cplxlower0”
(int) The number of this pass, used as a fragment of the dump file name. This is assigned automatically for custom passes.
(boolean) Is dumping enabled for this pass? Set this attribute to True to enable dumping. Not available from GCC 4.8 onwards
There are four subclasses of
gcc.Pass, signifying a pass called per-function on the GIMPLE representation of that function.
gcc.Pass, signifying a pass called per-function on the RTL representation of that function.
Creating new optimization passes¶
You can create new optimization passes. This involves three steps:
Here’s an example:
# Here's the (trivial) implementation of our new pass: class MyPass(gcc.GimplePass): # This is optional. # If present, it should return a bool, specifying whether or not # to execute this pass (and any child passes) def gate(self, fun): print('gate() called for %r' % fun) return True def execute(self, fun): print('execute() called for %r' % fun) # We now create an instance of the class: my_pass = MyPass(name='my-pass') # ...and wire it up, after the "cfg" pass: my_pass.register_after('cfg')
where fun is a
Unfortunately it doesn’t appear to be possible to implement gate() for gcc.IpaPass yet; for now, the gate() method on such passes will not be called. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54959
If an unhandled exception is raised within gate or execute, it will lead to a GCC error:
/home/david/test.c:36:1: error: Unhandled Python exception raised calling 'execute' method Traceback (most recent call last): File "script.py", line 79, in execute dot = gccutils.tree_to_dot(fun) NameError: global name 'gccutils' is not defined
Given the name of another pass, register this
gcc.Passto occur immediately after that other pass.
If the other pass occurs multiple times, the pass will be inserted at the specified instance number, or at every instance, if supplied 0.
If they don’t match, GCC won’t be able to find the other pass, giving an error like this:
cc1: fatal error: pass 'ssa' not found but is referenced by new pass 'my-ipa-pass'
As above, but this pass is registered immediately before the referenced pass.
As above, but replace the given pass. This method is included for completeness; the result is unlikely to work well.
Dumping per-pass information¶
GCC has a logging framework which supports per-pass logging (“dump files”).
By default, no logging is done; dumping must be explicitly enabled.
Dumping of passes can be enabled from the command-line in groups:
For more information, see http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
It’s not possible to directly enable dumping for a custom pass from the command-line (it would require adding new GCC command-line options). However, your script can directly enable dumping for a custom pass by writing to the dump_enabled attribute (perhaps in response to the arguments passed to plugin, or a driver script).
If enabled for a pass, then a file is written to the same directory as the output file, with a name based on the input file and the pass number.
For example, given a custom
gcc.Pass with name ‘test-pass’, then
when input.c is compiled to build/output.o:
$ gcc -fdump-tree-all -o build/output.o src/input.c
then a dump file input.c.225t.test-pass will be written to the directory build. In this case, 225 is the static_pass_number field, “t” signifies a tree pass, with the pass name appearing as the suffix.
Write str()