llvm.org GIT mirror llvm / a591995
Use llvm::lower_bound. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358161 91177308-0d34-0410-b5e6-96231b3b80d8 Fangrui Song 1 year, 7 months ago
9 changed file(s) with 32 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
461461 DWARFDie getDIEForOffset(uint32_t Offset) {
462462 extractDIEsIfNeeded(false);
463463 assert(!DieArray.empty());
464 auto it = std::lower_bound(
465 DieArray.begin(), DieArray.end(), Offset,
466 [](const DWARFDebugInfoEntry &LHS, uint32_t Offset) {
464 auto it = llvm::lower_bound(
465 DieArray, Offset, [](const DWARFDebugInfoEntry &LHS, uint32_t Offset) {
467466 return LHS.getOffset() < Offset;
468467 });
469468 if (it != DieArray.end() && it->getOffset() == Offset)
14961496 if (funcName.empty())
14971497 return false;
14981498
1499 std::vector::const_iterator I = std::lower_bound(
1500 VectorDescs.begin(), VectorDescs.end(), funcName,
1501 compareWithScalarFnName);
1499 std::vector::const_iterator I =
1500 llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName);
15021501 return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
15031502 }
15041503
15071506 F = sanitizeFunctionName(F);
15081507 if (F.empty())
15091508 return F;
1510 std::vector::const_iterator I = std::lower_bound(
1511 VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1509 std::vector::const_iterator I =
1510 llvm::lower_bound(VectorDescs, F, compareWithScalarFnName);
15121511 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
15131512 if (I->VectorizationFactor == VF)
15141513 return I->VectorFnName;
15231522 if (F.empty())
15241523 return F;
15251524
1526 std::vector::const_iterator I = std::lower_bound(
1527 ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1525 std::vector::const_iterator I =
1526 llvm::lower_bound(ScalarDescs, F, compareWithVectorFnName);
15281527 if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
15291528 return StringRef();
15301529 VF = I->VectorizationFactor;
179179 NewOp = RealVal;
180180 } else {
181181 // Otherwise, look up the placeholder in ResolveConstants.
182 ResolveConstantsTy::iterator It = std::lower_bound(
183 ResolveConstants.begin(), ResolveConstants.end(),
182 ResolveConstantsTy::iterator It = llvm::lower_bound(
183 ResolveConstants,
184184 std::pair(cast(*I), 0));
185185 assert(It != ResolveConstants.end() && It->first == *I);
186186 NewOp = operator[](It->second);
534534 uint64_t Offset = getOffsetFromIndices(U, *DL);
535535 ArrayRef SrcRegs = getOrCreateVRegs(*Src);
536536 ArrayRef Offsets = *VMap.getOffsets(*Src);
537 unsigned Idx = std::lower_bound(Offsets.begin(), Offsets.end(), Offset) -
538 Offsets.begin();
537 unsigned Idx = llvm::lower_bound(Offsets, Offset) - Offsets.begin();
539538 auto &DstRegs = allocateVRegs(U);
540539
541540 for (unsigned i = 0; i < DstRegs.size(); ++i)
22612261 ArrayRef RMS = LIS->getRegMaskSlotsInBlock(BI.MBB->getNumber());
22622262 LLVM_DEBUG(dbgs() << RMS.size() << " regmasks in block:");
22632263 // Constrain to VirtReg's live range.
2264 unsigned ri = std::lower_bound(RMS.begin(), RMS.end(),
2265 Uses.front().getRegSlot()) - RMS.begin();
2264 unsigned ri =
2265 llvm::lower_bound(RMS, Uses.front().getRegSlot()) - RMS.begin();
22662266 unsigned re = RMS.size();
22672267 for (unsigned i = 0; i != NumGaps && ri != re; ++i) {
22682268 // Look for Uses[i] <= RMS <= Uses[i+1].
5656
5757 DWARFDebugLoc::LocationList const *
5858 DWARFDebugLoc::getLocationListAtOffset(uint64_t Offset) const {
59 auto It = std::lower_bound(
60 Locations.begin(), Locations.end(), Offset,
59 auto It = llvm::lower_bound(
60 Locations, Offset,
6161 [](const LocationList &L, uint64_t Offset) { return L.Offset < Offset; });
6262 if (It != Locations.end() && It->Offset == Offset)
6363 return &(*It);
212212
213213 DWARFDebugLoclists::LocationList const *
214214 DWARFDebugLoclists::getLocationListAtOffset(uint64_t Offset) const {
215 auto It = std::lower_bound(
216 Locations.begin(), Locations.end(), Offset,
215 auto It = llvm::lower_bound(
216 Locations, Offset,
217217 [](const LocationList &L, uint64_t Offset) { return L.Offset < Offset; });
218218 if (It != Locations.end() && It->Offset == Offset)
219219 return &(*It);
6161 // Find the first range whose High field is >= R.High,
6262 // then check if the Low field is <= R.Low. If so, we
6363 // have a Range that covers R.
64 auto I = std::lower_bound(
65 Ranges.begin(), Ranges.end(), R,
66 [](const IntRange &A, const IntRange &B) { return A.High < B.High; });
64 auto I = llvm::lower_bound(
65 Ranges, R, [](IntRange A, IntRange B) { return A.High < B.High; });
6766 return I != Ranges.end() && I->Low <= R.Low;
6867 }
6968
486486 unsigned LoadIdx = LBI.getInstructionIndex(LI);
487487
488488 // Find the nearest store that has a lower index than this load.
489 StoresByIndexTy::iterator I =
490 std::lower_bound(StoresByIndex.begin(), StoresByIndex.end(),
491 std::make_pair(LoadIdx,
492 static_cast(nullptr)),
493 less_first());
489 StoresByIndexTy::iterator I = llvm::lower_bound(
490 StoresByIndex,
491 std::make_pair(LoadIdx, static_cast(nullptr)),
492 less_first());
494493 if (I == StoresByIndex.begin()) {
495494 if (StoresByIndex.empty())
496495 // If there are no stores, the load takes the undef value.
757756 // them from the Preds list.
758757 for (unsigned i = 0, e = SomePHI->getNumIncomingValues(); i != e; ++i) {
759758 // Do a log(n) search of the Preds list for the entry we want.
760 SmallVectorImpl::iterator EntIt = std::lower_bound(
761 Preds.begin(), Preds.end(), SomePHI->getIncomingBlock(i),
762 CompareBBNumbers);
759 SmallVectorImpl::iterator EntIt = llvm::lower_bound(
760 Preds, SomePHI->getIncomingBlock(i), CompareBBNumbers);
763761 assert(EntIt != Preds.end() && *EntIt == SomePHI->getIncomingBlock(i) &&
764762 "PHI node has entry for a block which is not a predecessor!");
765763
2020 static constexpr const char kIntegerPrefix[] = "i_0x";
2121 static constexpr const char kDoublePrefix[] = "f_";
2222 static constexpr const char kInvalidOperand[] = "INVALID";
23 static constexpr llvm::StringLiteral kNoRegister("%noreg");
2423
2524 namespace llvm {
2625
4746 llvm::StringMap
4847 generateRegNameToRegNoMapping(const llvm::MCRegisterInfo &RegInfo) {
4948 llvm::StringMap Map(RegInfo.getNumRegs());
50 // Special-case RegNo 0, which would otherwise be spelled as ''.
51 Map[kNoRegister] = 0;
52 for (unsigned I = 1, E = RegInfo.getNumRegs(); I < E; ++I)
49 for (unsigned I = 0, E = RegInfo.getNumRegs(); I < E; ++I)
5350 Map[RegInfo.getName(I)] = I;
5451 assert(Map.size() == RegInfo.getNumRegs() && "Size prediction failed");
5552 return Map;
8582 llvm::raw_string_ostream &getErrorStream() { return ErrorStream; }
8683
8784 llvm::StringRef getRegName(unsigned RegNo) {
88 // Special case: RegNo 0 is NoRegister. We have to deal with it explicitly.
89 if (RegNo == 0)
90 return kNoRegister;
9185 const llvm::StringRef RegName = State->getRegInfo().getName(RegNo);
9286 if (RegName.empty())
9387 ErrorStream << "No register with enum value '" << RegNo << "'\n";
9488 return RegName;
9589 }
9690
97 llvm::Optional getRegNo(llvm::StringRef RegName) {
91 unsigned getRegNo(llvm::StringRef RegName) {
9892 auto Iter = RegNameToRegNo.find(RegName);
9993 if (Iter != RegNameToRegNo.end())
10094 return Iter->second;
10195 ErrorStream << "No register with name '" << RegName << "'\n";
102 return llvm::None;
96 return 0;
10397 }
10498
10599 private:
147141 return llvm::MCOperand::createImm(IntValue);
148142 if (tryDeserializeFPOperand(String, DoubleValue))
149143 return llvm::MCOperand::createFPImm(DoubleValue);
150 if (auto RegNo = getRegNo(String))
151 return llvm::MCOperand::createReg(*RegNo);
144 if (unsigned RegNo = getRegNo(String))
145 return llvm::MCOperand::createReg(RegNo);
152146 if (String != kInvalidOperand)
153147 ErrorStream << "Unknown Operand: '" << String << "'\n";
154148 return {};
263257 String.split(Pieces, "=0x", /* MaxSplit */ -1,
264258 /* KeepEmpty */ false);
265259 YamlContext &Context = getTypedContext(Ctx);
266 llvm::Optional RegNo;
267 if (Pieces.size() == 2 && (RegNo = Context.getRegNo(Pieces[0]))) {
268 RV.Register = *RegNo;
260 if (Pieces.size() == 2) {
261 RV.Register = Context.getRegNo(Pieces[0]);
269262 const unsigned BitsNeeded = llvm::APInt::getBitsNeeded(Pieces[1], kRadix);
270263 RV.Value = llvm::APInt(BitsNeeded, Pieces[1], kRadix);
271264 } else {