Skip to content

[llvm] Use *Map::try_emplace (NFC) #140843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions llvm/lib/Analysis/MLInlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ int64_t MLInlineAdvisor::getModuleIRSize() const {
}

FunctionPropertiesInfo &MLInlineAdvisor::getCachedFPI(Function &F) const {
auto InsertPair =
FPICache.insert(std::make_pair(&F, FunctionPropertiesInfo()));
auto InsertPair = FPICache.try_emplace(&F);
if (!InsertPair.second)
return InsertPair.first->second;
InsertPair.first->second = FAM.getResult<FunctionPropertiesAnalysis>(F);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DwarfStringPool::DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm,

StringMapEntry<DwarfStringPool::EntryTy> &
DwarfStringPool::getEntryImpl(AsmPrinter &Asm, StringRef Str) {
auto I = Pool.insert(std::make_pair(Str, EntryTy()));
auto I = Pool.try_emplace(Str);
auto &Entry = I.first->second;
if (I.second) {
Entry.Index = EntryTy::NotIndexed;
Expand Down
14 changes: 5 additions & 9 deletions llvm/lib/LTO/LTOModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ void LTOModule::addObjCClass(const GlobalVariable *clgv) {
// second slot in __OBJC,__class is pointer to superclass name
std::string superclassName;
if (objcClassNameFromExpression(c->getOperand(1), superclassName)) {
auto IterBool =
_undefines.insert(std::make_pair(superclassName, NameAndAttributes()));
auto IterBool = _undefines.try_emplace(superclassName);
if (IterBool.second) {
NameAndAttributes &info = IterBool.first->second;
info.name = IterBool.first->first();
Expand Down Expand Up @@ -307,8 +306,7 @@ void LTOModule::addObjCCategory(const GlobalVariable *clgv) {
if (!objcClassNameFromExpression(c->getOperand(1), targetclassName))
return;

auto IterBool =
_undefines.insert(std::make_pair(targetclassName, NameAndAttributes()));
auto IterBool = _undefines.try_emplace(targetclassName);

if (!IterBool.second)
return;
Expand All @@ -326,8 +324,7 @@ void LTOModule::addObjCClassRef(const GlobalVariable *clgv) {
if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName))
return;

auto IterBool =
_undefines.insert(std::make_pair(targetclassName, NameAndAttributes()));
auto IterBool = _undefines.try_emplace(targetclassName);

if (!IterBool.second)
return;
Expand Down Expand Up @@ -522,7 +519,7 @@ void LTOModule::addAsmGlobalSymbol(StringRef name,
/// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the
/// undefined list.
void LTOModule::addAsmGlobalSymbolUndef(StringRef name) {
auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes()));
auto IterBool = _undefines.try_emplace(name);

_asm_undefines.push_back(IterBool.first->first());

Expand All @@ -549,8 +546,7 @@ void LTOModule::addPotentialUndefinedSymbol(ModuleSymbolTable::Symbol Sym,
name.c_str();
}

auto IterBool =
_undefines.insert(std::make_pair(name.str(), NameAndAttributes()));
auto IterBool = _undefines.try_emplace(name.str());

// we already have the symbol
if (!IterBool.second)
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/Hexagon/HexagonGenMux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ bool HexagonGenMux::genMuxInBlock(MachineBasicBlock &B) {
F = CM.end();
}
if (F == CM.end()) {
auto It = CM.insert(std::make_pair(DR, CondsetInfo()));
F = It.first;
F = CM.try_emplace(DR).first;
F->second.PredR = PR;
}
CondsetInfo &CI = F->second;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bool TruncInstCombine::buildTruncExpressionGraph() {
Worklist.pop_back();
Stack.pop_back();
// Insert I to the Info map.
InstInfoMap.insert(std::make_pair(I, Info()));
InstInfoMap.try_emplace(I);
continue;
}

Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ class RegUseTracker {

void
RegUseTracker::countRegister(const SCEV *Reg, size_t LUIdx) {
std::pair<RegUsesTy::iterator, bool> Pair =
RegUsesMap.insert(std::make_pair(Reg, RegSortData()));
std::pair<RegUsesTy::iterator, bool> Pair = RegUsesMap.try_emplace(Reg);
RegSortData &RSD = Pair.first->second;
if (Pair.second)
RegSequence.push_back(Reg);
Expand Down Expand Up @@ -4478,7 +4477,7 @@ void LSRInstance::GenerateCrossUseConstantOffsets() {
for (const SCEV *Use : RegUses) {
const SCEV *Reg = Use; // Make a copy for ExtractImmediate to modify.
Immediate Imm = ExtractImmediate(Reg, SE);
auto Pair = Map.insert(std::make_pair(Reg, ImmMapTy()));
auto Pair = Map.try_emplace(Reg);
if (Pair.second)
Sequence.push_back(Reg);
Pair.first->second.insert(std::make_pair(Imm, Use));
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Transforms/Utils/SCCPSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
ValueLatticeElement &getValueState(Value *V) {
assert(!V->getType()->isStructTy() && "Should use getStructValueState");

auto I = ValueState.insert(std::make_pair(V, ValueLatticeElement()));
auto I = ValueState.try_emplace(V);
ValueLatticeElement &LV = I.first->second;

if (!I.second)
Expand Down Expand Up @@ -765,10 +765,9 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
if (auto *STy = dyn_cast<StructType>(F->getReturnType())) {
MRVFunctionsTracked.insert(F);
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
TrackedMultipleRetVals.insert(
std::make_pair(std::make_pair(F, i), ValueLatticeElement()));
TrackedMultipleRetVals.try_emplace(std::make_pair(F, i));
} else if (!F->getReturnType()->isVoidTy())
TrackedRetVals.insert(std::make_pair(F, ValueLatticeElement()));
TrackedRetVals.try_emplace(F);
}

void addToMustPreserveReturnsInFunctions(Function *F) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/ValueMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ MDNode *MDNodeMapper::visitOperands(UniquedGraph &G, MDNode::op_iterator &I,
MDNode &OpN = *cast<MDNode>(Op);
assert(OpN.isUniqued() &&
"Only uniqued operands cannot be mapped immediately");
if (G.Info.insert(std::make_pair(&OpN, Data())).second)
if (G.Info.try_emplace(&OpN).second)
return &OpN; // This is a new one. Return it.
}
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-mca/Views/BottleneckAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void PressureTracker::getResourceUsers(uint64_t ResourceMask,
}

void PressureTracker::onInstructionDispatched(unsigned IID) {
IPI.insert(std::make_pair(IID, InstructionPressureInfo()));
IPI.try_emplace(IID);
}

void PressureTracker::onInstructionExecuted(unsigned IID) { IPI.erase(IID); }
Expand Down