本文整理汇总了C++中SmallVector::append方法的典型用法代码示例。如果您正苦于以下问题:C++ SmallVector::append方法的具体用法?C++ SmallVector::append怎么用?C++ SmallVector::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmallVector
的用法示例。
在下文中一共展示了SmallVector::append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gatherReferencedTypeVars
Constraint *Constraint::createDisjunction(ConstraintSystem &cs,
ArrayRef<Constraint *> constraints,
ConstraintLocator *locator,
RememberChoice_t rememberChoice) {
// Unwrap any disjunctions inside the disjunction constraint; we only allow
// disjunctions at the top level.
SmallVector<TypeVariableType *, 4> typeVars;
bool unwrappedAny = false;
SmallVector<Constraint *, 1> unwrapped;
unsigned index = 0;
for (auto constraint : constraints) {
// Gather type variables from this constraint.
gatherReferencedTypeVars(constraint, typeVars);
// If we have a nested disjunction, unwrap it.
if (constraint->getKind() == ConstraintKind::Disjunction) {
// If we haven't unwrapped anything before, copy all of the constraints
// we skipped.
if (!unwrappedAny) {
unwrapped.append(constraints.begin(), constraints.begin() + index);
unwrappedAny = true;
}
// Add all of the constraints in the disjunction.
unwrapped.append(constraint->getNestedConstraints().begin(),
constraint->getNestedConstraints().end());
} else if (unwrappedAny) {
// Since we unwrapped constraints before, add this constraint.
unwrapped.push_back(constraint);
}
++index;
}
// If we unwrapped anything, our list of constraints is the unwrapped list.
if (unwrappedAny)
constraints = unwrapped;
assert(!constraints.empty() && "Empty disjunction constraint");
// If there is a single constraint, this isn't a disjunction at all.
if (constraints.size() == 1) {
assert(!rememberChoice && "simplified an important disjunction?");
return constraints.front();
}
// Create the disjunction constraint.
uniqueTypeVariables(typeVars);
unsigned size = sizeof(Constraint)
+ typeVars.size() * sizeof(TypeVariableType*);
void *mem = cs.getAllocator().Allocate(size, alignof(Constraint));
auto disjunction = new (mem) Constraint(ConstraintKind::Disjunction,
cs.allocateCopy(constraints), locator, typeVars);
disjunction->RememberChoice = (bool) rememberChoice;
return disjunction;
}
示例2: ParseGotoStmt
Parser::StmtResult Parser::ParseGotoStmt() {
SourceLocation Loc = ConsumeToken();
if(ConsumeIfPresent(tok::l_paren)) {
// computed goto.
SmallVector<Expr*, 4> Targets;
do {
auto E = ParseStatementLabelReference();
if(E.isInvalid()) break;
Targets.append(1, E.get());
} while(ConsumeIfPresent(tok::comma));
ExprResult Operand;
bool ParseOperand = true;
if(!ExpectAndConsume(tok::r_paren)) {
if(!SkipUntil(tok::r_paren)) ParseOperand = false;
}
if(ParseOperand) Operand = ParseExpectedExpression();
return Actions.ActOnComputedGotoStmt(Context, Loc, Targets, Operand, StmtLabel);
}
auto Destination = ParseStatementLabelReference();
if(Destination.isInvalid()) {
if(!IsPresent(tok::identifier)) {
Diag.Report(getExpectedLoc(), diag::err_expected_stmt_label_after)
<< "GO TO";
return StmtError();
}
auto IDInfo = Tok.getIdentifierInfo();
auto IDLoc = ConsumeToken();
auto VD = Actions.ExpectVarRef(IDLoc, IDInfo);
if(!VD) return StmtError();
auto Var = VarExpr::Create(Context, IDLoc, VD);
// Assigned goto
SmallVector<Expr*, 4> AllowedValues;
if(ConsumeIfPresent(tok::l_paren)) {
do {
auto E = ParseStatementLabelReference();
if(E.isInvalid()) {
Diag.Report(getExpectedLoc(), diag::err_expected_stmt_label);
SkipUntilNextStatement();
return Actions.ActOnAssignedGotoStmt(Context, Loc, Var, AllowedValues, StmtLabel);
}
AllowedValues.append(1, E.get());
} while(ConsumeIfPresent(tok::comma));
ExpectAndConsume(tok::r_paren);
}
return Actions.ActOnAssignedGotoStmt(Context, Loc, Var, AllowedValues, StmtLabel);
}
// Uncoditional goto
return Actions.ActOnGotoStmt(Context, Loc, Destination, StmtLabel);
}
示例3: emitCollectionDowncastExpr
/// Emit a collection downcast expression.
///
/// \param conditional Whether to emit a conditional downcast; if
/// false, this will emit a forced downcast.
static RValue emitCollectionDowncastExpr(SILGenFunction &SGF,
ManagedValue source,
Type sourceType,
SILLocation loc,
Type destType,
SGFContext C,
bool conditional) {
// Compute substitutions for the intrinsic call.
auto fromCollection = cast<BoundGenericStructType>(
sourceType->getCanonicalType());
auto toCollection = cast<BoundGenericStructType>(
destType->getCanonicalType());
// Get the intrinsic function.
auto &ctx = SGF.getASTContext();
FuncDecl *fn = nullptr;
if (fromCollection->getDecl() == ctx.getArrayDecl()) {
fn = conditional ? SGF.SGM.getArrayConditionalCast(loc)
: SGF.SGM.getArrayForceCast(loc);
} else if (fromCollection->getDecl() == ctx.getDictionaryDecl()) {
fn = (conditional
? SGF.SGM.getDictionaryDownCastConditional(loc)
: SGF.SGM.getDictionaryDownCast(loc));
} else if (fromCollection->getDecl() == ctx.getSetDecl()) {
fn = (conditional
? SGF.SGM.getSetDownCastConditional(loc)
: SGF.SGM.getSetDownCast(loc));
} else {
llvm_unreachable("unsupported collection upcast kind");
}
// This will have been diagnosed by the accessors above.
if (!fn) return SGF.emitUndefRValue(loc, destType);
auto fnGenericParams = fn->getGenericSignature()->getGenericParams();
auto fromSubsts = fromCollection->gatherAllSubstitutions(
SGF.SGM.SwiftModule, nullptr);
auto toSubsts = toCollection->gatherAllSubstitutions(
SGF.SGM.SwiftModule, nullptr);
assert(fnGenericParams.size() == fromSubsts.size() + toSubsts.size() &&
"wrong number of generic collection parameters");
(void) fnGenericParams;
// Form type parameter substitutions.
SmallVector<Substitution, 4> subs;
subs.append(fromSubsts.begin(), fromSubsts.end());
subs.append(toSubsts.begin(), toSubsts.end());
return SGF.emitApplyOfLibraryIntrinsic(loc, fn, subs, {source}, C);
}
示例4: performSingleCommand
int Compilation::performSingleCommand(const Job *Cmd) {
assert(Cmd->getInputs().empty() &&
"This can only be used to run a single command with no inputs");
switch (Cmd->getCondition()) {
case Job::Condition::CheckDependencies:
return 0;
case Job::Condition::RunWithoutCascading:
case Job::Condition::Always:
case Job::Condition::NewlyAdded:
break;
}
if (!writeFilelistIfNecessary(Cmd, Diags))
return 1;
if (Level == OutputLevel::Verbose)
Cmd->printCommandLine(llvm::errs());
SmallVector<const char *, 128> Argv;
Argv.push_back(Cmd->getExecutable());
Argv.append(Cmd->getArguments().begin(), Cmd->getArguments().end());
Argv.push_back(0);
const char *ExecPath = Cmd->getExecutable();
const char **argv = Argv.data();
for (auto &envPair : Cmd->getExtraEnvironment())
setenv(envPair.first, envPair.second, /*replacing=*/true);
return ExecuteInPlace(ExecPath, argv);
}
示例5: while
void
CodeGenModule::EmitCXXGlobalInitFunc() {
while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
CXXGlobalInits.pop_back();
if (CXXGlobalInits.empty() && PrioritizedCXXGlobalInits.empty())
return;
llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
// Create our global initialization function.
llvm::Function *Fn =
CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__I_a");
if (!PrioritizedCXXGlobalInits.empty()) {
SmallVector<llvm::Constant*, 8> LocalCXXGlobalInits;
llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
PrioritizedCXXGlobalInits.end());
for (unsigned i = 0; i < PrioritizedCXXGlobalInits.size(); i++) {
llvm::Function *Fn = PrioritizedCXXGlobalInits[i].second;
LocalCXXGlobalInits.push_back(Fn);
}
LocalCXXGlobalInits.append(CXXGlobalInits.begin(), CXXGlobalInits.end());
CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
&LocalCXXGlobalInits[0],
LocalCXXGlobalInits.size());
}
else
CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
&CXXGlobalInits[0],
CXXGlobalInits.size());
AddGlobalCtor(Fn);
CXXGlobalInits.clear();
PrioritizedCXXGlobalInits.clear();
}
示例6: S
/// Parse a free-standing where clause attached to a declaration, adding it to
/// a generic parameter list that may (or may not) already exist.
ParserStatus Parser::
parseFreestandingGenericWhereClause(GenericParamList *&genericParams,
WhereClauseKind kind) {
assert(Tok.is(tok::kw_where) && "Shouldn't call this without a where");
// Push the generic arguments back into a local scope so that references will
// find them.
Scope S(this, ScopeKind::Generics);
if (genericParams)
for (auto pd : genericParams->getParams())
addToScope(pd);
SmallVector<RequirementRepr, 4> Requirements;
if (genericParams)
Requirements.append(genericParams->getRequirements().begin(),
genericParams->getRequirements().end());
SourceLoc WhereLoc;
bool FirstTypeInComplete;
auto result = parseGenericWhereClause(WhereLoc, Requirements,
FirstTypeInComplete);
if (result.shouldStopParsing() || Requirements.empty())
return result;
if (!genericParams)
diagnose(WhereLoc, diag::where_without_generic_params, unsigned(kind));
else
genericParams = GenericParamList::create(Context,
genericParams->getLAngleLoc(),
genericParams->getParams(),
WhereLoc, Requirements,
genericParams->getRAngleLoc());
return ParserStatus();
}
示例7: getSignature
Function *WebAssemblyLowerEmscriptenEHSjLj::getInvokeWrapper(CallOrInvoke *CI) {
Module *M = CI->getModule();
SmallVector<Type *, 16> ArgTys;
Value *Callee = CI->getCalledValue();
FunctionType *CalleeFTy;
if (auto *F = dyn_cast<Function>(Callee))
CalleeFTy = F->getFunctionType();
else {
auto *CalleeTy = cast<PointerType>(Callee->getType())->getElementType();
CalleeFTy = dyn_cast<FunctionType>(CalleeTy);
}
std::string Sig = getSignature(CalleeFTy);
if (InvokeWrappers.find(Sig) != InvokeWrappers.end())
return InvokeWrappers[Sig];
// Put the pointer to the callee as first argument
ArgTys.push_back(PointerType::getUnqual(CalleeFTy));
// Add argument types
ArgTys.append(CalleeFTy->param_begin(), CalleeFTy->param_end());
FunctionType *FTy = FunctionType::get(CalleeFTy->getReturnType(), ArgTys,
CalleeFTy->isVarArg());
Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage,
InvokePrefix + Sig, M);
InvokeWrappers[Sig] = F;
return F;
}
示例8: assert
Value *llvm::concatenateVectors(IRBuilder<> &Builder, ArrayRef<Value *> Vecs) {
unsigned NumVecs = Vecs.size();
assert(NumVecs > 1 && "Should be at least two vectors");
SmallVector<Value *, 8> ResList;
ResList.append(Vecs.begin(), Vecs.end());
do {
SmallVector<Value *, 8> TmpList;
for (unsigned i = 0; i < NumVecs - 1; i += 2) {
Value *V0 = ResList[i], *V1 = ResList[i + 1];
assert((V0->getType() == V1->getType() || i == NumVecs - 2) &&
"Only the last vector may have a different type");
TmpList.push_back(concatenateTwoVectors(Builder, V0, V1));
}
// Push the last vector if the total number of vectors is odd.
if (NumVecs % 2 != 0)
TmpList.push_back(ResList[NumVecs - 1]);
ResList = TmpList;
NumVecs = ResList.size();
} while (NumVecs > 1);
return ResList[0];
}
示例9: append
DIExpression *DIExpression::appendToStack(const DIExpression *Expr,
ArrayRef<uint64_t> Ops) {
assert(Expr && !Ops.empty() && "Can't append ops to this expression");
assert(none_of(Ops,
[](uint64_t Op) {
return Op == dwarf::DW_OP_stack_value ||
Op == dwarf::DW_OP_LLVM_fragment;
}) &&
"Can't append this op");
// Append a DW_OP_deref after Expr's current op list if it's non-empty and
// has no DW_OP_stack_value.
//
// Match .* DW_OP_stack_value (DW_OP_LLVM_fragment A B)?.
Optional<FragmentInfo> FI = Expr->getFragmentInfo();
unsigned DropUntilStackValue = FI.hasValue() ? 3 : 0;
ArrayRef<uint64_t> ExprOpsBeforeFragment =
Expr->getElements().drop_back(DropUntilStackValue);
bool NeedsDeref = (Expr->getNumElements() > DropUntilStackValue) &&
(ExprOpsBeforeFragment.back() != dwarf::DW_OP_stack_value);
bool NeedsStackValue = NeedsDeref || ExprOpsBeforeFragment.empty();
// Append a DW_OP_deref after Expr's current op list if needed, then append
// the new ops, and finally ensure that a single DW_OP_stack_value is present.
SmallVector<uint64_t, 16> NewOps;
if (NeedsDeref)
NewOps.push_back(dwarf::DW_OP_deref);
NewOps.append(Ops.begin(), Ops.end());
if (NeedsStackValue)
NewOps.push_back(dwarf::DW_OP_stack_value);
return DIExpression::append(Expr, NewOps);
}
示例10: DiagnosticsEngine
static IntrusiveRefCntPtr<DiagnosticsEngine>
createDiagnostics(unsigned int argc, char **argv) {
IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(new DiagnosticIDs());
// Buffer diagnostics from argument parsing so that we can output them using a
// well formed diagnostic object.
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
IntrusiveRefCntPtr<DiagnosticsEngine> InterimDiags(
new DiagnosticsEngine(DiagIDs, new DiagnosticOptions(), DiagsBuffer));
// Try to build a CompilerInvocation.
SmallVector<const char *, 4> Args;
Args.push_back("diagtool");
Args.append(argv, argv + argc);
std::unique_ptr<CompilerInvocation> Invocation(
createInvocationFromCommandLine(Args, InterimDiags));
if (!Invocation)
return nullptr;
// Build the diagnostics parser
IntrusiveRefCntPtr<DiagnosticsEngine> FinalDiags =
CompilerInstance::createDiagnostics(&Invocation->getDiagnosticOpts());
if (!FinalDiags)
return nullptr;
// Flush any errors created when initializing everything. This could happen
// for invalid command lines, which will probably give non-sensical results.
DiagsBuffer->FlushDiagnostics(*FinalDiags);
return FinalDiags;
}
示例11: escapeRegNode
/// Escape RegNode so that we can access it from child handlers. Find the call
/// to frameescape, if any, in the entry block and append RegNode to the list
/// of arguments.
int WinEHStatePass::escapeRegNode(Function &F) {
// Find the call to frameescape and extract its arguments.
IntrinsicInst *EscapeCall = nullptr;
for (Instruction &I : F.getEntryBlock()) {
IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I);
if (II && II->getIntrinsicID() == Intrinsic::frameescape) {
EscapeCall = II;
break;
}
}
SmallVector<Value *, 8> Args;
if (EscapeCall) {
auto Ops = EscapeCall->arg_operands();
Args.append(Ops.begin(), Ops.end());
}
Args.push_back(RegNode);
// Replace the call (if it exists) with new one. Otherwise, insert at the end
// of the entry block.
IRBuilder<> Builder(&F.getEntryBlock(),
EscapeCall ? EscapeCall : F.getEntryBlock().end());
Builder.CreateCall(FrameEscape, Args);
if (EscapeCall)
EscapeCall->eraseFromParent();
return Args.size() - 1;
}
示例12: Modules
LLVMContextImpl::~LLVMContextImpl() {
// NOTE: We need to delete the contents of OwnedModules, but we have to
// duplicate it into a temporary vector, because the destructor of Module
// will try to remove itself from OwnedModules set. This would cause
// iterator invalidation if we iterated on the set directly.
std::vector<Module*> Modules(OwnedModules.begin(), OwnedModules.end());
DeleteContainerPointers(Modules);
// Free the constants. This is important to do here to ensure that they are
// freed before the LeakDetector is torn down.
std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
DropReferences());
std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
DropFirst());
std::for_each(StructConstants.map_begin(), StructConstants.map_end(),
DropFirst());
std::for_each(VectorConstants.map_begin(), VectorConstants.map_end(),
DropFirst());
ExprConstants.freeConstants();
ArrayConstants.freeConstants();
StructConstants.freeConstants();
VectorConstants.freeConstants();
DeleteContainerSeconds(CAZConstants);
DeleteContainerSeconds(CPNConstants);
DeleteContainerSeconds(UVConstants);
InlineAsms.freeConstants();
DeleteContainerSeconds(IntConstants);
DeleteContainerSeconds(FPConstants);
for (StringMap<ConstantDataSequential*>::iterator I = CDSConstants.begin(),
E = CDSConstants.end(); I != E; ++I)
delete I->second;
CDSConstants.clear();
// Destroy attributes.
for (FoldingSetIterator<AttributesImpl> I = AttrsSet.begin(),
E = AttrsSet.end(); I != E;) {
FoldingSetIterator<AttributesImpl> Elem = I++;
delete &*Elem;
}
// Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet
// and the NonUniquedMDNodes sets, so copy the values out first.
SmallVector<MDNode*, 8> MDNodes;
MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size());
for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
I != E; ++I)
MDNodes.push_back(&*I);
MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end());
for (SmallVectorImpl<MDNode *>::iterator I = MDNodes.begin(),
E = MDNodes.end(); I != E; ++I)
(*I)->destroy();
assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() &&
"Destroying all MDNodes didn't empty the Context's sets.");
// Destroy MDStrings.
DeleteContainerSeconds(MDStringCache);
}
示例13: IRB
Value *WebAssemblyLowerEmscriptenEHSjLj::wrapInvoke(CallOrInvoke *CI) {
LLVMContext &C = CI->getModule()->getContext();
// If we are calling a function that is noreturn, we must remove that
// attribute. The code we insert here does expect it to return, after we
// catch the exception.
if (CI->doesNotReturn()) {
if (auto *F = dyn_cast<Function>(CI->getCalledValue()))
F->removeFnAttr(Attribute::NoReturn);
CI->removeAttribute(AttributeList::FunctionIndex, Attribute::NoReturn);
}
IRBuilder<> IRB(C);
IRB.SetInsertPoint(CI);
// Pre-invoke
// __THREW__ = 0;
IRB.CreateStore(IRB.getInt32(0), ThrewGV);
// Invoke function wrapper in JavaScript
SmallVector<Value *, 16> Args;
// Put the pointer to the callee as first argument, so it can be called
// within the invoke wrapper later
Args.push_back(CI->getCalledValue());
Args.append(CI->arg_begin(), CI->arg_end());
CallInst *NewCall = IRB.CreateCall(getInvokeWrapper(CI), Args);
NewCall->takeName(CI);
NewCall->setCallingConv(CI->getCallingConv());
NewCall->setDebugLoc(CI->getDebugLoc());
// Because we added the pointer to the callee as first argument, all
// argument attribute indices have to be incremented by one.
SmallVector<AttributeSet, 8> ArgAttributes;
const AttributeList &InvokeAL = CI->getAttributes();
// No attributes for the callee pointer.
ArgAttributes.push_back(AttributeSet());
// Copy the argument attributes from the original
for (unsigned i = 0, e = CI->getNumArgOperands(); i < e; ++i)
ArgAttributes.push_back(InvokeAL.getParamAttributes(i));
// Reconstruct the AttributesList based on the vector we constructed.
AttributeList NewCallAL =
AttributeList::get(C, InvokeAL.getFnAttributes(),
InvokeAL.getRetAttributes(), ArgAttributes);
NewCall->setAttributes(NewCallAL);
CI->replaceAllUsesWith(NewCall);
// Post-invoke
// %__THREW__.val = __THREW__; __THREW__ = 0;
Value *Threw = IRB.CreateLoad(ThrewGV, ThrewGV->getName() + ".val");
IRB.CreateStore(IRB.getInt32(0), ThrewGV);
return Threw;
}
示例14: get
DIExpression *DIExpression::append(const DIExpression *Expr,
ArrayRef<uint64_t> Ops) {
assert(Expr && !Ops.empty() && "Can't append ops to this expression");
// Copy Expr's current op list.
SmallVector<uint64_t, 16> NewOps;
for (auto Op : Expr->expr_ops()) {
// Append new opcodes before DW_OP_{stack_value, LLVM_fragment}.
if (Op.getOp() == dwarf::DW_OP_stack_value ||
Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
NewOps.append(Ops.begin(), Ops.end());
// Ensure that the new opcodes are only appended once.
Ops = None;
}
Op.appendToVector(NewOps);
}
NewOps.append(Ops.begin(), Ops.end());
return DIExpression::get(Expr->getContext(), NewOps);
}
示例15: canUseASTWithSnapshots
bool canUseASTWithSnapshots(
ArrayRef<ImmutableTextSnapshotRef> Snapshots) override {
if (!TryExistingAST) {
LOG_INFO_FUNC(High, "will resolve using up-to-date AST");
return false;
}
// If there is an existing AST and the offset can be mapped back to the
// document snapshot that was used to create it, then use that AST.
// The downside is that we may return stale information, but we get the
// benefit of increased responsiveness, since the request will not be
// blocked waiting on the AST to be fully typechecked.
ImmutableTextSnapshotRef InputSnap;
if (auto EditorDoc = Lang.getEditorDocuments().findByPath(InputFile))
InputSnap = EditorDoc->getLatestSnapshot();
if (!InputSnap)
return false;
auto mappedBackOffset = [&]()->llvm::Optional<unsigned> {
for (auto &Snap : Snapshots) {
if (Snap->isFromSameBuffer(InputSnap)) {
if (Snap->getStamp() == InputSnap->getStamp())
return Offset;
auto OptOffset = mapOffsetToOlderSnapshot(Offset, InputSnap, Snap);
if (!OptOffset.hasValue())
return None;
// Check that the new and old offset still point to the same token.
StringRef NewTok = getSourceToken(Offset, InputSnap);
if (NewTok.empty())
return None;
if (NewTok == getSourceToken(OptOffset.getValue(), Snap))
return OptOffset;
return None;
}
}
return None;
};
auto OldOffsetOpt = mappedBackOffset();
if (OldOffsetOpt.hasValue()) {
Offset = *OldOffsetOpt;
PreviousASTSnaps.append(Snapshots.begin(), Snapshots.end());
LOG_INFO_FUNC(High, "will try existing AST");
return true;
}
LOG_INFO_FUNC(High, "will resolve using up-to-date AST");
return false;
}