LLVM API Documentation
#include <Reader.h>
Inheritance diagram for llvm::BytecodeReader:
Public Types | |
Types | |
typedef const unsigned char * | BufPtr |
A convenience type for the buffer pointer. | |
typedef std::vector< PATypeHolder > | TypeListTy |
The type used for a vector of potentially abstract types. | |
typedef std::vector< ValueList * > | ValueTable |
A 2 dimensional table of values. | |
typedef std::map< std::pair< unsigned, unsigned >, Constant * > | ConstantRefsType |
A mapping of a Type/slot pair to a Constant*. | |
typedef std::map< Function *, LazyFunctionInfo > | LazyFunctionMap |
A mapping of functions to their LazyFunctionInfo for lazy reading. | |
typedef std::vector< std::pair< GlobalVariable *, unsigned > > | GlobalInitsList |
A list of global variables and the slot number that initializes them. | |
typedef std::map< std::pair< unsigned, unsigned >, Value * > | ForwardReferenceMap |
A map for dealing with forward references of values. | |
Public Member Functions | |
Methods | |
void | ParseBytecode (const unsigned char *Buf, unsigned Length, const std::string &ModuleID) |
Main interface to parsing a bytecode buffer. | |
void | ParseAllFunctionBodies () |
Parse all function bodies. | |
void | ParseFunction (Function *Func) |
Parse the next function of specific type. | |
virtual bool | materializeFunction (Function *F, std::string *ErrInfo=0) |
Make a specific function materialize. | |
virtual Module * | materializeModule (std::string *ErrInfo=0) |
Make the whole module materialize. | |
Module * | releaseModule (std::string *ErrInfo=0) |
Release our hold on the generated module. | |
Protected Member Functions | |
Parsing Units For Subclasses | |
void | ParseModule () |
Parse whole module scope. | |
void | ParseVersionInfo () |
Parse the version information block. | |
void | ParseModuleGlobalInfo () |
Parse the ModuleGlobalInfo block. | |
void | ParseSymbolTable (Function *Func, SymbolTable *ST) |
Parse a symbol table. | |
void | ParseFunctionLazily () |
Parse functions lazily. | |
void | ParseFunctionBody (Function *Func) |
Parse a function body. | |
void | ParseCompactionTypes (unsigned NumEntries) |
Parse the type list portion of a compaction table. | |
void | ParseCompactionTable () |
Parse a compaction table. | |
void | ParseGlobalTypes () |
Parse global types. | |
BasicBlock * | ParseBasicBlock (unsigned BlockNo) |
Parse a basic block (for LLVM 1.0 basic block blocks). | |
unsigned | ParseInstructionList (Function *F) |
parse an instruction list (for post LLVM 1.0 instruction lists with blocks differentiated by terminating instructions. | |
void | ParseInstruction (std::vector< unsigned > &Args, BasicBlock *BB) |
Parse a single instruction. | |
void | ParseConstantPool (ValueTable &Values, TypeListTy &Types, bool isFunction) |
Parse the whole constant pool. | |
Value * | ParseConstantPoolValue (unsigned TypeID) |
Parse a single constant pool value. | |
void | ParseTypes (TypeListTy &Tab, unsigned NumEntries) |
Parse a block of types constants. | |
const Type * | ParseType () |
Parse a single type constant. | |
void | ParseStringConstants (unsigned NumEntries, ValueTable &Tab) |
Parse a string constants block. | |
Classes | |
struct | LazyFunctionInfo |
Keeps pointers to function contents for later use. More... | |
class | ValueList |
A list of values as a User of those Values. More... |
This class defines the interface for parsing a buffer of bytecode. The parser itself takes no action except to call the various functions of the handler interface. The parser's sole responsibility is the correct interpretation of the bytecode buffer. The handler is responsible for instantiating and keeping track of all values. As a convenience, the parser is responsible for materializing types and will pass them through the handler interface as necessary.
Definition at line 41 of file lib/Bytecode/Reader/Reader.h.
typedef const unsigned char* llvm::BytecodeReader::BufPtr |
A convenience type for the buffer pointer.
Definition at line 66 of file lib/Bytecode/Reader/Reader.h.
typedef std::vector<PATypeHolder> llvm::BytecodeReader::TypeListTy |
The type used for a vector of potentially abstract types.
Definition at line 69 of file lib/Bytecode/Reader/Reader.h.
typedef std::vector<ValueList*> llvm::BytecodeReader::ValueTable |
typedef std::map<std::pair<unsigned,unsigned>, Constant*> llvm::BytecodeReader::ConstantRefsType |
A mapping of a Type/slot pair to a Constant*.
This map is needed so that forward references to constants can be looked up by Type and slot number when resolving those references.
Definition at line 110 of file lib/Bytecode/Reader/Reader.h.
typedef std::map<Function*, LazyFunctionInfo> llvm::BytecodeReader::LazyFunctionMap |
A mapping of functions to their LazyFunctionInfo for lazy reading.
Definition at line 124 of file lib/Bytecode/Reader/Reader.h.
typedef std::vector<std::pair<GlobalVariable*, unsigned> > llvm::BytecodeReader::GlobalInitsList |
A list of global variables and the slot number that initializes them.
Definition at line 128 of file lib/Bytecode/Reader/Reader.h.
typedef std::map<std::pair<unsigned,unsigned>,Value*> llvm::BytecodeReader::ForwardReferenceMap |
A map for dealing with forward references of values.
This type maps a typeslot/valueslot pair to the corresponding Value*. It is used for dealing with forward references as values are read in.
Definition at line 133 of file lib/Bytecode/Reader/Reader.h.
llvm::BytecodeReader::BytecodeReader | ( | BytecodeHandler * | h = 0 |
) | [inline] |
Default constructor. By default, no handler is used.
Definition at line 47 of file lib/Bytecode/Reader/Reader.h.
llvm::BytecodeReader::~BytecodeReader | ( | ) | [inline] |
Definition at line 52 of file lib/Bytecode/Reader/Reader.h.
llvm::BytecodeReader::BytecodeReader | ( | BytecodeHandler * | h = 0 |
) | [inline] |
Default constructor. By default, no handler is used.
Definition at line 47 of file lib/Bytecode/Reader/Reader.h.
llvm::BytecodeReader::~BytecodeReader | ( | ) | [inline] |
Definition at line 52 of file lib/Bytecode/Reader/Reader.h.
void BytecodeReader::ParseBytecode | ( | const unsigned char * | Buf, | |
unsigned | Length, | |||
const std::string & | ModuleID | |||
) |
Main interface to parsing a bytecode buffer.
This function completely parses a bytecode buffer given by the Buf
and Length
parameters.
Buf | Beginning of the bytecode buffer |
Length | Length of the bytecode buffer |
ModuleID | An identifier for the module constructed. |
Definition at line 2406 of file Reader.cpp.
References llvm::Compressor::decompressToNewBuffer(), llvm::BytecodeFormat::ModuleBlockID, ParseModule(), llvm::ModuleProvider::TheModule, llvm::UpgradeIntrinsicFunction(), llvm::utohexstr(), and llvm::utostr().
void BytecodeReader::ParseAllFunctionBodies | ( | ) |
Parse all function bodies.
The ParseAllFunctionBodies method parses through all the previously unparsed functions in the bytecode file. If you want to completely parse a bytecode file, this method should be called after Parsebytecode because Parsebytecode only records the locations in the bytecode file of where the function definitions are located. This function uses that information to materialize the functions.
Definition at line 1974 of file Reader.cpp.
References Func, and ParseFunctionBody().
Referenced by materializeModule().
void BytecodeReader::ParseFunction | ( | Function * | Func | ) |
Parse the next function of specific type.
The ParserFunction method lazily parses one function. Use this method to casue the parser to parse a specific function in the module. Note that this will remove the function from what is to be included by ParseAllFunctionBodies.
Definition at line 1948 of file Reader.cpp.
References Func, llvm::Type::getDescription(), llvm::GlobalValue::getType(), and ParseFunctionBody().
Referenced by materializeFunction().
virtual bool llvm::BytecodeReader::materializeFunction | ( | Function * | F, | |
std::string * | ErrInfo = 0 | |||
) | [inline, virtual] |
Make a specific function materialize.
This method is abstract in the parent ModuleProvider class. Its implementation is identical to the ParseFunction method.
Implements llvm::ModuleProvider.
Definition at line 156 of file lib/Bytecode/Reader/Reader.h.
References F, and ParseFunction().
virtual Module* llvm::BytecodeReader::materializeModule | ( | std::string * | ErrInfo = 0 |
) | [inline, virtual] |
Make the whole module materialize.
This method is abstract in the parent ModuleProvider class. Its implementation is identical to ParseAllFunctionBodies.
Implements llvm::ModuleProvider.
Definition at line 174 of file lib/Bytecode/Reader/Reader.h.
References ParseAllFunctionBodies(), and llvm::ModuleProvider::TheModule.
Module* llvm::BytecodeReader::releaseModule | ( | std::string * | ErrInfo = 0 |
) | [inline, virtual] |
Release our hold on the generated module.
This method is provided by the parent ModuleProvde class and overriden here. It simply releases the module from its provided and frees up our state.
Reimplemented from llvm::ModuleProvider.
Definition at line 190 of file lib/Bytecode/Reader/Reader.h.
References M, and llvm::ModuleProvider::releaseModule().
void BytecodeReader::ParseModule | ( | ) | [protected] |
Parse whole module scope.
Make sure we pulled them all out. If we didn't then there's a declaration but a missing body. That's not allowed.
Definition at line 2317 of file Reader.cpp.
References llvm::BytecodeFormat::ConstantPoolBlockID, llvm::BytecodeFormat::FunctionBlockID, llvm::SequentialType::getElementType(), llvm::Module::getSymbolTable(), llvm::GlobalValue::getType(), llvm::BytecodeFormat::GlobalTypePlaneBlockID, GV, llvm::BytecodeFormat::ModuleGlobalInfoBlockID, ParseConstantPool(), ParseFunctionLazily(), ParseGlobalTypes(), ParseModuleGlobalInfo(), ParseSymbolTable(), ParseVersionInfo(), llvm::BytecodeFormat::SymbolTableBlockID, llvm::ModuleProvider::TheModule, and llvm::utostr().
Referenced by ParseBytecode().
void BytecodeReader::ParseVersionInfo | ( | ) | [protected] |
Parse the version information block.
Parse the version information and decode it by setting flags on the Reader that enable backward compatibility of the reader.
Definition at line 2199 of file Reader.cpp.
References llvm::Module::AnyEndianness, llvm::Module::AnyPointerSize, llvm::Module::BigEndian, llvm::itostr(), llvm::Module::LittleEndian, llvm::Module::Pointer32, llvm::Module::Pointer64, llvm::DS::PointerSize, llvm::Module::setEndianness(), llvm::Module::setPointerSize(), and llvm::ModuleProvider::TheModule.
Referenced by ParseModule().
void BytecodeReader::ParseModuleGlobalInfo | ( | ) | [protected] |
Parse the ModuleGlobalInfo block.
SectionNames - This contains the list of section names encoded in the moduleinfoblock. Functions and globals with an explicit section index into this to get their section name.
Definition at line 2002 of file Reader.cpp.
References llvm::Module::addLibrary(), llvm::GlobalValue::AppendingLinkage, E, llvm::GlobalValue::ExternalLinkage, Func, GV, llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::LinkOnceLinkage, llvm::GlobalValue::setAlignment(), llvm::Module::setModuleInlineAsm(), llvm::Module::setTargetTriple(), llvm::ModuleProvider::TheModule, Ty, U, llvm::utostr(), llvm::Type::VoidTyID, and llvm::GlobalValue::WeakLinkage.
Referenced by ParseModule().
void BytecodeReader::ParseSymbolTable | ( | Function * | CurrentFunction, | |
SymbolTable * | ST | |||
) | [protected] |
Parse a symbol table.
Parse a symbol table. This works for both module level and function level symbol tables. For function level symbol tables, the CurrentFunction parameter must be non-zero and the ST parameter must correspond to CurrentFunction's symbol table. For Module level symbol tables, the CurrentFunction argument must be zero.
In LLVM 1.3 we write types separately from values so The types are always first in the symbol table. This is because Type no longer derives from Value.
Definition at line 1146 of file Reader.cpp.
References E, llvm::SymbolTable::insert(), llvm::Type::LabelTyID, Name, T, and V.
Referenced by ParseFunctionBody(), and ParseModule().
void BytecodeReader::ParseFunctionLazily | ( | ) | [protected] |
Parse functions lazily.
This function parses LLVM functions lazily. It obtains the type of the function and records where the body of the function is in the bytecode buffer. The caller can then use the ParseNextFunction and ParseAllFunctionBodies to get handler events for the functions.
Definition at line 1924 of file Reader.cpp.
References Func, llvm::GlobalValue::GhostLinkage, and llvm::GlobalValue::setLinkage().
Referenced by ParseModule().
void BytecodeReader::ParseFunctionBody | ( | Function * | F | ) | [protected] |
Parse a function body.
Parse the contents of a function. Note that this function can be called lazily by materializeFunction
Definition at line 1784 of file Reader.cpp.
References llvm::GlobalValue::AppendingLinkage, llvm::BytecodeFormat::BasicBlock, BB, llvm::BytecodeFormat::CompactionTableBlockID, llvm::BytecodeFormat::ConstantPoolBlockID, llvm::GlobalValue::ExternalLinkage, F, II, llvm::BytecodeFormat::InstructionListBlockID, llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::LinkOnceLinkage, ParseBasicBlock(), ParseCompactionTable(), ParseConstantPool(), ParseInstructionList(), ParseSymbolTable(), llvm::Value::replaceAllUsesWith(), llvm::BytecodeFormat::SymbolTableBlockID, llvm::UpgradeIntrinsicCall(), V, and llvm::GlobalValue::WeakLinkage.
Referenced by ParseAllFunctionBodies(), and ParseFunction().
void BytecodeReader::ParseCompactionTypes | ( | unsigned | NumEntries | ) | [protected] |
Parse the type list portion of a compaction table.
Definition at line 1211 of file Reader.cpp.
Referenced by ParseCompactionTable().
void BytecodeReader::ParseCompactionTable | ( | ) | [protected] |
Parse a compaction table.
Definition at line 1223 of file Reader.cpp.
References llvm::Constant::getNullValue(), ParseCompactionTypes(), and V.
Referenced by ParseFunctionBody().
void BytecodeReader::ParseGlobalTypes | ( | ) | [protected] |
Parse global types.
Definition at line 1990 of file Reader.cpp.
References ParseTypes().
Referenced by ParseModule().
BasicBlock * BytecodeReader::ParseBasicBlock | ( | unsigned | BlockNo | ) | [protected] |
Parse a basic block (for LLVM 1.0 basic block blocks).
In LLVM 1.0 bytecode files, we used to output one basicblock at a time. This method reads in one of the basicblock packets. This method is not used for bytecode files after LLVM 1.0
Definition at line 1088 of file Reader.cpp.
References llvm::ISD::BasicBlock, BB, and ParseInstruction().
Referenced by ParseFunctionBody().
unsigned BytecodeReader::ParseInstructionList | ( | Function * | F | ) | [protected] |
parse an instruction list (for post LLVM 1.0 instruction lists with blocks differentiated by terminating instructions.
Parse all of the BasicBlock's & Instruction's in the body of a function. In post 1.0 bytecode files, we no longer emit basic block individually, in order to avoid per-basic-block overhead.
F | The function into which BBs will be inserted |
Definition at line 1112 of file Reader.cpp.
References llvm::ISD::BasicBlock, BB, F, llvm::BasicBlock::getTerminator(), and ParseInstruction().
Referenced by ParseFunctionBody().
void BytecodeReader::ParseInstruction | ( | std::vector< unsigned > & | Oprnds, | |
BasicBlock * | BB | |||
) | [protected] |
Parse a single instruction.
This method parses a single instruction. The instruction is inserted at the end of the BB
provided. The arguments of the instruction are provided in the Oprnds
vector.
Oprnds | The arguments to be filled in |
BB | The BB the instruction goes in |
Definition at line 574 of file Reader.cpp.
References llvm::SwitchInst::addCase(), llvm::PHINode::addIncoming(), Align, llvm::Instruction::Alloca, BB, llvm::Type::BoolTyID, C, llvm::CallingConv::C, llvm::Instruction::Call, llvm::Instruction::Cast, llvm::BinaryOperator::create(), llvm::Instruction::ExtractElement, F, llvm::CallingConv::Fast, llvm::PackedType::get(), llvm::ConstantExpr::getCast(), llvm::SequentialType::getElementType(), llvm::GetElementPtrInst::getIndexedType(), llvm::BasicBlock::getInstList(), llvm::PackedType::getNumElements(), llvm::FunctionType::getNumParams(), llvm::Module::getOrInsertFunction(), llvm::FunctionType::getParamType(), llvm::Value::getType(), Idx, llvm::Instruction::InsertElement, llvm::Type::IntTyID, llvm::ShuffleVectorInst::isValidOperands(), llvm::InsertElementInst::isValidOperands(), llvm::ExtractElementInst::isValidOperands(), llvm::FunctionType::isVarArg(), llvm::Instruction::Load, llvm::Type::LongTyID, llvm::Instruction::Malloc, Op, llvm::FunctionType::param_begin(), llvm::FunctionType::param_end(), llvm::Instruction::PHI, llvm::PHINode::reserveOperandSpace(), llvm::Instruction::Select, llvm::Instruction::Shl, llvm::Instruction::ShuffleVector, llvm::BasicBlock::size(), llvm::SPII::Store, llvm::ModuleProvider::TheModule, llvm::Type::UByteTyID, llvm::Type::UIntTy, llvm::Type::UIntTyID, llvm::Type::ULongTyID, and llvm::Instruction::VAArg.
Referenced by ParseBasicBlock(), and ParseInstructionList().
void BytecodeReader::ParseConstantPool | ( | ValueTable & | Values, | |
TypeListTy & | Types, | |||
bool | isFunction | |||
) | [protected] |
Parse the whole constant pool.
In LLVM 1.3 Type does not derive from Value so the types do not occupy a plane. Consequently, we read the types first in the constant pool.
In LLVM 1.2 and before, Types were written to the bytecode file in the "Type Type" plane (#12). In 1.3 plane 12 is now the label plane. Handle this here.
Use of Type::VoidTyID is a misnomer. It actually means that the following plane is constant strings
Definition at line 1720 of file Reader.cpp.
References C, llvm::Type::getDescription(), llvm::Value::getName(), llvm::Value::getType(), ParseConstantPoolValue(), ParseStringConstants(), ParseTypes(), size, llvm::utostr(), and llvm::Type::VoidTyID.
Referenced by ParseFunctionBody(), and ParseModule().
Value * BytecodeReader::ParseConstantPoolValue | ( | unsigned | TypeID | ) | [protected] |
Parse a single constant pool value.
Definition at line 1419 of file Reader.cpp.
References llvm::Type::ArrayTyID, llvm::Type::BoolTyID, llvm::Instruction::Cast, llvm::Type::DoubleTyID, E, llvm::Instruction::ExtractElement, llvm::Type::FloatTyID, llvm::gep_type_begin(), llvm::gep_type_end(), llvm::ConstantPacked::get(), llvm::ConstantStruct::get(), llvm::ConstantArray::get(), llvm::ConstantFP::get(), llvm::ConstantSInt::get(), llvm::ConstantUInt::get(), llvm::ConstantBool::get(), llvm::ConstantExpr::get(), llvm::InlineAsm::get(), llvm::UndefValue::get(), llvm::ConstantExpr::getCast(), llvm::Type::getDescription(), llvm::StructType::getElementType(), llvm::SequentialType::getElementType(), llvm::ConstantExpr::getExtractElement(), llvm::ConstantExpr::getGetElementPtr(), llvm::ConstantExpr::getInsertElement(), llvm::PackedType::getNumElements(), llvm::StructType::getNumElements(), llvm::ArrayType::getNumElements(), llvm::ConstantExpr::getSelect(), llvm::ConstantExpr::getShuffleVector(), llvm::Value::getType(), llvm::Type::getTypeID(), GV, llvm::Instruction::InsertElement, llvm::Type::IntTyID, llvm::ShuffleVectorInst::isValidOperands(), llvm::InsertElementInst::isValidOperands(), llvm::ExtractElementInst::isValidOperands(), llvm::ConstantSInt::isValueValidForType(), llvm::ConstantUInt::isValueValidForType(), llvm::Type::LongTyID, llvm::Type::PackedTyID, llvm::Type::PointerTyID, llvm::Type::SByteTyID, llvm::Instruction::Select, llvm::Type::ShortTyID, llvm::Instruction::ShuffleVector, llvm::Type::StructTyID, Ty, U, llvm::Type::UByteTy, llvm::Type::UByteTyID, llvm::Type::UIntTy, llvm::Type::UIntTyID, llvm::Type::ULongTyID, llvm::Type::UShortTyID, Val, and llvm::InlineAsm::Verify().
Referenced by ParseConstantPool().
void BytecodeReader::ParseTypes | ( | TypeListTy & | Tab, | |
unsigned | NumEntries | |||
) | [protected] |
Parse a block of types constants.
Definition at line 1379 of file Reader.cpp.
References llvm::OpaqueType::get(), and ParseType().
Referenced by ParseConstantPool(), and ParseGlobalTypes().
const Type * BytecodeReader::ParseType | ( | ) | [protected] |
Parse a single type constant.
Definition at line 1299 of file Reader.cpp.
References llvm::Type::ArrayTyID, llvm::Type::FunctionTyID, llvm::OpaqueType::get(), llvm::PointerType::get(), llvm::StructType::get(), llvm::PackedType::get(), llvm::ArrayType::get(), llvm::FunctionType::get(), llvm::Type::getPrimitiveType(), llvm::Type::OpaqueTyID, llvm::Type::PackedTyID, llvm::Type::PointerTyID, llvm::Type::StructTyID, llvm::utostr(), and llvm::Type::VoidTy.
Referenced by ParseTypes().
void BytecodeReader::ParseStringConstants | ( | unsigned | NumEntries, | |
ValueTable & | Tab | |||
) | [protected] |
Parse a string constants block.
Definition at line 1685 of file Reader.cpp.
References C, llvm::ConstantArray::get(), llvm::ConstantUInt::get(), llvm::ConstantSInt::get(), llvm::SequentialType::getElementType(), llvm::ArrayType::getNumElements(), llvm::Type::SByteTy, Ty, and llvm::Type::UByteTy.
Referenced by ParseConstantPool().