Skip to content

Commit

Permalink
[RISCV] Remove an extra map lookup from RISCVCompressInstEmitter. NFC
Browse files Browse the repository at this point in the history
When we looked up the map to see if the entry already existed,
this created the new entry for us. So save a reference to it so
we can use it to update the entry instead of looking it up again.

Also remove unnecessary StringRef constructors around string
literals on calls to this function.
  • Loading branch information
topperc committed Jan 17, 2021
1 parent 1327c73 commit 061f681
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions llvm/utils/TableGen/RISCVCompressInstEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,13 @@ getReqFeatures(std::set<std::pair<bool, StringRef>> &FeaturesSet,
static unsigned getPredicates(DenseMap<const Record *, unsigned> &PredicateMap,
std::vector<const Record *> &Predicates,
Record *Rec, StringRef Name) {
unsigned Entry = PredicateMap[Rec];
unsigned &Entry = PredicateMap[Rec];
if (Entry)
return Entry;

if (!Rec->isValueUnset(Name)) {
Predicates.push_back(Rec);
Entry = Predicates.size();
PredicateMap[Rec] = Entry;
return Entry;
}

Expand Down Expand Up @@ -751,14 +750,16 @@ void RISCVCompressInstEmitter::emitCompressInstEmitter(raw_ostream &o,
} else {
// Handling immediate operands.
if (CompressOrUncompress) {
unsigned Entry = getPredicates(MCOpPredicateMap, MCOpPredicates,
DestOperand.Rec, StringRef("MCOperandPredicate"));
unsigned Entry =
getPredicates(MCOpPredicateMap, MCOpPredicates, DestOperand.Rec,
"MCOperandPredicate");
CondStream.indent(6)
<< Namespace << "ValidateMCOperand("
<< "MI.getOperand(" << OpIdx << "), STI, " << Entry << ") &&\n";
} else {
unsigned Entry = getPredicates(ImmLeafPredicateMap, ImmLeafPredicates,
DestOperand.Rec, StringRef("ImmediateCode"));
unsigned Entry =
getPredicates(ImmLeafPredicateMap, ImmLeafPredicates,
DestOperand.Rec, "ImmediateCode");
CondStream.indent(6)
<< "MI.getOperand(" << OpIdx << ").isImm() &&\n";
CondStream.indent(6) << Namespace << "ValidateMachineOperand("
Expand All @@ -774,14 +775,14 @@ void RISCVCompressInstEmitter::emitCompressInstEmitter(raw_ostream &o,
case OpData::Imm: {
if (CompressOrUncompress) {
unsigned Entry = getPredicates(MCOpPredicateMap, MCOpPredicates,
DestOperand.Rec, StringRef("MCOperandPredicate"));
DestOperand.Rec, "MCOperandPredicate");
CondStream.indent(6)
<< Namespace << "ValidateMCOperand("
<< "MCOperand::createImm(" << DestOperandMap[OpNo].Data.Imm
<< "), STI, " << Entry << ") &&\n";
} else {
unsigned Entry = getPredicates(ImmLeafPredicateMap, ImmLeafPredicates,
DestOperand.Rec, StringRef("ImmediateCode"));
DestOperand.Rec, "ImmediateCode");
CondStream.indent(6)
<< Namespace
<< "ValidateMachineOperand(MachineOperand::CreateImm("
Expand Down

0 comments on commit 061f681

Please sign in to comment.