本文整理汇总了C++中SmallVector::emplace_back方法的典型用法代码示例。如果您正苦于以下问题:C++ SmallVector::emplace_back方法的具体用法?C++ SmallVector::emplace_back怎么用?C++ SmallVector::emplace_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmallVector
的用法示例。
在下文中一共展示了SmallVector::emplace_back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: new
/// Returns a generated guard statement that checks whether the given lhs and
/// rhs expressions are equal. If not equal, the else block for the guard
/// returns false.
/// \p C The AST context.
/// \p lhsExpr The first expression to compare for equality.
/// \p rhsExpr The second expression to compare for equality.
static GuardStmt *returnIfNotEqualGuard(ASTContext &C,
Expr *lhsExpr,
Expr *rhsExpr) {
SmallVector<StmtConditionElement, 1> conditions;
SmallVector<ASTNode, 1> statements;
// First, generate the statement for the body of the guard.
// return false
auto falseExpr = new (C) BooleanLiteralExpr(false, SourceLoc(),
/*Implicit*/true);
auto returnStmt = new (C) ReturnStmt(SourceLoc(), falseExpr);
statements.emplace_back(ASTNode(returnStmt));
// Next, generate the condition being checked.
// lhs == rhs
auto cmpFuncExpr = new (C) UnresolvedDeclRefExpr(
DeclName(C.getIdentifier("==")), DeclRefKind::BinaryOperator,
DeclNameLoc());
auto cmpArgsTuple = TupleExpr::create(C, SourceLoc(),
{ lhsExpr, rhsExpr },
{ }, { }, SourceLoc(),
/*HasTrailingClosure*/false,
/*Implicit*/true);
auto cmpExpr = new (C) BinaryExpr(cmpFuncExpr, cmpArgsTuple,
/*Implicit*/true);
conditions.emplace_back(cmpExpr);
// Build and return the complete guard statement.
// guard lhs == rhs else { return false }
auto body = BraceStmt::create(C, SourceLoc(), statements, SourceLoc());
return new (C) GuardStmt(SourceLoc(), C.AllocateCopy(conditions), body);
}
示例2: translateCall
bool IRTranslator::translateCall(const CallInst &CI) {
auto TII = MIRBuilder.getMF().getTarget().getIntrinsicInfo();
const Function &F = *CI.getCalledFunction();
Intrinsic::ID ID = F.getIntrinsicID();
if (TII && ID == Intrinsic::not_intrinsic)
ID = static_cast<Intrinsic::ID>(TII->getIntrinsicID(&F));
assert(ID != Intrinsic::not_intrinsic && "FIXME: support real calls");
// Need types (starting with return) & args.
SmallVector<LLT, 4> Tys;
Tys.emplace_back(*CI.getType());
for (auto &Arg : CI.arg_operands())
Tys.emplace_back(*Arg->getType());
unsigned Res = CI.getType()->isVoidTy() ? 0 : getOrCreateVReg(CI);
MachineInstrBuilder MIB =
MIRBuilder.buildIntrinsic(Tys, ID, Res, !CI.doesNotAccessMemory());
for (auto &Arg : CI.arg_operands()) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Arg))
MIB.addImm(CI->getSExtValue());
else
MIB.addUse(getOrCreateVReg(*Arg));
}
return true;
}
示例3: emitColumnLabelsForIndex
/// Emit column labels for the table in the index.
static void emitColumnLabelsForIndex(raw_ostream &OS) {
SmallVector<std::string, 4> Columns;
Columns.emplace_back(tag("td", "Filename", "column-entry-left"));
for (const char *Label : {"Function Coverage", "Instantiation Coverage",
"Line Coverage", "Region Coverage"})
Columns.emplace_back(tag("td", Label, "column-entry"));
OS << tag("tr", join(Columns.begin(), Columns.end(), ""));
}
示例4: emitFileSummary
/// Render a file coverage summary (\p FCS) in a table row. If \p IsTotals is
/// false, link the summary to \p SF.
void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF,
const FileCoverageSummary &FCS,
bool IsTotals) const {
SmallVector<std::string, 8> Columns;
// Format a coverage triple and add the result to the list of columns.
auto AddCoverageTripleToColumn = [&Columns](unsigned Hit, unsigned Total,
float Pctg) {
std::string S;
{
raw_string_ostream RSO{S};
if (Total)
RSO << format("%*.2f", 7, Pctg) << "% ";
else
RSO << "- ";
RSO << '(' << Hit << '/' << Total << ')';
}
const char *CellClass = "column-entry-yellow";
if (Hit == Total)
CellClass = "column-entry-green";
else if (Pctg < 80.0)
CellClass = "column-entry-red";
Columns.emplace_back(tag("td", tag("pre", S), CellClass));
};
// Simplify the display file path, and wrap it in a link if requested.
std::string Filename;
if (IsTotals) {
Filename = SF;
} else {
Filename = buildLinkToFile(SF, FCS);
}
Columns.emplace_back(tag("td", tag("pre", Filename)));
AddCoverageTripleToColumn(FCS.FunctionCoverage.getExecuted(),
FCS.FunctionCoverage.getNumFunctions(),
FCS.FunctionCoverage.getPercentCovered());
if (Opts.ShowInstantiationSummary)
AddCoverageTripleToColumn(FCS.InstantiationCoverage.getExecuted(),
FCS.InstantiationCoverage.getNumFunctions(),
FCS.InstantiationCoverage.getPercentCovered());
AddCoverageTripleToColumn(FCS.LineCoverage.getCovered(),
FCS.LineCoverage.getNumLines(),
FCS.LineCoverage.getPercentCovered());
if (Opts.ShowRegionSummary)
AddCoverageTripleToColumn(FCS.RegionCoverage.getCovered(),
FCS.RegionCoverage.getNumRegions(),
FCS.RegionCoverage.getPercentCovered());
if (IsTotals)
OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row-bold");
else
OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row");
}
示例5: run
void InstructionTables::run() {
ArrayRef<uint64_t> Masks = IB.getProcResourceMasks();
SmallVector<std::pair<ResourceRef, double>, 4> UsedResources;
// Create an instruction descriptor for every instruction in the sequence.
while (S.hasNext()) {
UsedResources.clear();
SourceRef SR = S.peekNext();
std::unique_ptr<Instruction> Inst = IB.createInstruction(*SR.second);
const InstrDesc &Desc = Inst->getDesc();
// Now identify the resources consumed by this instruction.
for (const std::pair<uint64_t, ResourceUsage> Resource : Desc.Resources) {
// Skip zero-cycle resources (i.e. unused resources).
if (!Resource.second.size())
continue;
double Cycles = static_cast<double>(Resource.second.size());
unsigned Index =
std::distance(Masks.begin(), std::find(Masks.begin(), Masks.end(),
Resource.first));
const MCProcResourceDesc &ProcResource = *SM.getProcResource(Index);
unsigned NumUnits = ProcResource.NumUnits;
if (!ProcResource.SubUnitsIdxBegin) {
// The number of cycles consumed by each unit.
Cycles /= NumUnits;
for (unsigned I = 0, E = NumUnits; I < E; ++I) {
ResourceRef ResourceUnit = std::make_pair(Index, 1U << I);
UsedResources.emplace_back(std::make_pair(ResourceUnit, Cycles));
}
continue;
}
// This is a group. Obtain the set of resources contained in this
// group. Some of these resources may implement multiple units.
// Uniformly distribute Cycles across all of the units.
for (unsigned I1 = 0; I1 < NumUnits; ++I1) {
unsigned SubUnitIdx = ProcResource.SubUnitsIdxBegin[I1];
const MCProcResourceDesc &SubUnit = *SM.getProcResource(SubUnitIdx);
// Compute the number of cycles consumed by each resource unit.
double RUCycles = Cycles / (NumUnits * SubUnit.NumUnits);
for (unsigned I2 = 0, E2 = SubUnit.NumUnits; I2 < E2; ++I2) {
ResourceRef ResourceUnit = std::make_pair(SubUnitIdx, 1U << I2);
UsedResources.emplace_back(std::make_pair(ResourceUnit, RUCycles));
}
}
}
// Now send a fake instruction issued event to all the views.
InstRef IR(SR.first, Inst.get());
HWInstructionIssuedEvent Event(IR, UsedResources);
for (std::unique_ptr<View> &Listener : Views)
Listener->onInstructionEvent(Event);
S.updateNext();
}
}
示例6: emitFileSummary
/// Render a file coverage summary (\p FCS) in a table row. If \p IsTotals is
/// false, link the summary to \p SF.
void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF,
const FileCoverageSummary &FCS,
bool IsTotals) const {
SmallVector<std::string, 8> Columns;
// Format a coverage triple and add the result to the list of columns.
auto AddCoverageTripleToColumn = [&Columns](unsigned Hit, unsigned Total,
float Pctg) {
std::string S;
{
raw_string_ostream RSO{S};
if (Total)
RSO << format("%*.2f", 7, Pctg) << "% ";
else
RSO << "- ";
RSO << '(' << Hit << '/' << Total << ')';
}
const char *CellClass = "column-entry-yellow";
if (Hit == Total)
CellClass = "column-entry-green";
else if (Pctg < 80.0)
CellClass = "column-entry-red";
Columns.emplace_back(tag("td", tag("pre", S), CellClass));
};
// Simplify the display file path, and wrap it in a link if requested.
std::string Filename;
if (IsTotals) {
Filename = "TOTALS";
} else {
SmallString<128> LinkTextStr(sys::path::relative_path(FCS.Name));
sys::path::remove_dots(LinkTextStr, /*remove_dot_dots=*/true);
sys::path::native(LinkTextStr);
std::string LinkText = escape(LinkTextStr, Opts);
std::string LinkTarget =
escape(getOutputPath(SF, "html", /*InToplevel=*/false), Opts);
Filename = a(LinkTarget, LinkText);
}
Columns.emplace_back(tag("td", tag("pre", Filename)));
AddCoverageTripleToColumn(FCS.FunctionCoverage.Executed,
FCS.FunctionCoverage.NumFunctions,
FCS.FunctionCoverage.getPercentCovered());
AddCoverageTripleToColumn(FCS.InstantiationCoverage.Executed,
FCS.InstantiationCoverage.NumFunctions,
FCS.InstantiationCoverage.getPercentCovered());
AddCoverageTripleToColumn(FCS.LineCoverage.Covered, FCS.LineCoverage.NumLines,
FCS.LineCoverage.getPercentCovered());
AddCoverageTripleToColumn(FCS.RegionCoverage.Covered,
FCS.RegionCoverage.NumRegions,
FCS.RegionCoverage.getPercentCovered());
OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row");
}
示例7: DiagnosticInfo
TEST(FileSpecificDiagnosticConsumer,
ErrorsInUnaffiliatedFilesGoToEveryConsumer) {
SourceManager sourceMgr;
// 01234
unsigned bufferA = sourceMgr.addMemBufferCopy("abcde", "A");
unsigned bufferB = sourceMgr.addMemBufferCopy("vwxyz", "B");
SourceLoc frontOfA = sourceMgr.getLocForOffset(bufferA, 0);
SourceLoc middleOfA = sourceMgr.getLocForOffset(bufferA, 2);
SourceLoc backOfA = sourceMgr.getLocForOffset(bufferA, 4);
SourceLoc frontOfB = sourceMgr.getLocForOffset(bufferB, 0);
SourceLoc middleOfB = sourceMgr.getLocForOffset(bufferB, 2);
SourceLoc backOfB = sourceMgr.getLocForOffset(bufferB, 4);
ExpectedDiagnostic expectedA[] = {
{frontOfA, "front"},
{frontOfB, "front"},
{middleOfA, "middle"},
{middleOfB, "middle"},
{backOfA, "back"},
{backOfB, "back"}
};
ExpectedDiagnostic expectedUnaffiliated[] = {
{frontOfB, "front"},
{middleOfB, "middle"},
{backOfB, "back"}
};
auto consumerA = llvm::make_unique<ExpectationDiagnosticConsumer>(
nullptr, expectedA);
auto consumerUnaffiliated = llvm::make_unique<ExpectationDiagnosticConsumer>(
consumerA.get(), expectedUnaffiliated);
SmallVector<FileSpecificDiagnosticConsumer::Subconsumer, 2> consumers;
consumers.emplace_back("A", std::move(consumerA));
consumers.emplace_back("", std::move(consumerUnaffiliated));
auto topConsumer =
FileSpecificDiagnosticConsumer::consolidateSubconsumers(consumers);
topConsumer->handleDiagnostic(sourceMgr, frontOfA, DiagnosticKind::Error,
"front", {}, DiagnosticInfo(), SourceLoc());
topConsumer->handleDiagnostic(sourceMgr, frontOfB, DiagnosticKind::Error,
"front", {}, DiagnosticInfo(), SourceLoc());
topConsumer->handleDiagnostic(sourceMgr, middleOfA, DiagnosticKind::Error,
"middle", {}, DiagnosticInfo(), SourceLoc());
topConsumer->handleDiagnostic(sourceMgr, middleOfB, DiagnosticKind::Error,
"middle", {}, DiagnosticInfo(), SourceLoc());
topConsumer->handleDiagnostic(sourceMgr, backOfA, DiagnosticKind::Error,
"back", {}, DiagnosticInfo(), SourceLoc());
topConsumer->handleDiagnostic(sourceMgr, backOfB, DiagnosticKind::Error,
"back", {}, DiagnosticInfo(), SourceLoc());
topConsumer->finishProcessing();
}
示例8: emitColumnLabelsForIndex
/// Emit column labels for the table in the index.
static void emitColumnLabelsForIndex(raw_ostream &OS,
const CoverageViewOptions &Opts) {
SmallVector<std::string, 4> Columns;
Columns.emplace_back(tag("td", "Filename", "column-entry-left"));
Columns.emplace_back(tag("td", "Function Coverage", "column-entry"));
if (Opts.ShowInstantiationSummary)
Columns.emplace_back(tag("td", "Instantiation Coverage", "column-entry"));
Columns.emplace_back(tag("td", "Line Coverage", "column-entry"));
if (Opts.ShowRegionSummary)
Columns.emplace_back(tag("td", "Region Coverage", "column-entry"));
OS << tag("tr", join(Columns.begin(), Columns.end(), ""));
}
示例9: getInterfaceType
/// Hack to deal with the fact that Sema/CodeSynthesis.cpp creates ParamDecls
/// containing contextual types.
Type ParameterList::getInterfaceType(DeclContext *DC) const {
auto &C = DC->getASTContext();
if (size() == 0)
return TupleType::getEmpty(C);
SmallVector<TupleTypeElt, 8> argumentInfo;
for (auto P : *this) {
assert(P->hasType());
Type type;
if (P->hasInterfaceType())
type = P->getInterfaceType();
else if (!P->getTypeLoc().hasLocation())
type = ArchetypeBuilder::mapTypeOutOfContext(DC, P->getType());
else
type = P->getType();
assert(!type->hasArchetype());
argumentInfo.emplace_back(
type, P->getArgumentName(),
ParameterTypeFlags::fromParameterType(type, P->isVariadic()));
}
return TupleType::get(argumentInfo, C);
}
示例10: topConsumer
TEST(FileSpecificDiagnosticConsumer, SubConsumersFinishInOrder) {
SourceManager sourceMgr;
(void)sourceMgr.addMemBufferCopy("abcde", "A");
(void)sourceMgr.addMemBufferCopy("vwxyz", "B");
auto consumerA = llvm::make_unique<ExpectationDiagnosticConsumer>(
nullptr, None);
auto consumerUnaffiliated = llvm::make_unique<ExpectationDiagnosticConsumer>(
consumerA.get(), None);
SmallVector<FileSpecificDiagnosticConsumer::ConsumerPair, 2> consumers;
consumers.emplace_back("A", std::move(consumerA));
consumers.emplace_back("", std::move(consumerUnaffiliated));
FileSpecificDiagnosticConsumer topConsumer(consumers);
topConsumer.finishProcessing();
}
示例11: if
static SmallVector<StringRef, 2> getNames(const DWARFDie &DIE,
bool IncludeLinkageName = true) {
SmallVector<StringRef, 2> Result;
if (const char *Str = DIE.getName(DINameKind::ShortName))
Result.emplace_back(Str);
else if (DIE.getTag() == dwarf::DW_TAG_namespace)
Result.emplace_back("(anonymous namespace)");
if (IncludeLinkageName) {
if (const char *Str = DIE.getName(DINameKind::LinkageName)) {
if (Result.empty() || Result[0] != Str)
Result.emplace_back(Str);
}
}
return Result;
}
示例12:
// For WinEH exception representation backend need to know what funclet coro.end
// belongs to. That information is passed in a funclet bundle.
static SmallVector<llvm::OperandBundleDef, 1>
getBundlesForCoroEnd(CodeGenFunction &CGF) {
SmallVector<llvm::OperandBundleDef, 1> BundleList;
if (llvm::Instruction *EHPad = CGF.CurrentFuncletPad)
BundleList.emplace_back("funclet", EHPad);
return BundleList;
}
示例13: HandleBinding
bool HandleBinding(StoreManager &SMgr, Store S, const MemRegion *Region,
SVal Val) override {
if (!isa<GlobalsSpaceRegion>(Region->getMemorySpace()))
return true;
const MemRegion *VR = Val.getAsRegion();
if (VR && isa<StackSpaceRegion>(VR->getMemorySpace()) &&
!isArcManagedBlock(VR, Ctx) && !isNotInCurrentFrame(VR, Ctx))
V.emplace_back(Region, VR);
return true;
}
示例14: translateInvoke
bool IRTranslator::translateInvoke(const User &U) {
const InvokeInst &I = cast<InvokeInst>(U);
MachineFunction &MF = MIRBuilder.getMF();
MachineModuleInfo &MMI = MF.getMMI();
const BasicBlock *ReturnBB = I.getSuccessor(0);
const BasicBlock *EHPadBB = I.getSuccessor(1);
const Value *Callee(I.getCalledValue());
const Function *Fn = dyn_cast<Function>(Callee);
if (isa<InlineAsm>(Callee))
return false;
// FIXME: support invoking patchpoint and statepoint intrinsics.
if (Fn && Fn->isIntrinsic())
return false;
// FIXME: support whatever these are.
if (I.countOperandBundlesOfType(LLVMContext::OB_deopt))
return false;
// FIXME: support Windows exception handling.
if (!isa<LandingPadInst>(EHPadBB->front()))
return false;
// Emit the actual call, bracketed by EH_LABELs so that the MMI knows about
// the region covered by the try.
MCSymbol *BeginSymbol = MMI.getContext().createTempSymbol();
MIRBuilder.buildInstr(TargetOpcode::EH_LABEL).addSym(BeginSymbol);
unsigned Res = I.getType()->isVoidTy() ? 0 : getOrCreateVReg(I);
SmallVector<CallLowering::ArgInfo, 8> Args;
for (auto &Arg: I.arg_operands())
Args.emplace_back(getOrCreateVReg(*Arg), Arg->getType());
if (!CLI->lowerCall(MIRBuilder, MachineOperand::CreateGA(Fn, 0),
CallLowering::ArgInfo(Res, I.getType()), Args))
return false;
MCSymbol *EndSymbol = MMI.getContext().createTempSymbol();
MIRBuilder.buildInstr(TargetOpcode::EH_LABEL).addSym(EndSymbol);
// FIXME: track probabilities.
MachineBasicBlock &EHPadMBB = getOrCreateBB(*EHPadBB),
&ReturnMBB = getOrCreateBB(*ReturnBB);
MMI.addInvoke(&EHPadMBB, BeginSymbol, EndSymbol);
MIRBuilder.getMBB().addSuccessor(&ReturnMBB);
MIRBuilder.getMBB().addSuccessor(&EHPadMBB);
return true;
}
示例15: Create
/// Create a call instruction with the correct funclet token. Should be used
/// instead of calling CallInst::Create directly.
static CallInst *
createCallInst(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
const Twine &NameStr, Instruction *InsertBefore,
const DenseMap<BasicBlock *, ColorVector> &BlockColors) {
SmallVector<OperandBundleDef, 1> OpBundles;
if (!BlockColors.empty()) {
const ColorVector &CV = BlockColors.find(InsertBefore->getParent())->second;
assert(CV.size() == 1 && "non-unique color for block!");
Instruction *EHPad = CV.front()->getFirstNonPHI();
if (EHPad->isEHPad())
OpBundles.emplace_back("funclet", EHPad);
}
return CallInst::Create(FTy, Func, Args, OpBundles, NameStr, InsertBefore);
}