[llvm] [M68k] Remove use of APInt::getRawData(). NFC (PR #103529)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 13 20:37:01 PDT 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/103529
getRawData exposes some internal details of APInt.
The code was iterating over the uint64_t pieces and then iterating breaking them into 4 uint16_t pieces.
This patch changes the code to extract 16-bit pieces directly from the APInt without using getRawData.
>From 19fcd515f9b1e749003956ee68264ec52397f836 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 13 Aug 2024 20:21:26 -0700
Subject: [PATCH] [M68k] Remove use of APInt::getRawData(). NFC
getRawData exposes some internal details of APInt.
The code was iterating over the uint64_t pieces and then iterating
breaking them into 4 uint16_t pieces.
This patch changes the code to extract 16-bit pieces directly from
the APInt without using getRawData.
---
.../Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp b/llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp
index e6bc3af6e191a1..78783084ee59a0 100644
--- a/llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp
+++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp
@@ -236,15 +236,11 @@ void M68kMCCodeEmitter::encodeInstruction(const MCInst &MI,
APInt Scratch(64, 0U); // One APInt word is enough.
getBinaryCodeForInstr(MI, Fixups, EncodedInst, Scratch, STI);
- ArrayRef<uint64_t> Data(EncodedInst.getRawData(), EncodedInst.getNumWords());
- int64_t InstSize = EncodedInst.getBitWidth();
- for (uint64_t Word : Data) {
- for (int i = 0; i < 4 && InstSize > 0; ++i, InstSize -= 16) {
- support::endian::write<uint16_t>(CB, static_cast<uint16_t>(Word),
- llvm::endianness::big);
- Word >>= 16;
- }
- }
+ unsigned InstSize = EncodedInst.getBitWidth();
+ for (unsigned i = 0; i != InstSize; i += 16)
+ support::endian::write<uint16_t>(
+ CB, static_cast<uint16_t>(EncodedInst.extractBitsAsZExtValue(16, i)),
+ llvm::endianness::big);
}
MCCodeEmitter *llvm::createM68kMCCodeEmitter(const MCInstrInfo &MCII,
More information about the llvm-commits
mailing list