[llvm] 20831c3 - [MachineInst] Switch NumOperands to 16bits

Dávid Bolvanský via llvm-commits llvm-commits at lists.llvm.org
Tue May 2 13:48:29 PDT 2023


Author: Dávid Bolvanský
Date: 2023-05-02T22:48:22+02:00
New Revision: 20831c3c23852063b796a6d86bf44d5bc8508ceb

URL: https://github.com/llvm/llvm-project/commit/20831c3c23852063b796a6d86bf44d5bc8508ceb
DIFF: https://github.com/llvm/llvm-project/commit/20831c3c23852063b796a6d86bf44d5bc8508ceb.diff

LOG: [MachineInst] Switch NumOperands to 16bits

Decrease NumOperands from 32 to 16bits (matches MCInstrDesc) so we can use saved bits to extend Flags (https://reviews.llvm.org/D118118).

Reviewed By: barannikov88

Differential Revision: https://reviews.llvm.org/D149445

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/MachineInstr.h
    llvm/lib/CodeGen/MachineInstr.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h
index ad3f919824b3..411653abf6ae 100644
--- a/llvm/include/llvm/CodeGen/MachineInstr.h
+++ b/llvm/include/llvm/CodeGen/MachineInstr.h
@@ -120,7 +120,7 @@ class MachineInstr
 
   // Operands are allocated by an ArrayRecycler.
   MachineOperand *Operands = nullptr;   // Pointer to the first operand.
-  unsigned NumOperands = 0;             // Number of operands on instruction.
+  uint16_t NumOperands = 0;             // Number of operands on instruction.
 
   uint16_t Flags = 0;                   // Various bits of additional
                                         // information about machine

diff  --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 2a43ed0a7c2b..0b5e3e833528 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -192,6 +192,7 @@ static void moveOperands(MachineOperand *Dst, MachineOperand *Src,
 /// an explicit operand it is added at the end of the explicit operand list
 /// (before the first implicit operand).
 void MachineInstr::addOperand(MachineFunction &MF, const MachineOperand &Op) {
+  assert(NumOperands < USHRT_MAX && "Cannot add more operands.");
   assert(MCID && "Cannot add operands before providing an instr descriptor");
 
   // Check if we're adding one of our existing operands.


        


More information about the llvm-commits mailing list