Skip to content

[Mips] Add support of MipsInstrInfo::getNop() #139863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/lib/Target/Mips/MipsInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/MC/MCInstBuilder.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
Expand Down Expand Up @@ -53,6 +54,13 @@ bool MipsInstrInfo::isZeroImm(const MachineOperand &op) const {
return op.isImm() && op.getImm() == 0;
}

MCInst MipsInstrInfo::getNop() const {
return MCInstBuilder(Mips::SLL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should try to support micromips?

.addReg(Mips::ZERO)
.addReg(Mips::ZERO)
.addImm(0);
}

/// insertNoop - If data hazard condition is found insert the target nop
/// instruction.
void MipsInstrInfo::
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/Mips/MipsInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class MipsInstrInfo : public MipsGenInstrInfo {

explicit MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBrOpc);

MCInst getNop() const override;

static const MipsInstrInfo *create(MipsSubtarget &STI);

/// Branch Analysis
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/CodeGen/Mips/unreachable.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -mtriple=mipsel-windows-gnu < %s | FileCheck %s -check-prefix=MIPSEL

define void @unreachable() {
; MIPSEL-LABEL: unreachable:
; MIPSEL: # %bb.0: # %entry
; MIPSEL-NEXT: .insn
; MIPSEL-NEXT: nop

entry:
unreachable
}