Skip to content

Commit 970070e

Browse files
Fill out more SuperPMI cases for LoongArch64 and RISCV64 (#114136)
* Fill out more SuperPMI cases for LoongArch64 and RISCV64 With these changes, SuperPMI can be used with a LoongArch64 or RISCV64 cross-targeting altjit and x64 MCH files to generate and view some code. There are lots of "missing data" cases; for RISCV64 about half of x64 contexts replay successfully. More work is required for asmdiffs to work, such as updating coredistools and implementing Loongarch64/RISCV64 relocation handling. * Fix Release build
1 parent 7c05ef1 commit 970070e

File tree

10 files changed

+79
-17
lines changed

10 files changed

+79
-17
lines changed

src/coreclr/jit/compiler.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10793,7 +10793,15 @@ class Compiler
1079310793
{
1079410794
return info.compMethodSuperPMIIndex != -1;
1079510795
}
10796-
#endif // DEBUG
10796+
#else // !DEBUG
10797+
// Are we running a replay under SuperPMI?
10798+
// Note: you can certainly run a SuperPMI replay with a non-DEBUG JIT, and if necessary and useful we could
10799+
// make compMethodSuperPMIIndex always available.
10800+
bool RunningSuperPmiReplay() const
10801+
{
10802+
return false;
10803+
}
10804+
#endif // !DEBUG
1079710805

1079810806
ReturnTypeDesc compRetTypeDesc; // ABI return type descriptor for the method
1079910807

src/coreclr/jit/disasm.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,10 @@ bool DisAssembler::InitCoredistoolsDisasm()
17041704
coreDisTargetArchitecture = Target_X86;
17051705
#elif defined(TARGET_AMD64)
17061706
coreDisTargetArchitecture = Target_X64;
1707+
#elif defined(TARGET_LOONGARCH64)
1708+
coreDisTargetArchitecture = Target_LoongArch64;
1709+
#elif 0 && defined(TARGET_RISCV64) // TODO-RISCV64: enable this when coredistools is updated
1710+
coreDisTargetArchitecture = Target_RiscV64;
17071711
#else
17081712
#error Unsupported target for LATE_DISASM with USE_COREDISTOOLS
17091713
#endif

src/coreclr/jit/importercalls.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,12 @@ var_types Compiler::impImportCall(OPCODE opcode,
219219
// <NICE> Factor this into getCallInfo </NICE>
220220
bool isSpecialIntrinsic = false;
221221

222-
if (isIntrinsic || !info.compMatchedVM)
222+
if (isIntrinsic || (!info.compMatchedVM && !RunningSuperPmiReplay()))
223223
{
224224
// For mismatched VM (AltJit) we want to check all methods as intrinsic to ensure
225-
// we get more accurate codegen. This particularly applies to HWIntrinsic usage
225+
// we get more accurate codegen. This particularly applies to HWIntrinsic usage.
226+
// But don't do this under SuperPMI replay, because it's unlikely we'll have
227+
// the right data in the MethodContext in that case.
226228

227229
const bool isTailCall = canTailCall && (tailCallFlags != 0);
228230

src/coreclr/scripts/superpmi.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@
145145

146146
host_os_help = "OS (windows, osx, linux). Default: current OS."
147147

148-
arch_help = "Architecture (x64, x86, arm, arm64). Default: current architecture."
148+
arch_help = "Architecture (x64, x86, arm, arm64, loongarch64, riscv64). Default: current architecture."
149149

150150
target_os_help = "Target OS, for use with cross-compilation JIT (windows, osx, linux). Default: current OS."
151151

152-
target_arch_help = "Target architecture, for use with cross-compilation JIT (x64, x86, arm, arm64). Passed as asm diffs target to SuperPMI. Default: current architecture."
152+
target_arch_help = "Target architecture, for use with cross-compilation JIT (x64, x86, arm, arm64, loongarch64, riscv64). Passed as asm diffs target to SuperPMI. Default: current architecture."
153153

154-
mch_arch_help = "Architecture of MCH files to download, used for cross-compilation altjit (x64, x86, arm, arm64). Default: target architecture."
154+
mch_arch_help = "Architecture of MCH files to download, used for cross-compilation altjit (x64, x86, arm, arm64, loongarch64, riscv64). Default: target architecture."
155155

156156
build_type_help = "Build type (Debug, Checked, Release). Default: Checked."
157157

@@ -4629,6 +4629,15 @@ def verify_target_args():
46294629
lambda mch_arch: "Unknown mch_arch {}\nSupported architectures: {}".format(mch_arch, (", ".join(coreclr_args.valid_arches))),
46304630
modify_arg=lambda mch_arch: mch_arch if mch_arch is not None else coreclr_args.target_arch) # Default to `target_arch`
46314631

4632+
# For LoongArch64, RiscV64, assume we are doing altjit cross-compilation and set mch_arch to 'arch', and target_os to Linux.
4633+
if coreclr_args.target_arch == "loongarch64" or coreclr_args.target_arch == "riscv64":
4634+
if coreclr_args.target_os == coreclr_args.host_os and coreclr_args.target_os != "linux":
4635+
logging.warning("Overriding 'target_os' to 'linux'")
4636+
coreclr_args.target_os = "linux"
4637+
if coreclr_args.mch_arch == coreclr_args.target_arch and coreclr_args.mch_arch != coreclr_args.arch:
4638+
logging.warning("Overriding 'mch_arch' to '%s'", coreclr_args.arch)
4639+
coreclr_args.mch_arch = coreclr_args.arch
4640+
46324641
def verify_superpmi_common_args():
46334642

46344643
coreclr_args.verify(args,

src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,11 +911,6 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b
911911
}
912912
}
913913

914-
if (targetArch == SPMI_TARGET_ARCHITECTURE_LOONGARCH64)
915-
{
916-
Assert(!"FIXME: Not Implements on loongarch64");
917-
}
918-
919914
if (IsSpmiTarget64Bit())
920915
{
921916
if (!wasRelocHandled && (relocType == IMAGE_REL_BASED_DIR64))

src/coreclr/tools/superpmi/superpmi-shared/spmiutil.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,16 @@ void SetSpmiTargetArchitecture(SPMI_TARGET_ARCHITECTURE spmiTargetArchitecture);
6363

6464
inline bool IsSpmiTarget32Bit()
6565
{
66-
return (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_X86) || (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_ARM);
66+
return (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_X86) ||
67+
(GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_ARM);
6768
}
6869

6970
inline bool IsSpmiTarget64Bit()
7071
{
71-
return (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_AMD64) || (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_ARM64) || (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_LOONGARCH64) || (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_RISCV64);
72+
return (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_AMD64) ||
73+
(GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_ARM64) ||
74+
(GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_LOONGARCH64) ||
75+
(GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_RISCV64);
7276
}
7377

7478
inline size_t SpmiTargetPointerSize()

src/coreclr/tools/superpmi/superpmi/commandline.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ void CommandLine::DumpHelp(const char* program)
127127
printf(" trying to measure JIT throughput for a specific set of methods. Default=1.\n");
128128
printf("\n");
129129
printf(" -target <target>\n");
130-
printf(" Used by the assembly differences calculator. This specifies the target\n");
131-
printf(" architecture for cross-compilation. Currently allowed <target> values: x64, x86, arm, arm64\n");
130+
printf(" Specifies the target architecture if doing cross-compilation.\n");
131+
printf(" Allowed <target> values: x64, x86, arm, arm64, loongarch64, riscv64\n");
132+
printf(" Used by the assembly differences calculator; to determine a default JIT dll name;\n");
133+
printf(" and to avoid treating mismatched cross-compilation replay as failure.\n");
132134
printf("\n");
133135
printf(" -coredistools\n");
134136
printf(" Use disassembly tools from the CoreDisTools library\n");
@@ -685,9 +687,11 @@ bool CommandLine::Parse(int argc, char* argv[], /* OUT */ Options* o)
685687
(0 != _stricmp(o->targetArchitecture, "x86")) &&
686688
(0 != _stricmp(o->targetArchitecture, "arm64")) &&
687689
(0 != _stricmp(o->targetArchitecture, "arm")) &&
688-
(0 != _stricmp(o->targetArchitecture, "arm32")))
690+
(0 != _stricmp(o->targetArchitecture, "arm32")) &&
691+
(0 != _stricmp(o->targetArchitecture, "loongarch64")) &&
692+
(0 != _stricmp(o->targetArchitecture, "riscv64")))
689693
{
690-
LogError("Illegal target architecture specified with -target (use 'x64', 'x86', 'arm64', or 'arm').");
694+
LogError("Illegal target architecture specified with -target.");
691695
DumpHelp(argv[0]);
692696
return false;
693697
}
@@ -753,6 +757,10 @@ bool CommandLine::Parse(int argc, char* argv[], /* OUT */ Options* o)
753757
hostArch = "arm";
754758
#elif defined(HOST_ARM64)
755759
hostArch = "arm64";
760+
#elif defined(HOST_LOONGARCH64)
761+
hostArch = "loongarch64";
762+
#elif defined(HOST_RISCV64)
763+
hostArch = "riscv64";
756764
#else
757765
allowDefaultJIT = false;
758766
#endif
@@ -773,6 +781,12 @@ bool CommandLine::Parse(int argc, char* argv[], /* OUT */ Options* o)
773781
case SPMI_TARGET_ARCHITECTURE_ARM64:
774782
targetArch = "arm64";
775783
break;
784+
case SPMI_TARGET_ARCHITECTURE_LOONGARCH64:
785+
targetArch = "loongarch64";
786+
break;
787+
case SPMI_TARGET_ARCHITECTURE_RISCV64:
788+
targetArch = "riscv64";
789+
break;
776790
default:
777791
allowDefaultJIT = false;
778792
break;
@@ -810,6 +824,10 @@ bool CommandLine::Parse(int argc, char* argv[], /* OUT */ Options* o)
810824
case SPMI_TARGET_ARCHITECTURE_ARM64:
811825
jitOSName = "universal";
812826
break;
827+
case SPMI_TARGET_ARCHITECTURE_LOONGARCH64:
828+
case SPMI_TARGET_ARCHITECTURE_RISCV64:
829+
jitOSName = "unix";
830+
break;
813831
default:
814832
// Can't get here if `allowDefaultJIT` was properly set above.
815833
break;

src/coreclr/tools/superpmi/superpmi/jitinstance.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ ReplayResults JitInstance::CompileMethod(MethodContext* MethodToCompile, int mcI
297297
matchesTargetArch = (targetArch == SPMI_TARGET_ARCHITECTURE_ARM64);
298298
break;
299299

300+
case IMAGE_FILE_MACHINE_LOONGARCH64:
301+
matchesTargetArch = (targetArch == SPMI_TARGET_ARCHITECTURE_LOONGARCH64);
302+
break;
303+
304+
case IMAGE_FILE_MACHINE_RISCV64:
305+
matchesTargetArch = (targetArch == SPMI_TARGET_ARCHITECTURE_RISCV64);
306+
break;
307+
300308
default:
301309
LogError("Unknown target architecture");
302310
break;

src/coreclr/tools/superpmi/superpmi/neardiffer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ bool NearDiffer::InitAsmDiff()
149149
{
150150
coreDisTargetArchitecture = Target_Arm64;
151151
}
152+
else if (0 == _stricmp(TargetArchitecture, "loongarch64"))
153+
{
154+
coreDisTargetArchitecture = Target_LoongArch64;
155+
}
156+
#if 0 // TODO-RISCV64: enable this when coredistools is updated with one that supports RISC-V
157+
else if (0 == _stricmp(TargetArchitecture, "riscv64"))
158+
{
159+
coreDisTargetArchitecture = Target_RiscV64;
160+
}
161+
#endif // 0
152162
else
153163
{
154164
LogError("Illegal target architecture '%s'", TargetArchitecture);

src/coreclr/tools/superpmi/superpmi/superpmi.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ void SetSuperPmiTargetArchitecture(const char* targetArchitecture)
5858
{
5959
SetSpmiTargetArchitecture(SPMI_TARGET_ARCHITECTURE_LOONGARCH64);
6060
}
61+
else if (0 == _stricmp(targetArchitecture, "riscv64"))
62+
{
63+
SetSpmiTargetArchitecture(SPMI_TARGET_ARCHITECTURE_RISCV64);
64+
}
6165
else
6266
{
6367
LogError("Illegal target architecture '%s'", targetArchitecture);

0 commit comments

Comments
 (0)