Index: lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp |
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp |
similarity index 91% |
copy from lib/Bitcode/Writer/BitcodeWriter.cpp |
copy to lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp |
index 1765a845295411c35d1a8a2a9ce4d7102cc437e1..a33e3cb29d6348d0ee6f35ea2ae07d56aa934990 100644 |
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp |
+++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp |
@@ -1,4 +1,4 @@ |
-//===--- Bitcode/Writer/BitcodeWriter.cpp - Bitcode Writer ----------------===// |
+//===--- Bitcode/PNaCl/Writer/PNaClBitcodeWriter.cpp - Bitcode Writer -----===// |
jvoung (off chromium)
2013/04/25 17:49:06
PNaCl -> NaCl (from the directory move)
Karl
2013/04/25 20:48:17
Done.
|
// |
// The LLVM Compiler Infrastructure |
// |
@@ -11,10 +11,10 @@ |
// |
//===----------------------------------------------------------------------===// |
-#include "llvm/Bitcode/ReaderWriter.h" |
-#include "ValueEnumerator.h" |
+#include "llvm/Bitcode/NaCl/NaClReaderWriter.h" |
+#include "NaClValueEnumerator.h" |
#include "llvm/ADT/Triple.h" |
-#include "llvm/Bitcode/BitstreamWriter.h" |
+#include "llvm/Bitcode/NaCl/NaClBitstreamWriter.h" |
#include "llvm/Bitcode/LLVMBitCodes.h" |
#include "llvm/IR/Constants.h" |
#include "llvm/IR/DerivedTypes.h" |
@@ -32,12 +32,6 @@ |
#include <map> |
using namespace llvm; |
-static cl::opt<bool> |
-EnablePreserveUseListOrdering("enable-bc-uselist-preserve", |
- cl::desc("Turn on experimental support for " |
- "use-list order preservation."), |
- cl::init(false), cl::Hidden); |
- |
/// 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. |
enum { |
@@ -147,7 +141,7 @@ static unsigned GetEncodedSynchScope(SynchronizationScope SynchScope) { |
} |
static void WriteStringRecord(unsigned Code, StringRef Str, |
- unsigned AbbrevToUse, BitstreamWriter &Stream) { |
+ unsigned AbbrevToUse, PNaClBitstreamWriter &Stream) { |
Karl
2013/04/25 20:48:17
File replaced all occurrences: PNaCl -> NaCl
|
SmallVector<unsigned, 64> Vals; |
// Code: [strchar x N] |
@@ -161,8 +155,8 @@ static void WriteStringRecord(unsigned Code, StringRef Str, |
Stream.EmitRecord(Code, Vals, AbbrevToUse); |
} |
-static void WriteAttributeGroupTable(const ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
+static void WriteAttributeGroupTable(const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream) { |
const std::vector<AttributeSet> &AttrGrps = VE.getAttributeGroups(); |
if (AttrGrps.empty()) return; |
@@ -209,8 +203,8 @@ static void WriteAttributeGroupTable(const ValueEnumerator &VE, |
Stream.ExitBlock(); |
} |
-static void WriteAttributeTable(const ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
+static void WriteAttributeTable(const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream) { |
const std::vector<AttributeSet> &Attrs = VE.getAttributes(); |
if (Attrs.empty()) return; |
@@ -230,8 +224,9 @@ static void WriteAttributeTable(const ValueEnumerator &VE, |
} |
/// WriteTypeTable - Write out the type table for a module. |
-static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) { |
- const ValueEnumerator::TypeList &TypeList = VE.getTypes(); |
+static void WriteTypeTable(const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream) { |
+ const PNaClValueEnumerator::TypeList &TypeList = VE.getTypes(); |
Stream.EnterSubblock(bitc::TYPE_BLOCK_ID_NEW, 4 /*count from # abbrevs */); |
SmallVector<uint64_t, 64> TypeVals; |
@@ -434,8 +429,8 @@ static unsigned getEncodedThreadLocalMode(const GlobalVariable *GV) { |
// Emit top-level description of module, including target triple, inline asm, |
// descriptors for global variables, and function prototype info. |
-static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
+static void WriteModuleInfo(const Module *M, const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream) { |
// Emit various pieces of data attached to a module. |
if (!M->getTargetTriple().empty()) |
WriteStringRecord(bitc::MODULE_CODE_TRIPLE, M->getTargetTriple(), |
@@ -612,8 +607,8 @@ static uint64_t GetOptimizationFlags(const Value *V) { |
} |
static void WriteMDNode(const MDNode *N, |
- const ValueEnumerator &VE, |
- BitstreamWriter &Stream, |
+ const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream, |
SmallVector<uint64_t, 64> &Record) { |
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
if (N->getOperand(i)) { |
@@ -631,9 +626,9 @@ static void WriteMDNode(const MDNode *N, |
} |
static void WriteModuleMetadata(const Module *M, |
- const ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
- const ValueEnumerator::ValueList &Vals = VE.getMDValues(); |
+ const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream) { |
+ const PNaClValueEnumerator::ValueList &Vals = VE.getMDValues(); |
bool StartedMetadataBlock = false; |
unsigned MDSAbbrev = 0; |
SmallVector<uint64_t, 64> Record; |
@@ -697,8 +692,8 @@ static void WriteModuleMetadata(const Module *M, |
} |
static void WriteFunctionLocalMetadata(const Function &F, |
- const ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
+ const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream) { |
bool StartedMetadataBlock = false; |
SmallVector<uint64_t, 64> Record; |
const SmallVector<const MDNode *, 8> &Vals = VE.getFunctionLocalMDValues(); |
@@ -717,8 +712,8 @@ static void WriteFunctionLocalMetadata(const Function &F, |
} |
static void WriteMetadataAttachment(const Function &F, |
- const ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
+ const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream) { |
Stream.EnterSubblock(bitc::METADATA_ATTACHMENT_ID, 3); |
SmallVector<uint64_t, 64> Record; |
@@ -749,7 +744,7 @@ static void WriteMetadataAttachment(const Function &F, |
Stream.ExitBlock(); |
} |
-static void WriteModuleMetadataStore(const Module *M, BitstreamWriter &Stream) { |
+static void WriteModuleMetadataStore(const Module *M, PNaClBitstreamWriter &Stream) { |
SmallVector<uint64_t, 64> Record; |
// Write metadata kinds |
@@ -809,8 +804,8 @@ static void EmitAPInt(SmallVectorImpl<uint64_t> &Vals, |
} |
static void WriteConstants(unsigned FirstVal, unsigned LastVal, |
- const ValueEnumerator &VE, |
- BitstreamWriter &Stream, bool isGlobal) { |
+ const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream, bool isGlobal) { |
if (FirstVal == LastVal) return; |
Stream.EnterSubblock(bitc::CONSTANTS_BLOCK_ID, 4); |
@@ -850,7 +845,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, |
SmallVector<uint64_t, 64> Record; |
- const ValueEnumerator::ValueList &Vals = VE.getValues(); |
+ const PNaClValueEnumerator::ValueList &Vals = VE.getValues(); |
Type *LastTy = 0; |
for (unsigned i = FirstVal; i != LastVal; ++i) { |
const Value *V = Vals[i].first; |
@@ -1055,9 +1050,9 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, |
Stream.ExitBlock(); |
} |
-static void WriteModuleConstants(const ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
- const ValueEnumerator::ValueList &Vals = VE.getValues(); |
+static void WriteModuleConstants(const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream) { |
+ const PNaClValueEnumerator::ValueList &Vals = VE.getValues(); |
// Find the first constant to emit, which is the first non-globalvalue value. |
// We know globalvalues have been emitted by WriteModuleInfo. |
@@ -1079,7 +1074,7 @@ static void WriteModuleConstants(const ValueEnumerator &VE, |
/// type ID. The value ID that is written is encoded relative to the InstID. |
static bool PushValueAndType(const Value *V, unsigned InstID, |
SmallVector<unsigned, 64> &Vals, |
- ValueEnumerator &VE) { |
+ PNaClValueEnumerator &VE) { |
unsigned ValID = VE.getValueID(V); |
// Make encoding relative to the InstID. |
Vals.push_back(InstID - ValID); |
@@ -1094,21 +1089,21 @@ static bool PushValueAndType(const Value *V, unsigned InstID, |
/// omitted (perhaps it was already encoded in an earlier operand). |
static void pushValue(const Value *V, unsigned InstID, |
SmallVector<unsigned, 64> &Vals, |
- ValueEnumerator &VE) { |
+ PNaClValueEnumerator &VE) { |
unsigned ValID = VE.getValueID(V); |
Vals.push_back(InstID - ValID); |
} |
static void pushValue64(const Value *V, unsigned InstID, |
SmallVector<uint64_t, 128> &Vals, |
- ValueEnumerator &VE) { |
+ PNaClValueEnumerator &VE) { |
uint64_t ValID = VE.getValueID(V); |
Vals.push_back(InstID - ValID); |
} |
static void pushValueSigned(const Value *V, unsigned InstID, |
SmallVector<uint64_t, 128> &Vals, |
- ValueEnumerator &VE) { |
+ PNaClValueEnumerator &VE) { |
unsigned ValID = VE.getValueID(V); |
int64_t diff = ((int32_t)InstID - (int32_t)ValID); |
emitSignedInt64(Vals, diff); |
@@ -1116,7 +1111,7 @@ static void pushValueSigned(const Value *V, unsigned InstID, |
/// WriteInstruction - Emit an instruction to the specified stream. |
static void WriteInstruction(const Instruction &I, unsigned InstID, |
- ValueEnumerator &VE, BitstreamWriter &Stream, |
+ PNaClValueEnumerator &VE, PNaClBitstreamWriter &Stream, |
SmallVector<unsigned, 64> &Vals) { |
unsigned Code = 0; |
unsigned AbbrevToUse = 0; |
@@ -1473,8 +1468,8 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, |
// Emit names for globals/functions etc. |
static void WriteValueSymbolTable(const ValueSymbolTable &VST, |
- const ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
+ const PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream) { |
if (VST.empty()) return; |
Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 4); |
@@ -1530,8 +1525,8 @@ static void WriteValueSymbolTable(const ValueSymbolTable &VST, |
} |
/// WriteFunction - Emit a function body to the module stream. |
-static void WriteFunction(const Function &F, ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
+static void WriteFunction(const Function &F, PNaClValueEnumerator &VE, |
+ PNaClBitstreamWriter &Stream) { |
Stream.EnterSubblock(bitc::FUNCTION_BLOCK_ID, 4); |
VE.incorporateFunction(F); |
@@ -1602,7 +1597,7 @@ static void WriteFunction(const Function &F, ValueEnumerator &VE, |
} |
// Emit blockinfo, which defines the standard abbreviations etc. |
-static void WriteBlockInfo(const ValueEnumerator &VE, BitstreamWriter &Stream) { |
+static void WriteBlockInfo(const PNaClValueEnumerator &VE, PNaClBitstreamWriter &Stream) { |
// We only want to emit block info records for blocks that have multiple |
// instances: CONSTANTS_BLOCK, FUNCTION_BLOCK and VALUE_SYMTAB_BLOCK. |
// Other blocks can define their abbrevs inline. |
@@ -1762,105 +1757,8 @@ static void WriteBlockInfo(const ValueEnumerator &VE, BitstreamWriter &Stream) { |
Stream.ExitBlock(); |
} |
-// Sort the Users based on the order in which the reader parses the bitcode |
-// file. |
-static bool bitcodereader_order(const User *lhs, const User *rhs) { |
- // TODO: Implement. |
- return true; |
-} |
- |
-static void WriteUseList(const Value *V, const ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
- |
- // One or zero uses can't get out of order. |
- if (V->use_empty() || V->hasNUses(1)) |
- return; |
- |
- // Make a copy of the in-memory use-list for sorting. |
- unsigned UseListSize = std::distance(V->use_begin(), V->use_end()); |
- SmallVector<const User*, 8> UseList; |
- UseList.reserve(UseListSize); |
- for (Value::const_use_iterator I = V->use_begin(), E = V->use_end(); |
- I != E; ++I) { |
- const User *U = *I; |
- UseList.push_back(U); |
- } |
- |
- // Sort the copy based on the order read by the BitcodeReader. |
- std::sort(UseList.begin(), UseList.end(), bitcodereader_order); |
- |
- // TODO: Generate a diff between the BitcodeWriter in-memory use-list and the |
- // sorted list (i.e., the expected BitcodeReader in-memory use-list). |
- |
- // TODO: Emit the USELIST_CODE_ENTRYs. |
-} |
- |
-static void WriteFunctionUseList(const Function *F, ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
- VE.incorporateFunction(*F); |
- |
- for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end(); |
- AI != AE; ++AI) |
- WriteUseList(AI, VE, Stream); |
- for (Function::const_iterator BB = F->begin(), FE = F->end(); BB != FE; |
- ++BB) { |
- WriteUseList(BB, VE, Stream); |
- for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end(); II != IE; |
- ++II) { |
- WriteUseList(II, VE, Stream); |
- for (User::const_op_iterator OI = II->op_begin(), E = II->op_end(); |
- OI != E; ++OI) { |
- if ((isa<Constant>(*OI) && !isa<GlobalValue>(*OI)) || |
- isa<InlineAsm>(*OI)) |
- WriteUseList(*OI, VE, Stream); |
- } |
- } |
- } |
- VE.purgeFunction(); |
-} |
- |
-// Emit use-lists. |
-static void WriteModuleUseLists(const Module *M, ValueEnumerator &VE, |
- BitstreamWriter &Stream) { |
- Stream.EnterSubblock(bitc::USELIST_BLOCK_ID, 3); |
- |
- // XXX: this modifies the module, but in a way that should never change the |
- // behavior of any pass or codegen in LLVM. The problem is that GVs may |
- // contain entries in the use_list that do not exist in the Module and are |
- // not stored in the .bc file. |
- for (Module::const_global_iterator I = M->global_begin(), E = M->global_end(); |
- I != E; ++I) |
- I->removeDeadConstantUsers(); |
- |
- // Write the global variables. |
- for (Module::const_global_iterator GI = M->global_begin(), |
- GE = M->global_end(); GI != GE; ++GI) { |
- WriteUseList(GI, VE, Stream); |
- |
- // Write the global variable initializers. |
- if (GI->hasInitializer()) |
- WriteUseList(GI->getInitializer(), VE, Stream); |
- } |
- |
- // Write the functions. |
- for (Module::const_iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI) { |
- WriteUseList(FI, VE, Stream); |
- if (!FI->isDeclaration()) |
- WriteFunctionUseList(FI, VE, Stream); |
- } |
- |
- // Write the aliases. |
- for (Module::const_alias_iterator AI = M->alias_begin(), AE = M->alias_end(); |
- AI != AE; ++AI) { |
- WriteUseList(AI, VE, Stream); |
- WriteUseList(AI->getAliasee(), VE, Stream); |
- } |
- |
- Stream.ExitBlock(); |
-} |
- |
/// WriteModule - Emit the specified module to the bitstream. |
-static void WriteModule(const Module *M, BitstreamWriter &Stream) { |
+static void WriteModule(const Module *M, PNaClBitstreamWriter &Stream) { |
Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3); |
SmallVector<unsigned, 1> Vals; |
@@ -1869,7 +1767,7 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) { |
Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals); |
// Analyze the module, enumerating globals, functions, etc. |
- ValueEnumerator VE(M); |
+ PNaClValueEnumerator VE(M); |
// Emit blockinfo, which defines the standard abbreviations etc. |
WriteBlockInfo(VE, Stream); |
@@ -1899,10 +1797,6 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) { |
// Emit names for globals/functions etc. |
WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream); |
- // Emit use-lists. |
- if (EnablePreserveUseListOrdering) |
- WriteModuleUseLists(M, VE, Stream); |
- |
// Emit function bodies. |
for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) |
if (!F->isDeclaration()) |
@@ -1986,7 +1880,7 @@ static void EmitDarwinBCHeaderAndTrailer(SmallVectorImpl<char> &Buffer, |
/// WriteBitcodeToFile - Write the specified module to the specified output |
/// stream. |
-void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) { |
+void llvm::PNaClWriteBitcodeToFile(const Module *M, raw_ostream &Out) { |
SmallVector<char, 0> Buffer; |
Buffer.reserve(256*1024); |
@@ -2001,7 +1895,7 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) { |
// Emit the module into the buffer. |
{ |
- BitstreamWriter Stream(Buffer); |
+ PNaClBitstreamWriter Stream(Buffer); |
// Emit the file header. |
Stream.Emit((unsigned)'B', 8); |