本文整理汇总了C++中MutableArrayRef类的典型用法代码示例。如果您正苦于以下问题:C++ MutableArrayRef类的具体用法?C++ MutableArrayRef怎么用?C++ MutableArrayRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MutableArrayRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: combineRegions
/// Combine counts of regions which cover the same area.
static ArrayRef<CountedRegion>
combineRegions(MutableArrayRef<CountedRegion> Regions) {
if (Regions.empty())
return Regions;
auto Active = Regions.begin();
auto End = Regions.end();
for (auto I = Regions.begin() + 1; I != End; ++I) {
if (Active->startLoc() != I->startLoc() ||
Active->endLoc() != I->endLoc()) {
// Shift to the next region.
++Active;
if (Active != I)
*Active = *I;
continue;
}
// Merge duplicate region.
// If CodeRegions and ExpansionRegions cover the same area, it's probably
// a macro which is fully expanded to another macro. In that case, we need
// to accumulate counts only from CodeRegions, or else the area will be
// counted twice.
// On the other hand, a macro may have a nested macro in its body. If the
// outer macro is used several times, the ExpansionRegion for the nested
// macro will also be added several times. These ExpansionRegions cover
// the same source locations and have to be combined to reach the correct
// value for that area.
// We add counts of the regions of the same kind as the active region
// to handle the both situations.
if (I->Kind == Active->Kind)
Active->ExecutionCount += I->ExecutionCount;
}
return Regions.drop_back(std::distance(++Active, End));
}
示例2: readBytes
std::error_code ByteStream::readBytes(uint32_t Offset,
MutableArrayRef<uint8_t> Buffer) const {
if (Data.size() < Buffer.size() + Offset)
return std::make_error_code(std::errc::bad_address);
::memcpy(Buffer.data(), Data.data() + Offset, Buffer.size());
return std::error_code();
}
示例3: readBytes
Error MappedBlockStream::readBytes(uint32_t Offset,
MutableArrayRef<uint8_t> Buffer) const {
uint32_t BlockNum = Offset / Pdb.getBlockSize();
uint32_t OffsetInBlock = Offset % Pdb.getBlockSize();
// Make sure we aren't trying to read beyond the end of the stream.
if (Buffer.size() > Data->getLength())
return make_error<RawError>(raw_error_code::insufficient_buffer);
if (Offset > Data->getLength() - Buffer.size())
return make_error<RawError>(raw_error_code::insufficient_buffer);
uint32_t BytesLeft = Buffer.size();
uint32_t BytesWritten = 0;
uint8_t *WriteBuffer = Buffer.data();
auto BlockList = Data->getStreamBlocks();
while (BytesLeft > 0) {
uint32_t StreamBlockAddr = BlockList[BlockNum];
auto Data = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());
const uint8_t *ChunkStart = Data.data() + OffsetInBlock;
uint32_t BytesInChunk =
std::min(BytesLeft, Pdb.getBlockSize() - OffsetInBlock);
::memcpy(WriteBuffer + BytesWritten, ChunkStart, BytesInChunk);
BytesWritten += BytesInChunk;
BytesLeft -= BytesInChunk;
++BlockNum;
OffsetInBlock = 0;
}
return Error::success();
}
示例4: readBytes
Error MappedBlockStream::readBytes(uint32_t Offset,
MutableArrayRef<uint8_t> Buffer) const {
uint32_t BlockNum = Offset / BlockSize;
uint32_t OffsetInBlock = Offset % BlockSize;
// Make sure we aren't trying to read beyond the end of the stream.
if (Buffer.size() > StreamLayout.Length)
return make_error<MSFError>(msf_error_code::insufficient_buffer);
if (Offset > StreamLayout.Length - Buffer.size())
return make_error<MSFError>(msf_error_code::insufficient_buffer);
uint32_t BytesLeft = Buffer.size();
uint32_t BytesWritten = 0;
uint8_t *WriteBuffer = Buffer.data();
while (BytesLeft > 0) {
uint32_t StreamBlockAddr = StreamLayout.Blocks[BlockNum];
ArrayRef<uint8_t> BlockData;
uint32_t Offset = blockToOffset(StreamBlockAddr, BlockSize);
if (auto EC = MsfData.readBytes(Offset, BlockSize, BlockData))
return EC;
const uint8_t *ChunkStart = BlockData.data() + OffsetInBlock;
uint32_t BytesInChunk = std::min(BytesLeft, BlockSize - OffsetInBlock);
::memcpy(WriteBuffer + BytesWritten, ChunkStart, BytesInChunk);
BytesWritten += BytesInChunk;
BytesLeft -= BytesInChunk;
++BlockNum;
OffsetInBlock = 0;
}
return Error::success();
}
示例5: readBytes
Error ByteStream::readBytes(uint32_t Offset,
MutableArrayRef<uint8_t> Buffer) const {
if (Data.size() < Buffer.size() + Offset)
return make_error<RawError>(raw_error_code::insufficient_buffer);
::memcpy(Buffer.data(), Data.data() + Offset, Buffer.size());
return Error::success();
}
示例6: mergeSymbolRecords
static void mergeSymbolRecords(BumpPtrAllocator &Alloc, ObjectFile *File,
ArrayRef<TypeIndex> TypeIndexMap,
BinaryStreamRef SymData) {
// FIXME: Improve error recovery by warning and skipping records when
// possible.
CVSymbolArray Syms;
BinaryStreamReader Reader(SymData);
ExitOnErr(Reader.readArray(Syms, Reader.getLength()));
for (const CVSymbol &Sym : Syms) {
// Discover type index references in the record. Skip it if we don't know
// where they are.
SmallVector<TiReference, 32> TypeRefs;
if (!discoverTypeIndices(Sym, TypeRefs)) {
log("ignoring unknown symbol record with kind 0x" + utohexstr(Sym.kind()));
continue;
}
// Copy the symbol record so we can mutate it.
MutableArrayRef<uint8_t> NewData = copySymbolForPdb(Sym, Alloc);
// Re-map all the type index references.
MutableArrayRef<uint8_t> Contents =
NewData.drop_front(sizeof(RecordPrefix));
if (!remapTypesInSymbolRecord(File, Contents, TypeIndexMap, TypeRefs))
continue;
// FIXME: Fill in "Parent" and "End" fields by maintaining a stack of
// scopes.
// Add the symbol to the module.
File->ModuleDBI->addSymbol(CVSymbol(Sym.kind(), NewData));
}
}
示例7: writeBytes
static Error writeBytes(uint32_t Offset, ArrayRef<uint8_t> Src,
MutableArrayRef<uint8_t> Dest) {
if (Dest.size() < Src.size())
return make_error<CodeViewError>(cv_error_code::insufficient_buffer);
if (Offset > Src.size() - Dest.size())
return make_error<CodeViewError>(cv_error_code::insufficient_buffer);
::memcpy(Dest.data() + Offset, Src.data(), Src.size());
return Error::success();
}
示例8: toUTF8
static StringRef toUTF8(UTF32 C, MutableArrayRef<UTF8> Storage) {
const UTF32 *Begin32 = &C;
UTF8 *Begin8 = Storage.begin();
// The case-folded output should always be a valid unicode character, so use
// strict mode here.
ConversionResult CR = ConvertUTF32toUTF8(&Begin32, &C + 1, &Begin8,
Storage.end(), strictConversion);
assert(CR == conversionOK && "Case folding produced invalid char?");
(void)CR;
return StringRef(reinterpret_cast<char *>(Storage.begin()),
Begin8 - Storage.begin());
}
示例9: getAllOperands
void SILInstruction::dropAllReferences() {
MutableArrayRef<Operand> PossiblyDeadOps = getAllOperands();
for (auto OpI = PossiblyDeadOps.begin(),
OpE = PossiblyDeadOps.end(); OpI != OpE; ++OpI) {
OpI->drop();
}
// If we have a function ref inst, we need to especially drop its function
// argument so that it gets a proper ref decrement.
auto *FRI = dyn_cast<FunctionRefInst>(this);
if (!FRI || !FRI->getReferencedFunction())
return;
FRI->dropReferencedFunction();
}
示例10: peekTokens
size_t AsmLexer::peekTokens(MutableArrayRef<AsmToken> Buf,
bool ShouldSkipSpace) {
const char *SavedTokStart = TokStart;
const char *SavedCurPtr = CurPtr;
bool SavedAtStartOfLine = IsAtStartOfLine;
bool SavedAtStartOfStatement = IsAtStartOfStatement;
bool SavedSkipSpace = SkipSpace;
std::string SavedErr = getErr();
SMLoc SavedErrLoc = getErrLoc();
SkipSpace = ShouldSkipSpace;
size_t ReadCount;
for (ReadCount = 0; ReadCount < Buf.size(); ++ReadCount) {
AsmToken Token = LexToken();
Buf[ReadCount] = Token;
if (Token.is(AsmToken::Eof))
break;
}
SetError(SavedErrLoc, SavedErr);
SkipSpace = SavedSkipSpace;
IsAtStartOfLine = SavedAtStartOfLine;
IsAtStartOfStatement = SavedAtStartOfStatement;
CurPtr = SavedCurPtr;
TokStart = SavedTokStart;
return ReadCount;
}
示例11: expand
void ABISignature::expand(GenIR &Reader,
ArrayRef<ABIArgInfo::Expansion> Expansions,
Value *Source, MutableArrayRef<Value *> Values,
MutableArrayRef<Type *> Types, bool IsResult) {
assert(Source != nullptr);
assert(Source->getType()->isPointerTy());
assert(Reader.doesValueRepresentStruct(Source));
assert(Expansions.size() > 0);
assert((IsResult && Values.size() == 1) ||
(Values.size() == Expansions.size()));
LLVMContext &LLVMContext = *Reader.JitContext->LLVMContext;
IRBuilder<> &Builder = *Reader.LLVMBuilder;
Type *ResultType = nullptr;
Value *ResultValue = nullptr;
if (IsResult) {
ResultType = getExpandedResultType(LLVMContext, Expansions);
ResultValue = Constant::getNullValue(ResultType);
}
Type *BytePtrTy = Type::getInt8PtrTy(LLVMContext, 0);
Value *SourcePtr = Builder.CreatePointerCast(Source, BytePtrTy);
for (int32_t I = 0; I < static_cast<int32_t>(Expansions.size()); I++) {
const ABIArgInfo::Expansion &Exp = Expansions[I];
Value *LoadPtr = Builder.CreateConstGEP1_32(SourcePtr, Exp.Offset);
LoadPtr = Builder.CreatePointerCast(LoadPtr, Exp.TheType->getPointerTo(0));
const bool IsVolatile = false;
Value *Value = Builder.CreateLoad(LoadPtr, IsVolatile);
if (IsResult) {
ResultValue = Builder.CreateInsertValue(ResultValue, Value, I);
} else {
Values[I] = Value;
}
if (Types.size() > 0) {
Types[I] = Exp.TheType;
}
}
if (IsResult) {
Values[0] = ResultValue;
}
}
示例12: withValueInPayload
static void withValueInPayload(IRGenFunction &IGF,
const EnumPayload &payload,
llvm::Type *valueType,
int numBitsUsedInValue,
unsigned payloadOffset,
Fn &&f) {
auto &DataLayout = IGF.IGM.DataLayout;
int valueTypeBitWidth = DataLayout.getTypeSizeInBits(valueType);
int valueBitWidth =
numBitsUsedInValue < 0 ? valueTypeBitWidth : numBitsUsedInValue;
assert(numBitsUsedInValue <= valueTypeBitWidth);
// Find the elements we need to touch.
// TODO: Linear search through the payload elements is lame.
MutableArrayRef<EnumPayload::LazyValue> payloads = payload.PayloadValues;
llvm::Type *payloadType;
int payloadBitWidth;
int valueOffset = 0, payloadValueOffset = payloadOffset;
for (;;) {
payloadType = getPayloadType(payloads.front());
payloadBitWidth = IGF.IGM.DataLayout.getTypeSizeInBits(payloadType);
// Does this element overlap the area we need to touch?
if (payloadValueOffset < payloadBitWidth) {
// See how much of the value we can fit here.
int valueChunkWidth = payloadBitWidth - payloadValueOffset;
valueChunkWidth = std::min(valueChunkWidth, valueBitWidth - valueOffset);
f(payloads.front(),
payloadBitWidth, payloadValueOffset,
valueTypeBitWidth, valueOffset);
// If we used the entire value, we're done.
valueOffset += valueChunkWidth;
if (valueOffset >= valueBitWidth)
return;
}
payloadValueOffset = std::max(payloadValueOffset - payloadBitWidth, 0);
payloads = payloads.slice(1);
}
}
示例13: remapTypesInSymbolRecord
static bool remapTypesInSymbolRecord(ObjectFile *File,
MutableArrayRef<uint8_t> Contents,
ArrayRef<TypeIndex> TypeIndexMap,
ArrayRef<TiReference> TypeRefs) {
for (const TiReference &Ref : TypeRefs) {
unsigned ByteSize = Ref.Count * sizeof(TypeIndex);
if (Contents.size() < Ref.Offset + ByteSize) {
log("ignoring short symbol record");
return false;
}
MutableArrayRef<TypeIndex> TIs(
reinterpret_cast<TypeIndex *>(Contents.data() + Ref.Offset), Ref.Count);
for (TypeIndex &TI : TIs)
if (!remapTypeIndex(TI, TypeIndexMap)) {
log("ignoring symbol record in " + File->getName() +
" with bad type index 0x" + utohexstr(TI.getIndex()));
return false;
}
}
return true;
}
示例14: sortNestedRegions
/// Sort a nested sequence of regions from a single file.
static void sortNestedRegions(MutableArrayRef<CountedRegion> Regions) {
std::sort(Regions.begin(), Regions.end(), [](const CountedRegion &LHS,
const CountedRegion &RHS) {
if (LHS.startLoc() != RHS.startLoc())
return LHS.startLoc() < RHS.startLoc();
if (LHS.endLoc() != RHS.endLoc())
// When LHS completely contains RHS, we sort LHS first.
return RHS.endLoc() < LHS.endLoc();
// If LHS and RHS cover the same area, we need to sort them according
// to their kinds so that the most suitable region will become "active"
// in combineRegions(). Because we accumulate counter values only from
// regions of the same kind as the first region of the area, prefer
// CodeRegion to ExpansionRegion and ExpansionRegion to SkippedRegion.
static_assert(CounterMappingRegion::CodeRegion <
CounterMappingRegion::ExpansionRegion &&
CounterMappingRegion::ExpansionRegion <
CounterMappingRegion::SkippedRegion,
"Unexpected order of region kind values");
return LHS.Kind < RHS.Kind;
});
}
示例15: prepareIndirectResultInit
/// Prepare an Initialization that will initialize the result of the
/// current function.
///
/// \param directResultsBuffer - will be filled with the direct
/// components of the result
/// \param cleanups - will be filled (after initialization completes)
/// with all the active cleanups managing the result values
static std::unique_ptr<Initialization>
prepareIndirectResultInit(SILGenFunction &gen, CanType formalResultType,
SmallVectorImpl<SILValue> &directResultsBuffer,
SmallVectorImpl<CleanupHandle> &cleanups) {
auto fnType = gen.F.getLoweredFunctionType();
// Make space in the direct-results array for all the entries we need.
directResultsBuffer.append(fnType->getNumDirectResults(), SILValue());
ArrayRef<SILResultInfo> allResults = fnType->getAllResults();
MutableArrayRef<SILValue> directResults = directResultsBuffer;
ArrayRef<SILArgument*> indirectResultAddrs = gen.F.getIndirectResults();
auto init = prepareIndirectResultInit(gen, formalResultType, allResults,
directResults, indirectResultAddrs,
cleanups);
assert(allResults.empty());
assert(directResults.empty());
assert(indirectResultAddrs.empty());
return init;
}