Skip to content

Commit 6653fa5

Browse files
committed
1.0.10
1 parent 688aed9 commit 6653fa5

22 files changed

Lines changed: 681 additions & 394 deletions

Packages/blueamulet.udonsharpoptimizer/Editor/Optimizations.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Collections.Generic;
2+
using UdonSharp.Compiler.Assembly;
3+
4+
namespace UdonSharpOptimizer.Optimizations
5+
{
6+
internal interface IBaseOptimization
7+
{
8+
bool Enabled();
9+
10+
void ProcessInstruction(Optimizer optimizer, List<AssemblyInstruction> instrs, int i);
11+
}
12+
}

Packages/blueamulet.udonsharpoptimizer/Editor/Optimizations/IBaseOptimization.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using UdonSharp.Compiler.Assembly;
3+
using UdonSharp.Compiler.Assembly.Instructions;
4+
5+
namespace UdonSharpOptimizer.Optimizations
6+
{
7+
internal class OPTCopyLoad : IBaseOptimization
8+
{
9+
public bool Enabled()
10+
{
11+
return OptimizerSettings.Instance.CopyAndLoad;
12+
}
13+
14+
public void ProcessInstruction(Optimizer optimizer, List<AssemblyInstruction> instrs, int i)
15+
{
16+
// Remove Copy: Copy + JumpIf
17+
if (instrs[i] is CopyInstruction cInst && instrs[i + 1] is PushInstruction pInst)
18+
{
19+
if (Optimizer.IsPrivate(cInst.TargetValue) && cInst.TargetValue.UniqueID == pInst.PushValue.UniqueID && !optimizer.HasJump(pInst) && !optimizer.ReadScan(n => n == i + 1, cInst.TargetValue))
20+
{
21+
instrs[i] = optimizer.TransferInstr(Optimizer.CopyComment("OPTCopyLoad", cInst), cInst);
22+
instrs[i + 1] = optimizer.TransferInstr(new PushInstruction(cInst.SourceValue), pInst);
23+
optimizer.removedInsts += 3; // PUSH, PUSH, COPY
24+
}
25+
}
26+
}
27+
}
28+
}

Packages/blueamulet.udonsharpoptimizer/Editor/Optimizations/OPTCopyLoad.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using UdonSharp.Compiler.Assembly;
3+
using UdonSharp.Compiler.Assembly.Instructions;
4+
5+
namespace UdonSharpOptimizer.Optimizations
6+
{
7+
internal class OPTCopyTest : IBaseOptimization
8+
{
9+
public bool Enabled()
10+
{
11+
return OptimizerSettings.Instance.CopyAndTest;
12+
}
13+
14+
public void ProcessInstruction(Optimizer optimizer, List<AssemblyInstruction> instrs, int i)
15+
{
16+
// Remove Copy: Copy + JumpIf
17+
if (instrs[i] is CopyInstruction cInst && i < instrs.Count - 1 && instrs[i + 1] is JumpIfFalseInstruction jifInst)
18+
{
19+
if (Optimizer.IsPrivate(cInst.TargetValue) && cInst.TargetValue.UniqueID == jifInst.ConditionValue.UniqueID && !optimizer.HasJump(jifInst) && !optimizer.ReadScan(n => n == i + 1, cInst.TargetValue))
20+
{
21+
instrs[i] = optimizer.TransferInstr(Optimizer.CopyComment("OPTCopyTest", cInst), cInst);
22+
instrs[i + 1] = optimizer.TransferInstr(new JumpIfFalseInstruction(jifInst.JumpTarget, cInst.SourceValue), jifInst);
23+
optimizer.removedInsts += 3; // PUSH, PUSH, COPY
24+
}
25+
}
26+
}
27+
}
28+
}

Packages/blueamulet.udonsharpoptimizer/Editor/Optimizations/OPTCopyTest.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using UdonSharp.Compiler.Assembly;
3+
using UdonSharp.Compiler.Assembly.Instructions;
4+
5+
namespace UdonSharpOptimizer.Optimizations
6+
{
7+
internal class OPTDoubleCopy : IBaseOptimization
8+
{
9+
public bool Enabled()
10+
{
11+
return OptimizerSettings.Instance.DoubleCopy;
12+
}
13+
14+
public void ProcessInstruction(Optimizer optimizer, List<AssemblyInstruction> instrs, int i)
15+
{
16+
// Remove Copy: Copy + Copy
17+
if (instrs[i] is CopyInstruction cInst1 && i < instrs.Count - 1 && instrs[i + 1] is CopyInstruction cInst2)
18+
{
19+
if (Optimizer.IsPrivate(cInst1.TargetValue) && cInst1.TargetValue.UniqueID == cInst2.SourceValue.UniqueID && !optimizer.HasJump(cInst2) && !optimizer.ReadScan(n => n == i + 1, cInst1.TargetValue))
20+
{
21+
instrs[i] = optimizer.TransferInstr(Optimizer.CopyComment("OPTDoubleCopy", cInst1), cInst1);
22+
instrs[i + 1] = optimizer.TransferInstr(new CopyInstruction(cInst1.SourceValue, cInst2.TargetValue), cInst2);
23+
optimizer.removedInsts += 3; // PUSH, PUSH, COPY
24+
}
25+
}
26+
}
27+
}
28+
}

Packages/blueamulet.udonsharpoptimizer/Editor/Optimizations/OPTDoubleCopy.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using UdonSharp.Compiler.Assembly;
3+
using UdonSharp.Compiler.Assembly.Instructions;
4+
5+
namespace UdonSharpOptimizer.Optimizations
6+
{
7+
internal class OPTStoreCopy : IBaseOptimization
8+
{
9+
public bool Enabled()
10+
{
11+
return OptimizerSettings.Instance.StoreAndCopy;
12+
}
13+
14+
public void ProcessInstruction(Optimizer optimizer, List<AssemblyInstruction> instrs, int i)
15+
{
16+
// Remove Copy: Extern + Copy
17+
if (instrs[i] is PushInstruction pInst && i < instrs.Count - 2 && Optimizer.IsExternWrite(instrs[i + 1]) && instrs[i + 2] is CopyInstruction cInst)
18+
{
19+
if (Optimizer.IsPrivate(pInst.PushValue) && pInst.PushValue.UniqueID == cInst.SourceValue.UniqueID && !optimizer.HasJump(i + 1, i + 2) && !optimizer.ReadScan(n => n == i || n == i + 2, pInst.PushValue))
20+
{
21+
instrs[i] = optimizer.TransferInstr(new PushInstruction(cInst.TargetValue), pInst);
22+
instrs[i + 2] = optimizer.TransferInstr(Optimizer.CopyComment("OPTStoreCopy", cInst), cInst);
23+
optimizer.removedInsts += 3; // PUSH, PUSH, COPY
24+
}
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)