本文整理汇总了C++中SmallVectorImpl::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ SmallVectorImpl::erase方法的具体用法?C++ SmallVectorImpl::erase怎么用?C++ SmallVectorImpl::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmallVectorImpl
的用法示例。
在下文中一共展示了SmallVectorImpl::erase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetIndiceDifference
/// GetIndiceDifference - Dest and Src are the variable indices from two
/// decomposed GetElementPtr instructions GEP1 and GEP2 which have common base
/// pointers. Subtract the GEP2 indices from GEP1 to find the symbolic
/// difference between the two pointers.
static void GetIndiceDifference(
SmallVectorImpl<std::pair<const Value*, int64_t> > &Dest,
const SmallVectorImpl<std::pair<const Value*, int64_t> > &Src) {
if (Src.empty()) return;
for (unsigned i = 0, e = Src.size(); i != e; ++i) {
const Value *V = Src[i].first;
int64_t Scale = Src[i].second;
// Find V in Dest. This is N^2, but pointer indices almost never have more
// than a few variable indexes.
for (unsigned j = 0, e = Dest.size(); j != e; ++j) {
if (Dest[j].first != V) continue;
// If we found it, subtract off Scale V's from the entry in Dest. If it
// goes to zero, remove the entry.
if (Dest[j].second != Scale)
Dest[j].second -= Scale;
else
Dest.erase(Dest.begin()+j);
Scale = 0;
break;
}
// If we didn't consume this entry, add it to the end of the Dest list.
if (Scale)
Dest.push_back(std::make_pair(V, -Scale));
}
}
示例2: VerifySubExpr
static bool VerifySubExpr(Value *Expr,
SmallVectorImpl<Instruction*> &InstInputs) {
// If this is a non-instruction value, there is nothing to do.
Instruction *I = dyn_cast<Instruction>(Expr);
if (!I) return true;
// If it's an instruction, it is either in Tmp or its operands recursively
// are.
SmallVectorImpl<Instruction*>::iterator Entry =
std::find(InstInputs.begin(), InstInputs.end(), I);
if (Entry != InstInputs.end()) {
InstInputs.erase(Entry);
return true;
}
// If it isn't in the InstInputs list it is a subexpr incorporated into the
// address. Sanity check that it is phi translatable.
if (!CanPHITrans(I)) {
errs() << "Instruction in PHITransAddr is not phi-translatable:\n";
errs() << *I << '\n';
llvm_unreachable("Either something is missing from InstInputs or "
"CanPHITrans is wrong.");
}
// Validate the operands of the instruction.
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
if (!VerifySubExpr(I->getOperand(i), InstInputs))
return false;
return true;
}
示例3: uniqueTypeVariables
/// Unique the given set of type variables.
static void uniqueTypeVariables(SmallVectorImpl<TypeVariableType *> &typeVars) {
// Remove any duplicate type variables.
llvm::SmallPtrSet<TypeVariableType *, 4> knownTypeVars;
typeVars.erase(std::remove_if(typeVars.begin(), typeVars.end(),
[&](TypeVariableType *typeVar) {
return !knownTypeVars.insert(typeVar).second;
}),
typeVars.end());
}
示例4: finish
// Flushes the internal diagnostics buffer to the ClangTidyContext.
void ClangTidyDiagnosticConsumer::finish() {
finalizeLastError();
std::sort(Errors.begin(), Errors.end(), LessClangTidyError());
Errors.erase(std::unique(Errors.begin(), Errors.end(), EqualClangTidyError()),
Errors.end());
removeIncompatibleErrors(Errors);
for (const ClangTidyError &Error : Errors)
Context.storeError(Error);
Errors.clear();
}
示例5: removeRegLanes
static void removeRegLanes(SmallVectorImpl<RegisterMaskPair> &RegUnits,
RegisterMaskPair Pair) {
unsigned RegUnit = Pair.RegUnit;
assert(Pair.LaneMask.any());
auto I = find_if(RegUnits, [RegUnit](const RegisterMaskPair Other) {
return Other.RegUnit == RegUnit;
});
if (I != RegUnits.end()) {
I->LaneMask &= ~Pair.LaneMask;
if (I->LaneMask.none())
RegUnits.erase(I);
}
}
示例6: removeOverriddenDecls
bool swift::removeOverriddenDecls(SmallVectorImpl<ValueDecl*> &decls) {
if (decls.empty())
return false;
ASTContext &ctx = decls.front()->getASTContext();
llvm::SmallPtrSet<ValueDecl*, 8> overridden;
for (auto decl : decls) {
while (auto overrides = decl->getOverriddenDecl()) {
overridden.insert(overrides);
// Because initializers from Objective-C base classes have greater
// visibility than initializers written in Swift classes, we can
// have a "break" in the set of declarations we found, where
// C.init overrides B.init overrides A.init, but only C.init and
// A.init are in the chain. Make sure we still remove A.init from the
// set in this case.
if (decl->getFullName().getBaseName() == ctx.Id_init) {
/// FIXME: Avoid the possibility of an infinite loop by fixing the root
/// cause instead (incomplete circularity detection).
assert(decl != overrides && "Circular class inheritance?");
decl = overrides;
continue;
}
break;
}
}
// If no methods were overridden, we're done.
if (overridden.empty()) return false;
// Erase any overridden declarations
bool anyOverridden = false;
decls.erase(std::remove_if(decls.begin(), decls.end(),
[&](ValueDecl *decl) -> bool {
if (overridden.count(decl) > 0) {
anyOverridden = true;
return true;
}
return false;
}),
decls.end());
return anyOverridden;
}
示例7: lookupAllObjCMethods
void DeclContext::lookupAllObjCMethods(
ObjCSelector selector,
SmallVectorImpl<AbstractFunctionDecl *> &results) const {
// Collect all of the methods with this selector.
forAllVisibleModules(this, [&](Module::ImportedModule import) {
import.second->lookupObjCMethods(selector, results);
});
// Filter out duplicates.
llvm::SmallPtrSet<AbstractFunctionDecl *, 8> visited;
results.erase(
std::remove_if(results.begin(), results.end(),
[&](AbstractFunctionDecl *func) -> bool {
return !visited.insert(func).second;
}),
results.end());
}
示例8: readRecord
unsigned NaClBitstreamCursor::readRecord(unsigned AbbrevID,
SmallVectorImpl<uint64_t> &Vals) {
if (AbbrevID == naclbitc::UNABBREV_RECORD) {
unsigned Code = ReadVBR(6);
unsigned NumElts = ReadVBR(6);
for (unsigned i = 0; i != NumElts; ++i)
Vals.push_back(ReadVBR64(6));
return Code;
}
const NaClBitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
const NaClBitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
if (Op.isLiteral()) {
readAbbreviatedLiteral(Op, Vals);
continue;
}
if (Op.getEncoding() == NaClBitCodeAbbrevOp::Blob)
report_fatal_error("Should not reach here");
if (Op.getEncoding() != NaClBitCodeAbbrevOp::Array) {
readAbbreviatedField(Op, Vals);
continue;
}
if (Op.getEncoding() == NaClBitCodeAbbrevOp::Array) {
// Array case. Read the number of elements as a vbr6.
unsigned NumElts = ReadVBR(6);
// Get the element encoding.
assert(i+2 == e && "array op not second to last?");
const NaClBitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
// Read all the elements.
for (; NumElts; --NumElts)
readAbbreviatedField(EltEnc, Vals);
continue;
}
}
unsigned Code = (unsigned)Vals[0];
Vals.erase(Vals.begin());
return Code;
}
示例9: RemoveInstInputs
static void RemoveInstInputs(Value *V,
SmallVectorImpl<Instruction*> &InstInputs) {
Instruction *I = dyn_cast<Instruction>(V);
if (!I) return;
// If the instruction is in the InstInputs list, remove it.
SmallVectorImpl<Instruction *>::iterator Entry = find(InstInputs, I);
if (Entry != InstInputs.end()) {
InstInputs.erase(Entry);
return;
}
assert(!isa<PHINode>(I) && "Error, removing something that isn't an input");
// Otherwise, it must have instruction inputs itself. Zap them recursively.
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
if (Instruction *Op = dyn_cast<Instruction>(I->getOperand(i)))
RemoveInstInputs(Op, InstInputs);
}
}
示例10: filterForDiscriminator
static void filterForDiscriminator(SmallVectorImpl<Result> &results,
DebuggerClient *debugClient) {
Identifier discriminator = debugClient->getPreferredPrivateDiscriminator();
if (discriminator.empty())
return;
auto doesNotMatch = [discriminator](Result next) -> bool {
return !matchesDiscriminator(discriminator, next);
};
auto lastMatchIter = std::find_if_not(results.rbegin(), results.rend(),
doesNotMatch);
if (lastMatchIter == results.rend())
return;
Result lastMatch = *lastMatchIter;
auto newEnd = std::remove_if(results.begin(), lastMatchIter.base()-1,
doesNotMatch);
results.erase(newEnd, results.end());
results.push_back(lastMatch);
}
示例11: EraseUnwantedCUDAMatches
void Sema::EraseUnwantedCUDAMatches(
const FunctionDecl *Caller,
SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches) {
if (Matches.size() <= 1)
return;
using Pair = std::pair<DeclAccessPair, FunctionDecl*>;
// Gets the CUDA function preference for a call from Caller to Match.
auto GetCFP = [&](const Pair &Match) {
return IdentifyCUDAPreference(Caller, Match.second);
};
// Find the best call preference among the functions in Matches.
CUDAFunctionPreference BestCFP = GetCFP(*std::max_element(
Matches.begin(), Matches.end(),
[&](const Pair &M1, const Pair &M2) { return GetCFP(M1) < GetCFP(M2); }));
// Erase all functions with lower priority.
Matches.erase(
llvm::remove_if(
Matches, [&](const Pair &Match) { return GetCFP(Match) < BestCFP; }),
Matches.end());
}
示例12: removeShadowedDecls
//.........这里部分代码省略.........
auto secondDecl = collidingDecls.second[secondIdx];
auto secondModule = secondDecl->getModuleContext();
// If one declaration is in a protocol or extension thereof and the
// other is not, prefer the one that is not.
if ((bool)firstDecl->getDeclContext()
->getAsProtocolOrProtocolExtensionContext()
!= (bool)secondDecl->getDeclContext()
->getAsProtocolOrProtocolExtensionContext()) {
if (firstDecl->getDeclContext()
->getAsProtocolOrProtocolExtensionContext()) {
shadowed.insert(firstDecl);
break;
} else {
shadowed.insert(secondDecl);
continue;
}
}
// If one declaration is available and the other is not, prefer the
// available one.
if (firstDecl->getAttrs().isUnavailable(ctx) !=
secondDecl->getAttrs().isUnavailable(ctx)) {
if (firstDecl->getAttrs().isUnavailable(ctx)) {
shadowed.insert(firstDecl);
break;
} else {
shadowed.insert(secondDecl);
continue;
}
}
// Don't apply module-shadowing rules to members of protocol types.
if (isa<ProtocolDecl>(firstDecl->getDeclContext()) ||
isa<ProtocolDecl>(secondDecl->getDeclContext()))
continue;
// Prefer declarations in the current module over those in another
// module.
// FIXME: This is a hack. We should query a (lazily-built, cached)
// module graph to determine shadowing.
if ((firstModule == curModule) == (secondModule == curModule))
continue;
// If the first module is the current module, the second declaration
// is shadowed by the first.
if (firstModule == curModule) {
shadowed.insert(secondDecl);
continue;
}
// Otherwise, the first declaration is shadowed by the second. There is
// no point in continuing to compare the first declaration to others.
shadowed.insert(firstDecl);
break;
}
}
}
// Check for collisions among Objective-C initializers. When such collisions
// exist, we pick the
for (const auto &colliding : ObjCCollidingConstructors) {
if (colliding.second.size() == 1)
continue;
// Find the "best" constructor with this signature.
ConstructorDecl *bestCtor = colliding.second[0];
for (auto ctor : colliding.second) {
auto comparison = compareConstructors(ctor, bestCtor, ctx);
if (comparison == ConstructorComparison::Better)
bestCtor = ctor;
}
// Shadow any initializers that are worse.
for (auto ctor : colliding.second) {
auto comparison = compareConstructors(ctor, bestCtor, ctx);
if (comparison == ConstructorComparison::Worse)
shadowed.insert(ctor);
}
}
// If none of the declarations were shadowed, we're done.
if (shadowed.empty())
return false;
// Remove shadowed declarations from the list of declarations.
bool anyRemoved = false;
decls.erase(std::remove_if(decls.begin(), decls.end(),
[&](ValueDecl *vd) {
if (shadowed.count(vd) > 0) {
anyRemoved = true;
return true;
}
return false;
}),
decls.end());
return anyRemoved;
}
示例13: diff
//.........这里部分代码省略.........
case SolutionCompareResult::Worse:
losers[i] = true;
break;
case SolutionCompareResult::Better:
losers[bestIdx] = true;
bestIdx = i;
break;
}
}
// Make sure that our current best is better than all of the solved systems.
bool ambiguous = false;
for (unsigned i = 0, n = viable.size(); i != n && !ambiguous; ++i) {
if (i == bestIdx)
continue;
switch (compareSolutions(*this, viable, diff, bestIdx, i)) {
case SolutionCompareResult::Identical:
// FIXME: Might want to warn about this in debug builds, so we can
// find a way to eliminate the redundancy in the search space.
break;
case SolutionCompareResult::Better:
losers[i] = true;
break;
case SolutionCompareResult::Worse:
losers[bestIdx] = true;
SWIFT_FALLTHROUGH;
case SolutionCompareResult::Incomparable:
// If we're not supposed to minimize the result set, just return eagerly.
if (!minimize)
return None;
ambiguous = true;
break;
}
}
// If the result was not ambiguous, we're done.
if (!ambiguous) {
NumDiscardedSolutions += viable.size() - 1;
return bestIdx;
}
// The comparison was ambiguous. Identify any solutions that are worse than
// any other solution.
for (unsigned i = 0, n = viable.size(); i != n; ++i) {
// If the first solution has already lost once, don't bother looking
// further.
if (losers[i])
continue;
for (unsigned j = i + 1; j != n; ++j) {
// If the second solution has already lost once, don't bother looking
// further.
if (losers[j])
continue;
switch (compareSolutions(*this, viable, diff, i, j)) {
case SolutionCompareResult::Identical:
// FIXME: Dub one of these the loser arbitrarily?
break;
case SolutionCompareResult::Better:
losers[j] = true;
break;
case SolutionCompareResult::Worse:
losers[i] = true;
break;
case SolutionCompareResult::Incomparable:
break;
}
}
}
// Remove any solution that is worse than some other solution.
unsigned outIndex = 0;
for (unsigned i = 0, n = viable.size(); i != n; ++i) {
// Skip over the losing solutions.
if (losers[i])
continue;
// If we have skipped any solutions, move this solution into the next
// open position.
if (outIndex < i)
viable[outIndex] = std::move(viable[i]);
++outIndex;
}
viable.erase(viable.begin() + outIndex, viable.end());
NumDiscardedSolutions += viable.size() - outIndex;
return None;
}
示例14: if
//.........这里部分代码省略.........
.Case("cmovnbl", "cmovael")
.Case("cmovnbel", "cmoval")
.Case("cmovncl", "cmovael")
.Case("cmovngl", "cmovlel")
.Case("cmovnl", "cmovgel")
.Case("cmovngl", "cmovlel")
.Case("cmovngel", "cmovll")
.Case("cmovnll", "cmovgel")
.Case("cmovnlel", "cmovgl")
.Case("cmovnzl", "cmovnel")
.Case("cmovzl", "cmovel")
.Case("fwait", "wait")
.Case("movzx", "movzb")
.Default(Name);
// FIXME: Hack to recognize cmp<comparison code>{ss,sd,ps,pd}.
const MCExpr *ExtraImmOp = 0;
if (PatchedName.startswith("cmp") &&
(PatchedName.endswith("ss") || PatchedName.endswith("sd") ||
PatchedName.endswith("ps") || PatchedName.endswith("pd"))) {
unsigned SSEComparisonCode = StringSwitch<unsigned>(
PatchedName.slice(3, PatchedName.size() - 2))
.Case("eq", 0)
.Case("lt", 1)
.Case("le", 2)
.Case("unord", 3)
.Case("neq", 4)
.Case("nlt", 5)
.Case("nle", 6)
.Case("ord", 7)
.Default(~0U);
if (SSEComparisonCode != ~0U) {
ExtraImmOp = MCConstantExpr::Create(SSEComparisonCode, Parser->getContext());
if (PatchedName.endswith("ss")) {
PatchedName = "cmpss";
} else if (PatchedName.endswith("sd")) {
PatchedName = "cmpsd";
} else if (PatchedName.endswith("ps")) {
PatchedName = "cmpps";
} else {
assert(PatchedName.endswith("pd") && "Unexpected mnemonic!");
PatchedName = "cmppd";
}
}
}
Operands.push_back(X86Operand::CreateToken(PatchedName, NameLoc));
if (ExtraImmOp)
Operands.push_back(X86Operand::CreateImm(ExtraImmOp, NameLoc, NameLoc));
if (Parser->getLexer().isNot(AsmToken::EndOfStatement)) {
// Parse '*' modifier.
if (Parser->getLexer().is(AsmToken::Star)) {
SMLoc Loc = Parser->getTok().getLoc();
Operands.push_back(X86Operand::CreateToken("*", Loc));
Parser->Lex(); // Eat the star.
}
// Read the first operand.
if (X86Operand *Op = ParseOperand())
Operands.push_back(Op);
else
return true;
while (Parser->getLexer().is(AsmToken::Comma)) {
Parser->Lex(); // Eat the comma.
// Parse and remember the operand.
if (X86Operand *Op = ParseOperand())
Operands.push_back(Op);
else
return true;
}
}
// FIXME: Hack to handle recognizing s{hr,ar,hl}? $1.
if ((Name.startswith("shr") || Name.startswith("sar") ||
Name.startswith("shl")) &&
Operands.size() == 3 &&
static_cast<X86Operand*>(Operands[1])->isImm() &&
isa<MCConstantExpr>(static_cast<X86Operand*>(Operands[1])->getImm()) &&
cast<MCConstantExpr>(static_cast<X86Operand*>(Operands[1])->getImm())->getValue() == 1) {
delete Operands[1];
Operands.erase(Operands.begin() + 1);
}
// FIXME: Hack to handle "f{mul*,add*,sub*,div*} $op, st(0)" the same as
// "f{mul*,add*,sub*,div*} $op"
if ((Name.startswith("fmul") || Name.startswith("fadd") ||
Name.startswith("fsub") || Name.startswith("fdiv")) &&
Operands.size() == 3 &&
static_cast<X86Operand*>(Operands[2])->isReg() &&
static_cast<X86Operand*>(Operands[2])->getReg() == X86::ST0) {
delete Operands[2];
Operands.erase(Operands.begin() + 2);
}
return false;
}
示例15: readRecord
unsigned BitstreamCursor::readRecord(unsigned AbbrevID,
SmallVectorImpl<uint64_t> &Vals,
StringRef *Blob) {
if (AbbrevID == bitc::UNABBREV_RECORD) {
unsigned Code = ReadVBR(6);
unsigned NumElts = ReadVBR(6);
for (unsigned i = 0; i != NumElts; ++i)
Vals.push_back(ReadVBR64(6));
return Code;
}
const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
if (Op.isLiteral()) {
readAbbreviatedLiteral(Op, Vals);
continue;
}
if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
Op.getEncoding() != BitCodeAbbrevOp::Blob) {
readAbbreviatedField(Op, Vals);
continue;
}
if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
// Array case. Read the number of elements as a vbr6.
unsigned NumElts = ReadVBR(6);
// Get the element encoding.
assert(i+2 == e && "array op not second to last?");
const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
// Read all the elements.
for (; NumElts; --NumElts)
readAbbreviatedField(EltEnc, Vals);
continue;
}
assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
// Blob case. Read the number of bytes as a vbr6.
unsigned NumElts = ReadVBR(6);
SkipToFourByteBoundary(); // 32-bit alignment
// Figure out where the end of this blob will be including tail padding.
size_t CurBitPos = GetCurrentBitNo();
size_t NewEnd = CurBitPos+((NumElts+3)&~3)*8;
// If this would read off the end of the bitcode file, just set the
// record to empty and return.
if (!canSkipToPos(NewEnd/8)) {
Vals.append(NumElts, 0);
NextChar = BitStream->getBitcodeBytes().getExtent();
break;
}
// Otherwise, inform the streamer that we need these bytes in memory.
const char *Ptr = (const char*)
BitStream->getBitcodeBytes().getPointer(CurBitPos/8, NumElts);
// If we can return a reference to the data, do so to avoid copying it.
if (Blob) {
*Blob = StringRef(Ptr, NumElts);
} else {
// Otherwise, unpack into Vals with zero extension.
for (; NumElts; --NumElts)
Vals.push_back((unsigned char)*Ptr++);
}
// Skip over tail padding.
JumpToBit(NewEnd);
}
unsigned Code = (unsigned)Vals[0];
Vals.erase(Vals.begin());
return Code;
}