aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-16 01:59:50 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-16 01:59:50 +0800
commit3c998e2fc02c6ca7869c586cbf2e1cbb7ea3c7bf (patch)
treee0fb78534283e4cd74499e6779fb8a11cbc43261 /backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp
parent0146ac880f8acac482be73a23aac99ad37452c20 (diff)
downloadrcc-project-3c998e2fc02c6ca7869c586cbf2e1cbb7ea3c7bf.tar.gz
rcc-project-3c998e2fc02c6ca7869c586cbf2e1cbb7ea3c7bf.tar.xz
[GlobalISel] Propagate no-fp-except flags
Diffstat (limited to 'backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp')
-rw-r--r--backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp
index 862b63f..1f7f453 100644
--- a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp
+++ b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp
@@ -169,6 +169,36 @@ void combineFingerprint(std::uint64_t &State, std::uint64_t Value) noexcept {
} // namespace
+Expected<void> InstructionSelector::propagateSelectionFlags(MachineInstr &Output,
+ MachineInstrFlags InputFlags,
+ bool InputMayRaiseFPException,
+ const TargetDescription &Target) const {
+ const InstructionDescriptor *OutputDescriptor = Target.instructionDescriptor(Output.opcode());
+ if (OutputDescriptor == nullptr) {
+ return makeUnexpected(ErrorCode::VerificationError,
+ "instruction selector produced an unknown instruction descriptor");
+ }
+ if (!InputMayRaiseFPException &&
+ OutputDescriptor->Flags.has(InstructionFlag::MayRaiseFPException)) {
+ InputFlags.set(MachineInstrFlag::NoFPExcept);
+ }
+ Output.setFlags(InputFlags);
+ return {};
+}
+
+Expected<void> InstructionSelector::propagateSelectionFlags(MachineInstr &Output,
+ const MachineInstr &Input,
+ const TargetDescription &Target) const {
+ const InstructionDescriptor *InputDescriptor = Target.instructionDescriptor(Input.opcode());
+ if (InputDescriptor == nullptr) {
+ return makeUnexpected(ErrorCode::VerificationError,
+ "instruction selector input has an unknown instruction descriptor");
+ }
+ return propagateSelectionFlags(Output, Input.flags(),
+ InputDescriptor->Flags.has(InstructionFlag::MayRaiseFPException),
+ Target);
+}
+
const MachinePassContract &InstructionSelect::contract() const noexcept {
return instructionSelectContract();
}
@@ -272,6 +302,9 @@ Expected<MachinePassResult> InstructionSelect::runImplementation(MachineFunction
CurrentDescriptor->Name + "'",
ErrorCode::VerificationError));
}
+ const MachineInstrFlags InputFlags = Instruction->flags();
+ const bool InputMayRaiseFPException =
+ CurrentDescriptor->Flags.has(InstructionFlag::MayRaiseFPException);
auto Selection = Info->select(*Instruction, Function, Target);
if (!Selection)
return std::unexpected(Selection.error());
@@ -279,6 +312,10 @@ Expected<MachinePassResult> InstructionSelect::runImplementation(MachineFunction
if (Selected == nullptr)
return std::unexpected(
passFailure("instruction selector produced an unknown instruction descriptor"));
+ auto FlagPropagation =
+ Info->propagateSelectionFlags(*Instruction, InputFlags, InputMayRaiseFPException, Target);
+ if (!FlagPropagation)
+ return std::unexpected(FlagPropagation.error());
auto Constraint = Info->constrainSelectedInstruction(*Instruction, Function, Target);
if (!Constraint) {
return std::unexpected(withErrorContext(