Skip to content

Instantly share code, notes, and snippets.

@pgoodman
Created March 25, 2012 20:10
Show Gist options
  • Select an option

  • Save pgoodman/2199466 to your computer and use it in GitHub Desktop.

Select an option

Save pgoodman/2199466 to your computer and use it in GitHub Desktop.
#define MAIN static simple_instr *print_dot(simple_instr *inlist, char *proc_name)
# include "dot.cc"
#undef MAIN
#include "include/optimizer.h"
#include "include/opt/cf.h"
#include "include/opt/cp.h"
#include "include/opt/dce.h"
#include "include/opt/cse.h"
static optimizer::pass CF, CP, DCE, CSE;
/// set up and run the optimizer
///
/// the optimizer is organized in terms of groups of single pass optimizations,
/// where each group is treated as an optimization. The distinction exists to
/// allow cycles among optimization groups but not optimizations.
simple_instr *do_procedure(simple_instr *in_list, char *proc_name) {
optimizer o(in_list);
CF = o.add_pass(fold_constants);
CP = o.add_pass(propagate_copies);
DCE = o.add_pass(eliminate_dead_code);
CSE = o.add_pass(eliminate_common_sub_expressions);
// 5 7
// 1 .--------<---------.-<--.
// .-<-. 2 4 | |
// -`-> CP ->- CF ->- DCE -'->- CSE ->-
// `--<--' 6 8
// 3
o.cascade_if(CP, CP, true); // 1
o.cascade_if(CP, CF, false); // 2
o.cascade_if(CF, CP, true); // 3
o.cascade_if(CF, DCE, false); // 4
o.cascade_if(DCE, CP, true); // 5
o.cascade_if(DCE, CSE, false); // 6
o.cascade_if(CSE, CP, true); // 7
o.run(CP);
//return o.first_instruction();
return print_dot(o.first_instruction(), proc_name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment