-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LoongArch64] implements the crossgen2 for LoongArch64.
- Loading branch information
Showing
25 changed files
with
899 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_LoongArch64/AddrMode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
namespace ILCompiler.DependencyAnalysis.LoongArch64 | ||
{ | ||
public enum AddrModeSize | ||
{ | ||
Int8 = 1, | ||
Int16 = 2, | ||
Int32 = 4, | ||
Int64 = 8, | ||
Int128 = 16 | ||
} | ||
|
||
public struct AddrMode | ||
{ | ||
public readonly Register BaseReg; | ||
public readonly Register? IndexReg; | ||
public readonly int Offset; | ||
public readonly byte Scale; | ||
public readonly AddrModeSize Size; | ||
|
||
public AddrMode(Register baseRegister, Register? indexRegister, int offset, byte scale, AddrModeSize size) | ||
{ | ||
BaseReg = baseRegister; | ||
IndexReg = indexRegister; | ||
Offset = offset; | ||
Scale = scale; | ||
Size = size; | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...coreclr/tools/Common/Compiler/DependencyAnalysis/Target_LoongArch64/LoongArch64Emitter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// 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.Diagnostics; | ||
|
||
namespace ILCompiler.DependencyAnalysis.LoongArch64 | ||
{ | ||
public struct LoongArch64Emitter | ||
{ | ||
public LoongArch64Emitter(NodeFactory factory, bool relocsOnly) | ||
{ | ||
Builder = new ObjectDataBuilder(factory, relocsOnly); | ||
TargetRegister = new TargetRegisterMap(factory.Target.OperatingSystem); | ||
} | ||
|
||
public ObjectDataBuilder Builder; | ||
public TargetRegisterMap TargetRegister; | ||
|
||
// Assembly stub creation api. TBD, actually make this general purpose | ||
|
||
public void EmitMOV(Register regDst, ushort imm16) | ||
{ | ||
Debug.Assert((uint)regDst <= 0x1f); | ||
Debug.Assert(imm16 <= 0xfff); | ||
uint instruction = 0x03800000u | (uint)((imm16 & 0xfff) << 10) | (uint)regDst; | ||
Builder.EmitUInt(instruction); | ||
} | ||
|
||
// pcaddi regDst, 0 | ||
public void EmitPC(Register regDst) | ||
{ | ||
Debug.Assert((uint)regDst > 0 && (uint)regDst < 32); | ||
Builder.EmitUInt(0x18000000 | (uint)regDst); | ||
} | ||
|
||
// ld_d regDst, regAddr, offset | ||
public void EmitLD(Register regDst, Register regSrc, int offset) | ||
{ | ||
Debug.Assert(offset >= -2048 && offset <= 2047); | ||
|
||
Builder.EmitUInt((uint)(0x28c00000 | (uint)((offset & 0xfff) << 12) | ((uint)regSrc << 5) | (uint)regDst)); | ||
} | ||
|
||
public void EmitJMP(ISymbolNode symbol) | ||
{ | ||
if (symbol.RepresentsIndirectionCell) | ||
{ | ||
// pcaddi R21, 0 | ||
EmitPC(Register.R21); | ||
|
||
EmitLD(Register.R21, Register.R21, 0x10); | ||
|
||
// ld_d R21, R21, 0 | ||
EmitLD(Register.R21, Register.R21, 0); | ||
|
||
// jirl R0,R21,0 | ||
Builder.EmitUInt(0x4c0002a0); | ||
|
||
Builder.EmitReloc(symbol, RelocType.IMAGE_REL_BASED_DIR64); | ||
} | ||
else | ||
{ | ||
//Builder.EmitReloc(symbol, RelocType.IMAGE_REL_BASED_LOONGARCH64_PC); | ||
Builder.EmitUInt(0xffffffff); // bad code. | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_LoongArch64/Register.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ILCompiler.DependencyAnalysis.LoongArch64 | ||
{ | ||
public enum Register | ||
{ | ||
R0 = 0, | ||
R1 = 1, | ||
R2 = 2, | ||
R3 = 3, | ||
R4 = 4, | ||
R5 = 5, | ||
R6 = 6, | ||
R7 = 7, | ||
R8 = 8, | ||
R9 = 9, | ||
R10 = 10, | ||
R11 = 11, | ||
R12 = 12, | ||
R13 = 13, | ||
R14 = 14, | ||
R15 = 15, | ||
R16 = 16, | ||
R17 = 17, | ||
R18 = 18, | ||
R19 = 19, | ||
R20 = 20, | ||
R21 = 21, | ||
R22 = 22, | ||
R23 = 23, | ||
R24 = 24, | ||
R25 = 25, | ||
R26 = 26, | ||
R27 = 27, | ||
R28 = 28, | ||
R29 = 29, | ||
R30 = 30, | ||
R31 = 31, | ||
|
||
None = 32, | ||
NoIndex = 128, | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_LoongArch64/TargetRegisterMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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 Internal.TypeSystem; | ||
|
||
namespace ILCompiler.DependencyAnalysis.LoongArch64 | ||
{ | ||
/// <summary> | ||
/// Maps logical registers to physical registers on a specified OS. | ||
/// </summary> | ||
public struct TargetRegisterMap | ||
{ | ||
public readonly Register Arg0; | ||
public readonly Register Arg1; | ||
public readonly Register Arg2; | ||
public readonly Register Arg3; | ||
public readonly Register Arg4; | ||
public readonly Register Arg5; | ||
public readonly Register Arg6; | ||
public readonly Register Arg7; | ||
public readonly Register Result; | ||
|
||
public TargetRegisterMap(TargetOS os) | ||
{ | ||
Arg0 = Register.R4; | ||
Arg1 = Register.R5; | ||
Arg2 = Register.R6; | ||
Arg3 = Register.R7; | ||
Arg4 = Register.R8; | ||
Arg5 = Register.R9; | ||
Arg6 = Register.R11; | ||
Arg7 = Register.R12; | ||
Result = Register.R4; // TODO: ??? | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.