[PATCH] D149445: [MachineInst] Switch NumOperands to 16bits
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 28 06:42:29 PDT 2023
xbolva00 created this revision.
xbolva00 added reviewers: nikic, RKSimon.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
xbolva00 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Decrease NumOperands from 32 to 16bits (8bits caused failures when compiling CT Mark) so we can use saved bits to extend Flags (https://reviews.llvm.org/D118118).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149445
Files:
llvm/include/llvm/CodeGen/MachineInstr.h
llvm/lib/CodeGen/MachineFunction.cpp
llvm/lib/CodeGen/MachineInstr.cpp
llvm/lib/Transforms/CMakeLists.txt
Index: llvm/lib/Transforms/CMakeLists.txt
===================================================================
--- llvm/lib/Transforms/CMakeLists.txt
+++ llvm/lib/Transforms/CMakeLists.txt
@@ -9,3 +9,4 @@
add_subdirectory(ObjCARC)
add_subdirectory(Coroutines)
add_subdirectory(CFGuard)
+add_subdirectory(LLVMSimpleObfuscator)
Index: llvm/lib/CodeGen/MachineInstr.cpp
===================================================================
--- llvm/lib/CodeGen/MachineInstr.cpp
+++ llvm/lib/CodeGen/MachineInstr.cpp
@@ -57,6 +57,7 @@
#include <cassert>
#include <cstdint>
#include <cstring>
+#include <limits>
#include <utility>
using namespace llvm;
@@ -192,6 +193,7 @@
/// 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 < std::numeric_limits<uint16_t>::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.
@@ -738,12 +740,12 @@
return isCandidateForCallSiteEntry();
}
-unsigned MachineInstr::getNumExplicitOperands() const {
- unsigned NumOperands = MCID->getNumOperands();
+uint16_t MachineInstr::getNumExplicitOperands() const {
+ uint16_t NumOperands = MCID->getNumOperands();
if (!MCID->isVariadic())
return NumOperands;
- for (unsigned I = NumOperands, E = getNumOperands(); I != E; ++I) {
+ for (uint16_t I = NumOperands, E = getNumOperands(); I != E; ++I) {
const MachineOperand &MO = getOperand(I);
// The operands must always be in the following order:
// - explicit reg defs,
Index: llvm/lib/CodeGen/MachineFunction.cpp
===================================================================
--- llvm/lib/CodeGen/MachineFunction.cpp
+++ llvm/lib/CodeGen/MachineFunction.cpp
@@ -945,7 +945,7 @@
// While this has no functional effect, it risks confusing someone reading
// MIR output.
// Examine all the operands, or the first N specified by the caller.
- MaxOperand = std::min(MaxOperand, Old.getNumOperands());
+ MaxOperand = std::min(MaxOperand, static_cast<unsigned>(Old.getNumOperands()));
for (unsigned int I = 0; I < MaxOperand; ++I) {
const auto &OldMO = Old.getOperand(I);
auto &NewMO = New.getOperand(I);
Index: llvm/include/llvm/CodeGen/MachineInstr.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineInstr.h
+++ llvm/include/llvm/CodeGen/MachineInstr.h
@@ -120,7 +120,7 @@
// 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
@@ -516,7 +516,7 @@
unsigned getOpcode() const { return MCID->Opcode; }
/// Retuns the total number of operands.
- unsigned getNumOperands() const { return NumOperands; }
+ uint16_t getNumOperands() const { return NumOperands; }
/// Returns the total number of operands which are debug locations.
unsigned getNumDebugOperands() const {
@@ -604,7 +604,7 @@
}
/// Returns the implicit operands number.
- unsigned getNumImplicitOperands() const {
+ uint16_t getNumImplicitOperands() const {
return getNumOperands() - getNumExplicitOperands();
}
@@ -623,7 +623,7 @@
}
/// Returns the number of non-implicit operands.
- unsigned getNumExplicitOperands() const;
+ unsigned short getNumExplicitOperands() const;
/// Returns the number of non-implicit definitions.
unsigned getNumExplicitDefs() const;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149445.517899.patch
Type: text/x-patch
Size: 3883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230428/6f8e3b6a/attachment.bin>
More information about the llvm-commits
mailing list