From f6fdfb8d484b4e52cdb24a94a31b0f00d41a5eb7 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Sat, 15 Aug 2026 00:38:20 +0800 Subject: [GlobalISel] Match LLVM CSE builder result semantics --- backend/lib/CodeGen/GlobalISel/LegalizerInfo.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'backend/lib/CodeGen/GlobalISel/LegalizerInfo.cpp') diff --git a/backend/lib/CodeGen/GlobalISel/LegalizerInfo.cpp b/backend/lib/CodeGen/GlobalISel/LegalizerInfo.cpp index c4cf946..ee7f856 100644 --- a/backend/lib/CodeGen/GlobalISel/LegalizerInfo.cpp +++ b/backend/lib/CodeGen/GlobalISel/LegalizerInfo.cpp @@ -295,7 +295,7 @@ LegalizeRuleSet &LegalizeRuleSet::clampScalar(std::size_t TypeIndex, LowLevelTyp LegalizeRuleSet &LegalizeRuleSet::scalarSameSizeAs(std::size_t TypeIndex, std::size_t ReferenceTypeIndex) { - const auto changeToReference = [TypeIndex, ReferenceTypeIndex](const LegalizationQuery &Query) { + const auto ChangeToReference = [TypeIndex, ReferenceTypeIndex](const LegalizationQuery &Query) { return std::pair{TypeIndex, scalarType(Query.Types[ReferenceTypeIndex].scalarBitWidth())}; }; widenScalarIf( @@ -306,7 +306,7 @@ LegalizeRuleSet &LegalizeRuleSet::scalarSameSizeAs(std::size_t TypeIndex, Query.Types[TypeIndex].scalarBitWidth() < Query.Types[ReferenceTypeIndex].scalarBitWidth(); }, - changeToReference); + ChangeToReference); return narrowScalarIf( [TypeIndex, ReferenceTypeIndex](const LegalizationQuery &Query) { return TypeIndex < Query.Types.size() && ReferenceTypeIndex < Query.Types.size() && @@ -315,7 +315,7 @@ LegalizeRuleSet &LegalizeRuleSet::scalarSameSizeAs(std::size_t TypeIndex, Query.Types[TypeIndex].scalarBitWidth() > Query.Types[ReferenceTypeIndex].scalarBitWidth(); }, - changeToReference); + ChangeToReference); } LegalizeRuleSet &LegalizeRuleSet::lowerIfMemSizeNotByteSizePow2(std::size_t MemoryIndex) { @@ -327,6 +327,10 @@ LegalizeRuleSet &LegalizeRuleSet::lowerIfMemSizeNotByteSizePow2(std::size_t Memo }); } +LegalizeRuleSet &LegalizeRuleSet::custom() { + return customIf([](const LegalizationQuery &) { return true; }); +} + LegalizeRuleSet &LegalizeRuleSet::alwaysLegal() { return legalIf([](const LegalizationQuery &) { return true; }); } @@ -401,13 +405,15 @@ Expected LegalizerInfo::buildQuery(const MachineInstr &Instru auto Info = Function.registerInfo().virtualRegisterInfo(*Reg); if (!Info) return std::unexpected(Info.error()); - if (!Info->get().Type) + const std::optional &RegisterType = Info->get().Type; + if (!RegisterType.has_value()) return makeUnexpected(ErrorCode::VerificationError, "legalization type operand has no LowLevelType"); - if (OptionalTypes[TypeIndex] && *OptionalTypes[TypeIndex] != *Info->get().Type) + std::optional &ExistingType = OptionalTypes[TypeIndex]; + if (ExistingType.has_value() && ExistingType.value() != RegisterType.value()) return makeUnexpected(ErrorCode::VerificationError, "legalization type operands disagree within one type index"); - OptionalTypes[TypeIndex] = *Info->get().Type; + ExistingType = RegisterType.value(); TypeOperands[TypeIndex].push_back(Index); } -- cgit v1.2.3