本文整理汇总了C++中ArrayRef::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayRef::empty方法的具体用法?C++ ArrayRef::empty怎么用?C++ ArrayRef::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayRef
的用法示例。
在下文中一共展示了ArrayRef::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExecuteAndWait
int sys::ExecuteAndWait(StringRef Program, const char **Args, const char **Envp,
ArrayRef<Optional<StringRef>> Redirects,
unsigned SecondsToWait, unsigned MemoryLimit,
std::string *ErrMsg, bool *ExecutionFailed) {
assert(Redirects.empty() || Redirects.size() == 3);
ProcessInfo PI;
if (Execute(PI, Program, Args, Envp, Redirects, MemoryLimit, ErrMsg)) {
if (ExecutionFailed)
*ExecutionFailed = false;
ProcessInfo Result = Wait(
PI, SecondsToWait, /*WaitUntilTerminates=*/SecondsToWait == 0, ErrMsg);
return Result.ReturnCode;
}
if (ExecutionFailed)
*ExecutionFailed = true;
return -1;
}
示例2: printRuntimeFunctionRels
/// Prints out the given RuntimeFunction struct for x64, assuming that Obj is
/// pointing to an object file. Unlike executable, fields in RuntimeFunction
/// struct are filled with zeros, but instead there are relocations pointing to
/// them so that the linker will fill targets' RVAs to the fields at link
/// time. This function interprets the relocations to find the data to be used
/// in the resulting executable.
static void printRuntimeFunctionRels(const COFFObjectFile *Obj,
const RuntimeFunction &RF,
uint64_t SectionOffset,
const std::vector<RelocationRef> &Rels) {
outs() << "Function Table:\n";
outs() << " Start Address: ";
printCOFFSymbolAddress(outs(), Rels,
SectionOffset +
/*offsetof(RuntimeFunction, StartAddress)*/ 0,
RF.StartAddress);
outs() << "\n";
outs() << " End Address: ";
printCOFFSymbolAddress(outs(), Rels,
SectionOffset +
/*offsetof(RuntimeFunction, EndAddress)*/ 4,
RF.EndAddress);
outs() << "\n";
outs() << " Unwind Info Address: ";
printCOFFSymbolAddress(outs(), Rels,
SectionOffset +
/*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
RF.UnwindInfoOffset);
outs() << "\n";
ArrayRef<uint8_t> XContents;
uint64_t UnwindInfoOffset = 0;
error(getSectionContents(
Obj, Rels, SectionOffset +
/*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
XContents, UnwindInfoOffset));
if (XContents.empty())
return;
UnwindInfoOffset += RF.UnwindInfoOffset;
if (UnwindInfoOffset > XContents.size())
return;
auto *UI = reinterpret_cast<const Win64EH::UnwindInfo *>(XContents.data() +
UnwindInfoOffset);
printWin64EHUnwindInfo(UI);
}
示例3: OutputFilesComputer
Optional<OutputFilesComputer>
OutputFilesComputer::create(const llvm::opt::ArgList &args,
DiagnosticEngine &diags,
const FrontendInputsAndOutputs &inputsAndOutputs) {
Optional<std::vector<std::string>> outputArguments =
getOutputFilenamesFromCommandLineOrFilelist(args, diags);
if (!outputArguments)
return None;
const StringRef outputDirectoryArgument =
outputArguments->size() == 1 &&
llvm::sys::fs::is_directory(outputArguments->front())
? StringRef(outputArguments->front())
: StringRef();
ArrayRef<std::string> outputFileArguments =
outputDirectoryArgument.empty() ? ArrayRef<std::string>(*outputArguments)
: ArrayRef<std::string>();
const StringRef firstInput =
inputsAndOutputs.hasSingleInput()
? StringRef(inputsAndOutputs.getFilenameOfFirstInput())
: StringRef();
const FrontendOptions::ActionType requestedAction =
ArgsToFrontendOptionsConverter::determineRequestedAction(args);
if (!outputFileArguments.empty() &&
outputFileArguments.size() !=
inputsAndOutputs.countOfInputsProducingMainOutputs()) {
diags.diagnose(
SourceLoc(),
diag::error_if_any_output_files_are_specified_they_all_must_be);
return None;
}
const file_types::ID outputType =
FrontendOptions::formatForPrincipalOutputFileForAction(requestedAction);
return OutputFilesComputer(
diags, inputsAndOutputs, std::move(outputFileArguments),
outputDirectoryArgument, firstInput, requestedAction,
args.getLastArg(options::OPT_module_name),
file_types::getExtension(outputType),
FrontendOptions::doesActionProduceTextualOutput(requestedAction));
}
示例4: InjectCoverageForIndirectCalls
// On every indirect call we call a run-time function
// __sanitizer_cov_indir_call* with two parameters:
// - callee address,
// - global cache array that contains kCacheSize pointers (zero-initialized).
// The cache is used to speed up recording the caller-callee pairs.
// The address of the caller is passed implicitly via caller PC.
// kCacheSize is encoded in the name of the run-time function.
void SanitizerCoverageModule::InjectCoverageForIndirectCalls(
Function &F, ArrayRef<Instruction *> IndirCalls) {
if (IndirCalls.empty()) return;
const int kCacheSize = 16;
const int kCacheAlignment = 64; // Align for better performance.
Type *Ty = ArrayType::get(IntptrTy, kCacheSize);
for (auto I : IndirCalls) {
IRBuilder<> IRB(I);
CallSite CS(I);
Value *Callee = CS.getCalledValue();
if (isa<InlineAsm>(Callee)) continue;
GlobalVariable *CalleeCache = new GlobalVariable(
*F.getParent(), Ty, false, GlobalValue::PrivateLinkage,
Constant::getNullValue(Ty), "__sancov_gen_callee_cache");
CalleeCache->setAlignment(kCacheAlignment);
IRB.CreateCall(SanCovIndirCallFunction,
{IRB.CreatePointerCast(Callee, IntptrTy),
IRB.CreatePointerCast(CalleeCache, IntptrTy)});
}
}
示例5: insertBranch
unsigned BPFInstrInfo::insertBranch(MachineBasicBlock &MBB,
MachineBasicBlock *TBB,
MachineBasicBlock *FBB,
ArrayRef<MachineOperand> Cond,
const DebugLoc &DL,
int *BytesAdded) const {
assert(!BytesAdded && "code size not handled");
// Shouldn't be a fall through.
assert(TBB && "insertBranch must not be told to insert a fallthrough");
if (Cond.empty()) {
// Unconditional branch
assert(!FBB && "Unconditional branch with multiple successors!");
BuildMI(&MBB, DL, get(BPF::JMP)).addMBB(TBB);
return 1;
}
llvm_unreachable("Unexpected conditional branch");
}
示例6: getFunctionCounts
std::error_code IndexedInstrProfReader::getFunctionCounts(
StringRef FuncName, uint64_t FuncHash, std::vector<uint64_t> &Counts) {
auto Iter = Index->find(FuncName);
if (Iter == Index->end())
return error(instrprof_error::unknown_function);
// Found it. Look for counters with the right hash.
ArrayRef<InstrProfRecord> Data = (*Iter);
if (Data.empty())
return error(instrprof_error::malformed);
for (unsigned I = 0, E = Data.size(); I < E; ++I) {
// Check for a match and fill the vector if there is one.
if (Data[I].Hash == FuncHash) {
Counts = Data[I].Counts;
return success();
}
}
return error(instrprof_error::hash_mismatch);
}
示例7: emitGlobal
void WebAssemblyTargetAsmStreamer::emitGlobal(
ArrayRef<wasm::Global> Globals) {
if (!Globals.empty()) {
OS << "\t.globalvar \t";
bool First = true;
for (const wasm::Global &G : Globals) {
if (First)
First = false;
else
OS << ", ";
OS << WebAssembly::TypeToString(G.Type);
if (!G.InitialModule.empty())
OS << '=' << G.InitialModule << ':' << G.InitialName;
else
OS << '=' << G.InitialValue;
}
OS << '\n';
}
}
示例8: getInstanceStart
Size ClassLayout::getInstanceStart() const {
ArrayRef<ElementLayout> elements = AllElements;
while (!elements.empty()) {
auto element = elements.front();
elements = elements.drop_front();
// Ignore empty elements.
if (element.isEmpty()) {
continue;
} else if (element.hasByteOffset()) {
// FIXME: assumes layout is always sequential!
return element.getByteOffset();
} else {
return Size(0);
}
}
// If there are no non-empty elements, just return the computed size.
return getSize();
}
示例9:
// For a forwarding instruction, we loop over all operands and make sure that
// all non-trivial values have the same ownership.
ValueOwnershipKind
ValueOwnershipKindVisitor::visitForwardingInst(SILInstruction *I) {
ArrayRef<Operand> Ops = I->getAllOperands();
// A forwarding inst without operands must be trivial.
if (Ops.empty())
return ValueOwnershipKind::Trivial;
// Find the first index where we have a trivial value.
auto Iter =
find_if(Ops,
[](const Operand &Op) -> bool {
return Op.get().getOwnershipKind() != ValueOwnershipKind::Trivial;
});
// All trivial.
if (Iter == Ops.end()) {
return ValueOwnershipKind::Trivial;
}
// See if we have any Any. If we do, just return that for now.
if (any_of(Ops,
[](const Operand &Op) -> bool {
return Op.get().getOwnershipKind() == ValueOwnershipKind::Any;
}))
return ValueOwnershipKind::Any;
unsigned Index = std::distance(Ops.begin(), Iter);
ValueOwnershipKind Base = Ops[Index].get().getOwnershipKind();
for (const Operand &Op : Ops.slice(Index+1)) {
auto OpKind = Op.get().getOwnershipKind();
if (OpKind.merge(ValueOwnershipKind::Trivial))
continue;
auto MergedValue = Base.merge(OpKind.Value);
if (!MergedValue.hasValue()) {
llvm_unreachable("Forwarding inst with mismatching ownership kinds?!");
}
}
return Base;
}
示例10: getName
std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
assert(id < num_intrinsics && "Invalid intrinsic ID!");
static const char * const Table[] = {
"not_intrinsic",
#define GET_INTRINSIC_NAME_TABLE
#include "llvm/Intrinsics.gen"
#undef GET_INTRINSIC_NAME_TABLE
};
if (Tys.empty())
return Table[id];
std::string Result(Table[id]);
for (unsigned i = 0; i < Tys.size(); ++i) {
if (PointerType* PTyp = dyn_cast<PointerType>(Tys[i])) {
Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) +
EVT::getEVT(PTyp->getElementType()).getEVTString();
}
else if (Tys[i])
Result += "." + EVT::getEVT(Tys[i]).getEVTString();
}
return Result;
}
示例11: hasDiagnostic
bool CapturedDiagList::hasDiagnostic(ArrayRef<unsigned> IDs,
SourceRange range) const {
if (range.isInvalid())
return false;
ListTy::const_iterator I = List.begin();
while (I != List.end()) {
FullSourceLoc diagLoc = I->getLocation();
if ((IDs.empty() || // empty means any diagnostic in the range.
std::find(IDs.begin(), IDs.end(), I->getID()) != IDs.end()) &&
!diagLoc.isBeforeInTranslationUnitThan(range.getBegin()) &&
(diagLoc == range.getEnd() ||
diagLoc.isBeforeInTranslationUnitThan(range.getEnd()))) {
return true;
}
++I;
}
return false;
}
示例12: shouldRunAsSubcommand
/// Determine if the given invocation should run as a subcommand.
///
/// \param ExecName The name of the argv[0] we were invoked as.
/// \param SubcommandName On success, the full name of the subcommand to invoke.
/// \param Args On return, the adjusted program arguments to use.
/// \returns True if running as a subcommand.
static bool shouldRunAsSubcommand(StringRef ExecName,
SmallString<256> &SubcommandName,
const ArrayRef<const char *> Args,
bool &isRepl) {
assert(!Args.empty());
// If we are not run as 'swift', don't do anything special. This doesn't work
// with symlinks with alternate names, but we can't detect 'swift' vs 'swiftc'
// if we try and resolve using the actual executable path.
if (ExecName != "swift")
return false;
// If there are no program arguments, always invoke as normal.
if (Args.size() == 1)
return false;
// Otherwise, we have a program argument. If it looks like an option or a
// path, then invoke in interactive mode with the arguments as given.
StringRef FirstArg(Args[1]);
if (FirstArg.startswith("-") || FirstArg.find('.') != StringRef::npos ||
FirstArg.find('/') != StringRef::npos)
return false;
// Otherwise, we should have some sort of subcommand. Get the subcommand name
// and remove it from the program arguments.
StringRef Subcommand = Args[1];
// If the subcommand is the "built-in" 'repl', then use the
// normal driver.
if (Subcommand == "repl") {
isRepl = true;
return false;
}
// Form the subcommand name.
SubcommandName.assign("swift-");
SubcommandName.append(Subcommand);
return true;
}
示例13: mapHeader
StringRef CanonicalIncludes::mapHeader(ArrayRef<std::string> Headers,
StringRef QualifiedName) const {
assert(!Headers.empty());
auto SE = SymbolMapping.find(QualifiedName);
if (SE != SymbolMapping.end())
return SE->second;
// Find the first header such that the extension is not '.inc', and isn't a
// recognized non-header file
auto I = llvm::find_if(Headers, [](StringRef Include) {
// Skip .inc file whose including header file should
// be #included instead.
return !Include.endswith(".inc");
});
if (I == Headers.end())
return Headers[0]; // Fallback to the declaring header.
StringRef Header = *I;
// If Header is not expected be included (e.g. .cc file), we fall back to
// the declaring header.
StringRef Ext = sys::path::extension(Header).trim('.');
// Include-able headers must have precompile type. Treat files with
// non-recognized extenstions (TY_INVALID) as headers.
auto ExtType = driver::types::lookupTypeForExtension(Ext);
if ((ExtType != driver::types::TY_INVALID) &&
!driver::types::onlyPrecompileType(ExtType))
return Headers[0];
auto MapIt = FullPathMapping.find(Header);
if (MapIt != FullPathMapping.end())
return MapIt->second;
int Components = 1;
for (auto It = sys::path::rbegin(Header), End = sys::path::rend(Header);
It != End && Components <= MaxSuffixComponents; ++It, ++Components) {
auto SubPath = Header.substr(It->data() - Header.begin());
auto MappingIt = SuffixHeaderMapping.find(SubPath);
if (MappingIt != SuffixHeaderMapping.end())
return MappingIt->second;
}
return Header;
}
示例14: InsertBranch
unsigned WebAssemblyInstrInfo::InsertBranch(MachineBasicBlock &MBB,
MachineBasicBlock *TBB,
MachineBasicBlock *FBB,
ArrayRef<MachineOperand> Cond,
DebugLoc DL) const {
assert(Cond.size() <= 1);
if (Cond.empty()) {
if (!TBB)
return 0;
BuildMI(&MBB, DL, get(WebAssembly::BR)).addMBB(TBB);
return 1;
}
BuildMI(&MBB, DL, get(WebAssembly::BR_IF)).addOperand(Cond[0]).addMBB(TBB);
if (!FBB)
return 1;
BuildMI(&MBB, DL, get(WebAssembly::BR)).addMBB(FBB);
return 2;
}
示例15: translateIndices
/// Recursively walk into the given formal index type, expanding tuples,
/// in order to form the arguments to a subscript accessor.
static void translateIndices(SILGenFunction &gen, SILLocation loc,
AbstractionPattern pattern, CanType formalType,
ArrayRef<ManagedValue> &sourceIndices,
RValue &result) {
// Expand if the pattern was a tuple.
if (pattern.isTuple()) {
auto formalTupleType = cast<TupleType>(formalType);
for (auto i : indices(formalTupleType.getElementTypes())) {
translateIndices(gen, loc, pattern.getTupleElementType(i),
formalTupleType.getElementType(i),
sourceIndices, result);
}
return;
}
assert(!sourceIndices.empty() && "ran out of elements in index!");
ManagedValue value = sourceIndices.front();
sourceIndices = sourceIndices.slice(1);
// We're going to build an RValue here, so make sure we translate
// indirect arguments to be scalar if we have a loadable type.
if (value.getType().isAddress()) {
auto &valueTL = gen.getTypeLowering(value.getType());
if (!valueTL.isAddressOnly()) {
value = gen.emitLoad(loc, value.forward(gen), valueTL,
SGFContext(), IsTake);
}
}
// Reabstract the subscripts from the requirement pattern to the
// formal type.
value = gen.emitOrigToSubstValue(loc, value, pattern, formalType);
// Invoking the accessor will expect a value of the formal type, so
// don't reabstract to that here.
// Add that to the result, further expanding if necessary.
result.addElement(gen, value, formalType, loc);
}