[llvm] 1f995b5 - [M68k] Remove use of APInt::getRawData(). NFC (#103529)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 07:12:32 PDT 2024


Author: Craig Topper
Date: 2024-08-14T07:12:27-07:00
New Revision: 1f995b55347bb76a4251fa6727ceb83b6a4ddf56

URL: https://github.com/llvm/llvm-project/commit/1f995b55347bb76a4251fa6727ceb83b6a4ddf56
DIFF: https://github.com/llvm/llvm-project/commit/1f995b55347bb76a4251fa6727ceb83b6a4ddf56.diff

LOG: [M68k] Remove use of APInt::getRawData(). NFC (#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.

Added: 
    

Modified: 
    llvm/lib/Target/M68k/MCTargetDesc/M68kMCCodeEmitter.cpp

Removed: 
    


################################################################################
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