Skip to content

Commit 245e3dd

Browse files
committed
[MC] Do not copy MCInstrDescs. NFC.
Avoid copying MCInstrDesc instances because a future patch will change them to find their implicit operands and operand info array based on their own "this" pointer, so it will only work for MCInstrDescs in the TargetInsts table, not for a copy of an MCInstrDesc at a different address. Differential Revision: https://reviews.llvm.org/D142214
1 parent 1af7164 commit 245e3dd

File tree

9 files changed

+20
-11
lines changed

9 files changed

+20
-11
lines changed

llvm/include/llvm/MC/MCInstrDesc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ enum Flag {
197197
/// directly to describe itself.
198198
class MCInstrDesc {
199199
public:
200+
// Do not allow MCInstrDescs to be copied or moved. They should only exist in
201+
// the <Target>Insts table because they rely on knowing their own address to
202+
// find other information elsewhere in the same table.
203+
MCInstrDesc(const MCInstrDesc &) = delete;
204+
MCInstrDesc(MCInstrDesc &&) = delete;
205+
MCInstrDesc &operator=(const MCInstrDesc &) = delete;
206+
MCInstrDesc &operator=(MCInstrDesc &&) = delete;
207+
200208
unsigned short Opcode; // The opcode number
201209
unsigned short NumOperands; // Num of args (may be more if variable_ops)
202210
unsigned char NumDefs; // Num of args that are definitions

llvm/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static void GetCostForDef(const ScheduleDAGSDNodes::RegDefIter &RegDefPos,
340340
}
341341

342342
unsigned Idx = RegDefPos.GetIdx();
343-
const MCInstrDesc Desc = TII->get(Opcode);
343+
const MCInstrDesc &Desc = TII->get(Opcode);
344344
const TargetRegisterClass *RC = TII->getRegClass(Desc, Idx, TRI, MF);
345345
assert(RC && "Not a valid register class");
346346
RegClass = RC->getID();

llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2938,7 +2938,7 @@ bool AMDGPUDAGToDAGISel::isVGPRImm(const SDNode * N) const {
29382938
SDNode * User = *U;
29392939
if (User->isMachineOpcode()) {
29402940
unsigned Opc = User->getMachineOpcode();
2941-
MCInstrDesc Desc = SII->get(Opc);
2941+
const MCInstrDesc &Desc = SII->get(Opc);
29422942
if (Desc.isCommutable()) {
29432943
unsigned OpIdx = Desc.getNumDefs() + U.getOperandNo();
29442944
unsigned CommuteIdx1 = TargetInstrInfo::CommuteAnyOperandIndex;

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2452,7 +2452,8 @@ bool SIInstrInfo::findCommutedOpIndices(const MachineInstr &MI,
24522452
return findCommutedOpIndices(MI.getDesc(), SrcOpIdx0, SrcOpIdx1);
24532453
}
24542454

2455-
bool SIInstrInfo::findCommutedOpIndices(MCInstrDesc Desc, unsigned &SrcOpIdx0,
2455+
bool SIInstrInfo::findCommutedOpIndices(const MCInstrDesc &Desc,
2456+
unsigned &SrcOpIdx0,
24562457
unsigned &SrcOpIdx1) const {
24572458
if (!Desc.isCommutable())
24582459
return false;

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
268268
bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx0,
269269
unsigned &SrcOpIdx1) const override;
270270

271-
bool findCommutedOpIndices(MCInstrDesc Desc, unsigned &SrcOpIdx0,
271+
bool findCommutedOpIndices(const MCInstrDesc &Desc, unsigned &SrcOpIdx0,
272272
unsigned &SrcOpIdx1) const;
273273

274274
bool isBranchOffsetInRange(unsigned BranchOpc,

llvm/lib/Target/Lanai/LanaiDelaySlotFiller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void Filler::insertDefsUses(MachineBasicBlock::instr_iterator MI,
224224
SmallSet<unsigned, 32> &RegDefs,
225225
SmallSet<unsigned, 32> &RegUses) {
226226
// If MI is a call or return, just examine the explicit non-variadic operands.
227-
MCInstrDesc MCID = MI->getDesc();
227+
const MCInstrDesc &MCID = MI->getDesc();
228228
unsigned E = MI->isCall() || MI->isReturn() ? MCID.getNumOperands()
229229
: MI->getNumOperands();
230230
for (unsigned I = 0; I != E; ++I) {

llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void SPIRVInstPrinter::printInst(const MCInst *MI, uint64_t Address,
8080
printOpExtInst(MI, OS);
8181
} else {
8282
// Print any extra operands for variadic instructions.
83-
MCInstrDesc MCDesc = MII.get(OpCode);
83+
const MCInstrDesc &MCDesc = MII.get(OpCode);
8484
if (MCDesc.isVariadic()) {
8585
const unsigned NumFixedOps = MCDesc.getNumOperands();
8686
const unsigned LastFixedIndex = NumFixedOps - 1;
@@ -185,7 +185,7 @@ void SPIRVInstPrinter::printInst(const MCInst *MI, uint64_t Address,
185185
void SPIRVInstPrinter::printOpExtInst(const MCInst *MI, raw_ostream &O) {
186186
// The fixed operands have already been printed, so just need to decide what
187187
// type of ExtInst operands to print based on the instruction set and number.
188-
MCInstrDesc MCDesc = MII.get(MI->getOpcode());
188+
const MCInstrDesc &MCDesc = MII.get(MI->getOpcode());
189189
unsigned NumFixedOps = MCDesc.getNumOperands();
190190
const auto NumOps = MI->getNumOperands();
191191
if (NumOps == NumFixedOps)
@@ -200,7 +200,7 @@ void SPIRVInstPrinter::printOpExtInst(const MCInst *MI, raw_ostream &O) {
200200
void SPIRVInstPrinter::printOpDecorate(const MCInst *MI, raw_ostream &O) {
201201
// The fixed operands have already been printed, so just need to decide what
202202
// type of decoration operands to print based on the Decoration type.
203-
MCInstrDesc MCDesc = MII.get(MI->getOpcode());
203+
const MCInstrDesc &MCDesc = MII.get(MI->getOpcode());
204204
unsigned NumFixedOps = MCDesc.getNumOperands();
205205

206206
if (NumFixedOps != MI->getNumOperands()) {

llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVMCCodeEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ using EndianWriter = support::endian::Writer;
6161
// output register in operand 0. If so, we need to swap operands 0 and 1 so the
6262
// type comes first in the output, despide coming second in the MCInst.
6363
static bool hasType(const MCInst &MI, const MCInstrInfo &MII) {
64-
MCInstrDesc MCDesc = MII.get(MI.getOpcode());
64+
const MCInstrDesc &MCDesc = MII.get(MI.getOpcode());
6565
// If we define an output, and have at least one other argument.
6666
if (MCDesc.getNumDefs() == 1 && MCDesc.getNumOperands() >= 2) {
6767
// Check if we define an ID, and take a type as operand 1.

llvm/unittests/CodeGen/LexicalScopesTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class LexicalScopesTest : public testing::Test {
5858
// Some meaningless instructions -- the first is fully meaningless,
5959
// while the second is supposed to impersonate DBG_VALUEs through its
6060
// opcode.
61-
MCInstrDesc BeanInst;
62-
MCInstrDesc DbgValueInst;
61+
MCInstrDesc BeanInst{};
62+
MCInstrDesc DbgValueInst{};
6363

6464
LexicalScopesTest() : Ctx(), Mod("beehives", Ctx) {
6565
memset(&BeanInst, 0, sizeof(BeanInst));

0 commit comments

Comments
 (0)