You've already forked linux-packaging-mono
Imported Upstream version 5.18.0.182
Former-commit-id: f9d55cf82631bfd710c387739687e5845296aea1
This commit is contained in:
parent
8625704ad8
commit
b716dc8d12
2
external/llvm/lib/Bitcode/CMakeLists.txt
vendored
2
external/llvm/lib/Bitcode/CMakeLists.txt
vendored
@ -1,2 +0,0 @@
|
||||
add_subdirectory(Reader)
|
||||
add_subdirectory(Writer)
|
24
external/llvm/lib/Bitcode/LLVMBuild.txt
vendored
24
external/llvm/lib/Bitcode/LLVMBuild.txt
vendored
@ -1,24 +0,0 @@
|
||||
;===- ./lib/Bitcode/LLVMBuild.txt ------------------------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
;
|
||||
; This is an LLVMBuild description file for the components in this subdirectory.
|
||||
;
|
||||
; For more information on the LLVMBuild system, please see:
|
||||
;
|
||||
; http://llvm.org/docs/LLVMBuild.html
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[common]
|
||||
subdirectories = Reader Writer
|
||||
|
||||
[component_0]
|
||||
type = Group
|
||||
name = Bitcode
|
||||
parent = Libraries
|
134
external/llvm/lib/Bitcode/Reader/BitReader.cpp
vendored
134
external/llvm/lib/Bitcode/Reader/BitReader.cpp
vendored
@ -1,134 +0,0 @@
|
||||
//===-- BitReader.cpp -----------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm-c/BitReader.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm/Bitcode/BitcodeReader.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
/* Builds a module from the bitcode in the specified memory buffer, returning a
|
||||
reference to the module via the OutModule parameter. Returns 0 on success.
|
||||
Optionally returns a human-readable error message via OutMessage. */
|
||||
LLVMBool LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutModule,
|
||||
char **OutMessage) {
|
||||
return LLVMParseBitcodeInContext(LLVMGetGlobalContext(), MemBuf, OutModule,
|
||||
OutMessage);
|
||||
}
|
||||
|
||||
LLVMBool LLVMParseBitcode2(LLVMMemoryBufferRef MemBuf,
|
||||
LLVMModuleRef *OutModule) {
|
||||
return LLVMParseBitcodeInContext2(LLVMGetGlobalContext(), MemBuf, OutModule);
|
||||
}
|
||||
|
||||
LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
|
||||
LLVMMemoryBufferRef MemBuf,
|
||||
LLVMModuleRef *OutModule,
|
||||
char **OutMessage) {
|
||||
MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef();
|
||||
LLVMContext &Ctx = *unwrap(ContextRef);
|
||||
|
||||
Expected<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(Buf, Ctx);
|
||||
if (Error Err = ModuleOrErr.takeError()) {
|
||||
std::string Message;
|
||||
handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
|
||||
Message = EIB.message();
|
||||
});
|
||||
if (OutMessage)
|
||||
*OutMessage = strdup(Message.c_str());
|
||||
*OutModule = wrap((Module *)nullptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
*OutModule = wrap(ModuleOrErr.get().release());
|
||||
return 0;
|
||||
}
|
||||
|
||||
LLVMBool LLVMParseBitcodeInContext2(LLVMContextRef ContextRef,
|
||||
LLVMMemoryBufferRef MemBuf,
|
||||
LLVMModuleRef *OutModule) {
|
||||
MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef();
|
||||
LLVMContext &Ctx = *unwrap(ContextRef);
|
||||
|
||||
ErrorOr<std::unique_ptr<Module>> ModuleOrErr =
|
||||
expectedToErrorOrAndEmitErrors(Ctx, parseBitcodeFile(Buf, Ctx));
|
||||
if (ModuleOrErr.getError()) {
|
||||
*OutModule = wrap((Module *)nullptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
*OutModule = wrap(ModuleOrErr.get().release());
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Reads a module from the specified path, returning via the OutModule parameter
|
||||
a module provider which performs lazy deserialization. Returns 0 on success.
|
||||
Optionally returns a human-readable error message via OutMessage. */
|
||||
LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
|
||||
LLVMMemoryBufferRef MemBuf,
|
||||
LLVMModuleRef *OutM, char **OutMessage) {
|
||||
LLVMContext &Ctx = *unwrap(ContextRef);
|
||||
std::unique_ptr<MemoryBuffer> Owner(unwrap(MemBuf));
|
||||
Expected<std::unique_ptr<Module>> ModuleOrErr =
|
||||
getOwningLazyBitcodeModule(std::move(Owner), Ctx);
|
||||
// Release the buffer if we didn't take ownership of it since we never owned
|
||||
// it anyway.
|
||||
(void)Owner.release();
|
||||
|
||||
if (Error Err = ModuleOrErr.takeError()) {
|
||||
std::string Message;
|
||||
handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
|
||||
Message = EIB.message();
|
||||
});
|
||||
if (OutMessage)
|
||||
*OutMessage = strdup(Message.c_str());
|
||||
*OutM = wrap((Module *)nullptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
*OutM = wrap(ModuleOrErr.get().release());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
LLVMBool LLVMGetBitcodeModuleInContext2(LLVMContextRef ContextRef,
|
||||
LLVMMemoryBufferRef MemBuf,
|
||||
LLVMModuleRef *OutM) {
|
||||
LLVMContext &Ctx = *unwrap(ContextRef);
|
||||
std::unique_ptr<MemoryBuffer> Owner(unwrap(MemBuf));
|
||||
|
||||
ErrorOr<std::unique_ptr<Module>> ModuleOrErr = expectedToErrorOrAndEmitErrors(
|
||||
Ctx, getOwningLazyBitcodeModule(std::move(Owner), Ctx));
|
||||
Owner.release();
|
||||
|
||||
if (ModuleOrErr.getError()) {
|
||||
*OutM = wrap((Module *)nullptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
*OutM = wrap(ModuleOrErr.get().release());
|
||||
return 0;
|
||||
}
|
||||
|
||||
LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
|
||||
char **OutMessage) {
|
||||
return LLVMGetBitcodeModuleInContext(LLVMGetGlobalContext(), MemBuf, OutM,
|
||||
OutMessage);
|
||||
}
|
||||
|
||||
LLVMBool LLVMGetBitcodeModule2(LLVMMemoryBufferRef MemBuf,
|
||||
LLVMModuleRef *OutM) {
|
||||
return LLVMGetBitcodeModuleInContext2(LLVMGetGlobalContext(), MemBuf, OutM);
|
||||
}
|
@ -1 +0,0 @@
|
||||
945ac451536862033d0336f38be662d9657a3e72
|
390
external/llvm/lib/Bitcode/Reader/BitstreamReader.cpp
vendored
390
external/llvm/lib/Bitcode/Reader/BitstreamReader.cpp
vendored
@ -1,390 +0,0 @@
|
||||
//===- BitstreamReader.cpp - BitstreamReader implementation ---------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Bitcode/BitstreamReader.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// BitstreamCursor implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter
|
||||
/// the block, and return true if the block has an error.
|
||||
bool BitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) {
|
||||
// Save the current block's state on BlockScope.
|
||||
BlockScope.push_back(Block(CurCodeSize));
|
||||
BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
|
||||
|
||||
// Add the abbrevs specific to this block to the CurAbbrevs list.
|
||||
if (BlockInfo) {
|
||||
if (const BitstreamBlockInfo::BlockInfo *Info =
|
||||
BlockInfo->getBlockInfo(BlockID)) {
|
||||
CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(),
|
||||
Info->Abbrevs.end());
|
||||
}
|
||||
}
|
||||
|
||||
// Get the codesize of this block.
|
||||
CurCodeSize = ReadVBR(bitc::CodeLenWidth);
|
||||
// We can't read more than MaxChunkSize at a time
|
||||
if (CurCodeSize > MaxChunkSize)
|
||||
return true;
|
||||
|
||||
SkipToFourByteBoundary();
|
||||
unsigned NumWords = Read(bitc::BlockSizeWidth);
|
||||
if (NumWordsP) *NumWordsP = NumWords;
|
||||
|
||||
// Validate that this block is sane.
|
||||
return CurCodeSize == 0 || AtEndOfStream();
|
||||
}
|
||||
|
||||
static uint64_t readAbbreviatedField(BitstreamCursor &Cursor,
|
||||
const BitCodeAbbrevOp &Op) {
|
||||
assert(!Op.isLiteral() && "Not to be used with literals!");
|
||||
|
||||
// Decode the value as we are commanded.
|
||||
switch (Op.getEncoding()) {
|
||||
case BitCodeAbbrevOp::Array:
|
||||
case BitCodeAbbrevOp::Blob:
|
||||
llvm_unreachable("Should not reach here");
|
||||
case BitCodeAbbrevOp::Fixed:
|
||||
assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
|
||||
return Cursor.Read((unsigned)Op.getEncodingData());
|
||||
case BitCodeAbbrevOp::VBR:
|
||||
assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
|
||||
return Cursor.ReadVBR64((unsigned)Op.getEncodingData());
|
||||
case BitCodeAbbrevOp::Char6:
|
||||
return BitCodeAbbrevOp::DecodeChar6(Cursor.Read(6));
|
||||
}
|
||||
llvm_unreachable("invalid abbreviation encoding");
|
||||
}
|
||||
|
||||
static void skipAbbreviatedField(BitstreamCursor &Cursor,
|
||||
const BitCodeAbbrevOp &Op) {
|
||||
assert(!Op.isLiteral() && "Not to be used with literals!");
|
||||
|
||||
// Decode the value as we are commanded.
|
||||
switch (Op.getEncoding()) {
|
||||
case BitCodeAbbrevOp::Array:
|
||||
case BitCodeAbbrevOp::Blob:
|
||||
llvm_unreachable("Should not reach here");
|
||||
case BitCodeAbbrevOp::Fixed:
|
||||
assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
|
||||
Cursor.Read((unsigned)Op.getEncodingData());
|
||||
break;
|
||||
case BitCodeAbbrevOp::VBR:
|
||||
assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
|
||||
Cursor.ReadVBR64((unsigned)Op.getEncodingData());
|
||||
break;
|
||||
case BitCodeAbbrevOp::Char6:
|
||||
Cursor.Read(6);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// skipRecord - Read the current record and discard it.
|
||||
unsigned BitstreamCursor::skipRecord(unsigned AbbrevID) {
|
||||
// Skip unabbreviated records by reading past their entries.
|
||||
if (AbbrevID == bitc::UNABBREV_RECORD) {
|
||||
unsigned Code = ReadVBR(6);
|
||||
unsigned NumElts = ReadVBR(6);
|
||||
for (unsigned i = 0; i != NumElts; ++i)
|
||||
(void)ReadVBR64(6);
|
||||
return Code;
|
||||
}
|
||||
|
||||
const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
|
||||
const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0);
|
||||
unsigned Code;
|
||||
if (CodeOp.isLiteral())
|
||||
Code = CodeOp.getLiteralValue();
|
||||
else {
|
||||
if (CodeOp.getEncoding() == BitCodeAbbrevOp::Array ||
|
||||
CodeOp.getEncoding() == BitCodeAbbrevOp::Blob)
|
||||
report_fatal_error("Abbreviation starts with an Array or a Blob");
|
||||
Code = readAbbreviatedField(*this, CodeOp);
|
||||
}
|
||||
|
||||
for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i < e; ++i) {
|
||||
const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
|
||||
if (Op.isLiteral())
|
||||
continue;
|
||||
|
||||
if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
|
||||
Op.getEncoding() != BitCodeAbbrevOp::Blob) {
|
||||
skipAbbreviatedField(*this, Op);
|
||||
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.
|
||||
// Decode the value as we are commanded.
|
||||
switch (EltEnc.getEncoding()) {
|
||||
default:
|
||||
report_fatal_error("Array element type can't be an Array or a Blob");
|
||||
case BitCodeAbbrevOp::Fixed:
|
||||
assert((unsigned)EltEnc.getEncodingData() <= MaxChunkSize);
|
||||
JumpToBit(GetCurrentBitNo() + NumElts * EltEnc.getEncodingData());
|
||||
break;
|
||||
case BitCodeAbbrevOp::VBR:
|
||||
assert((unsigned)EltEnc.getEncodingData() <= MaxChunkSize);
|
||||
for (; NumElts; --NumElts)
|
||||
ReadVBR64((unsigned)EltEnc.getEncodingData());
|
||||
break;
|
||||
case BitCodeAbbrevOp::Char6:
|
||||
JumpToBit(GetCurrentBitNo() + NumElts * 6);
|
||||
break;
|
||||
}
|
||||
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 NewEnd = GetCurrentBitNo()+((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)) {
|
||||
skipToEnd();
|
||||
break;
|
||||
}
|
||||
|
||||
// Skip over the blob.
|
||||
JumpToBit(NewEnd);
|
||||
}
|
||||
return Code;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// Read the record code first.
|
||||
assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?");
|
||||
const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0);
|
||||
unsigned Code;
|
||||
if (CodeOp.isLiteral())
|
||||
Code = CodeOp.getLiteralValue();
|
||||
else {
|
||||
if (CodeOp.getEncoding() == BitCodeAbbrevOp::Array ||
|
||||
CodeOp.getEncoding() == BitCodeAbbrevOp::Blob)
|
||||
report_fatal_error("Abbreviation starts with an Array or a Blob");
|
||||
Code = readAbbreviatedField(*this, CodeOp);
|
||||
}
|
||||
|
||||
for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) {
|
||||
const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
|
||||
if (Op.isLiteral()) {
|
||||
Vals.push_back(Op.getLiteralValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
|
||||
Op.getEncoding() != BitCodeAbbrevOp::Blob) {
|
||||
Vals.push_back(readAbbreviatedField(*this, Op));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
|
||||
// Array case. Read the number of elements as a vbr6.
|
||||
unsigned NumElts = ReadVBR(6);
|
||||
|
||||
// Get the element encoding.
|
||||
if (i + 2 != e)
|
||||
report_fatal_error("Array op not second to last");
|
||||
const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
|
||||
if (!EltEnc.isEncoding())
|
||||
report_fatal_error(
|
||||
"Array element type has to be an encoding of a type");
|
||||
|
||||
// Read all the elements.
|
||||
switch (EltEnc.getEncoding()) {
|
||||
default:
|
||||
report_fatal_error("Array element type can't be an Array or a Blob");
|
||||
case BitCodeAbbrevOp::Fixed:
|
||||
for (; NumElts; --NumElts)
|
||||
Vals.push_back(Read((unsigned)EltEnc.getEncodingData()));
|
||||
break;
|
||||
case BitCodeAbbrevOp::VBR:
|
||||
for (; NumElts; --NumElts)
|
||||
Vals.push_back(ReadVBR64((unsigned)EltEnc.getEncodingData()));
|
||||
break;
|
||||
case BitCodeAbbrevOp::Char6:
|
||||
for (; NumElts; --NumElts)
|
||||
Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6)));
|
||||
}
|
||||
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);
|
||||
skipToEnd();
|
||||
break;
|
||||
}
|
||||
|
||||
// Otherwise, inform the streamer that we need these bytes in memory. Skip
|
||||
// over tail padding first, in case jumping to NewEnd invalidates the Blob
|
||||
// pointer.
|
||||
JumpToBit(NewEnd);
|
||||
const char *Ptr = (const char *)getPointerToBit(CurBitPos, 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++);
|
||||
}
|
||||
}
|
||||
|
||||
return Code;
|
||||
}
|
||||
|
||||
void BitstreamCursor::ReadAbbrevRecord() {
|
||||
auto Abbv = std::make_shared<BitCodeAbbrev>();
|
||||
unsigned NumOpInfo = ReadVBR(5);
|
||||
for (unsigned i = 0; i != NumOpInfo; ++i) {
|
||||
bool IsLiteral = Read(1);
|
||||
if (IsLiteral) {
|
||||
Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8)));
|
||||
continue;
|
||||
}
|
||||
|
||||
BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3);
|
||||
if (BitCodeAbbrevOp::hasEncodingData(E)) {
|
||||
uint64_t Data = ReadVBR64(5);
|
||||
|
||||
// As a special case, handle fixed(0) (i.e., a fixed field with zero bits)
|
||||
// and vbr(0) as a literal zero. This is decoded the same way, and avoids
|
||||
// a slow path in Read() to have to handle reading zero bits.
|
||||
if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
|
||||
Data == 0) {
|
||||
Abbv->Add(BitCodeAbbrevOp(0));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
|
||||
Data > MaxChunkSize)
|
||||
report_fatal_error(
|
||||
"Fixed or VBR abbrev record with size > MaxChunkData");
|
||||
|
||||
Abbv->Add(BitCodeAbbrevOp(E, Data));
|
||||
} else
|
||||
Abbv->Add(BitCodeAbbrevOp(E));
|
||||
}
|
||||
|
||||
if (Abbv->getNumOperandInfos() == 0)
|
||||
report_fatal_error("Abbrev record with no operands");
|
||||
CurAbbrevs.push_back(std::move(Abbv));
|
||||
}
|
||||
|
||||
Optional<BitstreamBlockInfo>
|
||||
BitstreamCursor::ReadBlockInfoBlock(bool ReadBlockInfoNames) {
|
||||
if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return None;
|
||||
|
||||
BitstreamBlockInfo NewBlockInfo;
|
||||
|
||||
SmallVector<uint64_t, 64> Record;
|
||||
BitstreamBlockInfo::BlockInfo *CurBlockInfo = nullptr;
|
||||
|
||||
// Read all the records for this module.
|
||||
while (true) {
|
||||
BitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrevs);
|
||||
|
||||
switch (Entry.Kind) {
|
||||
case llvm::BitstreamEntry::SubBlock: // Handled for us already.
|
||||
case llvm::BitstreamEntry::Error:
|
||||
return None;
|
||||
case llvm::BitstreamEntry::EndBlock:
|
||||
return std::move(NewBlockInfo);
|
||||
case llvm::BitstreamEntry::Record:
|
||||
// The interesting case.
|
||||
break;
|
||||
}
|
||||
|
||||
// Read abbrev records, associate them with CurBID.
|
||||
if (Entry.ID == bitc::DEFINE_ABBREV) {
|
||||
if (!CurBlockInfo) return None;
|
||||
ReadAbbrevRecord();
|
||||
|
||||
// ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the
|
||||
// appropriate BlockInfo.
|
||||
CurBlockInfo->Abbrevs.push_back(std::move(CurAbbrevs.back()));
|
||||
CurAbbrevs.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Read a record.
|
||||
Record.clear();
|
||||
switch (readRecord(Entry.ID, Record)) {
|
||||
default: break; // Default behavior, ignore unknown content.
|
||||
case bitc::BLOCKINFO_CODE_SETBID:
|
||||
if (Record.size() < 1) return None;
|
||||
CurBlockInfo = &NewBlockInfo.getOrCreateBlockInfo((unsigned)Record[0]);
|
||||
break;
|
||||
case bitc::BLOCKINFO_CODE_BLOCKNAME: {
|
||||
if (!CurBlockInfo) return None;
|
||||
if (!ReadBlockInfoNames)
|
||||
break; // Ignore name.
|
||||
std::string Name;
|
||||
for (unsigned i = 0, e = Record.size(); i != e; ++i)
|
||||
Name += (char)Record[i];
|
||||
CurBlockInfo->Name = Name;
|
||||
break;
|
||||
}
|
||||
case bitc::BLOCKINFO_CODE_SETRECORDNAME: {
|
||||
if (!CurBlockInfo) return None;
|
||||
if (!ReadBlockInfoNames)
|
||||
break; // Ignore name.
|
||||
std::string Name;
|
||||
for (unsigned i = 1, e = Record.size(); i != e; ++i)
|
||||
Name += (char)Record[i];
|
||||
CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0],
|
||||
Name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
external/llvm/lib/Bitcode/Reader/CMakeLists.txt
vendored
13
external/llvm/lib/Bitcode/Reader/CMakeLists.txt
vendored
@ -1,13 +0,0 @@
|
||||
add_llvm_library(LLVMBitReader
|
||||
BitReader.cpp
|
||||
BitcodeReader.cpp
|
||||
BitstreamReader.cpp
|
||||
MetadataLoader.cpp
|
||||
ValueList.cpp
|
||||
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
${LLVM_MAIN_INCLUDE_DIR}/llvm/Bitcode
|
||||
|
||||
DEPENDS
|
||||
intrinsics_gen
|
||||
)
|
22
external/llvm/lib/Bitcode/Reader/LLVMBuild.txt
vendored
22
external/llvm/lib/Bitcode/Reader/LLVMBuild.txt
vendored
@ -1,22 +0,0 @@
|
||||
;===- ./lib/Bitcode/Reader/LLVMBuild.txt -----------------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
;
|
||||
; This is an LLVMBuild description file for the components in this subdirectory.
|
||||
;
|
||||
; For more information on the LLVMBuild system, please see:
|
||||
;
|
||||
; http://llvm.org/docs/LLVMBuild.html
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[component_0]
|
||||
type = Library
|
||||
name = BitReader
|
||||
parent = Bitcode
|
||||
required_libraries = Core Support
|
1977
external/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
vendored
1977
external/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
vendored
File diff suppressed because it is too large
Load Diff
@ -1,88 +0,0 @@
|
||||
//===-- Bitcode/Reader/MetadataLoader.h - Load Metadatas -------*- C++ -*-====//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This class handles loading Metadatas.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_BITCODE_READER_METADATALOADER_H
|
||||
#define LLVM_LIB_BITCODE_READER_METADATALOADER_H
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace llvm {
|
||||
class BitcodeReaderValueList;
|
||||
class BitstreamCursor;
|
||||
class DISubprogram;
|
||||
class Error;
|
||||
class Function;
|
||||
class Instruction;
|
||||
class Metadata;
|
||||
class MDNode;
|
||||
class Module;
|
||||
class Type;
|
||||
|
||||
/// Helper class that handles loading Metadatas and keeping them available.
|
||||
class MetadataLoader {
|
||||
class MetadataLoaderImpl;
|
||||
std::unique_ptr<MetadataLoaderImpl> Pimpl;
|
||||
Error parseMetadata(bool ModuleLevel);
|
||||
|
||||
public:
|
||||
~MetadataLoader();
|
||||
MetadataLoader(BitstreamCursor &Stream, Module &TheModule,
|
||||
BitcodeReaderValueList &ValueList, bool IsImporting,
|
||||
std::function<Type *(unsigned)> getTypeByID);
|
||||
MetadataLoader &operator=(MetadataLoader &&);
|
||||
MetadataLoader(MetadataLoader &&);
|
||||
|
||||
// Parse a module metadata block
|
||||
Error parseModuleMetadata() { return parseMetadata(true); }
|
||||
|
||||
// Parse a function metadata block
|
||||
Error parseFunctionMetadata() { return parseMetadata(false); }
|
||||
|
||||
/// Set the mode to strip TBAA metadata on load.
|
||||
void setStripTBAA(bool StripTBAA = true);
|
||||
|
||||
/// Return true if the Loader is stripping TBAA metadata.
|
||||
bool isStrippingTBAA();
|
||||
|
||||
// Return true there are remaining unresolved forward references.
|
||||
bool hasFwdRefs() const;
|
||||
|
||||
/// Return the given metadata, creating a replaceable forward reference if
|
||||
/// necessary.
|
||||
Metadata *getMetadataFwdRefOrLoad(unsigned Idx);
|
||||
|
||||
MDNode *getMDNodeFwdRefOrNull(unsigned Idx);
|
||||
|
||||
/// Return the DISubprogra metadata for a Function if any, null otherwise.
|
||||
DISubprogram *lookupSubprogramForFunction(Function *F);
|
||||
|
||||
/// Parse a `METADATA_ATTACHMENT` block for a function.
|
||||
Error parseMetadataAttachment(
|
||||
Function &F, const SmallVectorImpl<Instruction *> &InstructionList);
|
||||
|
||||
/// Parse a `METADATA_KIND` block for the current module.
|
||||
Error parseMetadataKinds();
|
||||
|
||||
unsigned size() const;
|
||||
void shrinkTo(unsigned N);
|
||||
|
||||
/// Perform bitcode upgrades on llvm.dbg.* calls.
|
||||
void upgradeDebugIntrinsics(Function &F);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H
|
216
external/llvm/lib/Bitcode/Reader/ValueList.cpp
vendored
216
external/llvm/lib/Bitcode/Reader/ValueList.cpp
vendored
@ -1,216 +0,0 @@
|
||||
//===- ValueList.cpp - Internal BitcodeReader implementation --------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ValueList.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/IR/Argument.h"
|
||||
#include "llvm/IR/Constant.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/GlobalValue.h"
|
||||
#include "llvm/IR/Instruction.h"
|
||||
#include "llvm/IR/Type.h"
|
||||
#include "llvm/IR/User.h"
|
||||
#include "llvm/IR/Value.h"
|
||||
#include "llvm/IR/ValueHandle.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace llvm {
|
||||
|
||||
namespace {
|
||||
|
||||
/// \brief A class for maintaining the slot number definition
|
||||
/// as a placeholder for the actual definition for forward constants defs.
|
||||
class ConstantPlaceHolder : public ConstantExpr {
|
||||
public:
|
||||
explicit ConstantPlaceHolder(Type *Ty, LLVMContext &Context)
|
||||
: ConstantExpr(Ty, Instruction::UserOp1, &Op<0>(), 1) {
|
||||
Op<0>() = UndefValue::get(Type::getInt32Ty(Context));
|
||||
}
|
||||
|
||||
ConstantPlaceHolder &operator=(const ConstantPlaceHolder &) = delete;
|
||||
|
||||
// allocate space for exactly one operand
|
||||
void *operator new(size_t s) { return User::operator new(s, 1); }
|
||||
|
||||
/// \brief Methods to support type inquiry through isa, cast, and dyn_cast.
|
||||
static bool classof(const Value *V) {
|
||||
return isa<ConstantExpr>(V) &&
|
||||
cast<ConstantExpr>(V)->getOpcode() == Instruction::UserOp1;
|
||||
}
|
||||
|
||||
/// Provide fast operand accessors
|
||||
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
// FIXME: can we inherit this from ConstantExpr?
|
||||
template <>
|
||||
struct OperandTraits<ConstantPlaceHolder>
|
||||
: public FixedNumOperandTraits<ConstantPlaceHolder, 1> {};
|
||||
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantPlaceHolder, Value)
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
void BitcodeReaderValueList::assignValue(Value *V, unsigned Idx) {
|
||||
if (Idx == size()) {
|
||||
push_back(V);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Idx >= size())
|
||||
resize(Idx + 1);
|
||||
|
||||
WeakTrackingVH &OldV = ValuePtrs[Idx];
|
||||
if (!OldV) {
|
||||
OldV = V;
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle constants and non-constants (e.g. instrs) differently for
|
||||
// efficiency.
|
||||
if (Constant *PHC = dyn_cast<Constant>(&*OldV)) {
|
||||
ResolveConstants.push_back(std::make_pair(PHC, Idx));
|
||||
OldV = V;
|
||||
} else {
|
||||
// If there was a forward reference to this value, replace it.
|
||||
Value *PrevVal = OldV;
|
||||
OldV->replaceAllUsesWith(V);
|
||||
PrevVal->deleteValue();
|
||||
}
|
||||
}
|
||||
|
||||
Constant *BitcodeReaderValueList::getConstantFwdRef(unsigned Idx, Type *Ty) {
|
||||
if (Idx >= size())
|
||||
resize(Idx + 1);
|
||||
|
||||
if (Value *V = ValuePtrs[Idx]) {
|
||||
if (Ty != V->getType())
|
||||
report_fatal_error("Type mismatch in constant table!");
|
||||
return cast<Constant>(V);
|
||||
}
|
||||
|
||||
// Create and return a placeholder, which will later be RAUW'd.
|
||||
Constant *C = new ConstantPlaceHolder(Ty, Context);
|
||||
ValuePtrs[Idx] = C;
|
||||
return C;
|
||||
}
|
||||
|
||||
Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, Type *Ty) {
|
||||
// Bail out for a clearly invalid value. This would make us call resize(0)
|
||||
if (Idx == std::numeric_limits<unsigned>::max())
|
||||
return nullptr;
|
||||
|
||||
if (Idx >= size())
|
||||
resize(Idx + 1);
|
||||
|
||||
if (Value *V = ValuePtrs[Idx]) {
|
||||
// If the types don't match, it's invalid.
|
||||
if (Ty && Ty != V->getType())
|
||||
return nullptr;
|
||||
return V;
|
||||
}
|
||||
|
||||
// No type specified, must be invalid reference.
|
||||
if (!Ty)
|
||||
return nullptr;
|
||||
|
||||
// Create and return a placeholder, which will later be RAUW'd.
|
||||
Value *V = new Argument(Ty);
|
||||
ValuePtrs[Idx] = V;
|
||||
return V;
|
||||
}
|
||||
|
||||
/// Once all constants are read, this method bulk resolves any forward
|
||||
/// references. The idea behind this is that we sometimes get constants (such
|
||||
/// as large arrays) which reference *many* forward ref constants. Replacing
|
||||
/// each of these causes a lot of thrashing when building/reuniquing the
|
||||
/// constant. Instead of doing this, we look at all the uses and rewrite all
|
||||
/// the place holders at once for any constant that uses a placeholder.
|
||||
void BitcodeReaderValueList::resolveConstantForwardRefs() {
|
||||
// Sort the values by-pointer so that they are efficient to look up with a
|
||||
// binary search.
|
||||
std::sort(ResolveConstants.begin(), ResolveConstants.end());
|
||||
|
||||
SmallVector<Constant *, 64> NewOps;
|
||||
|
||||
while (!ResolveConstants.empty()) {
|
||||
Value *RealVal = operator[](ResolveConstants.back().second);
|
||||
Constant *Placeholder = ResolveConstants.back().first;
|
||||
ResolveConstants.pop_back();
|
||||
|
||||
// Loop over all users of the placeholder, updating them to reference the
|
||||
// new value. If they reference more than one placeholder, update them all
|
||||
// at once.
|
||||
while (!Placeholder->use_empty()) {
|
||||
auto UI = Placeholder->user_begin();
|
||||
User *U = *UI;
|
||||
|
||||
// If the using object isn't uniqued, just update the operands. This
|
||||
// handles instructions and initializers for global variables.
|
||||
if (!isa<Constant>(U) || isa<GlobalValue>(U)) {
|
||||
UI.getUse().set(RealVal);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Otherwise, we have a constant that uses the placeholder. Replace that
|
||||
// constant with a new constant that has *all* placeholder uses updated.
|
||||
Constant *UserC = cast<Constant>(U);
|
||||
for (User::op_iterator I = UserC->op_begin(), E = UserC->op_end(); I != E;
|
||||
++I) {
|
||||
Value *NewOp;
|
||||
if (!isa<ConstantPlaceHolder>(*I)) {
|
||||
// Not a placeholder reference.
|
||||
NewOp = *I;
|
||||
} else if (*I == Placeholder) {
|
||||
// Common case is that it just references this one placeholder.
|
||||
NewOp = RealVal;
|
||||
} else {
|
||||
// Otherwise, look up the placeholder in ResolveConstants.
|
||||
ResolveConstantsTy::iterator It = std::lower_bound(
|
||||
ResolveConstants.begin(), ResolveConstants.end(),
|
||||
std::pair<Constant *, unsigned>(cast<Constant>(*I), 0));
|
||||
assert(It != ResolveConstants.end() && It->first == *I);
|
||||
NewOp = operator[](It->second);
|
||||
}
|
||||
|
||||
NewOps.push_back(cast<Constant>(NewOp));
|
||||
}
|
||||
|
||||
// Make the new constant.
|
||||
Constant *NewC;
|
||||
if (ConstantArray *UserCA = dyn_cast<ConstantArray>(UserC)) {
|
||||
NewC = ConstantArray::get(UserCA->getType(), NewOps);
|
||||
} else if (ConstantStruct *UserCS = dyn_cast<ConstantStruct>(UserC)) {
|
||||
NewC = ConstantStruct::get(UserCS->getType(), NewOps);
|
||||
} else if (isa<ConstantVector>(UserC)) {
|
||||
NewC = ConstantVector::get(NewOps);
|
||||
} else {
|
||||
assert(isa<ConstantExpr>(UserC) && "Must be a ConstantExpr.");
|
||||
NewC = cast<ConstantExpr>(UserC)->getWithOperands(NewOps);
|
||||
}
|
||||
|
||||
UserC->replaceAllUsesWith(NewC);
|
||||
UserC->destroyConstant();
|
||||
NewOps.clear();
|
||||
}
|
||||
|
||||
// Update all ValueHandles, they should be the only users at this point.
|
||||
Placeholder->replaceAllUsesWith(RealVal);
|
||||
Placeholder->deleteValue();
|
||||
}
|
||||
}
|
86
external/llvm/lib/Bitcode/Reader/ValueList.h
vendored
86
external/llvm/lib/Bitcode/Reader/ValueList.h
vendored
@ -1,86 +0,0 @@
|
||||
//===-- Bitcode/Reader/ValueList.h - Number values --------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This class gives values and types Unique ID's.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_BITCODE_READER_VALUELIST_H
|
||||
#define LLVM_LIB_BITCODE_READER_VALUELIST_H
|
||||
|
||||
#include "llvm/IR/ValueHandle.h"
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class Constant;
|
||||
class LLVMContext;
|
||||
class Type;
|
||||
class Value;
|
||||
|
||||
class BitcodeReaderValueList {
|
||||
std::vector<WeakTrackingVH> ValuePtrs;
|
||||
|
||||
/// As we resolve forward-referenced constants, we add information about them
|
||||
/// to this vector. This allows us to resolve them in bulk instead of
|
||||
/// resolving each reference at a time. See the code in
|
||||
/// ResolveConstantForwardRefs for more information about this.
|
||||
///
|
||||
/// The key of this vector is the placeholder constant, the value is the slot
|
||||
/// number that holds the resolved value.
|
||||
using ResolveConstantsTy = std::vector<std::pair<Constant *, unsigned>>;
|
||||
ResolveConstantsTy ResolveConstants;
|
||||
LLVMContext &Context;
|
||||
|
||||
public:
|
||||
BitcodeReaderValueList(LLVMContext &C) : Context(C) {}
|
||||
|
||||
~BitcodeReaderValueList() {
|
||||
assert(ResolveConstants.empty() && "Constants not resolved?");
|
||||
}
|
||||
|
||||
// vector compatibility methods
|
||||
unsigned size() const { return ValuePtrs.size(); }
|
||||
void resize(unsigned N) { ValuePtrs.resize(N); }
|
||||
void push_back(Value *V) { ValuePtrs.emplace_back(V); }
|
||||
|
||||
void clear() {
|
||||
assert(ResolveConstants.empty() && "Constants not resolved?");
|
||||
ValuePtrs.clear();
|
||||
}
|
||||
|
||||
Value *operator[](unsigned i) const {
|
||||
assert(i < ValuePtrs.size());
|
||||
return ValuePtrs[i];
|
||||
}
|
||||
|
||||
Value *back() const { return ValuePtrs.back(); }
|
||||
void pop_back() { ValuePtrs.pop_back(); }
|
||||
bool empty() const { return ValuePtrs.empty(); }
|
||||
|
||||
void shrinkTo(unsigned N) {
|
||||
assert(N <= size() && "Invalid shrinkTo request!");
|
||||
ValuePtrs.resize(N);
|
||||
}
|
||||
|
||||
Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
|
||||
Value *getValueFwdRef(unsigned Idx, Type *Ty);
|
||||
|
||||
void assignValue(Value *V, unsigned Idx);
|
||||
|
||||
/// Once all constants are read, this method bulk resolves any forward
|
||||
/// references.
|
||||
void resolveConstantForwardRefs();
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_LIB_BITCODE_READER_VALUELIST_H
|
50
external/llvm/lib/Bitcode/Writer/BitWriter.cpp
vendored
50
external/llvm/lib/Bitcode/Writer/BitWriter.cpp
vendored
@ -1,50 +0,0 @@
|
||||
//===-- BitWriter.cpp -----------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm-c/BitWriter.h"
|
||||
#include "llvm/Bitcode/BitcodeWriter.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
using namespace llvm;
|
||||
|
||||
|
||||
/*===-- Operations on modules ---------------------------------------------===*/
|
||||
|
||||
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
|
||||
std::error_code EC;
|
||||
raw_fd_ostream OS(Path, EC, sys::fs::F_None);
|
||||
|
||||
if (EC)
|
||||
return -1;
|
||||
|
||||
WriteBitcodeToFile(unwrap(M), OS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
|
||||
int Unbuffered) {
|
||||
raw_fd_ostream OS(FD, ShouldClose, Unbuffered);
|
||||
|
||||
WriteBitcodeToFile(unwrap(M), OS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
|
||||
return LLVMWriteBitcodeToFD(M, FileHandle, true, false);
|
||||
}
|
||||
|
||||
LLVMMemoryBufferRef LLVMWriteBitcodeToMemoryBuffer(LLVMModuleRef M) {
|
||||
std::string Data;
|
||||
raw_string_ostream OS(Data);
|
||||
|
||||
WriteBitcodeToFile(unwrap(M), OS);
|
||||
return wrap(MemoryBuffer::getMemBufferCopy(OS.str()).release());
|
||||
}
|
@ -1 +0,0 @@
|
||||
7bf37857eb9725542edd45f022546e7df6bcb3b8
|
@ -1,82 +0,0 @@
|
||||
//===- BitcodeWriterPass.cpp - Bitcode writing pass -----------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// BitcodeWriterPass implementation.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Bitcode/BitcodeWriterPass.h"
|
||||
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
|
||||
#include "llvm/Bitcode/BitcodeWriter.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/Pass.h"
|
||||
using namespace llvm;
|
||||
|
||||
PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
|
||||
const ModuleSummaryIndex *Index =
|
||||
EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
|
||||
: nullptr;
|
||||
WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
||||
namespace {
|
||||
class WriteBitcodePass : public ModulePass {
|
||||
raw_ostream &OS; // raw_ostream to print on
|
||||
bool ShouldPreserveUseListOrder;
|
||||
bool EmitSummaryIndex;
|
||||
bool EmitModuleHash;
|
||||
|
||||
public:
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
WriteBitcodePass() : ModulePass(ID), OS(dbgs()) {
|
||||
initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder,
|
||||
bool EmitSummaryIndex, bool EmitModuleHash)
|
||||
: ModulePass(ID), OS(o),
|
||||
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
|
||||
EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {
|
||||
initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
StringRef getPassName() const override { return "Bitcode Writer"; }
|
||||
|
||||
bool runOnModule(Module &M) override {
|
||||
const ModuleSummaryIndex *Index =
|
||||
EmitSummaryIndex
|
||||
? &(getAnalysis<ModuleSummaryIndexWrapperPass>().getIndex())
|
||||
: nullptr;
|
||||
WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, Index,
|
||||
EmitModuleHash);
|
||||
return false;
|
||||
}
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.setPreservesAll();
|
||||
if (EmitSummaryIndex)
|
||||
AU.addRequired<ModuleSummaryIndexWrapperPass>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
char WriteBitcodePass::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
|
||||
true)
|
||||
INITIALIZE_PASS_DEPENDENCY(ModuleSummaryIndexWrapperPass)
|
||||
INITIALIZE_PASS_END(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
|
||||
true)
|
||||
|
||||
ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str,
|
||||
bool ShouldPreserveUseListOrder,
|
||||
bool EmitSummaryIndex, bool EmitModuleHash) {
|
||||
return new WriteBitcodePass(Str, ShouldPreserveUseListOrder,
|
||||
EmitSummaryIndex, EmitModuleHash);
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
add_llvm_library(LLVMBitWriter
|
||||
BitWriter.cpp
|
||||
BitcodeWriter.cpp
|
||||
BitcodeWriterPass.cpp
|
||||
ValueEnumerator.cpp
|
||||
|
||||
DEPENDS
|
||||
intrinsics_gen
|
||||
)
|
22
external/llvm/lib/Bitcode/Writer/LLVMBuild.txt
vendored
22
external/llvm/lib/Bitcode/Writer/LLVMBuild.txt
vendored
@ -1,22 +0,0 @@
|
||||
;===- ./lib/Bitcode/Writer/LLVMBuild.txt -----------------------*- Conf -*--===;
|
||||
;
|
||||
; The LLVM Compiler Infrastructure
|
||||
;
|
||||
; This file is distributed under the University of Illinois Open Source
|
||||
; License. See LICENSE.TXT for details.
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
;
|
||||
; This is an LLVMBuild description file for the components in this subdirectory.
|
||||
;
|
||||
; For more information on the LLVMBuild system, please see:
|
||||
;
|
||||
; http://llvm.org/docs/LLVMBuild.html
|
||||
;
|
||||
;===------------------------------------------------------------------------===;
|
||||
|
||||
[component_0]
|
||||
type = Library
|
||||
name = BitWriter
|
||||
parent = Bitcode
|
||||
required_libraries = Analysis Core MC Object Support
|
1040
external/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
vendored
1040
external/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
vendored
File diff suppressed because it is too large
Load Diff
304
external/llvm/lib/Bitcode/Writer/ValueEnumerator.h
vendored
304
external/llvm/lib/Bitcode/Writer/ValueEnumerator.h
vendored
@ -1,304 +0,0 @@
|
||||
//===- Bitcode/Writer/ValueEnumerator.h - Number values ---------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This class gives values and types Unique ID's.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H
|
||||
#define LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/UniqueVector.h"
|
||||
#include "llvm/IR/Attributes.h"
|
||||
#include "llvm/IR/Metadata.h"
|
||||
#include "llvm/IR/Type.h"
|
||||
#include "llvm/IR/UseListOrder.h"
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class BasicBlock;
|
||||
class Comdat;
|
||||
class Function;
|
||||
class Instruction;
|
||||
class LocalAsMetadata;
|
||||
class MDNode;
|
||||
class Metadata;
|
||||
class Module;
|
||||
class NamedMDNode;
|
||||
class raw_ostream;
|
||||
class Type;
|
||||
class Value;
|
||||
class ValueSymbolTable;
|
||||
|
||||
class ValueEnumerator {
|
||||
public:
|
||||
using TypeList = std::vector<Type *>;
|
||||
|
||||
// For each value, we remember its Value* and occurrence frequency.
|
||||
using ValueList = std::vector<std::pair<const Value *, unsigned>>;
|
||||
|
||||
/// Attribute groups as encoded in bitcode are almost AttributeSets, but they
|
||||
/// include the AttributeList index, so we have to track that in our map.
|
||||
using IndexAndAttrSet = std::pair<unsigned, AttributeSet>;
|
||||
|
||||
UseListOrderStack UseListOrders;
|
||||
|
||||
private:
|
||||
using TypeMapType = DenseMap<Type *, unsigned>;
|
||||
TypeMapType TypeMap;
|
||||
TypeList Types;
|
||||
|
||||
using ValueMapType = DenseMap<const Value *, unsigned>;
|
||||
ValueMapType ValueMap;
|
||||
ValueList Values;
|
||||
|
||||
using ComdatSetType = UniqueVector<const Comdat *>;
|
||||
ComdatSetType Comdats;
|
||||
|
||||
std::vector<const Metadata *> MDs;
|
||||
std::vector<const Metadata *> FunctionMDs;
|
||||
|
||||
/// Index of information about a piece of metadata.
|
||||
struct MDIndex {
|
||||
unsigned F = 0; ///< The ID of the function for this metadata, if any.
|
||||
unsigned ID = 0; ///< The implicit ID of this metadata in bitcode.
|
||||
|
||||
MDIndex() = default;
|
||||
explicit MDIndex(unsigned F) : F(F) {}
|
||||
|
||||
/// Check if this has a function tag, and it's different from NewF.
|
||||
bool hasDifferentFunction(unsigned NewF) const { return F && F != NewF; }
|
||||
|
||||
/// Fetch the MD this references out of the given metadata array.
|
||||
const Metadata *get(ArrayRef<const Metadata *> MDs) const {
|
||||
assert(ID && "Expected non-zero ID");
|
||||
assert(ID <= MDs.size() && "Expected valid ID");
|
||||
return MDs[ID - 1];
|
||||
}
|
||||
};
|
||||
|
||||
using MetadataMapType = DenseMap<const Metadata *, MDIndex>;
|
||||
MetadataMapType MetadataMap;
|
||||
|
||||
/// Range of metadata IDs, as a half-open range.
|
||||
struct MDRange {
|
||||
unsigned First = 0;
|
||||
unsigned Last = 0;
|
||||
|
||||
/// Number of strings in the prefix of the metadata range.
|
||||
unsigned NumStrings = 0;
|
||||
|
||||
MDRange() = default;
|
||||
explicit MDRange(unsigned First) : First(First) {}
|
||||
};
|
||||
SmallDenseMap<unsigned, MDRange, 1> FunctionMDInfo;
|
||||
|
||||
bool ShouldPreserveUseListOrder;
|
||||
|
||||
using AttributeGroupMapType = DenseMap<IndexAndAttrSet, unsigned>;
|
||||
AttributeGroupMapType AttributeGroupMap;
|
||||
std::vector<IndexAndAttrSet> AttributeGroups;
|
||||
|
||||
using AttributeListMapType = DenseMap<AttributeList, unsigned>;
|
||||
AttributeListMapType AttributeListMap;
|
||||
std::vector<AttributeList> AttributeLists;
|
||||
|
||||
/// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
|
||||
/// the "getGlobalBasicBlockID" method.
|
||||
mutable DenseMap<const BasicBlock*, unsigned> GlobalBasicBlockIDs;
|
||||
|
||||
using InstructionMapType = DenseMap<const Instruction *, unsigned>;
|
||||
InstructionMapType InstructionMap;
|
||||
unsigned InstructionCount;
|
||||
|
||||
/// BasicBlocks - This contains all the basic blocks for the currently
|
||||
/// incorporated function. Their reverse mapping is stored in ValueMap.
|
||||
std::vector<const BasicBlock*> BasicBlocks;
|
||||
|
||||
/// When a function is incorporated, this is the size of the Values list
|
||||
/// before incorporation.
|
||||
unsigned NumModuleValues;
|
||||
|
||||
/// When a function is incorporated, this is the size of the Metadatas list
|
||||
/// before incorporation.
|
||||
unsigned NumModuleMDs = 0;
|
||||
unsigned NumMDStrings = 0;
|
||||
|
||||
unsigned FirstFuncConstantID;
|
||||
unsigned FirstInstID;
|
||||
|
||||
public:
|
||||
ValueEnumerator(const Module &M, bool ShouldPreserveUseListOrder);
|
||||
ValueEnumerator(const ValueEnumerator &) = delete;
|
||||
ValueEnumerator &operator=(const ValueEnumerator &) = delete;
|
||||
|
||||
void dump() const;
|
||||
void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const;
|
||||
void print(raw_ostream &OS, const MetadataMapType &Map,
|
||||
const char *Name) const;
|
||||
|
||||
unsigned getValueID(const Value *V) const;
|
||||
|
||||
unsigned getMetadataID(const Metadata *MD) const {
|
||||
auto ID = getMetadataOrNullID(MD);
|
||||
assert(ID != 0 && "Metadata not in slotcalculator!");
|
||||
return ID - 1;
|
||||
}
|
||||
|
||||
unsigned getMetadataOrNullID(const Metadata *MD) const {
|
||||
return MetadataMap.lookup(MD).ID;
|
||||
}
|
||||
|
||||
unsigned numMDs() const { return MDs.size(); }
|
||||
|
||||
bool shouldPreserveUseListOrder() const { return ShouldPreserveUseListOrder; }
|
||||
|
||||
unsigned getTypeID(Type *T) const {
|
||||
TypeMapType::const_iterator I = TypeMap.find(T);
|
||||
assert(I != TypeMap.end() && "Type not in ValueEnumerator!");
|
||||
return I->second-1;
|
||||
}
|
||||
|
||||
unsigned getInstructionID(const Instruction *I) const;
|
||||
void setInstructionID(const Instruction *I);
|
||||
|
||||
unsigned getAttributeListID(AttributeList PAL) const {
|
||||
if (PAL.isEmpty()) return 0; // Null maps to zero.
|
||||
AttributeListMapType::const_iterator I = AttributeListMap.find(PAL);
|
||||
assert(I != AttributeListMap.end() && "Attribute not in ValueEnumerator!");
|
||||
return I->second;
|
||||
}
|
||||
|
||||
unsigned getAttributeGroupID(IndexAndAttrSet Group) const {
|
||||
if (!Group.second.hasAttributes())
|
||||
return 0; // Null maps to zero.
|
||||
AttributeGroupMapType::const_iterator I = AttributeGroupMap.find(Group);
|
||||
assert(I != AttributeGroupMap.end() && "Attribute not in ValueEnumerator!");
|
||||
return I->second;
|
||||
}
|
||||
|
||||
/// getFunctionConstantRange - Return the range of values that corresponds to
|
||||
/// function-local constants.
|
||||
void getFunctionConstantRange(unsigned &Start, unsigned &End) const {
|
||||
Start = FirstFuncConstantID;
|
||||
End = FirstInstID;
|
||||
}
|
||||
|
||||
const ValueList &getValues() const { return Values; }
|
||||
|
||||
/// Check whether the current block has any metadata to emit.
|
||||
bool hasMDs() const { return NumModuleMDs < MDs.size(); }
|
||||
|
||||
/// Get the MDString metadata for this block.
|
||||
ArrayRef<const Metadata *> getMDStrings() const {
|
||||
return makeArrayRef(MDs).slice(NumModuleMDs, NumMDStrings);
|
||||
}
|
||||
|
||||
/// Get the non-MDString metadata for this block.
|
||||
ArrayRef<const Metadata *> getNonMDStrings() const {
|
||||
return makeArrayRef(MDs).slice(NumModuleMDs).slice(NumMDStrings);
|
||||
}
|
||||
|
||||
const TypeList &getTypes() const { return Types; }
|
||||
|
||||
const std::vector<const BasicBlock*> &getBasicBlocks() const {
|
||||
return BasicBlocks;
|
||||
}
|
||||
|
||||
const std::vector<AttributeList> &getAttributeLists() const { return AttributeLists; }
|
||||
|
||||
const std::vector<IndexAndAttrSet> &getAttributeGroups() const {
|
||||
return AttributeGroups;
|
||||
}
|
||||
|
||||
const ComdatSetType &getComdats() const { return Comdats; }
|
||||
unsigned getComdatID(const Comdat *C) const;
|
||||
|
||||
/// getGlobalBasicBlockID - This returns the function-specific ID for the
|
||||
/// specified basic block. This is relatively expensive information, so it
|
||||
/// should only be used by rare constructs such as address-of-label.
|
||||
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const;
|
||||
|
||||
/// incorporateFunction/purgeFunction - If you'd like to deal with a function,
|
||||
/// use these two methods to get its data into the ValueEnumerator!
|
||||
void incorporateFunction(const Function &F);
|
||||
|
||||
void purgeFunction();
|
||||
uint64_t computeBitsRequiredForTypeIndicies() const;
|
||||
|
||||
private:
|
||||
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
|
||||
|
||||
/// Reorder the reachable metadata.
|
||||
///
|
||||
/// This is not just an optimization, but is mandatory for emitting MDString
|
||||
/// correctly.
|
||||
void organizeMetadata();
|
||||
|
||||
/// Drop the function tag from the transitive operands of the given node.
|
||||
void dropFunctionFromMetadata(MetadataMapType::value_type &FirstMD);
|
||||
|
||||
/// Incorporate the function metadata.
|
||||
///
|
||||
/// This should be called before enumerating LocalAsMetadata for the
|
||||
/// function.
|
||||
void incorporateFunctionMetadata(const Function &F);
|
||||
|
||||
/// Enumerate a single instance of metadata with the given function tag.
|
||||
///
|
||||
/// If \c MD has already been enumerated, check that \c F matches its
|
||||
/// function tag. If not, call \a dropFunctionFromMetadata().
|
||||
///
|
||||
/// Otherwise, mark \c MD as visited. Assign it an ID, or just return it if
|
||||
/// it's an \a MDNode.
|
||||
const MDNode *enumerateMetadataImpl(unsigned F, const Metadata *MD);
|
||||
|
||||
unsigned getMetadataFunctionID(const Function *F) const;
|
||||
|
||||
/// Enumerate reachable metadata in (almost) post-order.
|
||||
///
|
||||
/// Enumerate all the metadata reachable from MD. We want to minimize the
|
||||
/// cost of reading bitcode records, and so the primary consideration is that
|
||||
/// operands of uniqued nodes are resolved before the nodes are read. This
|
||||
/// avoids re-uniquing them on the context and factors away RAUW support.
|
||||
///
|
||||
/// This algorithm guarantees that subgraphs of uniqued nodes are in
|
||||
/// post-order. Distinct subgraphs reachable only from a single uniqued node
|
||||
/// will be in post-order.
|
||||
///
|
||||
/// \note The relative order of a distinct and uniqued node is irrelevant.
|
||||
/// \a organizeMetadata() will later partition distinct nodes ahead of
|
||||
/// uniqued ones.
|
||||
///{
|
||||
void EnumerateMetadata(const Function *F, const Metadata *MD);
|
||||
void EnumerateMetadata(unsigned F, const Metadata *MD);
|
||||
///}
|
||||
|
||||
void EnumerateFunctionLocalMetadata(const Function &F,
|
||||
const LocalAsMetadata *Local);
|
||||
void EnumerateFunctionLocalMetadata(unsigned F, const LocalAsMetadata *Local);
|
||||
void EnumerateNamedMDNode(const NamedMDNode *NMD);
|
||||
void EnumerateValue(const Value *V);
|
||||
void EnumerateType(Type *T);
|
||||
void EnumerateOperandType(const Value *V);
|
||||
void EnumerateAttributes(AttributeList PAL);
|
||||
|
||||
void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
|
||||
void EnumerateNamedMetadata(const Module &M);
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H
|
Reference in New Issue
Block a user