[clang] [llvm] [Mips] Implement MipsInstrInfo::getNop() operation (PR #135524)
Hervé Poussineau via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 12 23:53:13 PDT 2025
https://github.com/hpoussin created https://github.com/llvm/llvm-project/pull/135524
Previously, this was calling TargetInstrInfo::getNop(), which contains:
llvm_unreachable("Not implemented");
Fixes #134913.
>From 34f79c8ba4b8a906a68f4058f0b09d5e7f9e932a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= <hpoussin at reactos.org>
Date: Sun, 13 Apr 2025 07:47:35 +0200
Subject: [PATCH] [Mips] Implement getNop() operation
Previously, this was calling TargetInstrInfo::getNop(),
which contains:
llvm_unreachable("Not implemented");
Fixes #134913.
---
clang/test/CodeGen/Mips/unreachable.cpp | 13 +++++++++++++
llvm/lib/Target/Mips/MipsInstrInfo.cpp | 7 +++++++
llvm/lib/Target/Mips/MipsInstrInfo.h | 2 ++
3 files changed, 22 insertions(+)
create mode 100644 clang/test/CodeGen/Mips/unreachable.cpp
diff --git a/clang/test/CodeGen/Mips/unreachable.cpp b/clang/test/CodeGen/Mips/unreachable.cpp
new file mode 100644
index 0000000000000..04fec8598088d
--- /dev/null
+++ b/clang/test/CodeGen/Mips/unreachable.cpp
@@ -0,0 +1,13 @@
+// REQUIRES: mips-registered-target
+// RUN: %clang_cc1 -triple mipsel-w64-windows-gnu -x c++ -mrelocation-model static -emit-obj %s -o - | llvm-objdump -a - | FileCheck %s
+// CHECK: file format coff-mips
+
+[[__noreturn__]] inline void g() {
+ __builtin_unreachable();
+}
+
+void f(int i)
+{
+ if (i == 0)
+ g();
+}
diff --git a/llvm/lib/Target/Mips/MipsInstrInfo.cpp b/llvm/lib/Target/Mips/MipsInstrInfo.cpp
index b81bb1186de72..0abe228b7547a 100644
--- a/llvm/lib/Target/Mips/MipsInstrInfo.cpp
+++ b/llvm/lib/Target/Mips/MipsInstrInfo.cpp
@@ -87,6 +87,13 @@ MipsInstrInfo::GetMemOperand(MachineBasicBlock &MBB, int FI,
MFI.getObjectAlign(FI));
}
+MCInst MipsInstrInfo::getNop() const {
+ MCInst Nop;
+ // using Mips::NOP gives "fatal error: error in backend: Not supported instr: <MCInst 580>"
+ Nop.setOpcode(Mips::SSNOP);
+ return Nop;
+}
+
//===----------------------------------------------------------------------===//
// Branch Analysis
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Target/Mips/MipsInstrInfo.h b/llvm/lib/Target/Mips/MipsInstrInfo.h
index 06964c0161b4b..367f0ac5e8390 100644
--- a/llvm/lib/Target/Mips/MipsInstrInfo.h
+++ b/llvm/lib/Target/Mips/MipsInstrInfo.h
@@ -59,6 +59,8 @@ class MipsInstrInfo : public MipsGenInstrInfo {
static const MipsInstrInfo *create(MipsSubtarget &STI);
+ MCInst getNop() const override;
+
/// Branch Analysis
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
MachineBasicBlock *&FBB,
More information about the llvm-commits
mailing list