From 789d25061363a737d6211f86f1e4a4bb10c6e4f8 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 27 Dec 2020 09:57:27 -0800 Subject: [PATCH] [CodeGen, Transforms] Use *Map::lookup (NFC) --- llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h | 5 +---- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h | 3 +-- llvm/lib/CodeGen/MIRParser/MIParser.cpp | 10 ++-------- .../Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | 7 +------ llvm/lib/Transforms/Utils/Evaluator.cpp | 6 +----- llvm/lib/Transforms/Utils/SSAUpdater.cpp | 3 +-- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 12 ++---------- llvm/lib/Transforms/Vectorize/VPlan.h | 4 +--- 8 files changed, 10 insertions(+), 40 deletions(-) diff --git a/llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h b/llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h index 8a03875..50b186d 100644 --- a/llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h +++ b/llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h @@ -388,10 +388,7 @@ namespace llvm { /// Returns an existing SUnit for this MI, or nullptr. inline SUnit *ScheduleDAGInstrs::getSUnit(MachineInstr *MI) const { - DenseMap::const_iterator I = MISUnitMap.find(MI); - if (I == MISUnitMap.end()) - return nullptr; - return I->second; + return MISUnitMap.lookup(MI); } } // end namespace llvm diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index eb8f201..502aef4 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -787,8 +787,7 @@ public: } unsigned getStringTypeLoc(const DIStringType *ST) const { - auto I = StringTypeLocMap.find(ST); - return I != StringTypeLocMap.end() ? I->second : 0; + return StringTypeLocMap.lookup(ST); } void addStringTypeLoc(const DIStringType *ST, unsigned Loc) { diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 5ba896b..43eaf86 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -369,10 +369,7 @@ static void initSlots2Values(const Function &F, const Value* PerFunctionMIParsingState::getIRValue(unsigned Slot) { if (Slots2Values.empty()) initSlots2Values(MF.getFunction(), Slots2Values); - auto ValueInfo = Slots2Values.find(Slot); - if (ValueInfo == Slots2Values.end()) - return nullptr; - return ValueInfo->second; + return Slots2Values.lookup(Slot); } namespace { @@ -3169,10 +3166,7 @@ static void initSlots2BasicBlocks( static const BasicBlock *getIRBlockFromSlot( unsigned Slot, const DenseMap &Slots2BasicBlocks) { - auto BlockInfo = Slots2BasicBlocks.find(Slot); - if (BlockInfo == Slots2BasicBlocks.end()) - return nullptr; - return BlockInfo->second; + return Slots2BasicBlocks.lookup(Slot); } const BasicBlock *MIParser::getIRBlock(unsigned Slot) { diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index ac617ec..6bc2a68 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -273,12 +273,7 @@ bool PointerReplacer::collectUsers(Instruction &I) { return true; } -Value *PointerReplacer::getReplacement(Value *V) { - auto Loc = WorkMap.find(V); - if (Loc != WorkMap.end()) - return Loc->second; - return nullptr; -} +Value *PointerReplacer::getReplacement(Value *V) { return WorkMap.lookup(V); } void PointerReplacer::replace(Instruction *I) { if (getReplacement(I)) diff --git a/llvm/lib/Transforms/Utils/Evaluator.cpp b/llvm/lib/Transforms/Utils/Evaluator.cpp index a01dc7a..732b006 100644 --- a/llvm/lib/Transforms/Utils/Evaluator.cpp +++ b/llvm/lib/Transforms/Utils/Evaluator.cpp @@ -210,11 +210,7 @@ static Constant *getInitializer(Constant *C) { Constant *Evaluator::ComputeLoadResult(Constant *P) { // If this memory location has been recently stored, use the stored value: it // is the most up-to-date. - auto findMemLoc = [this](Constant *Ptr) { - DenseMap::const_iterator I = - MutatedMemory.find(Ptr); - return I != MutatedMemory.end() ? I->second : nullptr; - }; + auto findMemLoc = [this](Constant *Ptr) { return MutatedMemory.lookup(Ptr); }; if (Constant *Val = findMemLoc(P)) return Val; diff --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp index 57df233..c3add49 100644 --- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp +++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp @@ -64,8 +64,7 @@ bool SSAUpdater::HasValueForBlock(BasicBlock *BB) const { } Value *SSAUpdater::FindValueForBlock(BasicBlock *BB) const { - AvailableValsTy::iterator AVI = getAvailableVals(AV).find(BB); - return (AVI != getAvailableVals(AV).end()) ? AVI->second : nullptr; + return getAvailableVals(AV).lookup(BB); } void SSAUpdater::AddAvailableValue(BasicBlock *BB, Value *V) { diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 8a455f3..9f17689 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1840,18 +1840,10 @@ private: } #endif - TreeEntry *getTreeEntry(Value *V) { - auto I = ScalarToTreeEntry.find(V); - if (I != ScalarToTreeEntry.end()) - return I->second; - return nullptr; - } + TreeEntry *getTreeEntry(Value *V) { return ScalarToTreeEntry.lookup(V); } const TreeEntry *getTreeEntry(Value *V) const { - auto I = ScalarToTreeEntry.find(V); - if (I != ScalarToTreeEntry.end()) - return I->second; - return nullptr; + return ScalarToTreeEntry.lookup(V); } /// Maps a specific scalar to its tree entry. diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 2b4c957..e6635e7 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -2013,9 +2013,7 @@ public: /// \returns nullptr if doesn't have such group. InterleaveGroup * getInterleaveGroup(VPInstruction *Instr) const { - if (InterleaveGroupMap.count(Instr)) - return InterleaveGroupMap.find(Instr)->second; - return nullptr; + return InterleaveGroupMap.lookup(Instr); } }; -- 2.7.4