Просмотр исходного кода

misc: chore: Fix object creation in ARMeilleure

Evan Husted 1 год назад
Родитель
Сommit
15d1528774

+ 1 - 1
src/ARMeilleure/CodeGen/Arm64/Arm64Optimizer.cs

@@ -13,7 +13,7 @@ namespace ARMeilleure.CodeGen.Arm64
 
         public static void RunPass(ControlFlowGraph cfg)
         {
-            Dictionary<ulong, Operand> constants = new Dictionary<ulong, Operand>();
+            Dictionary<ulong, Operand> constants = new();
 
             Operand GetConstantCopy(BasicBlock block, Operation operation, Operand source)
             {

+ 1 - 1
src/ARMeilleure/CodeGen/Linking/RelocInfo.cs

@@ -10,7 +10,7 @@ namespace ARMeilleure.CodeGen.Linking
         /// <summary>
         /// Gets an empty <see cref="RelocInfo"/>.
         /// </summary>
-        public static RelocInfo Empty { get; } = new RelocInfo(null);
+        public static RelocInfo Empty { get; } = new(null);
 
         private readonly RelocEntry[] _entries;
 

+ 2 - 2
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);

+ 2 - 2
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);
         }

+ 1 - 1
src/ARMeilleure/CodeGen/X86/X86Optimizer.cs

@@ -13,7 +13,7 @@ namespace ARMeilleure.CodeGen.X86
 
         public static void RunPass(ControlFlowGraph cfg)
         {
-            Dictionary<ulong, Operand> constants = new Dictionary<ulong, Operand>();
+            Dictionary<ulong, Operand> constants = new();
 
             Operand GetConstantCopy(BasicBlock block, Operation operation, Operand source)
             {

+ 2 - 2
src/ARMeilleure/Common/BitMap.cs

@@ -130,12 +130,12 @@ namespace ARMeilleure.Common
             if (count > _count)
             {
                 long* oldMask = _masks;
-                Span<long> oldSpan = new Span<long>(_masks, _count);
+                Span<long> oldSpan = new(_masks, _count);
 
                 _masks = _allocator.Allocate<long>((uint)count);
                 _count = count;
 
-                Span<long> newSpan = new Span<long>(_masks, _count);
+                Span<long> newSpan = new(_masks, _count);
 
                 oldSpan.CopyTo(newSpan);
                 newSpan[oldSpan.Length..].Clear();

+ 1 - 1
src/ARMeilleure/Decoders/Optimizations/TailCallRemover.cs

@@ -69,7 +69,7 @@ namespace ARMeilleure.Decoders.Optimizations
                 }
             }
 
-            List<Block> newBlocks = new List<Block>(blocks.Count);
+            List<Block> newBlocks = new(blocks.Count);
 
             // Finally, rebuild decoded block list, ignoring blocks outside the contiguous range.
             for (int i = 0; i < blocks.Count; i++)

+ 1 - 1
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)
             {

+ 4 - 4
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<T> oldSpan = new Span<T>(data, count);
+                Span<T> oldSpan = new(data, count);
 
                 capacity = newCapacity;
                 data = Allocators.References.Allocate<T>(capacity);
@@ -338,7 +338,7 @@ namespace ARMeilleure.IntermediateRepresentation
                     throw new OverflowException();
                 }
 
-                Span<T> oldSpan = new Span<T>(data, (int)count);
+                Span<T> oldSpan = new(data, (int)count);
 
                 capacity = newCapacity;
                 data = Allocators.References.Allocate<T>(capacity);
@@ -352,7 +352,7 @@ namespace ARMeilleure.IntermediateRepresentation
 
         private static void Remove<T>(in T item, ref T* data, ref ushort count) where T : unmanaged
         {
-            Span<T> span = new Span<T>(data, count);
+            Span<T> span = new(data, count);
 
             for (int i = 0; i < span.Length; i++)
             {
@@ -372,7 +372,7 @@ namespace ARMeilleure.IntermediateRepresentation
 
         private static void Remove<T>(in T item, ref T* data, ref uint count) where T : unmanaged
         {
-            Span<T> span = new Span<T>(data, (int)count);
+            Span<T> span = new(data, (int)count);
 
             for (int i = 0; i < span.Length; i++)
             {

+ 4 - 4
src/ARMeilleure/Translation/ControlFlowGraph.cs

@@ -47,8 +47,8 @@ namespace ARMeilleure.Translation
         {
             RemoveUnreachableBlocks(Blocks);
 
-            HashSet<BasicBlock> visited = new HashSet<BasicBlock>();
-            Stack<BasicBlock> blockStack = new Stack<BasicBlock>();
+            HashSet<BasicBlock> visited = new();
+            Stack<BasicBlock> 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<BasicBlock> blocks)
         {
-            HashSet<BasicBlock> visited = new HashSet<BasicBlock>();
-            Queue<BasicBlock> workQueue = new Queue<BasicBlock>();
+            HashSet<BasicBlock> visited = new();
+            Queue<BasicBlock> workQueue = new();
 
             visited.Add(Entry);
             workQueue.Enqueue(Entry);

+ 3 - 3
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<GuestFunction>(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);
 

+ 1 - 1
src/ARMeilleure/Translation/PTC/PtcProfiler.cs

@@ -111,7 +111,7 @@ namespace ARMeilleure.Translation.PTC
 
         public ConcurrentQueue<(ulong address, FuncProfile funcProfile)> GetProfiledFuncsToTranslate(TranslatorCache<TranslatedFunction> funcs)
         {
-            ConcurrentQueue<(ulong address, FuncProfile funcProfile)> profiledFuncsToTranslate = new ConcurrentQueue<(ulong address, FuncProfile funcProfile)>();
+            ConcurrentQueue<(ulong address, FuncProfile funcProfile)> profiledFuncsToTranslate = new();
 
             foreach (KeyValuePair<ulong, FuncProfile> profiledFunc in ProfiledFuncs)
             {

+ 1 - 1
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);
             }

+ 1 - 1
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<BasicBlock> dfPhiBlocks = new Queue<BasicBlock>();
+            Queue<BasicBlock> dfPhiBlocks = new();
 
             for (BasicBlock block = cfg.Blocks.First; block != null; block = block.ListNext)
             {

+ 1 - 1
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,

+ 4 - 4
src/ARMeilleure/Translation/TranslatorStubs.cs

@@ -142,7 +142,7 @@ namespace ARMeilleure.Translation
         /// <returns>Generated <see cref="DispatchStub"/></returns>
         private nint GenerateDispatchStub()
         {
-            EmitterContext context = new EmitterContext();
+            EmitterContext context = new();
 
             Operand lblFallback = Label();
             Operand lblEnd = Label();
@@ -200,7 +200,7 @@ namespace ARMeilleure.Translation
         /// <returns>Generated <see cref="SlowDispatchStub"/></returns>
         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
         /// <returns><see cref="DispatchLoop"/> function</returns>
         private DispatcherFunction GenerateDispatchLoop()
         {
-            EmitterContext context = new EmitterContext();
+            EmitterContext context = new();
 
             Operand beginLbl = Label();
             Operand endLbl = Label();
@@ -292,7 +292,7 @@ namespace ARMeilleure.Translation
         /// <returns><see cref="ContextWrapper"/> function</returns>
         private WrapperFunction GenerateContextWrapper()
         {
-            EmitterContext context = new EmitterContext();
+            EmitterContext context = new();
 
             Operand nativeContext = context.LoadArgument(OperandType.I64, 0);
             Operand guestMethod = context.LoadArgument(OperandType.I64, 1);