@@ -37,17 +37,17 @@ public class Environment
3737 /// </summary>
3838 private System . Collections . BitArray _metricUpdated ;
3939 /// <summary>
40- /// Current Cyclic execution Thresold by block index.
40+ /// Current Cyclic execution Threshold by block index.
4141 /// </summary>
4242 private Dictionary < int , int > _cyclicThreshold ;
4343 /// <summary>
44- /// The Cyclic relation from one block index to another block index
44+ /// The Cyclic transition from one block index to another block index
4545 /// </summary>
46- private Dictionary < int , HashSet < int > > _cyclicRelation ;
46+ private Dictionary < int , HashSet < int > > _cyclicTransition ;
4747 /// <summary>
4848 /// Number maximal of cyclic execution for a block index.
4949 /// </summary>
50- private int _cyclicExecutionThresold ;
50+ private int _cyclicExecutionThreshold ;
5151 /// <summary>
5252 /// Current CFG being run.
5353 /// </summary>
@@ -63,9 +63,9 @@ public Environment(params IObserver[] observers)
6363 }
6464
6565 /// <summary>
66- /// Intialize internal data structures.
66+ /// Reset internal data structures.
6767 /// </summary>
68- private void Initialize ( )
68+ private void Reset ( )
6969 {
7070 if ( _interpretationStack == null )
7171 _interpretationStack = new Stack < BasicBlock < N , D > > ( ) ;
@@ -76,10 +76,10 @@ private void Initialize()
7676 _cyclicThreshold = new Dictionary < int , int > ( ) ;
7777 else
7878 _cyclicThreshold . Clear ( ) ;
79- if ( _cyclicRelation == null )
80- _cyclicRelation = new Dictionary < int , HashSet < int > > ( ) ;
79+ if ( _cyclicTransition == null )
80+ _cyclicTransition = new Dictionary < int , HashSet < int > > ( ) ;
8181 else
82- _cyclicRelation . Clear ( ) ;
82+ _cyclicTransition . Clear ( ) ;
8383 }
8484
8585 /// <summary>
@@ -91,9 +91,9 @@ private void Initialize()
9191 public virtual Metrics Run ( ControlFlowGraph < N , D > cfg , int cyclicExecutionThreshold = 0 )
9292 {
9393 this . Cfg = cfg ;
94- this . _cyclicExecutionThresold = cyclicExecutionThreshold ;
95- Initialize ( ) ;
96- SetCyclicityThresold ( ) ;
94+ this . _cyclicExecutionThreshold = cyclicExecutionThreshold ;
95+ Reset ( ) ;
96+ SetCyclicityThreshold ( ) ;
9797 this . _metrics = new Metrics ( ) ;
9898 Run ( cfg . RootBlock , null ) ;
9999 System . Diagnostics . Debug . Assert ( _interpretationStack . Count == 0 ) ;
@@ -102,9 +102,9 @@ public virtual Metrics Run(ControlFlowGraph<N, D> cfg, int cyclicExecutionThresh
102102 }
103103
104104 /// <summary>
105- /// Set the Cyclicity Thresold for cyclic blocks of the graph.
105+ /// Set the Cyclicity Threshold for cyclic blocks of the graph.
106106 /// </summary>
107- public void SetCyclicityThresold ( )
107+ public void SetCyclicityThreshold ( )
108108 {
109109 BitSet _domain = new BitSet ( ) ;
110110 Dictionary < int , int > _N = new Dictionary < int , int > ( ) ;
@@ -142,11 +142,11 @@ void dfs(int a)
142142 _nb = Visited ( b ) ;
143143 if ( _nb < _na )
144144 {
145- _cyclicThreshold [ b ] = _cyclicExecutionThresold ;
146- if ( ! _cyclicRelation . TryGetValue ( a , out var set ) )
145+ _cyclicThreshold [ b ] = _cyclicExecutionThreshold ;
146+ if ( ! _cyclicTransition . TryGetValue ( a , out var set ) )
147147 {
148148 set = new HashSet < int > ( ) ;
149- _cyclicRelation . Add ( a , set ) ;
149+ _cyclicTransition . Add ( a , set ) ;
150150 }
151151 set . Add ( b ) ;
152152 }
@@ -209,6 +209,13 @@ protected virtual void Run(BasicBlock<N, D> startBlock, BasicBlock<N, D> stopBlo
209209 }
210210 }
211211
212+ /// <summary>
213+ /// CanExecute is used during execution to check for a block that contributes to a cycle,
214+ /// if can be executed, that is to say if its cyclic threshold is not consumed.
215+ /// Other blocks are always executed.
216+ /// </summary>
217+ /// <param name="b">The block to be checked</param>
218+ /// <returns>Return true if yes, false otherwise.</returns>
212219 bool CanExecute ( BasicBlock < N , D > b )
213220 {
214221 if ( _cyclicThreshold . TryGetValue ( b . Index , out int t ) )
@@ -217,37 +224,50 @@ bool CanExecute(BasicBlock<N, D> b)
217224 }
218225 return true ;
219226 }
220- }
221-
222- private bool IsCyclic ( BasicBlock < N , D > from , BasicBlock < N , D > to )
223- {
224- if ( _cyclicRelation . TryGetValue ( from . Index , out var toindices ) )
227+ /// <summary>
228+ /// Checks if the transition from one block to another can lead to a cycle.
229+ /// </summary>
230+ /// <param name="from"></param>
231+ /// <param name="to"></param>
232+ /// <returns>Return true if yes, false otherwise.</returns>
233+ bool IsCyclic ( BasicBlock < N , D > from , BasicBlock < N , D > to )
225234 {
226- return toindices . Contains ( to . Index ) ;
235+ if ( _cyclicTransition . TryGetValue ( from . Index , out var toindices ) )
236+ {
237+ return toindices . Contains ( to . Index ) ;
238+ }
239+ return false ;
227240 }
228- return false ;
229- }
230241
231- private bool CanAddExecution ( BasicBlock < N , D > from , BasicBlock < N , D > to )
232- {
233- if ( IsCyclic ( from , to ) )
242+ /// <summary>
243+ /// CanAddExecution Checks if a transition from one block to another can be pushed as to be executed.
244+ /// For a transition that can lead to a cycle, the cyclic threshold value is decreased, if the threshold
245+ /// is consumed the transition cannot be executed.
246+ /// </summary>
247+ /// <param name="from"></param>
248+ /// <param name="to"></param>
249+ /// <returns>True if the transition can be added, false otherwise.</returns>
250+ bool CanAddExecution ( BasicBlock < N , D > from , BasicBlock < N , D > to )
234251 {
235- if ( ! _cyclicThreshold . TryGetValue ( to . Index , out int t ) )
252+ if ( IsCyclic ( from , to ) )
236253 {
237- t = 0 ;
238- }
239- if ( t >= 0 && t <= _cyclicExecutionThresold )
240- {
241- _cyclicThreshold [ to . Index ] = t - 1 ;
242- return true ;
254+ if ( ! _cyclicThreshold . TryGetValue ( to . Index , out int t ) )
255+ {
256+ t = 0 ;
257+ }
258+ if ( t >= 0 && t <= _cyclicExecutionThreshold )
259+ {
260+ _cyclicThreshold [ to . Index ] = t - 1 ;
261+ return true ;
262+ }
263+ return false ;
243264 }
244- return false ;
265+ return true ;
245266 }
246- return true ;
247267 }
248268
249269 /// <summary>
250- /// Iterate over all instruction in the given block.
270+ /// Iterate over all instructions in the given block.
251271 /// </summary>
252272 /// <param name="block"></param>
253273 private void IterateBlock ( BasicBlock < N , D > block )
0 commit comments