Skip to content

Commit 8f3254a

Browse files
authored
[TableGen][DecoderEmitter] Returns insn_t / std::vector<Islands> by value (NFC) (#153354)
The containers passed by reference are always empty on entry to the functions that fill them. Return them by value instead and let the compiler do the return value optimization.
1 parent 2ae4e95 commit 8f3254a

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,10 @@ class FilterChooser {
533533

534534
protected:
535535
// Populates the insn given the uid.
536-
void insnWithID(insn_t &Insn, unsigned Opcode) const {
536+
insn_t insnWithID(unsigned Opcode) const {
537537
const Record *EncodingDef = AllInstructions[Opcode].EncodingDef;
538538
const BitsInit &Bits = getBitsField(*EncodingDef, "Inst");
539-
Insn.resize(std::max(BitWidth, Bits.getNumBits()), BitValue::BIT_UNSET);
539+
insn_t Insn(std::max(BitWidth, Bits.getNumBits()), BitValue::BIT_UNSET);
540540
// We may have a SoftFail bitmask, which specifies a mask where an encoding
541541
// may differ from the value in "Inst" and yet still be valid, but the
542542
// disassembler should return SoftFail instead of Success.
@@ -550,6 +550,7 @@ class FilterChooser {
550550
else
551551
Insn[i] = BitValue(Bits, i);
552552
}
553+
return Insn;
553554
}
554555

555556
// Populates the field of the insn given the start position and the number of
@@ -582,7 +583,7 @@ class FilterChooser {
582583
// This returns a list of undecoded bits of an instructions, for example,
583584
// Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
584585
// decoded bits in order to verify that the instruction matches the Opcode.
585-
unsigned getIslands(std::vector<Island> &Islands, const insn_t &Insn) const;
586+
std::vector<Island> getIslands(const insn_t &Insn) const;
586587

587588
// Emits code to check the Predicates member of an instruction are true.
588589
// Returns true if predicate matches were emitted, false otherwise.
@@ -658,10 +659,8 @@ Filter::Filter(const FilterChooser &owner, unsigned startBit, unsigned numBits)
658659
LastOpcFiltered = {0, 0};
659660

660661
for (const auto &OpcPair : Owner.Opcodes) {
661-
insn_t Insn;
662-
663662
// Populates the insn given the uid.
664-
Owner.insnWithID(Insn, OpcPair.EncodingID);
663+
insn_t Insn = Owner.insnWithID(OpcPair.EncodingID);
665664

666665
// Scans the segment for possibly well-specified encoding bits.
667666
auto [Ok, Field] = Owner.fieldFromInsn(Insn, StartBit, NumBits);
@@ -1162,8 +1161,9 @@ void FilterChooser::dumpStack(raw_ostream &OS, const char *prefix) const {
11621161
// This returns a list of undecoded bits of an instructions, for example,
11631162
// Inst{20} = 1 && Inst{3-0} == 0b1111 represents two islands of yet-to-be
11641163
// decoded bits in order to verify that the instruction matches the Opcode.
1165-
unsigned FilterChooser::getIslands(std::vector<Island> &Islands,
1166-
const insn_t &Insn) const {
1164+
std::vector<FilterChooser::Island>
1165+
FilterChooser::getIslands(const insn_t &Insn) const {
1166+
std::vector<Island> Islands;
11671167
uint64_t FieldVal;
11681168
unsigned StartBit;
11691169

@@ -1203,7 +1203,7 @@ unsigned FilterChooser::getIslands(std::vector<Island> &Islands,
12031203
if (State == 2)
12041204
Islands.push_back({StartBit, BitWidth - StartBit, FieldVal});
12051205

1206-
return Islands.size();
1206+
return Islands;
12071207
}
12081208

12091209
bool FilterChooser::emitBinaryParser(raw_ostream &OS, indent Indent,
@@ -1452,12 +1452,10 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
14521452
// Emits table entries to decode the singleton.
14531453
void FilterChooser::emitSingletonTableEntry(DecoderTableInfo &TableInfo,
14541454
EncodingIDAndOpcode Opc) const {
1455-
std::vector<Island> Islands;
1456-
insn_t Insn;
1457-
insnWithID(Insn, Opc.EncodingID);
1455+
insn_t Insn = insnWithID(Opc.EncodingID);
14581456

14591457
// Look for islands of undecoded bits of the singleton.
1460-
getIslands(Islands, Insn);
1458+
std::vector<Island> Islands = getIslands(Insn);
14611459

14621460
// Emit the predicate table entry if one is needed.
14631461
emitPredicateTableEntry(TableInfo, Opc.EncodingID);
@@ -1569,13 +1567,11 @@ bool FilterChooser::filterProcessor(bool AllowMixed, bool Greedy) {
15691567
assert(numInstructions == 3);
15701568

15711569
for (const auto &Opcode : Opcodes) {
1572-
std::vector<Island> Islands;
1573-
insn_t Insn;
1574-
1575-
insnWithID(Insn, Opcode.EncodingID);
1570+
insn_t Insn = insnWithID(Opcode.EncodingID);
15761571

15771572
// Look for islands of undecoded bits of any instruction.
1578-
if (getIslands(Islands, Insn) > 0) {
1573+
std::vector<Island> Islands = getIslands(Insn);
1574+
if (!Islands.empty()) {
15791575
// Found an instruction with island(s). Now just assign a filter.
15801576
runSingleFilter(Islands[0].StartBit, Islands[0].NumBits);
15811577
return true;
@@ -1611,9 +1607,7 @@ bool FilterChooser::filterProcessor(bool AllowMixed, bool Greedy) {
16111607
bitAttrs[BitIndex] = ATTR_FILTERED;
16121608

16131609
for (const auto &OpcPair : Opcodes) {
1614-
insn_t insn;
1615-
1616-
insnWithID(insn, OpcPair.EncodingID);
1610+
insn_t insn = insnWithID(OpcPair.EncodingID);
16171611

16181612
for (BitIndex = 0; BitIndex < BitWidth; ++BitIndex) {
16191613
switch (bitAttrs[BitIndex]) {

0 commit comments

Comments
 (0)