aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-15 00:38:20 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-15 00:38:20 +0800
commitf6fdfb8d484b4e52cdb24a94a31b0f00d41a5eb7 (patch)
tree9362d0230db6174acdbe095288f4bbb1c4a896a9 /backend/include/rcc/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
parent7e2660ad5b7ec5b74cafed27f674939691f9e0fc (diff)
downloadrcc-project-f6fdfb8d484b4e52cdb24a94a31b0f00d41a5eb7.tar.gz
rcc-project-f6fdfb8d484b4e52cdb24a94a31b0f00d41a5eb7.tar.xz
[GlobalISel] Match LLVM CSE builder result semantics
Diffstat (limited to 'backend/include/rcc/CodeGen/GlobalISel/LegalizationArtifactCombiner.h')
-rw-r--r--backend/include/rcc/CodeGen/GlobalISel/LegalizationArtifactCombiner.h28
1 files changed, 19 insertions, 9 deletions
diff --git a/backend/include/rcc/CodeGen/GlobalISel/LegalizationArtifactCombiner.h b/backend/include/rcc/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
index 7e2961d..c0c7be0 100644
--- a/backend/include/rcc/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
+++ b/backend/include/rcc/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
@@ -101,8 +101,11 @@ public:
break;
case GenericOpcode::G_TRUNC:
Changed = tryCombineTrunc(Instruction, DeadInstructions, UpdatedDefs, Observer);
- if (Changed && !*Changed)
- UpdatedDefs.push_back(*Instruction.operandAt(0)->registerValue());
+ if (Changed && !*Changed) {
+ const Register *Destination = Instruction.operandAt(0)->getIf<Register>();
+ assert(Destination != nullptr);
+ UpdatedDefs.push_back(*Destination);
+ }
break;
}
if (!Changed)
@@ -377,11 +380,11 @@ private:
}
}
- [[nodiscard]] Expected<bool> isInstUnsupported(LegalizationQuery Query) const {
+ [[nodiscard]] Expected<bool> isInstUnsupported(const LegalizationQuery &Query) const {
return LI.isUnsupported(Query);
}
- [[nodiscard]] Expected<bool> isInstLegal(LegalizationQuery Query) const {
+ [[nodiscard]] Expected<bool> isInstLegal(const LegalizationQuery &Query) const {
return LI.isLegal(Query);
}
};
@@ -438,12 +441,15 @@ inline Expected<void> LegalizationArtifactCombiner::buildConstant(Register Desti
inline Expected<Register> LegalizationArtifactCombiner::buildConstant(LowLevelType Type,
APInt Value) {
- auto Destination = MRI.createVirtualRegister(Type);
- if (!Destination)
- return std::unexpected(Destination.error());
- auto Built = buildConstant(*Destination, std::move(Value));
+ auto Built = Builder.buildConstant(Type, std::move(Value));
if (!Built)
return std::unexpected(Built.error());
+ const MachineOperand *Definition = (*Built)->operandAt(0);
+ const Register *Destination = Definition == nullptr ? nullptr : Definition->getIf<Register>();
+ if (Destination == nullptr || !Definition->isDef()) {
+ return makeUnexpected(ErrorCode::InternalError,
+ "constant builder returned an instruction without a register definition");
+ }
return *Destination;
}
@@ -1309,7 +1315,11 @@ inline Expected<bool> LegalizationArtifactCombiner::tryCombineUnmergeValues(
Destinations.reserve(NewDefCount);
for (std::size_t Index = 0; Index < NewDefCount; ++Index)
Destinations.push_back(Unmerge.getReg(SourceIndex * NewDefCount + Index));
- Register SplitSource = *registerOperand(*Merge, SourceIndex + 1);
+ const auto SplitSourceOperand = registerOperand(*Merge, SourceIndex + 1);
+ if (!SplitSourceOperand)
+ return makeUnexpected(ErrorCode::VerificationError,
+ "merge source is not a register operand");
+ Register SplitSource = SplitSourceOperand.value();
if (ConvertOpcode) {
auto ConvertedType = divideType(*OperandType, MergeSourceCount);
if (!ConvertedType)