@@ -30,29 +30,30 @@ template<Lattice L> inline void BlockState<L>::print(std::ostream& os) {
3030 os << std::endl;
3131}
3232
33- template <Lattice L, typename TransferFunction>
34- inline MonotoneCFGAnalyzer<L, TransferFunction>::MonotoneCFGAnalyzer(
35- L& lattice, TransferFunction& transferFunction, CFG& cfg)
36- : lattice(lattice), transferFunction(transferFunction), cfg(cfg) {
33+ template <Lattice L, TransferFunction TxFn>
34+ inline MonotoneCFGAnalyzer<L, TxFn>::MonotoneCFGAnalyzer(L& lattice,
35+ TxFn& txfn,
36+ CFG& cfg)
37+ : lattice(lattice), txfn(txfn), cfg(cfg) {
3738
3839 // Construct BlockStates for each BasicBlock.
3940 for (auto it = cfg.begin (); it != cfg.end (); it++) {
4041 stateBlocks.emplace_back (&(*it), lattice);
4142 }
4243}
4344
44- template <Lattice L, typename TransferFunction>
45- inline void MonotoneCFGAnalyzer<L, TransferFunction>::evaluateFunctionEntry(
46- Function* func) {
47- transferFunction .evaluateFunctionEntry (func, stateBlocks[0 ].inputState );
45+ template <Lattice L, TransferFunction TxFn >
46+ inline void
47+ MonotoneCFGAnalyzer<L, TxFn>::evaluateFunctionEntry( Function* func) {
48+ txfn .evaluateFunctionEntry (func, stateBlocks[0 ].inputState );
4849}
4950
50- template <Lattice L, typename TransferFunction>
51- inline void MonotoneCFGAnalyzer<L, TransferFunction >::evaluate() {
51+ template <Lattice L, TransferFunction TxFn >
52+ inline void MonotoneCFGAnalyzer<L, TxFn >::evaluate() {
5253 std::queue<const BasicBlock*> worklist;
5354
5455 // Transfer function enqueues the work in some order which is efficient.
55- transferFunction .enqueueWorklist (cfg, worklist);
56+ txfn .enqueueWorklist (cfg, worklist);
5657
5758 while (!worklist.empty ()) {
5859 BlockState<L>& currBlockState = stateBlocks[worklist.front ()->getIndex ()];
@@ -63,10 +64,10 @@ inline void MonotoneCFGAnalyzer<L, TransferFunction>::evaluate() {
6364 // to arrive at the expression's state. The beginning and end states of the
6465 // CFG block will be updated.
6566 typename L::Element outputState = currBlockState.inputState ;
66- transferFunction .transfer (currBlockState.cfgBlock , outputState);
67+ txfn .transfer (currBlockState.cfgBlock , outputState);
6768
6869 // Propagate state to dependents of currBlockState.
69- for (auto & dep : transferFunction .getDependents (currBlockState.cfgBlock )) {
70+ for (auto & dep : txfn .getDependents (currBlockState.cfgBlock )) {
7071 // If we need to change the input state of a dependent, we need
7172 // to enqueue the dependent to recalculate it.
7273 if (stateBlocks[dep.getIndex ()].inputState .makeLeastUpperBound (
@@ -77,28 +78,28 @@ inline void MonotoneCFGAnalyzer<L, TransferFunction>::evaluate() {
7778 }
7879}
7980
80- template <Lattice L, typename TransferFunction>
81- inline void MonotoneCFGAnalyzer<L, TransferFunction >::collectResults() {
81+ template <Lattice L, TransferFunction TxFn >
82+ inline void MonotoneCFGAnalyzer<L, TxFn >::collectResults() {
8283 for (BlockState currBlockState : stateBlocks) {
8384 typename L::Element inputStateCopy = currBlockState.inputState ;
8485
8586 // The transfer function generates the final set of states and uses it to
8687 // produce useful information. For example, in reaching definitions
8788 // analysis, these final states are used to populate a mapping of
8889 // local.get's to a set of local.set's that affect its value.
89- transferFunction .collectResults (currBlockState.cfgBlock , inputStateCopy);
90+ txfn .collectResults (currBlockState.cfgBlock , inputStateCopy);
9091 }
9192}
9293
9394// Currently prints both the basic information and intermediate states of each
9495// BlockState.
95- template <Lattice L, typename TransferFunction>
96- inline void MonotoneCFGAnalyzer<L, TransferFunction >::print(std::ostream& os) {
96+ template <Lattice L, TransferFunction TxFn >
97+ inline void MonotoneCFGAnalyzer<L, TxFn >::print(std::ostream& os) {
9798 os << " CFG Analyzer" << std::endl;
9899 for (auto state : stateBlocks) {
99100 state.print (os);
100101 typename L::Element temp = state.inputState ;
101- transferFunction .print (os, state.cfgBlock , temp);
102+ txfn .print (os, state.cfgBlock , temp);
102103 }
103104 os << " End" << std::endl;
104105}
0 commit comments