Inferno
0.2
|
00001 #ifndef STATE_OUT_HPP 00002 #define STATE_OUT_HPP 00003 00004 #include "sr/search_replace.hpp" 00005 00006 namespace Steps { 00007 00008 /// Make sure every SystemC wait is followed by a goto 00009 /** This is in preparation for state-out/fall-out. We will only reorganise the 00010 program around gotos, and so we need to have a goto in place to re-organise. 00011 This means we can't then optimise away ineffectual gotos, to do that we would 00012 need to mark the goto in some way, or just ignore it if preceeded by a wait */ 00013 class GotoAfterWait : public SearchReplace 00014 { 00015 public: 00016 GotoAfterWait(); 00017 }; 00018 00019 /** conditionasl branch with no else clause gets goto in both 00020 clauses - generates new label for this. */ 00021 class NormaliseConditionalGotos : public SearchReplace 00022 { 00023 public: 00024 NormaliseConditionalGotos(); 00025 }; 00026 00027 /** conditional branch follwed by goto becomes goto with a conditional (ternary 00028 op) on the address. */ 00029 class CompactGotos : public SearchReplace 00030 { 00031 public: 00032 CompactGotos(); 00033 }; 00034 00035 /** Labels not preceeded by a goto get a goto before them */ 00036 class AddGotoBeforeLabel : public SearchReplace 00037 { 00038 public: 00039 AddGotoBeforeLabel(); 00040 }; 00041 00042 /** Insert a bootstrapping state transition at the top of the function. */ 00043 class EnsureBootstrap : public SearchReplace 00044 { 00045 public: 00046 EnsureBootstrap(); 00047 }; 00048 00049 /** Add a variable for the current state as a label variable, and 00050 use it for the gotos. */ 00051 class AddStateLabelVar : public SearchReplace 00052 { 00053 public: 00054 AddStateLabelVar(); 00055 }; 00056 00057 /** If there is no infinite loop enclosing the whole function body 00058 (excluding initial assignments), insert one. */ 00059 class EnsureSuperLoop : public SearchReplace 00060 { 00061 public: 00062 EnsureSuperLoop(); 00063 }; 00064 00065 /** If there is an infinite loop with a goto at the top of it, replace any 00066 identical gotos elsewhere in the loop body with continues */ 00067 class ShareGotos : public SearchReplace 00068 { 00069 public: 00070 ShareGotos(); 00071 }; 00072 00073 /** If there's a structure of gotos and labels that looks like a switch statement 00074 then insert a switch statement, turn labels into enums and the type of the 00075 control variable from void * to the new enum */ 00076 class InsertSwitch : public SearchReplace 00077 { 00078 public: 00079 InsertSwitch(); 00080 }; 00081 00082 /** Just move the last part of a switch statement - from the last label (not case) 00083 onward out of the switch if there are no breaks */ 00084 class SwitchCleanUp : public SearchReplace 00085 { 00086 public: 00087 SwitchCleanUp(); 00088 }; 00089 00090 /** Insert break statements whenever there are equivalant gotos */ 00091 class InferBreak : public SearchReplace 00092 { 00093 public: 00094 InferBreak(); 00095 }; 00096 00097 /** fix fallthroughs by duplicating the fallen-into statements */ 00098 class FixFallthrough : public SearchReplace 00099 { 00100 public: 00101 FixFallthrough(); 00102 }; 00103 00104 /** Go to fallthrough machine style */ 00105 class MakeFallThroughMachine : public SearchReplace 00106 { 00107 public: 00108 MakeFallThroughMachine(); 00109 }; 00110 00111 /** Add a flag to the state machine for yields */ 00112 class AddYieldFlag : public SearchReplace 00113 { 00114 public: 00115 AddYieldFlag(); 00116 }; 00117 00118 /** Yield at bottom of superloop if not already yielded */ 00119 class AddInferredYield : public SearchReplace 00120 { 00121 public: 00122 AddInferredYield(); 00123 }; 00124 00125 /** Move initial code into superloop, but only on first delta cycle */ 00126 class MoveInitIntoSuperLoop : public SearchReplace 00127 { 00128 public: 00129 MoveInitIntoSuperLoop(); 00130 }; 00131 00132 /** Optimise loops that contain yields by rotating until yield reaches the bottom */ 00133 class LoopRotation : public SearchReplace 00134 { 00135 public: 00136 LoopRotation(); 00137 }; 00138 00139 }; // end namespace 00140 00141 #endif 00142