aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/Target/RISCV/RISCVTarget.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-07 22:03:11 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-07 22:03:11 +0800
commit3e15bfd7b075209ec3b65d30d0611e060f6fbb77 (patch)
tree9a55310fddbb48a87f32bd964ff94374593f3f4c /backend/lib/Target/RISCV/RISCVTarget.cpp
parente16de95dce32f077361577377d5c52fc4ad78339 (diff)
downloadrcc-project-3e15bfd7b075209ec3b65d30d0611e060f6fbb77.tar.gz
rcc-project-3e15bfd7b075209ec3b65d30d0611e060f6fbb77.tar.xz
[RISCV] Complete RV64GC instruction description
Diffstat (limited to 'backend/lib/Target/RISCV/RISCVTarget.cpp')
-rw-r--r--backend/lib/Target/RISCV/RISCVTarget.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/backend/lib/Target/RISCV/RISCVTarget.cpp b/backend/lib/Target/RISCV/RISCVTarget.cpp
index bbad827..8b3741a 100644
--- a/backend/lib/Target/RISCV/RISCVTarget.cpp
+++ b/backend/lib/Target/RISCV/RISCVTarget.cpp
@@ -2,11 +2,15 @@
#include "rcc/Target/RISCV/RISCVTarget.h"
+#include "rcc/CodeGen/GenericOpcodes.h"
+
+#include <array>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <memory>
+#include <span>
#include <utility>
#include <vector>
@@ -93,6 +97,27 @@ Expected<TargetMIRTextInfo> createMIRTextInfo() {
return TargetMIRTextInfo::create(std::move(Description), *Registers);
}
+Expected<TargetDescription> createTargetDescription() {
+ auto Registers = createRegisterInfo();
+ if (!Registers)
+ return std::unexpected(Registers.error());
+
+ std::vector<InstructionDescriptor> Descriptors;
+ std::vector<rcc::ImmediatePredicate> Predicates;
+ appendGeneratedInstructionInfo(Descriptors, Predicates);
+ auto GenericInfo = appendGenericInstructionInfo(Descriptors, Predicates);
+ if (!GenericInfo)
+ return std::unexpected(GenericInfo.error());
+ auto Instructions = InstructionSet::create(std::move(Descriptors), std::move(Predicates));
+ if (!Instructions)
+ return std::unexpected(Instructions.error());
+
+ TargetMIRTextInfoDesc MIRText;
+ appendGeneratedMIRTextInfo(MIRText);
+ return TargetDescription::create(std::move(*Instructions), std::move(*Registers),
+ std::move(MIRText));
+}
+
std::shared_ptr<const RegisterMask> createCallPreservedMask() {
TargetMIRTextInfoDesc Description;
appendGeneratedMIRTextInfo(Description);
@@ -100,4 +125,40 @@ std::shared_ptr<const RegisterMask> createCallPreservedMask() {
return Description.RegisterMasks.front().Mask;
}
+std::span<const SchedulingClassInfo> schedulingClasses() noexcept {
+ return GeneratedSchedulingClasses;
+}
+
+std::span<const EncodingCategoryInfo> encodingCategories() noexcept {
+ return GeneratedEncodingCategories;
+}
+
+std::span<const AssemblyFormatInfo> assemblyFormats() noexcept {
+ return GeneratedAssemblyFormats;
+}
+
+std::span<const AssemblyInstructionInfo> assemblyInstructions() noexcept {
+ return GeneratedAssemblyInstructions;
+}
+
+const AssemblyInstructionInfo *assemblyInstruction(Opcode InstructionOpcode) noexcept {
+ for (const AssemblyInstructionInfo &Info : GeneratedAssemblyInstructions) {
+ if (Info.InstructionOpcode == InstructionOpcode)
+ return &Info;
+ }
+ return nullptr;
+}
+
+std::span<const CallingConventionInfo> callingConventions() noexcept {
+ return GeneratedCallingConventions;
+}
+
+const CallingConventionInfo *callingConvention(CallingConvention ID) noexcept {
+ for (const CallingConventionInfo &Info : GeneratedCallingConventions) {
+ if (Info.ID == ID)
+ return &Info;
+ }
+ return nullptr;
+}
+
} // namespace rcc::riscv