diff options
author | gdkchan <gab.dark.100@gmail.com> | 2022-02-09 17:42:47 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-09 17:42:47 -0300 |
commit | c3c3914ed3f9508bd1acca301dbbc75babaef279 (patch) | |
tree | 27468423372fd8c3d6ade9a840b673aec88ffcf0 /ARMeilleure/CodeGen/X86/X86Optimizer.cs | |
parent | 6dffe0fad4bc8dee0e25ce038639d890b29d56a0 (diff) |
Add a limit on the number of uses a constant may have (#3097)1.1.23
Diffstat (limited to 'ARMeilleure/CodeGen/X86/X86Optimizer.cs')
-rw-r--r-- | ARMeilleure/CodeGen/X86/X86Optimizer.cs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/ARMeilleure/CodeGen/X86/X86Optimizer.cs b/ARMeilleure/CodeGen/X86/X86Optimizer.cs index ed040e15..98a19b9a 100644 --- a/ARMeilleure/CodeGen/X86/X86Optimizer.cs +++ b/ARMeilleure/CodeGen/X86/X86Optimizer.cs @@ -9,13 +9,17 @@ namespace ARMeilleure.CodeGen.X86 { static class X86Optimizer { + private const int MaxConstantUses = 10000; + public static void RunPass(ControlFlowGraph cfg) { var constants = new Dictionary<ulong, Operand>(); Operand GetConstantCopy(BasicBlock block, Operation operation, Operand source) { - if (!constants.TryGetValue(source.Value, out var constant)) + // If the constant has many uses, we also force a new constant mov to be added, in order + // to avoid overflow of the counts field (that is limited to 16 bits). + if (!constants.TryGetValue(source.Value, out var constant) || constant.UsesCount > MaxConstantUses) { constant = Local(source.Type); @@ -23,7 +27,7 @@ namespace ARMeilleure.CodeGen.X86 block.Operations.AddBefore(operation, copyOp); - constants.Add(source.Value, constant); + constants[source.Value] = constant; } return constant; |