/// <summary> /// Applies the LICM transformation to the given loop. /// </summary> /// <param name="builder">The parent method builder.</param> /// <param name="loop">The current loop.</param> /// <returns>True, if the transformation could be applied.</returns> private static bool ApplyLICM(Method.Builder builder, Loop loop) { // Initialize the current loop invariance cache var invariance = new LoopInvariance(loop); // Ensure that all blocks are in the correct order BasicBlockCollection <ReversePostOrder, Forwards> blocks = loop.ComputeOrderedBlocks(0); // Get the initial entry builder to move all values to var entry = loop.Entries[0]; var mover = new Mover(blocks.Count); // Traverse all blocks in reverse post order to move all values without // violating any SSA properties foreach (var block in blocks) { if (block == entry) { continue; } foreach (Value value in block) { // Move out of the loop if this value is loop invariant if (invariance.IsLoopInvariant(value)) { mover.Add(value); } } } // Move values var entryBuilder = builder[entry]; foreach (var valueToMove in mover.ToMove) { // Check whether this value should be moved out of the current loop if (mover.ShouldBeMoved(valueToMove)) { entryBuilder.AddFromOtherBlock(valueToMove); } } return(mover.ToMove.Length > 0); }
/// <summary> /// Applies the control-flow simplification transformation. /// </summary> protected override bool PerformTransformation(Method.Builder builder) { // We change the control-flow structure during the transformation but // need to get information about previous predecessors and successors builder.AcceptControlFlowUpdates(accept: true); BasicBlockCollection <ReversePostOrder, Forwards> blocks = builder.SourceBlocks; var visited = blocks.CreateSet(); bool result = false; foreach (var block in blocks) { result |= MergeChain(builder, block, ref visited); } return(result); }
/// <summary> /// Creates a new default block schedule using the given blocks. /// </summary> /// <param name="blocks">The input blocks.</param> /// <returns>The created block schedule.</returns> public static PTXBlockSchedule CreateDefaultPTXSchedule( this BasicBlockCollection <ReversePostOrder, Forwards> blocks) => new DefaultPTXBlockSchedule(blocks);
/// <summary> /// Creates a schedule from an already existing schedule. /// </summary> /// <typeparam name="TOrder">The current order.</typeparam> /// <typeparam name="TDirection">The control-flow direction.</typeparam> /// <param name="blocks">The input blocks.</param> /// <returns>The created block schedule.</returns> public static PTXBlockSchedule CreateOptimizedPTXSchedule <TOrder, TDirection>( this BasicBlockCollection <TOrder, TDirection> blocks) where TOrder : struct, ITraversalOrder where TDirection : struct, IControlFlowDirection => CreateSchedule(
/// <summary> /// Creates a new optimized block schedule using the given blocks. /// </summary> /// <typeparam name="TOrder">The current order.</typeparam> /// <typeparam name="TDirection">The control-flow direction.</typeparam> /// <param name="blocks">The input blocks.</param> /// <returns>The created block schedule.</returns> public static PTXBlockSchedule CreatePTXScheduleToOptimize <TOrder, TDirection>( this BasicBlockCollection <TOrder, TDirection> blocks) where TOrder : struct, ITraversalOrder where TDirection : struct, IControlFlowDirection => CreateSchedule(blocks.ChangeOrder <PreOrder, Forwards>());
public ControlFlowGraph(BasicBlockCollection collection) { this.blocks = collection; }