LLVM  4.0.0
Macros | Enumerations | Functions | Variables
BitcodeWriter.cpp File Reference
#include "llvm/Bitcode/BitcodeWriter.h"
#include "ValueEnumerator.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/UseListOrder.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/SHA1.h"
#include "llvm/Support/raw_ostream.h"
#include <cctype>
#include <map>
#include "llvm/IR/Metadata.def"
Include dependency graph for BitcodeWriter.cpp:

Go to the source code of this file.

Macros

#define HANDLE_MDNODE_LEAF(CLASS)   CLASS##AbbrevID,
 
#define HANDLE_MDNODE_LEAF(CLASS)   unsigned CLASS##Abbrev = 0;
 
#define HANDLE_MDNODE_LEAF(CLASS)
 

Enumerations

enum  
 These are manifest constants used by the bitcode writer. More...
 
enum  StringEncoding { SE_Char6, SE_Fixed7, SE_Fixed8 }
 
enum  MetadataAbbrev : unsigned { LastPlusOne }
 

Functions

static unsigned getEncodedCastOpcode (unsigned Opcode)
 
static unsigned getEncodedBinaryOpcode (unsigned Opcode)
 
static unsigned getEncodedRMWOperation (AtomicRMWInst::BinOp Op)
 
static unsigned getEncodedOrdering (AtomicOrdering Ordering)
 
static unsigned getEncodedSynchScope (SynchronizationScope SynchScope)
 
static void writeStringRecord (BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
 
static uint64_t getAttrKindEncoding (Attribute::AttrKind Kind)
 
static unsigned getEncodedLinkage (const GlobalValue::LinkageTypes Linkage)
 
static unsigned getEncodedLinkage (const GlobalValue &GV)
 
static uint64_t getEncodedGVSummaryFlags (GlobalValueSummary::GVFlags Flags)
 
static unsigned getEncodedVisibility (const GlobalValue &GV)
 
static unsigned getEncodedDLLStorageClass (const GlobalValue &GV)
 
static unsigned getEncodedThreadLocalMode (const GlobalValue &GV)
 
static unsigned getEncodedComdatSelectionKind (const Comdat &C)
 
static unsigned getEncodedUnnamedAddr (const GlobalValue &GV)
 
static StringEncoding getStringEncoding (const char *Str, unsigned StrLen)
 Determine the encoding to use for the given string name and length. More...
 
static uint64_t getOptimizationFlags (const Value *V)
 
static uint64_t rotateSign (int64_t I)
 
static void emitSignedInt64 (SmallVectorImpl< uint64_t > &Vals, uint64_t V)
 
void writeIdentificationBlock (BitstreamWriter &Stream)
 Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version, and a record for the epoch number. More...
 
static void writeInt32ToBuffer (uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
 
static void emitDarwinBCHeaderAndTrailer (SmallVectorImpl< char > &Buffer, const Triple &TT)
 If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with the system archiver. More...
 
static void writeBitcodeHeader (BitstreamWriter &Stream)
 Helper to write the header common to all bitcode files. More...
 

Variables

static const uint64_t INDEX_VERSION = 3
 

Macro Definition Documentation

#define HANDLE_MDNODE_LEAF (   CLASS)    CLASS##AbbrevID,

Definition at line 1865 of file BitcodeWriter.cpp.

#define HANDLE_MDNODE_LEAF (   CLASS)    unsigned CLASS##Abbrev = 0;

Definition at line 1865 of file BitcodeWriter.cpp.

#define HANDLE_MDNODE_LEAF (   CLASS)
Value:
case Metadata::CLASS##Kind: \
if (MDAbbrevs) \
write##CLASS(cast<CLASS>(N), Record, \
(*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
continue;
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
static void write(bool isBE, void *P, T V)
#define N
const unsigned Kind

Definition at line 1865 of file BitcodeWriter.cpp.

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.

Definition at line 48 of file BitcodeWriter.cpp.

Enumerator
LastPlusOne 

Definition at line 1864 of file BitcodeWriter.cpp.

Enumerator
SE_Char6 
SE_Fixed7 
SE_Fixed8 

Definition at line 1079 of file BitcodeWriter.cpp.

Function Documentation

static void emitDarwinBCHeaderAndTrailer ( SmallVectorImpl< char > &  Buffer,
const Triple TT 
)
static

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 ... };

Definition at line 3822 of file BitcodeWriter.cpp.

References llvm::Triple::arm, assert(), llvm::BWH_HeaderSize, llvm::Triple::getArch(), llvm::Triple::ppc, llvm::Triple::ppc64, llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::Triple::thumb, writeInt32ToBuffer(), llvm::Triple::x86, and llvm::Triple::x86_64.

Referenced by llvm::WriteBitcodeToFile().

static void emitSignedInt64 ( SmallVectorImpl< uint64_t > &  Vals,
uint64_t  V 
)
static
static uint64_t getAttrKindEncoding ( Attribute::AttrKind  Kind)
static

Definition at line 596 of file BitcodeWriter.cpp.

References llvm::bitc::ATTR_KIND_ALIGNMENT, llvm::bitc::ATTR_KIND_ALLOC_SIZE, llvm::bitc::ATTR_KIND_ALWAYS_INLINE, llvm::bitc::ATTR_KIND_ARGMEMONLY, llvm::bitc::ATTR_KIND_BUILTIN, llvm::bitc::ATTR_KIND_BY_VAL, llvm::bitc::ATTR_KIND_COLD, llvm::bitc::ATTR_KIND_CONVERGENT, llvm::bitc::ATTR_KIND_DEREFERENCEABLE, llvm::bitc::ATTR_KIND_DEREFERENCEABLE_OR_NULL, llvm::bitc::ATTR_KIND_IN_ALLOCA, llvm::bitc::ATTR_KIND_IN_REG, llvm::bitc::ATTR_KIND_INACCESSIBLEMEM_ONLY, llvm::bitc::ATTR_KIND_INACCESSIBLEMEM_OR_ARGMEMONLY, llvm::bitc::ATTR_KIND_INLINE_HINT, llvm::bitc::ATTR_KIND_JUMP_TABLE, llvm::bitc::ATTR_KIND_MIN_SIZE, llvm::bitc::ATTR_KIND_NAKED, llvm::bitc::ATTR_KIND_NEST, llvm::bitc::ATTR_KIND_NO_ALIAS, llvm::bitc::ATTR_KIND_NO_BUILTIN, llvm::bitc::ATTR_KIND_NO_CAPTURE, llvm::bitc::ATTR_KIND_NO_DUPLICATE, llvm::bitc::ATTR_KIND_NO_IMPLICIT_FLOAT, llvm::bitc::ATTR_KIND_NO_INLINE, llvm::bitc::ATTR_KIND_NO_RECURSE, llvm::bitc::ATTR_KIND_NO_RED_ZONE, llvm::bitc::ATTR_KIND_NO_RETURN, llvm::bitc::ATTR_KIND_NO_UNWIND, llvm::bitc::ATTR_KIND_NON_LAZY_BIND, llvm::bitc::ATTR_KIND_NON_NULL, llvm::bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE, llvm::bitc::ATTR_KIND_OPTIMIZE_NONE, llvm::bitc::ATTR_KIND_READ_NONE, llvm::bitc::ATTR_KIND_READ_ONLY, llvm::bitc::ATTR_KIND_RETURNED, llvm::bitc::ATTR_KIND_RETURNS_TWICE, llvm::bitc::ATTR_KIND_S_EXT, llvm::bitc::ATTR_KIND_SAFESTACK, llvm::bitc::ATTR_KIND_SANITIZE_ADDRESS, llvm::bitc::ATTR_KIND_SANITIZE_MEMORY, llvm::bitc::ATTR_KIND_SANITIZE_THREAD, llvm::bitc::ATTR_KIND_STACK_ALIGNMENT, llvm::bitc::ATTR_KIND_STACK_PROTECT, llvm::bitc::ATTR_KIND_STACK_PROTECT_REQ, llvm::bitc::ATTR_KIND_STACK_PROTECT_STRONG, llvm::bitc::ATTR_KIND_STRUCT_RET, llvm::bitc::ATTR_KIND_SWIFT_ERROR, llvm::bitc::ATTR_KIND_SWIFT_SELF, llvm::bitc::ATTR_KIND_UW_TABLE, llvm::bitc::ATTR_KIND_WRITEONLY, llvm::bitc::ATTR_KIND_Z_EXT, llvm::CallingConv::Cold, llvm::MCID::Convergent, llvm::Attribute::EndAttrKinds, llvm::ISD::JumpTable, llvm_unreachable, llvm::NoAlias, llvm::Attribute::None, AMDGPU::RuntimeMD::KernelArg::ReadOnly, and AMDGPU::RuntimeMD::KernelArg::WriteOnly.

static unsigned getEncodedBinaryOpcode ( unsigned  Opcode)
static
static unsigned getEncodedCastOpcode ( unsigned  Opcode)
static
static unsigned getEncodedComdatSelectionKind ( const Comdat C)
static
static unsigned getEncodedDLLStorageClass ( const GlobalValue GV)
static
static uint64_t getEncodedGVSummaryFlags ( GlobalValueSummary::GVFlags  Flags)
static
static unsigned getEncodedLinkage ( const GlobalValue::LinkageTypes  Linkage)
static
static unsigned getEncodedLinkage ( const GlobalValue GV)
static

Definition at line 966 of file BitcodeWriter.cpp.

References getEncodedLinkage(), and llvm::GlobalValue::getLinkage().

static unsigned getEncodedOrdering ( AtomicOrdering  Ordering)
static
static unsigned getEncodedRMWOperation ( AtomicRMWInst::BinOp  Op)
static
static unsigned getEncodedSynchScope ( SynchronizationScope  SynchScope)
static
static unsigned getEncodedThreadLocalMode ( const GlobalValue GV)
static
static unsigned getEncodedUnnamedAddr ( const GlobalValue GV)
static
static unsigned getEncodedVisibility ( const GlobalValue GV)
static
static uint64_t getOptimizationFlags ( const Value V)
static
static StringEncoding getStringEncoding ( const char *  Str,
unsigned  StrLen 
)
static

Determine the encoding to use for the given string name and length.

Definition at line 1082 of file BitcodeWriter.cpp.

References C, E, llvm::BitCodeAbbrevOp::isChar6(), SE_Char6, SE_Fixed7, and SE_Fixed8.

static uint64_t rotateSign ( int64_t  I)
static

Definition at line 1419 of file BitcodeWriter.cpp.

References I.

static void writeBitcodeHeader ( BitstreamWriter Stream)
static

Helper to write the header common to all bitcode files.

Definition at line 3869 of file BitcodeWriter.cpp.

References llvm::BitstreamWriter::Emit().

Referenced by llvm::BitcodeWriter::BitcodeWriter(), and llvm::WriteIndexToFile().

void writeIdentificationBlock ( BitstreamWriter Stream)
static void writeInt32ToBuffer ( uint32_t  Value,
SmallVectorImpl< char > &  Buffer,
uint32_t Position 
)
static

Definition at line 3803 of file BitcodeWriter.cpp.

References llvm::support::endian::write32le().

Referenced by emitDarwinBCHeaderAndTrailer().

static void writeStringRecord ( BitstreamWriter Stream,
unsigned  Code,
StringRef  Str,
unsigned  AbbrevToUse 
)
static

Variable Documentation

const uint64_t INDEX_VERSION = 3
static

Definition at line 3437 of file BitcodeWriter.cpp.