Skip to content

Commit

Permalink
[CodeGen] Use *{Set,Map}::contains (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Mar 14, 2023
1 parent 0702838 commit a585fa2
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 20 deletions.
4 changes: 1 addition & 3 deletions llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ class IRTranslator : public MachineFunctionPass {
return ValToVRegs.find(&V);
}

bool contains(const Value &V) const {
return ValToVRegs.find(&V) != ValToVRegs.end();
}
bool contains(const Value &V) const { return ValToVRegs.contains(&V); }

void reset() {
ValToVRegs.clear();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3405,7 +3405,7 @@ void CodeViewDebug::emitDebugInfoForGlobal(const CVGlobalVariable &CVGV) {
OS.AddComment("DataOffset");

uint64_t Offset = 0;
if (CVGlobalVariableOffsets.find(DIGV) != CVGlobalVariableOffsets.end())
if (CVGlobalVariableOffsets.contains(DIGV))
// Use the offset seen while collecting info on globals.
Offset = CVGlobalVariableOffsets[DIGV];
OS.emitCOFFSecRel32(GVSym, Offset);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3890,7 +3890,7 @@ class AddressingModeCombiner {
while (!Worklist.empty()) {
Value *Current = Worklist.pop_back_val();
// if it is already visited or it is an ending value then skip it.
if (Map.find(Current) != Map.end())
if (Map.contains(Current))
continue;
TraverseOrder.push_back(Current);

Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/CodeGen/InlineSpiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ void HoistSpillHelper::addToMergeableSpills(MachineInstr &Spill, int StackSlot,
LiveInterval &OrigLI = LIS.getInterval(Original);
// save a copy of LiveInterval in StackSlotToOrigLI because the original
// LiveInterval may be cleared after all its references are spilled.
if (StackSlotToOrigLI.find(StackSlot) == StackSlotToOrigLI.end()) {
if (!StackSlotToOrigLI.contains(StackSlot)) {
auto LI = std::make_unique<LiveInterval>(OrigLI.reg(), OrigLI.weight());
LI->assign(OrigLI, Allocator);
StackSlotToOrigLI[StackSlot] = std::move(LI);
Expand Down Expand Up @@ -1459,7 +1459,7 @@ void HoistSpillHelper::runHoistSpills(
MachineBasicBlock *Block = (*RIt)->getBlock();

// If Block contains an original spill, simply continue.
if (SpillsToKeep.find(*RIt) != SpillsToKeep.end() && !SpillsToKeep[*RIt]) {
if (SpillsToKeep.contains(*RIt) && !SpillsToKeep[*RIt]) {
SpillsInSubTreeMap[*RIt].first.insert(*RIt);
// SpillsInSubTreeMap[*RIt].second contains the cost of spill.
SpillsInSubTreeMap[*RIt].second = MBFI.getBlockFreq(Block);
Expand All @@ -1469,7 +1469,7 @@ void HoistSpillHelper::runHoistSpills(
// Collect spills in subtree of current node (*RIt) to
// SpillsInSubTreeMap[*RIt].first.
for (MachineDomTreeNode *Child : (*RIt)->children()) {
if (SpillsInSubTreeMap.find(Child) == SpillsInSubTreeMap.end())
if (!SpillsInSubTreeMap.contains(Child))
continue;
// The stmt "SpillsInSubTree = SpillsInSubTreeMap[*RIt].first" below
// should be placed before getting the begin and end iterators of
Expand Down Expand Up @@ -1508,8 +1508,7 @@ void HoistSpillHelper::runHoistSpills(
for (auto *const SpillBB : SpillsInSubTree) {
// When SpillBB is a BB contains original spill, insert the spill
// to SpillsToRm.
if (SpillsToKeep.find(SpillBB) != SpillsToKeep.end() &&
!SpillsToKeep[SpillBB]) {
if (SpillsToKeep.contains(SpillBB) && !SpillsToKeep[SpillBB]) {
MachineInstr *SpillToRm = SpillBBToSpill[SpillBB];
SpillsToRm.push_back(SpillToRm);
}
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3179,7 +3179,7 @@ void InstrRefBasedLDV::buildVLocValueMap(
SmallPtrSet<MachineBasicBlock *, 32> DefBlocks;
for (const MachineBasicBlock *ExpMBB : BlocksToExplore) {
auto &TransferFunc = AllTheVLocs[ExpMBB->getNumber()].Vars;
if (TransferFunc.find(Var) != TransferFunc.end())
if (TransferFunc.contains(Var))
DefBlocks.insert(const_cast<MachineBasicBlock *>(ExpMBB));
}

Expand Down Expand Up @@ -3295,7 +3295,7 @@ void InstrRefBasedLDV::buildVLocValueMap(
// to be visited next time around.
for (auto *s : MBB->successors()) {
// Ignore out of scope / not-to-be-explored successors.
if (LiveInIdx.find(s) == LiveInIdx.end())
if (!LiveInIdx.contains(s))
continue;

if (BBToOrder[s] > BBToOrder[MBB]) {
Expand Down Expand Up @@ -3411,7 +3411,7 @@ void InstrRefBasedLDV::initialSetup(MachineFunction &MF) {
for (MachineBasicBlock *MBB : RPOT)
processMBB(MBB);
for (MachineBasicBlock &MBB : MF)
if (BBToOrder.find(&MBB) == BBToOrder.end())
if (!BBToOrder.contains(&MBB))
processMBB(&MBB);

// Order value substitutions by their "source" operand pair, for quick lookup.
Expand Down Expand Up @@ -4195,7 +4195,7 @@ std::optional<ValueIDNum> InstrRefBasedLDV::resolveDbgPHIsImpl(
// Are all these things actually defined?
for (auto &PHIIt : PHI->IncomingValues) {
// Any undef input means DBG_PHIs didn't dominate the use point.
if (Updater.UndefMap.find(&PHIIt.first->BB) != Updater.UndefMap.end())
if (Updater.UndefMap.contains(&PHIIt.first->BB))
return std::nullopt;

ValueIDNum ValueToCheck;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ void VarLocBasedLDV::removeEntryValue(const MachineInstr &MI,
// Try to get non-debug instruction responsible for the DBG_VALUE.
const MachineInstr *TransferInst = nullptr;
Register Reg = MI.getDebugOperand(0).getReg();
if (Reg.isValid() && RegSetInstrs.find(Reg) != RegSetInstrs.end())
if (Reg.isValid() && RegSetInstrs.contains(Reg))
TransferInst = RegSetInstrs.find(Reg)->second;

// Case of the parameter's DBG_VALUE at the start of entry MBB.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MIRVRegNamerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ VRegRenamer::getVRegRenameMap(const std::vector<NamedVReg> &VRegs) {
StringMap<unsigned> VRegNameCollisionMap;

auto GetUniqueVRegName = [&VRegNameCollisionMap](const NamedVReg &Reg) {
if (VRegNameCollisionMap.find(Reg.getName()) == VRegNameCollisionMap.end())
if (!VRegNameCollisionMap.contains(Reg.getName()))
VRegNameCollisionMap[Reg.getName()] = 0;
const unsigned Counter = ++VRegNameCollisionMap[Reg.getName()];
return Reg.getName() + "__" + std::to_string(Counter);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MachineBlockPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ MachineBlockPlacement::FallThroughGains(
for (MachineBasicBlock *Succ : BestPred->successors()) {
if ((Succ == NewTop) || (Succ == BestPred) || !LoopBlockSet.count(Succ))
continue;
if (ComputedEdges.find(Succ) != ComputedEdges.end())
if (ComputedEdges.contains(Succ))
continue;
BlockChain *SuccChain = BlockToChain[Succ];
if ((SuccChain && (Succ != *SuccChain->begin())) ||
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MachineLICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ MachineLICMBase::calcRegisterCost(const MachineInstr *MI, bool ConsiderSeen,
continue;
const int *PS = TRI->getRegClassPressureSets(RC);
for (; *PS != -1; ++PS) {
if (Cost.find(*PS) == Cost.end())
if (!Cost.contains(*PS))
Cost[*PS] = RCCost;
else
Cost[*PS] += RCCost;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/SlotIndexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void SlotIndexes::repairIndexesInRange(MachineBasicBlock *MBB,
--MBBI;
else
pastStart = true;
} else if (MI && mi2iMap.find(MI) == mi2iMap.end()) {
} else if (MI && !mi2iMap.contains(MI)) {
if (MBBI != Begin)
--MBBI;
else
Expand All @@ -232,7 +232,7 @@ void SlotIndexes::repairIndexesInRange(MachineBasicBlock *MBB,
for (MachineBasicBlock::iterator I = End; I != Begin;) {
--I;
MachineInstr &MI = *I;
if (!MI.isDebugOrPseudoInstr() && mi2iMap.find(&MI) == mi2iMap.end())
if (!MI.isDebugOrPseudoInstr() && !mi2iMap.contains(&MI))
insertMachineInstrInMaps(MI);
}
}
Expand Down

0 comments on commit a585fa2

Please sign in to comment.