diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-28 18:51:10 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-28 18:51:10 +0800 |
| commit | f89d528efc0228c049c2867dcba886a56bac8619 (patch) | |
| tree | 7a47f751e729845af1537beee20bc57007d3e21c /backend/lib/Tooling/BackendInvocation.cpp | |
| parent | 6889b82a5c9ecc6bd178760c66653d7af0121162 (diff) | |
| download | rcc-project-f89d528efc0228c049c2867dcba886a56bac8619.tar.gz rcc-project-f89d528efc0228c049c2867dcba886a56bac8619.tar.xz | |
[CodeGen] Add target machine registry
Diffstat (limited to 'backend/lib/Tooling/BackendInvocation.cpp')
| -rw-r--r-- | backend/lib/Tooling/BackendInvocation.cpp | 72 |
1 files changed, 56 insertions, 16 deletions
diff --git a/backend/lib/Tooling/BackendInvocation.cpp b/backend/lib/Tooling/BackendInvocation.cpp index 232d34f..8fbc4d6 100644 --- a/backend/lib/Tooling/BackendInvocation.cpp +++ b/backend/lib/Tooling/BackendInvocation.cpp @@ -7,7 +7,9 @@ #include "rcc/CodeGen/TargetDescription.h" #include "rcc/CodeGen/TargetMIRTextInfo.h" #include "rcc/CodeGen/TargetRegisterInfo.h" +#include "rcc/MC/TargetRegistry.h" #include "rcc/Support/SHA256.h" +#include "rcc/Target/TargetMachine.h" #include <algorithm> #include <cctype> @@ -374,27 +376,65 @@ std::string BackendInvocation::canonicalText() const { return Output; } -BackendInvocation defaultRV64GCInvocation() { +Expected<BackendInvocation> defaultBackendInvocation(const Target &Target) { + TargetMachineOptions Defaults = Target.defaultMachineOptions(); BackendInvocation Result; - Result.Triple = "riscv64-unknown-linux-gnu"; - Result.CPU = "generic-rv64gc"; - Result.TuneCPU = "generic-rv64gc"; - Result.Features = {"+i", "+m", "+a", "+f", "+d", "+c", "+zicsr", "+zifencei"}; - Result.ABI = "lp64d"; - Result.DataLayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"; - Result.TargetOptions = { - {"function-sections", "false"}, - {"omit-frame-pointer", "true"}, - {"stack-realignment", "false"}, - }; - Result.AssemblerFlavor = "rcc-integrated-gnu"; - Result.AssemblerVersion = "rcc-mc-v1"; - Result.AssemblerOptions = {{"relax", "true"}}; + Result.Triple = std::move(Defaults.Triple); + Result.CPU = std::move(Defaults.CPU); + Result.TuneCPU = std::move(Defaults.TuneCPU); + Result.Features = std::move(Defaults.Features); + Result.ABI = std::move(Defaults.ABI); + Result.DataLayout = std::move(Defaults.DataLayout); + Result.Relocation = Defaults.Relocation; + Result.Code = Defaults.Code; + Result.Optimization = Defaults.Optimization; + Result.TargetOptions = std::move(Defaults.Options); + Result.TargetABILoweringVersion = std::move(Defaults.ABILoweringVersion); + Result.AssemblerFlavor = std::move(Defaults.AssemblerFlavor); + Result.AssemblerVersion = std::move(Defaults.AssemblerVersion); + Result.AssemblerOptions = std::move(Defaults.AssemblerOptions); auto Verified = Result.canonicalizeAndVerify(); - (void)Verified; + if (!Verified) + return std::unexpected(Verified.error()); return Result; } +Expected<std::unique_ptr<TargetMachine>> createTargetMachine(const BackendInvocation &Invocation) { + BackendInvocation Canonical = Invocation; + auto Verified = Canonical.canonicalizeAndVerify(); + if (!Verified) + return std::unexpected(Verified.error()); + if (Canonical != Invocation) { + return makeUnexpected(ErrorCode::InvalidInvocation, + "backend invocation must be canonicalized before execution"); + } + if (Invocation.MIRReferenceRevision != LLVMReferenceRevision || + Invocation.GenericOpcodeVersion != GenericOpcodeReferenceVersion) { + return makeUnexpected(ErrorCode::InvalidInvocation, + "backend invocation reference versions do not match this build"); + } + auto RegisteredTarget = TargetRegistry::lookupTarget(Invocation.Triple); + if (!RegisteredTarget) + return std::unexpected(RegisteredTarget.error()); + TargetMachineOptions Options{ + .Triple = Invocation.Triple, + .CPU = Invocation.CPU, + .TuneCPU = Invocation.TuneCPU, + .Features = Invocation.Features, + .ABI = Invocation.ABI, + .DataLayout = Invocation.DataLayout, + .Relocation = Invocation.Relocation, + .Code = Invocation.Code, + .Optimization = Invocation.Optimization, + .Options = Invocation.TargetOptions, + .ABILoweringVersion = Invocation.TargetABILoweringVersion, + .AssemblerFlavor = Invocation.AssemblerFlavor, + .AssemblerVersion = Invocation.AssemblerVersion, + .AssemblerOptions = Invocation.AssemblerOptions, + }; + return (*RegisteredTarget)->createTargetMachine(std::move(Options)); +} + Expected<std::string> computeTargetDescriptionFingerprint(const TargetDescription &Target) { std::string Canonical; appendField(Canonical, "fingerprint-schema", "rcc-target-fingerprint-v1"); |
