Browse Source

* Rename ControlFlowSimplification to ConditionDetection

* Rename OptimizingTransform to ControlFlowSimplification
* Move control flow transforms to separate namespace.
pull/728/head
Daniel Grunwald 10 years ago
parent
commit
2509f27223
  1. 10
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 6
      ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs
  3. 1
      ICSharpCode.Decompiler/FlowAnalysis/Dominance.cs
  4. 9
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  5. 4
      ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs
  6. 13
      ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs
  7. 5
      ICSharpCode.Decompiler/IL/ControlFlow/IntroduceExitPoints.cs
  8. 4
      ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs

10
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -20,18 +20,14 @@ using System; @@ -20,18 +20,14 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.NRefactory.Utils;
using Mono.Cecil;
using ICSharpCode.Decompiler.CSharp.Transforms;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.IL.ControlFlow;
using ICSharpCode.Decompiler.IL.Transforms;
namespace ICSharpCode.Decompiler.CSharp
@ -48,10 +44,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -48,10 +44,10 @@ namespace ICSharpCode.Decompiler.CSharp
readonly DecompilerSettings settings;
List<IILTransform> ilTransforms = new List<IILTransform> {
new OptimizingTransform(),
new ControlFlowSimplification(),
new LoopDetection(),
new IntroduceExitPoints(),
new ControlFlowSimplification(),
new ConditionDetection(),
new ILInlining(),
new TransformingVisitor(),
new ExpressionTransforms(),

6
ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs

@ -18,14 +18,8 @@ @@ -18,14 +18,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using ICSharpCode.NRefactory.Utils;
using ICSharpCode.Decompiler.Disassembler;
using Mono.Cecil.Cil;
namespace ICSharpCode.Decompiler.FlowAnalysis
{
/// <summary>

1
ICSharpCode.Decompiler/FlowAnalysis/Dominance.cs

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Diagnostics;

9
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -81,6 +81,10 @@ @@ -81,6 +81,10 @@
<Compile Include="CSharp\Transforms\ReplaceMethodCallsWithOperators.cs" />
<Compile Include="FlowAnalysis\ControlFlowNode.cs" />
<Compile Include="FlowAnalysis\Dominance.cs" />
<Compile Include="IL\ControlFlow\ConditionDetection.cs" />
<Compile Include="IL\ControlFlow\ControlFlowSimplification.cs" />
<Compile Include="IL\ControlFlow\IntroduceExitPoints.cs" />
<Compile Include="IL\ControlFlow\LoopDetection.cs" />
<Compile Include="IL\Instructions.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@ -109,12 +113,8 @@ @@ -109,12 +113,8 @@
<Compile Include="IL\IInlineContext.cs" />
<Compile Include="IL\NRTypeExtensions.cs" />
<Compile Include="IL\SlotInfo.cs" />
<Compile Include="IL\Transforms\ControlFlowSimplification.cs" />
<Compile Include="IL\Transforms\IILTransform.cs" />
<Compile Include="IL\Transforms\ILInlining.cs" />
<Compile Include="IL\Transforms\IntroduceExitPoints.cs" />
<Compile Include="IL\Transforms\LoopDetection.cs" />
<Compile Include="IL\Transforms\OptimizingTransform.cs" />
<Compile Include="IL\Transforms\ExpressionTransforms.cs" />
<Compile Include="IL\Transforms\TransformArrayInitializers.cs" />
<Compile Include="IL\Transforms\TransformingVisitor.cs" />
@ -185,6 +185,7 @@ @@ -185,6 +185,7 @@
<ItemGroup>
<Folder Include="FlowAnalysis" />
<Folder Include="ILAst" />
<Folder Include="IL\ControlFlow" />
<Folder Include="IL\Transforms" />
<Folder Include="TypeSystem" />
</ItemGroup>

4
ICSharpCode.Decompiler/IL/Transforms/ControlFlowSimplification.cs → ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs

@ -21,7 +21,7 @@ using System.Diagnostics; @@ -21,7 +21,7 @@ using System.Diagnostics;
using System.Linq;
using ICSharpCode.Decompiler.FlowAnalysis;
namespace ICSharpCode.Decompiler.IL.Transforms
namespace ICSharpCode.Decompiler.IL.ControlFlow
{
/// <summary>
/// Detects 'if' structure and other non-loop aspects of control flow.
@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// Blocks should be basic blocks prior to this transform.
/// After this transform, they will be extended basic blocks.
/// </remarks>
public class ControlFlowSimplification : IILTransform
public class ConditionDetection : IILTransform
{
public void Run(ILFunction function, ILTransformContext context)
{

13
ICSharpCode.Decompiler/IL/Transforms/OptimizingTransform.cs → ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs

@ -20,21 +20,21 @@ using System.Collections.Generic; @@ -20,21 +20,21 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace ICSharpCode.Decompiler.IL.Transforms
namespace ICSharpCode.Decompiler.IL.ControlFlow
{
/// <summary>
/// This transform 'optimizes' the IL code: it replaces constructs that
/// are generated by the C# compiler in debug mode with shorter constructs
/// that are more straightforward to analyze.
/// This transform 'optimizes' the control flow logic in the IL code:
/// it replaces constructs that are generated by the C# compiler in debug mode
/// with shorter constructs that are more straightforward to analyze.
/// </summary>
/// <remarks>
/// The optimizations performed are:
/// The transformations performed are:
/// * 'nop' instructions are removed
/// * branches that lead to other branches are replaced with branches that directly jump to the destination
/// * branches that lead to a 'return block' are replaced with a return instruction
/// * basic blocks are combined where possible
/// </remarks>
public class OptimizingTransform : IILTransform
public class ControlFlowSimplification : IILTransform
{
public void Run(ILFunction function, ILTransformContext context)
{
@ -109,7 +109,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -109,7 +109,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{
Debug.Assert(container == block.Parent);
// Ensure the block will stay a basic block -- we don't want extended basic blocks prior to LoopDetection.
// TODO: when LoopDetection is complete, check that it really can't handle EBBs
if (block.Instructions.Count > 1 && block.Instructions[block.Instructions.Count - 2].HasFlag(InstructionFlags.MayBranch))
return false;
Branch br = block.Instructions.Last() as Branch;

5
ICSharpCode.Decompiler/IL/Transforms/IntroduceExitPoints.cs → ICSharpCode.Decompiler/IL/ControlFlow/IntroduceExitPoints.cs

@ -15,10 +15,11 @@ @@ -15,10 +15,11 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Diagnostics;
namespace ICSharpCode.Decompiler.IL.Transforms
namespace ICSharpCode.Decompiler.IL.ControlFlow
{
/// <summary>
/// Control flow transform: use 'leave' instructions instead of 'br' where possible.
@ -97,7 +98,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -97,7 +98,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (currentExit == null) {
currentExit = inst;
inst.ReplaceWith(new Leave(currentContainer));
} else if (ControlFlowSimplification.CompatibleExitInstruction(inst, currentExit)) {
} else if (ConditionDetection.CompatibleExitInstruction(inst, currentExit)) {
inst.ReplaceWith(new Leave(currentContainer));
}
}

4
ICSharpCode.Decompiler/IL/Transforms/LoopDetection.cs → ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs

@ -15,14 +15,14 @@ @@ -15,14 +15,14 @@
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.NRefactory.Utils;
using ICSharpCode.Decompiler.FlowAnalysis;
namespace ICSharpCode.Decompiler.IL.Transforms
namespace ICSharpCode.Decompiler.IL.ControlFlow
{
/// <summary>
/// Detect loops in IL AST.
Loading…
Cancel
Save