Skip to content

[llvm] Value-initialize values with *Map::try_emplace (NFC) #141522

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
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
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/DebugHandlerBase.h
Original file line number Diff line number Diff line change
@@ -101,12 +101,12 @@ class DebugHandlerBase : public AsmPrinterHandler {

/// Ensure that a label will be emitted before MI.
void requestLabelBeforeInsn(const MachineInstr *MI) {
LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
LabelsBeforeInsn.try_emplace(MI);
}

/// Ensure that a label will be emitted after MI.
void requestLabelAfterInsn(const MachineInstr *MI) {
LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
LabelsAfterInsn.try_emplace(MI);
}

virtual void beginFunctionImpl(const MachineFunction *MF) = 0;
2 changes: 1 addition & 1 deletion llvm/include/llvm/SandboxIR/Context.h
Original file line number Diff line number Diff line change
@@ -253,7 +253,7 @@ class Context {
Type *getType(llvm::Type *LLVMTy) {
if (LLVMTy == nullptr)
return nullptr;
auto Pair = LLVMTypeToTypeMap.insert({LLVMTy, nullptr});
auto Pair = LLVMTypeToTypeMap.try_emplace(LLVMTy);
auto It = Pair.first;
if (Pair.second)
It->second = std::unique_ptr<Type, TypeDeleter>(new Type(LLVMTy, *this));
4 changes: 2 additions & 2 deletions llvm/include/llvm/Transforms/Instrumentation/CFGMST.h
Original file line number Diff line number Diff line change
@@ -305,13 +305,13 @@ template <class Edge, class BBInfo> class CFGMST {
uint32_t Index = BBInfos.size();
auto Iter = BBInfos.end();
bool Inserted;
std::tie(Iter, Inserted) = BBInfos.insert(std::make_pair(Src, nullptr));
std::tie(Iter, Inserted) = BBInfos.try_emplace(Src);
if (Inserted) {
// Newly inserted, update the real info.
Iter->second = std::make_unique<BBInfo>(Index);
Index++;
}
std::tie(Iter, Inserted) = BBInfos.insert(std::make_pair(Dest, nullptr));
std::tie(Iter, Inserted) = BBInfos.try_emplace(Dest);
if (Inserted)
// Newly inserted, update the real info.
Iter->second = std::make_unique<BBInfo>(Index);
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/BasicAliasAnalysis.cpp
Original file line number Diff line number Diff line change
@@ -216,7 +216,7 @@ bool EarliestEscapeAnalysis::isNotCapturedBefore(const Value *Object,
if (!isIdentifiedFunctionLocal(Object))
return false;

auto Iter = EarliestEscapes.insert({Object, nullptr});
auto Iter = EarliestEscapes.try_emplace(Object);
if (Iter.second) {
Instruction *EarliestCapture = FindEarliestCapture(
Object, *const_cast<Function *>(DT.getRoot()->getParent()),
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/LoopAccessAnalysis.cpp
Original file line number Diff line number Diff line change
@@ -2979,7 +2979,7 @@ void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const {
}

const LoopAccessInfo &LoopAccessInfoManager::getInfo(Loop &L) {
const auto &[It, Inserted] = LoopAccessInfoMap.insert({&L, nullptr});
const auto &[It, Inserted] = LoopAccessInfoMap.try_emplace(&L);

if (Inserted)
It->second =
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/MemorySSA.cpp
Original file line number Diff line number Diff line change
@@ -1277,15 +1277,15 @@ MemorySSA::~MemorySSA() {
}

MemorySSA::AccessList *MemorySSA::getOrCreateAccessList(const BasicBlock *BB) {
auto Res = PerBlockAccesses.insert(std::make_pair(BB, nullptr));
auto Res = PerBlockAccesses.try_emplace(BB);

if (Res.second)
Res.first->second = std::make_unique<AccessList>();
return Res.first->second.get();
}

MemorySSA::DefsList *MemorySSA::getOrCreateDefsList(const BasicBlock *BB) {
auto Res = PerBlockDefs.insert(std::make_pair(BB, nullptr));
auto Res = PerBlockDefs.try_emplace(BB);

if (Res.second)
Res.first->second = std::make_unique<DefsList>();
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
@@ -4470,7 +4470,7 @@ GCMetadataPrinter *AsmPrinter::getOrCreateGCPrinter(GCStrategy &S) {
if (!S.usesMetadata())
return nullptr;

auto [GCPI, Inserted] = GCMetadataPrinters.insert({&S, nullptr});
auto [GCPI, Inserted] = GCMetadataPrinters.try_emplace(&S);
if (!Inserted)
return GCPI->second.get();

4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/MIRParser/MIParser.cpp
Original file line number Diff line number Diff line change
@@ -326,7 +326,7 @@ PerFunctionMIParsingState::PerFunctionMIParsingState(MachineFunction &MF,
}

VRegInfo &PerFunctionMIParsingState::getVRegInfo(Register Num) {
auto I = VRegInfos.insert(std::make_pair(Num, nullptr));
auto I = VRegInfos.try_emplace(Num);
if (I.second) {
MachineRegisterInfo &MRI = MF.getRegInfo();
VRegInfo *Info = new (Allocator) VRegInfo;
@@ -339,7 +339,7 @@ VRegInfo &PerFunctionMIParsingState::getVRegInfo(Register Num) {
VRegInfo &PerFunctionMIParsingState::getVRegInfoNamed(StringRef RegName) {
assert(RegName != "" && "Expected named reg.");

auto I = VRegInfosNamed.insert(std::make_pair(RegName.str(), nullptr));
auto I = VRegInfosNamed.try_emplace(RegName.str());
if (I.second) {
VRegInfo *Info = new (Allocator) VRegInfo;
Info->VReg = MF.getRegInfo().createIncompleteVirtualRegister(RegName);
4 changes: 1 addition & 3 deletions llvm/lib/IR/Constants.cpp
Original file line number Diff line number Diff line change
@@ -2876,9 +2876,7 @@ Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) {

// Do a lookup to see if we have already formed one of these.
auto &Slot =
*Ty->getContext()
.pImpl->CDSConstants.insert(std::make_pair(Elements, nullptr))
.first;
*Ty->getContext().pImpl->CDSConstants.try_emplace(Elements).first;

// The bucket can point to a linked list of different CDS's that have the same
// body but different types. For example, 0,0,0,1 could be a 4 element array
3 changes: 1 addition & 2 deletions llvm/lib/Object/ELF.cpp
Original file line number Diff line number Diff line change
@@ -965,8 +965,7 @@ ELFFile<ELFT>::getSectionAndRelocations(
continue;
}
if (*DoesSectionMatch) {
if (SecToRelocMap.insert(std::make_pair(&Sec, (const Elf_Shdr *)nullptr))
.second)
if (SecToRelocMap.try_emplace(&Sec).second)
continue;
}

6 changes: 3 additions & 3 deletions llvm/lib/SandboxIR/Context.cpp
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ Value *Context::registerValue(std::unique_ptr<Value> &&VPtr) {
}

Value *Context::getOrCreateValueInternal(llvm::Value *LLVMV, llvm::User *U) {
auto Pair = LLVMValueToValueMap.insert({LLVMV, nullptr});
auto Pair = LLVMValueToValueMap.try_emplace(LLVMV);
auto It = Pair.first;
if (!Pair.second)
return It->second.get();
@@ -432,7 +432,7 @@ Value *Context::getOrCreateValueInternal(llvm::Value *LLVMV, llvm::User *U) {
}

Argument *Context::getOrCreateArgument(llvm::Argument *LLVMArg) {
auto Pair = LLVMValueToValueMap.insert({LLVMArg, nullptr});
auto Pair = LLVMValueToValueMap.try_emplace(LLVMArg);
auto It = Pair.first;
if (Pair.second) {
It->second = std::unique_ptr<Argument>(new Argument(LLVMArg, *this));
@@ -652,7 +652,7 @@ Module *Context::getModule(llvm::Module *LLVMM) const {
}

Module *Context::getOrCreateModule(llvm::Module *LLVMM) {
auto Pair = LLVMModuleToModuleMap.insert({LLVMM, nullptr});
auto Pair = LLVMModuleToModuleMap.try_emplace(LLVMM);
auto It = Pair.first;
if (!Pair.second)
return It->second.get();
Original file line number Diff line number Diff line change
@@ -270,7 +270,7 @@ bool FixFunctionBitcasts::runOnModule(Module &M) {
Function *F = UseFunc.second;
FunctionType *Ty = CB->getFunctionType();

auto Pair = Wrappers.insert(std::make_pair(std::make_pair(F, Ty), nullptr));
auto Pair = Wrappers.try_emplace(std::make_pair(F, Ty));
if (Pair.second)
Pair.first->second = createWrapper(F, Ty);

7 changes: 3 additions & 4 deletions llvm/lib/TextAPI/RecordsSlice.cpp
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ GlobalRecord *RecordsSlice::addGlobal(StringRef Name, RecordLinkage Linkage,
Flags |= SymbolFlags::Data;

Name = copyString(Name);
auto Result = Globals.insert({Name, nullptr});
auto Result = Globals.try_emplace(Name);
if (Result.second)
Result.first->second =
std::make_unique<GlobalRecord>(Name, Linkage, Flags, GV, Inlined);
@@ -194,7 +194,7 @@ ObjCInterfaceRecord *RecordsSlice::addObjCInterface(StringRef Name,
RecordLinkage Linkage,
ObjCIFSymbolKind SymType) {
Name = copyString(Name);
auto Result = Classes.insert({Name, nullptr});
auto Result = Classes.try_emplace(Name);
if (Result.second)
Result.first->second =
std::make_unique<ObjCInterfaceRecord>(Name, Linkage, SymType);
@@ -228,8 +228,7 @@ ObjCCategoryRecord *RecordsSlice::addObjCCategory(StringRef ClassToExtend,
ClassToExtend = copyString(ClassToExtend);

// Add owning record first into record slice.
auto Result =
Categories.insert({std::make_pair(ClassToExtend, Category), nullptr});
auto Result = Categories.try_emplace(std::make_pair(ClassToExtend, Category));
if (Result.second)
Result.first->second =
std::make_unique<ObjCCategoryRecord>(ClassToExtend, Category);
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Original file line number Diff line number Diff line change
@@ -1115,7 +1115,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
bool FoundSrcAgg = false;
for (BasicBlock *Pred : Preds) {
std::pair<decltype(SourceAggregates)::iterator, bool> IV =
SourceAggregates.insert({Pred, nullptr});
SourceAggregates.try_emplace(Pred);
// Did we already evaluate this predecessor?
if (!IV.second)
continue;
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Original file line number Diff line number Diff line change
@@ -5880,7 +5880,7 @@ void LSRInstance::RewriteForPHI(PHINode *PN, const LSRUse &LU,
}

std::pair<DenseMap<BasicBlock *, Value *>::iterator, bool> Pair =
Inserted.insert(std::make_pair(BB, static_cast<Value *>(nullptr)));
Inserted.try_emplace(BB);
if (!Pair.second)
PN->setIncomingValue(i, Pair.first->second);
else {
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/NewGVN.cpp
Original file line number Diff line number Diff line change
@@ -2383,7 +2383,7 @@ void NewGVN::performCongruenceFinding(Instruction *I, const Expression *E) {
EClass = TOPClass;
}
if (!EClass) {
auto lookupResult = ExpressionToClass.insert({E, nullptr});
auto lookupResult = ExpressionToClass.try_emplace(E);

// If it's not in the value table, create a new congruence class.
if (lookupResult.second) {
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
Original file line number Diff line number Diff line change
@@ -434,7 +434,7 @@ static const Loop *PickMostRelevantLoop(const Loop *A, const Loop *B,
/// expression, according to PickMostRelevantLoop.
const Loop *SCEVExpander::getRelevantLoop(const SCEV *S) {
// Test whether we've already computed the most relevant loop for this SCEV.
auto Pair = RelevantLoops.insert(std::make_pair(S, nullptr));
auto Pair = RelevantLoops.try_emplace(S);
if (!Pair.second)
return Pair.first->second;

3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Original file line number Diff line number Diff line change
@@ -1820,8 +1820,7 @@ void VPlanTransforms::truncateToMinimalBitwidths(
if (OpSizeInBits == NewResSizeInBits)
continue;
assert(OpSizeInBits > NewResSizeInBits && "nothing to truncate");
auto [ProcessedIter, IterIsEmpty] =
ProcessedTruncs.insert({Op, nullptr});
auto [ProcessedIter, IterIsEmpty] = ProcessedTruncs.try_emplace(Op);
VPWidenCastRecipe *NewOp =
IterIsEmpty
? new VPWidenCastRecipe(Instruction::Trunc, Op, NewResTy)