From a2e7448f0257a9bb4887fbb94ca55ff968b6cb06 Mon Sep 17 00:00:00 2001 From: qiaopengcheng Date: Wed, 19 Apr 2023 17:51:30 +0800 Subject: [PATCH 1/2] [LoongArch64] amend the crossgen2/r2rdump for LA64. --- .../ReadyToRun/ArgIterator.cs | 10 +- .../Target_LoongArch64/ImportThunk.cs | 2 +- .../ReadyToRun/TransitionBlock.cs | 16 +- .../Amd64/GcInfo.cs | 8 + .../Amd64/GcSlotTable.cs | 3 + .../Amd64/GcTransition.cs | 4 + .../DebugInfo.cs | 2 + .../GCInfoTypes.cs | 10 ++ .../LoongArch64/Registers.cs | 45 +++++ .../LoongArch64/UnwindInfo.cs | 163 ++++++++++++++++++ .../ReadyToRunMethod.cs | 10 +- .../ReadyToRunReader.cs | 1 + .../TransitionBlock.cs | 7 +- src/coreclr/tools/r2rdump/CoreDisTools.cs | 15 +- src/coreclr/tools/r2rdump/R2RDump.csproj | 2 +- 15 files changed, 270 insertions(+), 28 deletions(-) create mode 100644 src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/LoongArch64/Registers.cs create mode 100644 src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/LoongArch64/UnwindInfo.cs diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ArgIterator.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ArgIterator.cs index 70e258d8d297d..78dfc95c757be 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ArgIterator.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ArgIterator.cs @@ -1732,16 +1732,8 @@ private void ForceSigWalk() int floatRegOfsInBytes = argOffset - _transitionBlock.OffsetOfFloatArgumentRegisters; Debug.Assert((floatRegOfsInBytes % _transitionBlock.FloatRegisterSize) == 0); pLoc.m_idxFloatReg = floatRegOfsInBytes / _transitionBlock.FloatRegisterSize; + pLoc.m_cFloatReg = 1; - if (!_argTypeHandle.IsNull() && _argTypeHandle.IsHomogeneousAggregate()) - { - int haElementSize = _argTypeHandle.GetHomogeneousAggregateElementSize(); - pLoc.m_cFloatReg = GetArgSize() / haElementSize; - } - else - { - pLoc.m_cFloatReg = 1; - } return pLoc; } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_LoongArch64/ImportThunk.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_LoongArch64/ImportThunk.cs index 5e0a8751d472b..8d11f284f39bc 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_LoongArch64/ImportThunk.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_LoongArch64/ImportThunk.cs @@ -28,7 +28,7 @@ protected override void EmitCode(NodeFactory factory, ref LoongArch64Emitter ins if (!relocsOnly) { - // movz T0=R12, #index + // ori T0=R12, R0, #index int index = _containingImportSection.IndexFromBeginningOfArray; instructionEncoder.EmitMOV(Register.R12, checked((ushort)index)); } diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TransitionBlock.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TransitionBlock.cs index 2228cb248e760..09372f143813c 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TransitionBlock.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TransitionBlock.cs @@ -651,8 +651,8 @@ private class LoongArch64TransitionBlock : TransitionBlock public override int NumCalleeSavedRegisters => 12; // Callee-saves, argument registers public override int SizeOfTransitionBlock => SizeOfCalleeSavedRegisters + SizeOfArgumentRegisters; - public override int OffsetOfArgumentRegisters => SizeOfCalleeSavedRegisters; - public override int OffsetOfFirstGCRefMapSlot => OffsetOfArgumentRegisters; + public override int OffsetOfFirstGCRefMapSlot => SizeOfCalleeSavedRegisters; + public override int OffsetOfArgumentRegisters => OffsetOfFirstGCRefMapSlot; // F0..F7 public override int OffsetOfFloatArgumentRegisters => 8 * sizeof(double); @@ -671,19 +671,11 @@ public override bool IsArgPassedByRef(TypeHandle th) } else { - int numIntroducedFields = 0; - foreach (FieldDesc field in th.GetRuntimeTypeHandle().GetFields()) - { - if (!field.IsStatic) - { - numIntroducedFields++; - } - } - return ((numIntroducedFields == 0) || (numIntroducedFields > 2)); + return false; } } - public sealed override int GetRetBuffArgOffset(bool hasThis) => OffsetOfArgumentRegisters; + public sealed override int GetRetBuffArgOffset(bool hasThis) => OffsetOfFirstGCRefMapSlot + (hasThis ? 8 : 0); public override int StackElemSize(int parmSize, bool isValueType = false, bool isFloatHfa = false) { diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs index 52da7f3e91339..d7fb75285da82 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs @@ -259,6 +259,14 @@ public override string ToString() sb.AppendLine($" Has Tailcalls: {_wantsReportOnlyLeaf}"); } + else if (_machine == (Machine) 0x6264) /* LoongArch64 */ + { + if (StackBaseRegister != 0xffffffff) + { + sb.AppendLine($" StackBaseRegister: {(LoongArch64.Registers)StackBaseRegister}"); + } + sb.AppendLine($" Has Tailcalls: {_wantsReportOnlyLeaf}"); + } sb.AppendLine($" Size of parameter area: 0x{SizeOfStackOutgoingAndScratchArea:X}"); if (SizeOfEditAndContinuePreservedArea != 0xffffffff) diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcSlotTable.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcSlotTable.cs index 153b19d377258..17dc6a2da460e 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcSlotTable.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcSlotTable.cs @@ -68,6 +68,9 @@ private static string GetRegisterName(int registerNumber, Machine machine) case Machine.Arm64: return ((Arm64.Registers)registerNumber).ToString(); + case (Machine) 0x6264: /* LoongArch64 */ + return ((LoongArch64.Registers)registerNumber).ToString(); + default: throw new NotImplementedException(machine.ToString()); } diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcTransition.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcTransition.cs index 3c2bb7c8df9d8..7aa2ed6d593c7 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcTransition.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcTransition.cs @@ -65,6 +65,10 @@ public string GetSlotState(GcSlotTable slotTable, Machine machine) regType = typeof(Amd64.Registers); break; + case (Machine) 0x6264: /* LoongArch64 */ + regType = typeof(LoongArch64.Registers); + break; + default: throw new NotImplementedException(); } diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs index c619198d31fb6..88dbcb9b65188 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs @@ -72,6 +72,8 @@ public static string GetPlatformSpecificRegister(Machine machine, int regnum) return ((Arm.Registers)regnum).ToString(); case Machine.Arm64: return ((Arm64.Registers)regnum).ToString(); + case (Machine) 0x6264: /* LoongArch64 */ + return ((LoongArch64.Registers)regnum).ToString(); default: throw new NotImplementedException($"No implementation for machine type {machine}."); } diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/GCInfoTypes.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/GCInfoTypes.cs index 38e85a7896909..d7a0d80089192 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/GCInfoTypes.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/GCInfoTypes.cs @@ -149,6 +149,11 @@ internal GcInfoTypes(Machine machine) NUM_UNTRACKED_SLOTS_ENCBASE = 5; REGISTER_DELTA_ENCBASE = 3; break; + case (Machine) 0x6264: /* LoongArch64 */ + SIZE_OF_RETURN_KIND_FAT = 4; + STACK_BASE_REGISTER_ENCBASE = 2; + NUM_REGISTERS_ENCBASE = 3; + break; } } @@ -159,6 +164,7 @@ internal int DenormalizeCodeLength(int x) case Machine.ArmThumb2: return (x << 1); case Machine.Arm64: + case (Machine) 0x6264: /* LoongArch64 */ return (x << 2); } return x; @@ -173,6 +179,7 @@ internal int DenormalizeStackSlot(int x) case Machine.ArmThumb2: return (x << 2); case Machine.Arm64: + case (Machine) 0x6264: /* LoongArch64 */ return (x << 3); } return x; @@ -188,6 +195,8 @@ internal uint DenormalizeStackBaseRegister(uint x) return ((x ^ 7) + 4); case Machine.Arm64: return (x ^ 29); + case (Machine) 0x6264: /* LoongArch64 */ + return ((x ^ 22) & 0x3); } return x; } @@ -201,6 +210,7 @@ internal uint DenormalizeSizeOfStackArea(uint x) case Machine.ArmThumb2: return (x << 2); case Machine.Arm64: + case (Machine) 0x6264: /* LoongArch64 */ return (x << 3); } return x; diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/LoongArch64/Registers.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/LoongArch64/Registers.cs new file mode 100644 index 0000000000000..23b88ed478855 --- /dev/null +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/LoongArch64/Registers.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace ILCompiler.Reflection.ReadyToRun.LoongArch64 +{ + public enum Registers + { + R0, + Ra, + Tp, + Sp, + A0, + A1, + A2, + A3, + A4, + A5, + A6, + A7, + T0, + T1, + T2, + T3, + T4, + T5, + T6, + T7, + T8, + X0, + Fp, + S0, + S1, + S2, + S3, + S4, + S5, + S6, + S7, + S8 + } +} diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/LoongArch64/UnwindInfo.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/LoongArch64/UnwindInfo.cs new file mode 100644 index 0000000000000..98fe6cbfdde3e --- /dev/null +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/LoongArch64/UnwindInfo.cs @@ -0,0 +1,163 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Text; + +namespace ILCompiler.Reflection.ReadyToRun.LoongArch64 +{ + public class Epilog + { + public int Index { get; set; } + + public uint EpilogStartOffset { get; set; } + public uint Res { get; set; } + public uint Condition { get; set; } + public uint EpilogStartIndex { get; set; } + public uint EpilogStartOffsetFromMainFunctionBegin { get; set; } + + public Epilog() { } + + public Epilog(int index, int dw, uint startOffset) + { + Index = index; + + EpilogStartOffset = UnwindInfo.ExtractBits(dw, 0, 18); + Res = UnwindInfo.ExtractBits(dw, 18, 4); + Condition = UnwindInfo.ExtractBits(dw, 20, 4); + EpilogStartIndex = UnwindInfo.ExtractBits(dw, 22, 10); + + // Note that epilogStartOffset for a funclet is the offset from the beginning + // of the current funclet, not the offset from the beginning of the main function. + // To help find it when looking through JitDump output, also show the offset from + // the beginning of the main function. + EpilogStartOffsetFromMainFunctionBegin = EpilogStartOffset * 4 + startOffset; + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine($" Epilog Start Offset: 0x{EpilogStartOffset:X5} Actual offset = 0x{EpilogStartOffset * 4:X5} Offset from main function begin = 0x{EpilogStartOffsetFromMainFunctionBegin:X6}"); + sb.AppendLine($" Condition: {Condition} (0x{Condition:X})" + ((Condition == 0xE) ? " (always)" : "")); + sb.Append($" Epilog Start Index: {EpilogStartIndex} (0x{EpilogStartIndex:X})"); + return sb.ToString(); + } + } + + public class UnwindCode + { + public int Index { get; set; } + + public UnwindCode() { } + + public UnwindCode(int index) + { + Index = index; + + } + } + + /// + /// based on src/jit/unwindloongarch64.cpp DumpUnwindInfo + /// + public class UnwindInfo : BaseUnwindInfo + { + public uint CodeWords { get; set; } + public uint EpilogCount { get; set; } + public uint EBit { get; set; } + public uint XBit { get; set; } + public uint Vers { get; set; } + public uint FunctionLength { get; set; } + + public uint ExtendedCodeWords { get; set; } + public uint ExtendedEpilogCount { get; set; } + + public Epilog[] Epilogs { get; set; } + + public UnwindInfo() { } + + public UnwindInfo(byte[] image, int offset) + { + uint startOffset = (uint)offset; + + int dw = NativeReader.ReadInt32(image, ref offset); + CodeWords = ExtractBits(dw, 27, 5); + EpilogCount = ExtractBits(dw, 22, 5); + EBit = ExtractBits(dw, 21, 1); + XBit = ExtractBits(dw, 20, 1); + Vers = ExtractBits(dw, 18, 2); + FunctionLength = ExtractBits(dw, 0, 18) * 4; + + if (CodeWords == 0 && EpilogCount == 0) + { + // We have an extension word specifying a larger number of Code Words or Epilog Counts + // than can be specified in the header word. + dw = NativeReader.ReadInt32(image, ref offset); + ExtendedCodeWords = ExtractBits(dw, 16, 8); + ExtendedEpilogCount = ExtractBits(dw, 0, 16); + } + + bool[] epilogStartAt = new bool[1024]; // One byte per possible epilog start index; initialized to false + + if (EBit == 0) + { + Epilogs = new Epilog[EpilogCount]; + if (EpilogCount != 0) + { + for (int scope = 0; scope < EpilogCount; scope++) + { + dw = NativeReader.ReadInt32(image, ref offset); + Epilogs[scope] = new Epilog(scope, dw, startOffset); + epilogStartAt[Epilogs[scope].EpilogStartIndex] = true; // an epilog starts at this offset in the unwind codes + } + } + } + else + { + Epilogs = new Epilog[0]; + epilogStartAt[EpilogCount] = true; // the one and only epilog starts its unwind codes at this offset + } + + + + Size = offset - (int)startOffset + (int)CodeWords * 4; + int alignmentPad = ((Size + sizeof(int) - 1) & ~(sizeof(int) - 1)) - Size; + Size += (alignmentPad + sizeof(uint)); + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine($" CodeWords: {CodeWords}"); + sb.AppendLine($" EpilogCount: {EpilogCount}"); + sb.AppendLine($" EBit: {EBit}"); + sb.AppendLine($" XBit: {XBit}"); + sb.AppendLine($" Vers: {Vers}"); + sb.AppendLine($" FunctionLength: {FunctionLength}"); + if (CodeWords == 0 && EpilogCount == 0) + { + sb.AppendLine(" ---- Extension word ----"); + sb.AppendLine($" Extended Code Words: {CodeWords}"); + sb.AppendLine($" Extended Epilog Count: {EpilogCount}"); + } + if (EpilogCount == 0) + { + sb.AppendLine(" No epilogs"); + } + else + { + for (int i = 0; i < Epilogs.Length; i++) + { + sb.AppendLine(" -------------------------"); + sb.AppendLine(Epilogs[i].ToString()); + sb.AppendLine(" -------------------------"); + } + } + return sb.ToString(); + } + + internal static uint ExtractBits(int dw, int start, int length) + { + return (uint)((dw >> start) & ((1 << length) - 1)); + } + } +} diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs index ca9bc4996880a..cbd89421742cc 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs @@ -225,6 +225,10 @@ private int GetSize() { return (int)arm64Info.FunctionLength; } + else if (UnwindInfo is LoongArch64.UnwindInfo loongarch64Info) + { + return (int)loongarch64Info.FunctionLength; + } else if (Method.GcInfo != null) { return Method.GcInfo.CodeLength; @@ -488,7 +492,7 @@ private void EnsureInitialized() } else { - // Arm and Arm64 use the same GcInfo format as Amd64 + // Arm, Arm64 and LoongArch64 use the same GcInfo format as Amd64 _gcInfo = new Amd64.GcInfo(_readyToRunReader.Image, gcInfoOffset, _readyToRunReader.Machine, _readyToRunReader.ReadyToRunHeader.MajorVersion); } } @@ -604,6 +608,10 @@ private void ParseRuntimeFunctions(bool partial) { unwindInfo = new Arm64.UnwindInfo(_readyToRunReader.Image, unwindOffset); } + else if (_readyToRunReader.Machine == (Machine) 0x6264) /* LoongArch64 */ + { + unwindInfo = new LoongArch64.UnwindInfo(_readyToRunReader.Image, unwindOffset); + } if (i == 0 && unwindInfo != null) { diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs index 0b370d8ee5613..112a82c62e23a 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs @@ -1443,6 +1443,7 @@ private void EnsureImportSections() case Machine.Amd64: case Machine.Arm64: + case (Machine) 0x6264: /* LoongArch64 */ entrySize = 8; break; diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs index 96f4108f7910a..4c01e2a1d4ebd 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs @@ -29,6 +29,9 @@ public static TransitionBlock FromReader(ReadyToRunReader reader) case Architecture.Arm64: return Arm64TransitionBlock.Instance; + case (Architecture) 6: /* LoongArch64 */ + return LoongArch64TransitionBlock.Instance; + default: throw new NotImplementedException(); } @@ -161,8 +164,8 @@ private sealed class LoongArch64TransitionBlock : TransitionBlock public override int NumCalleeSavedRegisters => 12; // Callee-saves, padding, argument registers public override int SizeOfTransitionBlock => SizeOfCalleeSavedRegisters + SizeOfArgumentRegisters; - public override int OffsetOfArgumentRegisters => SizeOfCalleeSavedRegisters; - public override int OffsetOfFirstGCRefMapSlot => OffsetOfArgumentRegisters; + public override int OffsetOfFirstGCRefMapSlot => SizeOfCalleeSavedRegisters; + public override int OffsetOfArgumentRegisters => OffsetOfFirstGCRefMapSlot; } } } diff --git a/src/coreclr/tools/r2rdump/CoreDisTools.cs b/src/coreclr/tools/r2rdump/CoreDisTools.cs index 739a564814309..df752c70b1f0c 100644 --- a/src/coreclr/tools/r2rdump/CoreDisTools.cs +++ b/src/coreclr/tools/r2rdump/CoreDisTools.cs @@ -21,7 +21,8 @@ public enum TargetArch Target_X86, Target_X64, Target_Thumb, - Target_Arm64 + Target_Arm64, + Target_LoongArch64 }; [DllImport(_dll, CallingConvention = CallingConvention.Cdecl)] @@ -73,6 +74,9 @@ public static IntPtr GetDisasm(Machine machine) case Machine.ArmThumb2: target = TargetArch.Target_Thumb; break; + case (Machine) 0x6264: /* LoongArch64 */ + target = TargetArch.Target_LoongArch64; + break; default: Program.WriteWarning($"{machine} not supported on CoreDisTools"); return IntPtr.Zero; @@ -184,6 +188,9 @@ private void SetIndentations() // Instructions are dumped as 4-byte hexadecimal integers Machine.Arm64 => 4 * 2 + 1, + // Instructions are dumped as 4-byte hexadecimal integers + (Machine) 0x6264 => 4 * 2 + 1, /* LoongArch64 */ + _ => throw new NotImplementedException() }; @@ -253,7 +260,7 @@ public int GetInstruction(RuntimeFunction rtf, int imageOffset, int rtfOffset, o } else { - if (_reader.Machine == Machine.Arm64) + if ((_reader.Machine == Machine.Arm64) || (_reader.Machine == (Machine) 0x6264 /* LoongArch64 */)) { // Replace " hh hh hh hh " byte dump with " hhhhhhhh ". // CoreDisTools should be fixed to dump bytes this way for ARM64. @@ -334,6 +341,10 @@ public int GetInstruction(RuntimeFunction rtf, int imageOffset, int rtfOffset, o ProbeArm64Quirks(rtf, imageOffset, rtfOffset, ref fixedTranslatedLine); break; + case (Machine) 0x6264: /* LoongArch64 */ + //TODO-LoongArch64: maybe should add ProbeLoongArch64Quirks. At least it's unused now. + break; + case Machine.ArmThumb2: break; diff --git a/src/coreclr/tools/r2rdump/R2RDump.csproj b/src/coreclr/tools/r2rdump/R2RDump.csproj index 999cb7c4714d6..f0a60be4274e4 100644 --- a/src/coreclr/tools/r2rdump/R2RDump.csproj +++ b/src/coreclr/tools/r2rdump/R2RDump.csproj @@ -4,7 +4,7 @@ 1.0.0.0 true Exe - x64;x86;arm64;arm + x64;x86;arm64;arm;loongarch64 Open true $(NetCoreAppToolCurrent) From 82f55586a60381c8be31627dbb8ead78b9241645 Mon Sep 17 00:00:00 2001 From: qiaopengcheng Date: Wed, 10 May 2023 08:45:27 +0800 Subject: [PATCH 2/2] delete the hard coding of the Machine.LoongArch64 and Architecture.LoongArch64. --- .../ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs | 2 +- .../Amd64/GcSlotTable.cs | 2 +- .../Amd64/GcTransition.cs | 2 +- .../aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs | 2 +- .../ILCompiler.Reflection.ReadyToRun/GCInfoTypes.cs | 10 +++++----- .../ReadyToRunMethod.cs | 2 +- .../ReadyToRunReader.cs | 6 +++--- .../TransitionBlock.cs | 2 +- src/coreclr/tools/r2rdump/CoreDisTools.cs | 8 ++++---- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs index d7fb75285da82..cd578333425b7 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcInfo.cs @@ -259,7 +259,7 @@ public override string ToString() sb.AppendLine($" Has Tailcalls: {_wantsReportOnlyLeaf}"); } - else if (_machine == (Machine) 0x6264) /* LoongArch64 */ + else if (_machine == Machine.LoongArch64) { if (StackBaseRegister != 0xffffffff) { diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcSlotTable.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcSlotTable.cs index 17dc6a2da460e..8355a1a0976dc 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcSlotTable.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcSlotTable.cs @@ -68,7 +68,7 @@ private static string GetRegisterName(int registerNumber, Machine machine) case Machine.Arm64: return ((Arm64.Registers)registerNumber).ToString(); - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: return ((LoongArch64.Registers)registerNumber).ToString(); default: diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcTransition.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcTransition.cs index 7aa2ed6d593c7..ecea8cc1dfa6f 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcTransition.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/Amd64/GcTransition.cs @@ -65,7 +65,7 @@ public string GetSlotState(GcSlotTable slotTable, Machine machine) regType = typeof(Amd64.Registers); break; - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: regType = typeof(LoongArch64.Registers); break; diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs index 88dbcb9b65188..03110197b5877 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs @@ -72,7 +72,7 @@ public static string GetPlatformSpecificRegister(Machine machine, int regnum) return ((Arm.Registers)regnum).ToString(); case Machine.Arm64: return ((Arm64.Registers)regnum).ToString(); - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: return ((LoongArch64.Registers)regnum).ToString(); default: throw new NotImplementedException($"No implementation for machine type {machine}."); diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/GCInfoTypes.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/GCInfoTypes.cs index d7a0d80089192..9356bce3ccccd 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/GCInfoTypes.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/GCInfoTypes.cs @@ -149,7 +149,7 @@ internal GcInfoTypes(Machine machine) NUM_UNTRACKED_SLOTS_ENCBASE = 5; REGISTER_DELTA_ENCBASE = 3; break; - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: SIZE_OF_RETURN_KIND_FAT = 4; STACK_BASE_REGISTER_ENCBASE = 2; NUM_REGISTERS_ENCBASE = 3; @@ -164,7 +164,7 @@ internal int DenormalizeCodeLength(int x) case Machine.ArmThumb2: return (x << 1); case Machine.Arm64: - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: return (x << 2); } return x; @@ -179,7 +179,7 @@ internal int DenormalizeStackSlot(int x) case Machine.ArmThumb2: return (x << 2); case Machine.Arm64: - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: return (x << 3); } return x; @@ -195,7 +195,7 @@ internal uint DenormalizeStackBaseRegister(uint x) return ((x ^ 7) + 4); case Machine.Arm64: return (x ^ 29); - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: return ((x ^ 22) & 0x3); } return x; @@ -210,7 +210,7 @@ internal uint DenormalizeSizeOfStackArea(uint x) case Machine.ArmThumb2: return (x << 2); case Machine.Arm64: - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: return (x << 3); } return x; diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs index cbd89421742cc..dee60ea5daf3f 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs @@ -608,7 +608,7 @@ private void ParseRuntimeFunctions(bool partial) { unwindInfo = new Arm64.UnwindInfo(_readyToRunReader.Image, unwindOffset); } - else if (_readyToRunReader.Machine == (Machine) 0x6264) /* LoongArch64 */ + else if (_readyToRunReader.Machine == Machine.LoongArch64) { unwindInfo = new LoongArch64.UnwindInfo(_readyToRunReader.Image, unwindOffset); } diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs index 112a82c62e23a..3a1dd81575b55 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs @@ -658,8 +658,8 @@ private unsafe void EnsureHeader() _pointerSize = 8; break; - case (Machine)0x6264: /* LoongArch64 */ - _architecture = (Architecture)6; /* LoongArch64 */ + case Machine.LoongArch64: + _architecture = Architecture.LoongArch64; _pointerSize = 8; break; @@ -1443,7 +1443,7 @@ private void EnsureImportSections() case Machine.Amd64: case Machine.Arm64: - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: entrySize = 8; break; diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs index 4c01e2a1d4ebd..de5f9fa7db3bf 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs @@ -29,7 +29,7 @@ public static TransitionBlock FromReader(ReadyToRunReader reader) case Architecture.Arm64: return Arm64TransitionBlock.Instance; - case (Architecture) 6: /* LoongArch64 */ + case Architecture.LoongArch64: return LoongArch64TransitionBlock.Instance; default: diff --git a/src/coreclr/tools/r2rdump/CoreDisTools.cs b/src/coreclr/tools/r2rdump/CoreDisTools.cs index df752c70b1f0c..eda94336b6722 100644 --- a/src/coreclr/tools/r2rdump/CoreDisTools.cs +++ b/src/coreclr/tools/r2rdump/CoreDisTools.cs @@ -74,7 +74,7 @@ public static IntPtr GetDisasm(Machine machine) case Machine.ArmThumb2: target = TargetArch.Target_Thumb; break; - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: target = TargetArch.Target_LoongArch64; break; default: @@ -189,7 +189,7 @@ private void SetIndentations() Machine.Arm64 => 4 * 2 + 1, // Instructions are dumped as 4-byte hexadecimal integers - (Machine) 0x6264 => 4 * 2 + 1, /* LoongArch64 */ + Machine.LoongArch64 => 4 * 2 + 1, _ => throw new NotImplementedException() }; @@ -260,7 +260,7 @@ public int GetInstruction(RuntimeFunction rtf, int imageOffset, int rtfOffset, o } else { - if ((_reader.Machine == Machine.Arm64) || (_reader.Machine == (Machine) 0x6264 /* LoongArch64 */)) + if ((_reader.Machine == Machine.Arm64) || (_reader.Machine == Machine.LoongArch64)) { // Replace " hh hh hh hh " byte dump with " hhhhhhhh ". // CoreDisTools should be fixed to dump bytes this way for ARM64. @@ -341,7 +341,7 @@ public int GetInstruction(RuntimeFunction rtf, int imageOffset, int rtfOffset, o ProbeArm64Quirks(rtf, imageOffset, rtfOffset, ref fixedTranslatedLine); break; - case (Machine) 0x6264: /* LoongArch64 */ + case Machine.LoongArch64: //TODO-LoongArch64: maybe should add ProbeLoongArch64Quirks. At least it's unused now. break;