From 15d1528774b7acade9a269536846f4c1361acb6b Mon Sep 17 00:00:00 2001 From: Evan Husted Date: Sun, 26 Jan 2025 15:17:12 -0600 Subject: [PATCH] misc: chore: Fix object creation in ARMeilleure --- src/ARMeilleure/CodeGen/Arm64/Arm64Optimizer.cs | 2 +- src/ARMeilleure/CodeGen/Linking/RelocInfo.cs | 2 +- .../CodeGen/RegisterAllocators/LinearScanAllocator.cs | 4 ++-- src/ARMeilleure/CodeGen/X86/Assembler.cs | 4 ++-- src/ARMeilleure/CodeGen/X86/X86Optimizer.cs | 2 +- src/ARMeilleure/Common/BitMap.cs | 4 ++-- src/ARMeilleure/Decoders/Optimizations/TailCallRemover.cs | 2 +- src/ARMeilleure/Diagnostics/IRDumper.cs | 2 +- src/ARMeilleure/IntermediateRepresentation/Operand.cs | 8 ++++---- src/ARMeilleure/Translation/ControlFlowGraph.cs | 8 ++++---- src/ARMeilleure/Translation/PTC/Ptc.cs | 6 +++--- src/ARMeilleure/Translation/PTC/PtcProfiler.cs | 2 +- src/ARMeilleure/Translation/RegisterUsage.cs | 2 +- src/ARMeilleure/Translation/SsaConstruction.cs | 2 +- src/ARMeilleure/Translation/Translator.cs | 2 +- src/ARMeilleure/Translation/TranslatorStubs.cs | 8 ++++---- 16 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/ARMeilleure/CodeGen/Arm64/Arm64Optimizer.cs b/src/ARMeilleure/CodeGen/Arm64/Arm64Optimizer.cs index 979b471ac..a433cea65 100644 --- a/src/ARMeilleure/CodeGen/Arm64/Arm64Optimizer.cs +++ b/src/ARMeilleure/CodeGen/Arm64/Arm64Optimizer.cs @@ -13,7 +13,7 @@ namespace ARMeilleure.CodeGen.Arm64 public static void RunPass(ControlFlowGraph cfg) { - Dictionary constants = new Dictionary(); + Dictionary constants = new(); Operand GetConstantCopy(BasicBlock block, Operation operation, Operand source) { diff --git a/src/ARMeilleure/CodeGen/Linking/RelocInfo.cs b/src/ARMeilleure/CodeGen/Linking/RelocInfo.cs index 01ff0347b..fb8b449a7 100644 --- a/src/ARMeilleure/CodeGen/Linking/RelocInfo.cs +++ b/src/ARMeilleure/CodeGen/Linking/RelocInfo.cs @@ -10,7 +10,7 @@ namespace ARMeilleure.CodeGen.Linking /// /// Gets an empty . /// - public static RelocInfo Empty { get; } = new RelocInfo(null); + public static RelocInfo Empty { get; } = new(null); private readonly RelocEntry[] _entries; diff --git a/src/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs b/src/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs index fa0b8aa24..99e231a67 100644 --- a/src/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs +++ b/src/ARMeilleure/CodeGen/RegisterAllocators/LinearScanAllocator.cs @@ -115,7 +115,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators { NumberLocals(cfg, regMasks.RegistersCount); - AllocationContext context = new AllocationContext(stackAlloc, regMasks, _intervals.Count); + AllocationContext context = new(stackAlloc, regMasks, _intervals.Count); BuildIntervals(cfg, context); @@ -839,7 +839,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators { dest.NumberLocal(_intervals.Count); - LiveInterval interval = new LiveInterval(dest); + LiveInterval interval = new(dest); _intervals.Add(interval); SetVisited(dest); diff --git a/src/ARMeilleure/CodeGen/X86/Assembler.cs b/src/ARMeilleure/CodeGen/X86/Assembler.cs index 74774a8cf..a81976a09 100644 --- a/src/ARMeilleure/CodeGen/X86/Assembler.cs +++ b/src/ARMeilleure/CodeGen/X86/Assembler.cs @@ -1412,7 +1412,7 @@ namespace ARMeilleure.CodeGen.X86 _stream.Seek(0, SeekOrigin.Begin); using RecyclableMemoryStream codeStream = MemoryStreamManager.Shared.GetStream(); - Assembler assembler = new Assembler(codeStream, HasRelocs); + Assembler assembler = new(codeStream, HasRelocs); bool hasRelocs = HasRelocs; int relocIndex = 0; @@ -1471,7 +1471,7 @@ namespace ARMeilleure.CodeGen.X86 _stream.CopyTo(codeStream); byte[] code = codeStream.ToArray(); - RelocInfo relocInfo = new RelocInfo(relocEntries); + RelocInfo relocInfo = new(relocEntries); return (code, relocInfo); } diff --git a/src/ARMeilleure/CodeGen/X86/X86Optimizer.cs b/src/ARMeilleure/CodeGen/X86/X86Optimizer.cs index 8fcc41bc4..d72442c5a 100644 --- a/src/ARMeilleure/CodeGen/X86/X86Optimizer.cs +++ b/src/ARMeilleure/CodeGen/X86/X86Optimizer.cs @@ -13,7 +13,7 @@ namespace ARMeilleure.CodeGen.X86 public static void RunPass(ControlFlowGraph cfg) { - Dictionary constants = new Dictionary(); + Dictionary constants = new(); Operand GetConstantCopy(BasicBlock block, Operation operation, Operand source) { diff --git a/src/ARMeilleure/Common/BitMap.cs b/src/ARMeilleure/Common/BitMap.cs index a7bc69238..52e192699 100644 --- a/src/ARMeilleure/Common/BitMap.cs +++ b/src/ARMeilleure/Common/BitMap.cs @@ -130,12 +130,12 @@ namespace ARMeilleure.Common if (count > _count) { long* oldMask = _masks; - Span oldSpan = new Span(_masks, _count); + Span oldSpan = new(_masks, _count); _masks = _allocator.Allocate((uint)count); _count = count; - Span newSpan = new Span(_masks, _count); + Span newSpan = new(_masks, _count); oldSpan.CopyTo(newSpan); newSpan[oldSpan.Length..].Clear(); diff --git a/src/ARMeilleure/Decoders/Optimizations/TailCallRemover.cs b/src/ARMeilleure/Decoders/Optimizations/TailCallRemover.cs index 361a7f0d0..15ab3e6b8 100644 --- a/src/ARMeilleure/Decoders/Optimizations/TailCallRemover.cs +++ b/src/ARMeilleure/Decoders/Optimizations/TailCallRemover.cs @@ -69,7 +69,7 @@ namespace ARMeilleure.Decoders.Optimizations } } - List newBlocks = new List(blocks.Count); + List newBlocks = new(blocks.Count); // Finally, rebuild decoded block list, ignoring blocks outside the contiguous range. for (int i = 0; i < blocks.Count; i++) diff --git a/src/ARMeilleure/Diagnostics/IRDumper.cs b/src/ARMeilleure/Diagnostics/IRDumper.cs index 9d6a708b6..dcde1e360 100644 --- a/src/ARMeilleure/Diagnostics/IRDumper.cs +++ b/src/ARMeilleure/Diagnostics/IRDumper.cs @@ -285,7 +285,7 @@ namespace ARMeilleure.Diagnostics public static string GetDump(ControlFlowGraph cfg) { - IRDumper dumper = new IRDumper(1); + IRDumper dumper = new(1); for (BasicBlock block = cfg.Blocks.First; block != null; block = block.ListNext) { diff --git a/src/ARMeilleure/IntermediateRepresentation/Operand.cs b/src/ARMeilleure/IntermediateRepresentation/Operand.cs index 495a9d04a..9966308e6 100644 --- a/src/ARMeilleure/IntermediateRepresentation/Operand.cs +++ b/src/ARMeilleure/IntermediateRepresentation/Operand.cs @@ -304,7 +304,7 @@ namespace ARMeilleure.IntermediateRepresentation ushort newCount = checked((ushort)(count + 1)); ushort newCapacity = (ushort)Math.Min(capacity * 2, ushort.MaxValue); - Span oldSpan = new Span(data, count); + Span oldSpan = new(data, count); capacity = newCapacity; data = Allocators.References.Allocate(capacity); @@ -338,7 +338,7 @@ namespace ARMeilleure.IntermediateRepresentation throw new OverflowException(); } - Span oldSpan = new Span(data, (int)count); + Span oldSpan = new(data, (int)count); capacity = newCapacity; data = Allocators.References.Allocate(capacity); @@ -352,7 +352,7 @@ namespace ARMeilleure.IntermediateRepresentation private static void Remove(in T item, ref T* data, ref ushort count) where T : unmanaged { - Span span = new Span(data, count); + Span span = new(data, count); for (int i = 0; i < span.Length; i++) { @@ -372,7 +372,7 @@ namespace ARMeilleure.IntermediateRepresentation private static void Remove(in T item, ref T* data, ref uint count) where T : unmanaged { - Span span = new Span(data, (int)count); + Span span = new(data, (int)count); for (int i = 0; i < span.Length; i++) { diff --git a/src/ARMeilleure/Translation/ControlFlowGraph.cs b/src/ARMeilleure/Translation/ControlFlowGraph.cs index 03ef6f461..c9946d392 100644 --- a/src/ARMeilleure/Translation/ControlFlowGraph.cs +++ b/src/ARMeilleure/Translation/ControlFlowGraph.cs @@ -47,8 +47,8 @@ namespace ARMeilleure.Translation { RemoveUnreachableBlocks(Blocks); - HashSet visited = new HashSet(); - Stack blockStack = new Stack(); + HashSet visited = new(); + Stack blockStack = new(); Array.Resize(ref _postOrderBlocks, Blocks.Count); Array.Resize(ref _postOrderMap, Blocks.Count); @@ -88,8 +88,8 @@ namespace ARMeilleure.Translation private void RemoveUnreachableBlocks(IntrusiveList blocks) { - HashSet visited = new HashSet(); - Queue workQueue = new Queue(); + HashSet visited = new(); + Queue workQueue = new(); visited.Add(Entry); workQueue.Enqueue(Entry); diff --git a/src/ARMeilleure/Translation/PTC/Ptc.cs b/src/ARMeilleure/Translation/PTC/Ptc.cs index 10f8f3043..7a0bb750e 100644 --- a/src/ARMeilleure/Translation/PTC/Ptc.cs +++ b/src/ARMeilleure/Translation/PTC/Ptc.cs @@ -750,7 +750,7 @@ namespace ARMeilleure.Translation.PTC UnwindInfo unwindInfo, bool highCq) { - CompiledFunction cFunc = new CompiledFunction(code, unwindInfo, RelocInfo.Empty); + CompiledFunction cFunc = new(code, unwindInfo, RelocInfo.Empty); GuestFunction gFunc = cFunc.MapWithPointer(out nint gFuncPointer); return new TranslatedFunction(gFunc, gFuncPointer, callCounter, guestSize, highCq); @@ -945,7 +945,7 @@ namespace ARMeilleure.Translation.PTC WriteCode(code.AsSpan()); // WriteReloc. - using BinaryWriter relocInfoWriter = new BinaryWriter(_relocsStream, EncodingCache.UTF8NoBOM, true); + using BinaryWriter relocInfoWriter = new(_relocsStream, EncodingCache.UTF8NoBOM, true); foreach (RelocEntry entry in relocInfo.Entries) { @@ -955,7 +955,7 @@ namespace ARMeilleure.Translation.PTC } // WriteUnwindInfo. - using BinaryWriter unwindInfoWriter = new BinaryWriter(_unwindInfosStream, EncodingCache.UTF8NoBOM, true); + using BinaryWriter unwindInfoWriter = new(_unwindInfosStream, EncodingCache.UTF8NoBOM, true); unwindInfoWriter.Write(unwindInfo.PushEntries.Length); diff --git a/src/ARMeilleure/Translation/PTC/PtcProfiler.cs b/src/ARMeilleure/Translation/PTC/PtcProfiler.cs index 250ef70bb..051f8a5d0 100644 --- a/src/ARMeilleure/Translation/PTC/PtcProfiler.cs +++ b/src/ARMeilleure/Translation/PTC/PtcProfiler.cs @@ -111,7 +111,7 @@ namespace ARMeilleure.Translation.PTC public ConcurrentQueue<(ulong address, FuncProfile funcProfile)> GetProfiledFuncsToTranslate(TranslatorCache funcs) { - ConcurrentQueue<(ulong address, FuncProfile funcProfile)> profiledFuncsToTranslate = new ConcurrentQueue<(ulong address, FuncProfile funcProfile)>(); + ConcurrentQueue<(ulong address, FuncProfile funcProfile)> profiledFuncsToTranslate = new(); foreach (KeyValuePair profiledFunc in ProfiledFuncs) { diff --git a/src/ARMeilleure/Translation/RegisterUsage.cs b/src/ARMeilleure/Translation/RegisterUsage.cs index 472b0f67b..03d4a96e7 100644 --- a/src/ARMeilleure/Translation/RegisterUsage.cs +++ b/src/ARMeilleure/Translation/RegisterUsage.cs @@ -95,7 +95,7 @@ namespace ARMeilleure.Translation // This is required because we have a implicit context load at the start of the function, // but if there is a jump to the start of the function, the context load would trash the modified values. // Here we insert a new entry block that will jump to the existing entry block. - BasicBlock newEntry = new BasicBlock(cfg.Blocks.Count); + BasicBlock newEntry = new(cfg.Blocks.Count); cfg.UpdateEntry(newEntry); } diff --git a/src/ARMeilleure/Translation/SsaConstruction.cs b/src/ARMeilleure/Translation/SsaConstruction.cs index 3819340c6..e63cdc775 100644 --- a/src/ARMeilleure/Translation/SsaConstruction.cs +++ b/src/ARMeilleure/Translation/SsaConstruction.cs @@ -47,7 +47,7 @@ namespace ARMeilleure.Translation DefMap[] globalDefs = new DefMap[cfg.Blocks.Count]; Operand[] localDefs = new Operand[cfg.LocalsCount + RegisterConsts.TotalCount]; - Queue dfPhiBlocks = new Queue(); + Queue dfPhiBlocks = new(); for (BasicBlock block = cfg.Blocks.First; block != null; block = block.ListNext) { diff --git a/src/ARMeilleure/Translation/Translator.cs b/src/ARMeilleure/Translation/Translator.cs index 8e1a437db..77fdf949c 100644 --- a/src/ARMeilleure/Translation/Translator.cs +++ b/src/ARMeilleure/Translation/Translator.cs @@ -222,7 +222,7 @@ namespace ARMeilleure.Translation internal TranslatedFunction Translate(ulong address, ExecutionMode mode, bool highCq, bool singleStep = false) { - ArmEmitterContext context = new ArmEmitterContext( + ArmEmitterContext context = new( Memory, CountTable, FunctionTable, diff --git a/src/ARMeilleure/Translation/TranslatorStubs.cs b/src/ARMeilleure/Translation/TranslatorStubs.cs index e48349963..f149c1397 100644 --- a/src/ARMeilleure/Translation/TranslatorStubs.cs +++ b/src/ARMeilleure/Translation/TranslatorStubs.cs @@ -142,7 +142,7 @@ namespace ARMeilleure.Translation /// Generated private nint GenerateDispatchStub() { - EmitterContext context = new EmitterContext(); + EmitterContext context = new(); Operand lblFallback = Label(); Operand lblEnd = Label(); @@ -200,7 +200,7 @@ namespace ARMeilleure.Translation /// Generated private nint GenerateSlowDispatchStub() { - EmitterContext context = new EmitterContext(); + EmitterContext context = new(); // Load the target guest address from the native context. Operand nativeContext = context.LoadArgument(OperandType.I64, 0); @@ -251,7 +251,7 @@ namespace ARMeilleure.Translation /// function private DispatcherFunction GenerateDispatchLoop() { - EmitterContext context = new EmitterContext(); + EmitterContext context = new(); Operand beginLbl = Label(); Operand endLbl = Label(); @@ -292,7 +292,7 @@ namespace ARMeilleure.Translation /// function private WrapperFunction GenerateContextWrapper() { - EmitterContext context = new EmitterContext(); + EmitterContext context = new(); Operand nativeContext = context.LoadArgument(OperandType.I64, 0); Operand guestMethod = context.LoadArgument(OperandType.I64, 1);