Skip to content

Commit

Permalink
[llvm-mca] Fix processing thumb instruction set
Browse files Browse the repository at this point in the history
Differential revision: https://reviews.llvm.org/D91704
  • Loading branch information
eleviant committed Nov 24, 2020
1 parent c80fbdf commit 9c3b68d
Show file tree
Hide file tree
Showing 2 changed files with 2,740 additions and 3 deletions.
13 changes: 10 additions & 3 deletions llvm/lib/MCA/InstrBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ void InstrBuilder::populateWrites(InstrDesc &ID, const MCInst &MCI,
// the opcode descriptor (MCInstrDesc).
// 2. Uses start at index #(MCDesc.getNumDefs()).
// 3. There can only be a single optional register definition, an it is
// always the last operand of the sequence (excluding extra operands
// contributed by variadic opcodes).
// either the last operand of the sequence (excluding extra operands
// contributed by variadic opcodes) or one of the explicit register
// definitions. The latter occurs for some Thumb1 instructions.
//
// These assumptions work quite well for most out-of-order in-tree targets
// like x86. This is mainly because the vast majority of instructions is
Expand Down Expand Up @@ -308,12 +309,18 @@ void InstrBuilder::populateWrites(InstrDesc &ID, const MCInst &MCI,
// The first NumExplicitDefs register operands are expected to be register
// definitions.
unsigned CurrentDef = 0;
unsigned OptionalDefIdx = MCDesc.getNumOperands() - 1;
unsigned i = 0;
for (; i < MCI.getNumOperands() && CurrentDef < NumExplicitDefs; ++i) {
const MCOperand &Op = MCI.getOperand(i);
if (!Op.isReg())
continue;

if (MCDesc.OpInfo[CurrentDef].isOptionalDef()) {
OptionalDefIdx = CurrentDef++;
continue;
}

WriteDescriptor &Write = ID.Writes[CurrentDef];
Write.OpIndex = i;
if (CurrentDef < NumWriteLatencyEntries) {
Expand Down Expand Up @@ -369,7 +376,7 @@ void InstrBuilder::populateWrites(InstrDesc &ID, const MCInst &MCI,

if (MCDesc.hasOptionalDef()) {
WriteDescriptor &Write = ID.Writes[NumExplicitDefs + NumImplicitDefs];
Write.OpIndex = MCDesc.getNumOperands() - 1;
Write.OpIndex = OptionalDefIdx;
// Assign a default latency for this write.
Write.Latency = ID.MaxLatency;
Write.SClassOrWriteResourceID = 0;
Expand Down
Loading

0 comments on commit 9c3b68d

Please sign in to comment.