-
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] add crossgen2 for LoongArch64. (#72017)
* [LoongArch64] add crossgen2 for LoongArch64. * add `aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_LoongArch64` * amend the code format. * delete unused comments.
- Loading branch information
Showing
36 changed files
with
1,580 additions
and
26 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
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; | ||
} | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
...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,134 @@ | ||
// 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 EmitBreak() | ||
{ | ||
Builder.EmitUInt(0x002a0005); | ||
} | ||
|
||
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); | ||
} | ||
|
||
public void EmitMOV(Register regDst, Register regSrc) | ||
{ | ||
Builder.EmitUInt((uint)(0x03800000 | ((uint)regSrc << 5) | (uint)regDst)); | ||
} | ||
|
||
public void EmitMOV(Register regDst, ISymbolNode symbol) | ||
{ | ||
Builder.EmitReloc(symbol, RelocType.IMAGE_REL_BASED_LOONGARCH64_PC); | ||
// pcaddu12i reg, off-hi-20bits | ||
Builder.EmitUInt(0x1c000000u | (uint)regDst); | ||
|
||
// addi_d reg, reg, off-lo-12bits | ||
Builder.EmitUInt(0x02c00000u | (uint)(((uint)regDst << 5) | (uint)regDst)); | ||
} | ||
|
||
// pcaddi regDst, 0 | ||
public void EmitPC(Register regDst) | ||
{ | ||
Debug.Assert((uint)regDst > 0 && (uint)regDst < 32); | ||
Builder.EmitUInt(0x18000000 | (uint)regDst); | ||
} | ||
|
||
// addi.d regDst, regSrc, imm12 | ||
public void EmitADD(Register regDst, Register regSrc, int imm) | ||
{ | ||
Debug.Assert((imm >= -2048) && (imm <= 2047)); | ||
|
||
Builder.EmitUInt((uint)(0x02c00000 | (uint)((imm & 0xfff) << 10) | ((uint)regSrc << 5) | (uint)regDst)); | ||
} | ||
|
||
// xori regDst, regSrc, imm12 | ||
public void EmitXOR(Register regDst, Register regSrc, int imm) | ||
{ | ||
Debug.Assert((imm >= 0) && (imm <= 0xfff)); | ||
|
||
Builder.EmitUInt((uint)(0x03c00000 | (uint)((imm & 0xfff) << 10) | ((uint)regSrc << 5) | (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) << 10) | ((uint)regSrc << 5) | (uint)regDst)); | ||
} | ||
|
||
public void EmitRET() | ||
{ | ||
// jirl R0,R1,0 | ||
Builder.EmitUInt(0x4c000020); | ||
} | ||
|
||
public void EmitJMP(Register reg) | ||
{ | ||
Builder.EmitUInt(0x4c000000u | ((uint)reg << 5)); | ||
} | ||
|
||
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(); | ||
} | ||
} | ||
|
||
public void EmitRETIfEqual(Register regSrc) | ||
{ | ||
// BNEZ regSrc, 8 | ||
Builder.EmitUInt((uint)(0x44000000 | (2 << 10) | ((uint)regSrc << 5))); | ||
EmitRET(); | ||
} | ||
|
||
public void EmitJE(Register regSrc, ISymbolNode symbol) | ||
{ | ||
uint offset = symbol.RepresentsIndirectionCell ? 7u : 2u; | ||
|
||
// BNEZ regSrc, offset | ||
Builder.EmitUInt((uint)(0x44000000 | (offset << 10) | ((uint)regSrc << 5))); | ||
|
||
EmitJMP(symbol); | ||
} | ||
} | ||
} |
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, | ||
} | ||
} |
Oops, something went wrong.