LLVM API Documentation

BitcodeWriter.cpp File Reference

#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
#include "ValueEnumerator.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Program.h"

Include dependency graph for BitcodeWriter.cpp:

Go to the source code of this file.

Enumerations

enum  {
  CurVersion = 0, VST_ENTRY_8_ABBREV = bitc::FIRST_APPLICATION_ABBREV, VST_ENTRY_7_ABBREV, VST_ENTRY_6_ABBREV,
  VST_BBENTRY_6_ABBREV, CONSTANTS_SETTYPE_ABBREV = bitc::FIRST_APPLICATION_ABBREV, CONSTANTS_INTEGER_ABBREV, CONSTANTS_CE_CAST_Abbrev,
  CONSTANTS_NULL_Abbrev, FUNCTION_INST_LOAD_ABBREV = bitc::FIRST_APPLICATION_ABBREV, FUNCTION_INST_BINOP_ABBREV, FUNCTION_INST_CAST_ABBREV,
  FUNCTION_INST_RET_VOID_ABBREV, FUNCTION_INST_RET_VAL_ABBREV, FUNCTION_INST_UNREACHABLE_ABBREV
}
enum  { DarwinBCSizeFieldOffset = 3*4, DarwinBCHeaderSize = 5*4 }

Functions

static unsigned GetEncodedCastOpcode (unsigned Opcode)
static unsigned GetEncodedBinaryOpcode (unsigned Opcode)
static void WriteStringRecord (unsigned Code, const std::string &Str, unsigned AbbrevToUse, BitstreamWriter &Stream)
static void WriteAttributeTable (const ValueEnumerator &VE, BitstreamWriter &Stream)
static void WriteTypeTable (const ValueEnumerator &VE, BitstreamWriter &Stream)
 WriteTypeTable - Write out the type table for a module.
static unsigned getEncodedLinkage (const GlobalValue *GV)
static unsigned getEncodedVisibility (const GlobalValue *GV)
static void WriteModuleInfo (const Module *M, const ValueEnumerator &VE, BitstreamWriter &Stream)
static void WriteConstants (unsigned FirstVal, unsigned LastVal, const ValueEnumerator &VE, BitstreamWriter &Stream, bool isGlobal)
static void WriteModuleConstants (const ValueEnumerator &VE, BitstreamWriter &Stream)
static bool PushValueAndType (const Value *V, unsigned InstID, SmallVector< unsigned, 64 > &Vals, ValueEnumerator &VE)
static void WriteInstruction (const Instruction &I, unsigned InstID, ValueEnumerator &VE, BitstreamWriter &Stream, SmallVector< unsigned, 64 > &Vals)
 WriteInstruction - Emit an instruction to the specified stream.
static void WriteValueSymbolTable (const ValueSymbolTable &VST, const ValueEnumerator &VE, BitstreamWriter &Stream)
static void WriteFunction (const Function &F, ValueEnumerator &VE, BitstreamWriter &Stream)
 WriteFunction - Emit a function body to the module stream.
static void WriteTypeSymbolTable (const TypeSymbolTable &TST, const ValueEnumerator &VE, BitstreamWriter &Stream)
 WriteTypeSymbolTable - Emit a block for the specified type symtab.
static void WriteBlockInfo (const ValueEnumerator &VE, BitstreamWriter &Stream)
static void WriteModule (const Module *M, BitstreamWriter &Stream)
 WriteModule - Emit the specified module to the bitstream.
static void EmitDarwinBCHeader (BitstreamWriter &Stream, const std::string &TT)
static void EmitDarwinBCTrailer (BitstreamWriter &Stream, unsigned BufferSize)
void llvm::WriteBitcodeToFile (const Module *M, std::ostream &Out)
void llvm::WriteBitcodeToFile (const Module *M, raw_ostream &Out)
void llvm::WriteBitcodeToStream (const Module *M, BitstreamWriter &Stream)


Enumeration Type Documentation

anonymous enum

These are manifest constants used by the bitcode writer. They do not need to be kept in sync with the reader, but need to be consistent within this file.

Enumerator:
CurVersion 
VST_ENTRY_8_ABBREV 
VST_ENTRY_7_ABBREV 
VST_ENTRY_6_ABBREV 
VST_BBENTRY_6_ABBREV 
CONSTANTS_SETTYPE_ABBREV 
CONSTANTS_INTEGER_ABBREV 
CONSTANTS_CE_CAST_Abbrev 
CONSTANTS_NULL_Abbrev 
FUNCTION_INST_LOAD_ABBREV 
FUNCTION_INST_BINOP_ABBREV 
FUNCTION_INST_CAST_ABBREV 
FUNCTION_INST_RET_VOID_ABBREV 
FUNCTION_INST_RET_VAL_ABBREV 
FUNCTION_INST_UNREACHABLE_ABBREV 

Definition at line 33 of file BitcodeWriter.cpp.

anonymous enum

EmitDarwinBCHeader - If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with the system archiver. To do this we emit the following header, and then emit a trailer that pads the file out to be a multiple of 16 bytes.

struct bc_header { uint32_t Magic; // 0x0B17C0DE uint32_t Version; // Version, currently always 0. uint32_t BitcodeOffset; // Offset to traditional bitcode file. uint32_t BitcodeSize; // Size of traditional bitcode file. uint32_t CPUType; // CPU specifier. ... potentially more later ... };

Enumerator:
DarwinBCSizeFieldOffset 
DarwinBCHeaderSize 

Definition at line 1294 of file BitcodeWriter.cpp.


Function Documentation

static void EmitDarwinBCHeader ( BitstreamWriter &  Stream,
const std::string &  TT 
) [static]

Definition at line 1299 of file BitcodeWriter.cpp.

References DarwinBCHeaderSize, and llvm::BitstreamWriter::Emit().

Referenced by llvm::WriteBitcodeToStream().

static void EmitDarwinBCTrailer ( BitstreamWriter &  Stream,
unsigned  BufferSize 
) [static]

EmitDarwinBCTrailer - Emit the darwin epilog after the bitcode file and finalize the header.

Definition at line 1334 of file BitcodeWriter.cpp.

References llvm::BitstreamWriter::BackpatchWord(), DarwinBCHeaderSize, DarwinBCSizeFieldOffset, and llvm::BitstreamWriter::Emit().

Referenced by llvm::WriteBitcodeToStream().

static unsigned GetEncodedBinaryOpcode ( unsigned  Opcode  )  [static]

static unsigned GetEncodedCastOpcode ( unsigned  Opcode  )  [static]

static unsigned getEncodedLinkage ( const GlobalValue *  GV  )  [static]

Definition at line 274 of file BitcodeWriter.cpp.

References llvm::GlobalValue::getLinkage().

Referenced by WriteModuleInfo().

static unsigned getEncodedVisibility ( const GlobalValue *  GV  )  [static]

Definition at line 291 of file BitcodeWriter.cpp.

References llvm::GlobalValue::getVisibility().

Referenced by WriteModuleInfo().

static bool PushValueAndType ( const Value *  V,
unsigned  InstID,
SmallVector< unsigned, 64 > &  Vals,
ValueEnumerator &  VE 
) [static]

PushValueAndType - The file has to encode both the value and type id for many values, because we need to know what type to create for forward references. However, most operands are not forward references, so this type field is not needed.

This function adds V's value ID to Vals. If the value ID is higher than the instruction ID, then it is a forward reference, and it also includes the type ID.

Definition at line 701 of file BitcodeWriter.cpp.

References llvm::Value::getType(), llvm::ValueEnumerator::getTypeID(), llvm::ValueEnumerator::getValueID(), and llvm::SmallVectorImpl< T >::push_back().

Referenced by WriteInstruction().

static void WriteAttributeTable ( const ValueEnumerator &  VE,
BitstreamWriter &  Stream 
) [static]

static void WriteBlockInfo ( const ValueEnumerator &  VE,
BitstreamWriter &  Stream 
) [static]

static void WriteConstants ( unsigned  FirstVal,
unsigned  LastVal,
const ValueEnumerator &  VE,
BitstreamWriter &  Stream,
bool  isGlobal 
) [static]

static void WriteFunction ( const Function &  F,
ValueEnumerator &  VE,
BitstreamWriter &  Stream 
) [static]

static void WriteInstruction ( const Instruction &  I,
unsigned  InstID,
ValueEnumerator &  VE,
BitstreamWriter &  Stream,
SmallVector< unsigned, 64 > &  Vals 
) [static]

WriteInstruction - Emit an instruction to the specified stream.

Definition at line 714 of file BitcodeWriter.cpp.

References Call, llvm::SmallVectorImpl< T >::clear(), llvm::SectionFlags::Code, llvm::BitstreamWriter::EmitRecord(), ExtractValue, FCmp, llvm::bitc::FUNC_CODE_INST_ALLOCA, llvm::bitc::FUNC_CODE_INST_BINOP, llvm::bitc::FUNC_CODE_INST_BR, llvm::bitc::FUNC_CODE_INST_CALL, llvm::bitc::FUNC_CODE_INST_CAST, llvm::bitc::FUNC_CODE_INST_CMP, llvm::bitc::FUNC_CODE_INST_CMP2, llvm::bitc::FUNC_CODE_INST_EXTRACTELT, llvm::bitc::FUNC_CODE_INST_EXTRACTVAL, llvm::bitc::FUNC_CODE_INST_FREE, llvm::bitc::FUNC_CODE_INST_GEP, llvm::bitc::FUNC_CODE_INST_INSERTELT, llvm::bitc::FUNC_CODE_INST_INSERTVAL, llvm::bitc::FUNC_CODE_INST_INVOKE, llvm::bitc::FUNC_CODE_INST_LOAD, llvm::bitc::FUNC_CODE_INST_MALLOC, llvm::bitc::FUNC_CODE_INST_PHI, llvm::bitc::FUNC_CODE_INST_RET, llvm::bitc::FUNC_CODE_INST_SHUFFLEVEC, llvm::bitc::FUNC_CODE_INST_STORE2, llvm::bitc::FUNC_CODE_INST_SWITCH, llvm::bitc::FUNC_CODE_INST_UNREACHABLE, llvm::bitc::FUNC_CODE_INST_UNWIND, llvm::bitc::FUNC_CODE_INST_VAARG, llvm::bitc::FUNC_CODE_INST_VSELECT, FUNCTION_INST_BINOP_ABBREV, FUNCTION_INST_CAST_ABBREV, FUNCTION_INST_LOAD_ABBREV, FUNCTION_INST_RET_VAL_ABBREV, FUNCTION_INST_RET_VOID_ABBREV, FUNCTION_INST_UNREACHABLE_ABBREV, llvm::ValueEnumerator::getAttributeID(), llvm::CallInst::getAttributes(), llvm::InvokeInst::getAttributes(), llvm::InvokeInst::getCalledValue(), llvm::CallInst::getCallingConv(), llvm::InvokeInst::getCallingConv(), llvm::BranchInst::getCondition(), llvm::SequentialType::getElementType(), GetEncodedBinaryOpcode(), GetEncodedCastOpcode(), llvm::InvokeInst::getNormalDest(), llvm::User::getNumOperands(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::BranchInst::getSuccessor(), llvm::Value::getType(), llvm::ValueEnumerator::getTypeID(), llvm::InvokeInst::getUnwindDest(), llvm::ValueEnumerator::getValueID(), II, InsertElement, llvm::BranchInst::isConditional(), llvm::CallInst::isTailCall(), Load, llvm::Log2_32(), Malloc, PHI, PushValueAndType(), llvm::MipsISD::Ret, llvm::SPII::Store, VAArg, and VICmp.

Referenced by WriteFunction().

static void WriteModule ( const Module *  M,
BitstreamWriter &  Stream 
) [static]

static void WriteModuleConstants ( const ValueEnumerator &  VE,
BitstreamWriter &  Stream 
) [static]

Definition at line 679 of file BitcodeWriter.cpp.

References first, llvm::ValueEnumerator::getValues(), Vals, and WriteConstants().

Referenced by WriteModule().

static void WriteModuleInfo ( const Module *  M,
const ValueEnumerator &  VE,
BitstreamWriter &  Stream 
) [static]

static void WriteStringRecord ( unsigned  Code,
const std::string &  Str,
unsigned  AbbrevToUse,
BitstreamWriter &  Stream 
) [static]

static void WriteTypeSymbolTable ( const TypeSymbolTable &  TST,
const ValueEnumerator &  VE,
BitstreamWriter &  Stream 
) [static]

static void WriteTypeTable ( const ValueEnumerator &  VE,
BitstreamWriter &  Stream 
) [static]

static void WriteValueSymbolTable ( const ValueSymbolTable &  VST,
const ValueEnumerator &  VE,
BitstreamWriter &  Stream 
) [static]