merge in jb-release history after reset to jb-dev
diff --git a/BitWriter_2_9/BitcodeWriter.cpp b/BitWriter_2_9/BitcodeWriter.cpp
index 202aa21..1c5f325 100644
--- a/BitWriter_2_9/BitcodeWriter.cpp
+++ b/BitWriter_2_9/BitcodeWriter.cpp
@@ -132,7 +132,7 @@
}
// Emit information about parameter attributes.
-static void WriteAttributeTable(const ValueEnumerator &VE,
+static void WriteAttributeTable(const llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream) {
const std::vector<AttrListPtr> &Attrs = VE.getAttributes();
if (Attrs.empty()) return;
@@ -166,9 +166,9 @@
Stream.ExitBlock();
}
-static void WriteTypeSymbolTable(const ValueEnumerator &VE,
+static void WriteTypeSymbolTable(const llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream) {
- const ValueEnumerator::TypeList &TypeList = VE.getTypes();
+ const llvm_2_9::ValueEnumerator::TypeList &TypeList = VE.getTypes();
Stream.EnterSubblock(TYPE_SYMTAB_BLOCK_ID_OLD_3_0, 3);
// 7-bit fixed width VST_CODE_ENTRY strings.
@@ -239,8 +239,9 @@
}
/// 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 llvm_2_9::ValueEnumerator &VE,
+ BitstreamWriter &Stream) {
+ const llvm_2_9::ValueEnumerator::TypeList &TypeList = VE.getTypes();
Stream.EnterSubblock(TYPE_BLOCK_ID_OLD_3_0, 4 /*count from # abbrevs */);
SmallVector<uint64_t, 64> TypeVals;
@@ -429,7 +430,8 @@
// 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,
+static void WriteModuleInfo(const Module *M,
+ const llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream) {
// Emit the list of dependent libraries for the Module.
for (Module::lib_iterator I = M->lib_begin(), E = M->lib_end(); I != E; ++I)
@@ -596,7 +598,7 @@
}
static void WriteMDNode(const MDNode *N,
- const ValueEnumerator &VE,
+ const llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream,
SmallVector<uint64_t, 64> &Record) {
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
@@ -615,9 +617,9 @@
}
static void WriteModuleMetadata(const Module *M,
- const ValueEnumerator &VE,
+ const llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream) {
- const ValueEnumerator::ValueList &Vals = VE.getMDValues();
+ const llvm_2_9::ValueEnumerator::ValueList &Vals = VE.getMDValues();
bool StartedMetadataBlock = false;
unsigned MDSAbbrev = 0;
SmallVector<uint64_t, 64> Record;
@@ -681,7 +683,7 @@
}
static void WriteFunctionLocalMetadata(const Function &F,
- const ValueEnumerator &VE,
+ const llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream) {
bool StartedMetadataBlock = false;
SmallVector<uint64_t, 64> Record;
@@ -701,7 +703,7 @@
}
static void WriteMetadataAttachment(const Function &F,
- const ValueEnumerator &VE,
+ const llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream) {
Stream.EnterSubblock(bitc::METADATA_ATTACHMENT_ID, 3);
@@ -758,7 +760,7 @@
}
static void WriteConstants(unsigned FirstVal, unsigned LastVal,
- const ValueEnumerator &VE,
+ const llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream, bool isGlobal) {
if (FirstVal == LastVal) return;
@@ -799,7 +801,7 @@
SmallVector<uint64_t, 64> Record;
- const ValueEnumerator::ValueList &Vals = VE.getValues();
+ const llvm_2_9::ValueEnumerator::ValueList &Vals = VE.getValues();
Type *LastTy = 0;
for (unsigned i = FirstVal; i != LastVal; ++i) {
const Value *V = Vals[i].first;
@@ -912,25 +914,14 @@
AbbrevToUse = CString7Abbrev;
} else if (const ConstantDataSequential *CDS =
dyn_cast<ConstantDataSequential>(C)) {
- Code = bitc::CST_CODE_DATA;
- Type *EltTy = CDS->getType()->getElementType();
- if (isa<IntegerType>(EltTy)) {
- for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
- Record.push_back(CDS->getElementAsInteger(i));
- } else if (EltTy->isFloatTy()) {
- for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
- union { float F; uint32_t I; };
- F = CDS->getElementAsFloat(i);
- Record.push_back(I);
- }
- } else {
- assert(EltTy->isDoubleTy() && "Unknown ConstantData element type");
- for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
- union { double F; uint64_t I; };
- F = CDS->getElementAsDouble(i);
- Record.push_back(I);
- }
- }
+ // We must replace ConstantDataSequential's representation with the
+ // legacy ConstantArray/ConstantVector/ConstantStruct version.
+ // ValueEnumerator is similarly modified to mark the appropriate
+ // Constants as used (so they are emitted).
+ Code = bitc::CST_CODE_AGGREGATE;
+ for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
+ Record.push_back(VE.getValueID(CDS->getElementAsConstant(i)));
+ AbbrevToUse = AggregateAbbrev;
} else if (isa<ConstantArray>(C) || isa<ConstantStruct>(C) ||
isa<ConstantVector>(C)) {
Code = bitc::CST_CODE_AGGREGATE;
@@ -1026,9 +1017,9 @@
Stream.ExitBlock();
}
-static void WriteModuleConstants(const ValueEnumerator &VE,
+static void WriteModuleConstants(const llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream) {
- const ValueEnumerator::ValueList &Vals = VE.getValues();
+ const llvm_2_9::ValueEnumerator::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.
@@ -1050,7 +1041,7 @@
/// type ID.
static bool PushValueAndType(const Value *V, unsigned InstID,
SmallVector<unsigned, 64> &Vals,
- ValueEnumerator &VE) {
+ llvm_2_9::ValueEnumerator &VE) {
unsigned ValID = VE.getValueID(V);
Vals.push_back(ValID);
if (ValID >= InstID) {
@@ -1062,7 +1053,8 @@
/// WriteInstruction - Emit an instruction to the specified stream.
static void WriteInstruction(const Instruction &I, unsigned InstID,
- ValueEnumerator &VE, BitstreamWriter &Stream,
+ llvm_2_9::ValueEnumerator &VE,
+ BitstreamWriter &Stream,
SmallVector<unsigned, 64> &Vals) {
unsigned Code = 0;
unsigned AbbrevToUse = 0;
@@ -1287,7 +1279,7 @@
// Emit names for globals/functions etc.
static void WriteValueSymbolTable(const ValueSymbolTable &VST,
- const ValueEnumerator &VE,
+ const llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream) {
if (VST.empty()) return;
Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 4);
@@ -1344,7 +1336,7 @@
}
/// WriteFunction - Emit a function body to the module stream.
-static void WriteFunction(const Function &F, ValueEnumerator &VE,
+static void WriteFunction(const Function &F, llvm_2_9::ValueEnumerator &VE,
BitstreamWriter &Stream) {
Stream.EnterSubblock(bitc::FUNCTION_BLOCK_ID, 4);
VE.incorporateFunction(F);
@@ -1416,7 +1408,8 @@
}
// Emit blockinfo, which defines the standard abbreviations etc.
-static void WriteBlockInfo(const ValueEnumerator &VE, BitstreamWriter &Stream) {
+static void WriteBlockInfo(const llvm_2_9::ValueEnumerator &VE,
+ BitstreamWriter &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 defined their abbrevs inline.
@@ -1589,7 +1582,7 @@
}
// Analyze the module, enumerating globals, functions, etc.
- ValueEnumerator VE(M);
+ llvm_2_9::ValueEnumerator VE(M);
// Emit blockinfo, which defines the standard abbreviations etc.
WriteBlockInfo(VE, Stream);
diff --git a/BitWriter_2_9/ValueEnumerator.cpp b/BitWriter_2_9/ValueEnumerator.cpp
index 3764dec..b1cbbe9 100644
--- a/BitWriter_2_9/ValueEnumerator.cpp
+++ b/BitWriter_2_9/ValueEnumerator.cpp
@@ -19,9 +19,13 @@
#include "llvm/Module.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/Instructions.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace llvm;
+namespace llvm_2_9 {
+
static bool isIntegerValue(const std::pair<const Value*, unsigned> &V) {
return V.first->getType()->isIntegerTy();
}
@@ -107,7 +111,6 @@
OptimizeConstants(FirstConstant, Values.size());
}
-
unsigned ValueEnumerator::getInstructionID(const Instruction *Inst) const {
InstructionMapType::const_iterator I = InstructionMap.find(Inst);
assert(I != InstructionMap.end() && "Instruction is not mapped!");
@@ -130,6 +133,43 @@
return I->second-1;
}
+void ValueEnumerator::dump() const {
+ print(dbgs(), ValueMap, "Default");
+ dbgs() << '\n';
+ print(dbgs(), MDValueMap, "MetaData");
+ dbgs() << '\n';
+}
+
+void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,
+ const char *Name) const {
+
+ OS << "Map Name: " << Name << "\n";
+ OS << "Size: " << Map.size() << "\n";
+ for (ValueMapType::const_iterator I = Map.begin(),
+ E = Map.end(); I != E; ++I) {
+
+ const Value *V = I->first;
+ if (V->hasName())
+ OS << "Value: " << V->getName();
+ else
+ OS << "Value: [null]\n";
+ V->dump();
+
+ OS << " Uses(" << std::distance(V->use_begin(),V->use_end()) << "):";
+ for (Value::const_use_iterator UI = V->use_begin(), UE = V->use_end();
+ UI != UE; ++UI) {
+ if (UI != V->use_begin())
+ OS << ",";
+ if((*UI)->hasName())
+ OS << " " << (*UI)->getName();
+ else
+ OS << " [null]";
+
+ }
+ OS << "\n\n";
+ }
+}
+
// Optimize constant ordering.
namespace {
struct CstSortPredicate {
@@ -283,10 +323,6 @@
if (const Constant *C = dyn_cast<Constant>(V)) {
if (isa<GlobalValue>(C)) {
// Initializers for globals are handled explicitly elsewhere.
- //} else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {
- // Do not enumerate the initializers for an array of simple characters.
- // The initializers just pollute the value table, and we emit the strings
- // specially.
} else if (C->getNumOperands()) {
// If a constant has operands, enumerate them. This makes sure that if a
// constant has uses (for example an array of const ints), that they are
@@ -306,6 +342,16 @@
Values.push_back(std::make_pair(V, 1U));
ValueMap[V] = Values.size();
return;
+ } else if (const ConstantDataSequential *CDS =
+ dyn_cast<ConstantDataSequential>(C)) {
+ // For our legacy handling of the new ConstantDataSequential type, we
+ // need to enumerate the individual elements, as well as mark the
+ // outer constant as used.
+ for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
+ EnumerateValue(CDS->getElementAsConstant(i));
+ Values.push_back(std::make_pair(V, 1U));
+ ValueMap[V] = Values.size();
+ return;
}
}
@@ -492,3 +538,4 @@
return getGlobalBasicBlockID(BB);
}
+} // end llvm_2_9 namespace
diff --git a/BitWriter_2_9/ValueEnumerator.h b/BitWriter_2_9/ValueEnumerator.h
index b6fc920..9e21775 100644
--- a/BitWriter_2_9/ValueEnumerator.h
+++ b/BitWriter_2_9/ValueEnumerator.h
@@ -32,40 +32,45 @@
class AttrListPtr;
class ValueSymbolTable;
class MDSymbolTable;
+class raw_ostream;
+
+} // end llvm namespace
+
+namespace llvm_2_9 {
class ValueEnumerator {
public:
- typedef std::vector<Type*> TypeList;
+ typedef std::vector<llvm::Type*> TypeList;
// For each value, we remember its Value* and occurrence frequency.
- typedef std::vector<std::pair<const Value*, unsigned> > ValueList;
+ typedef std::vector<std::pair<const llvm::Value*, unsigned> > ValueList;
private:
- typedef DenseMap<Type*, unsigned> TypeMapType;
+ typedef llvm::DenseMap<llvm::Type*, unsigned> TypeMapType;
TypeMapType TypeMap;
TypeList Types;
- typedef DenseMap<const Value*, unsigned> ValueMapType;
+ typedef llvm::DenseMap<const llvm::Value*, unsigned> ValueMapType;
ValueMapType ValueMap;
ValueList Values;
ValueList MDValues;
- SmallVector<const MDNode *, 8> FunctionLocalMDs;
+ llvm::SmallVector<const llvm::MDNode *, 8> FunctionLocalMDs;
ValueMapType MDValueMap;
- typedef DenseMap<void*, unsigned> AttributeMapType;
+ typedef llvm::DenseMap<void*, unsigned> AttributeMapType;
AttributeMapType AttributeMap;
- std::vector<AttrListPtr> Attributes;
+ std::vector<llvm::AttrListPtr> Attributes;
/// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
/// the "getGlobalBasicBlockID" method.
- mutable DenseMap<const BasicBlock*, unsigned> GlobalBasicBlockIDs;
+ mutable llvm::DenseMap<const llvm::BasicBlock*, unsigned> GlobalBasicBlockIDs;
- typedef DenseMap<const Instruction*, unsigned> InstructionMapType;
+ typedef llvm::DenseMap<const llvm::Instruction*, unsigned> InstructionMapType;
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;
+ std::vector<const llvm::BasicBlock*> BasicBlocks;
/// When a function is incorporated, this is the size of the Values list
/// before incorporation.
@@ -81,20 +86,23 @@
ValueEnumerator(const ValueEnumerator &); // DO NOT IMPLEMENT
void operator=(const ValueEnumerator &); // DO NOT IMPLEMENT
public:
- ValueEnumerator(const Module *M);
+ ValueEnumerator(const llvm::Module *M);
- unsigned getValueID(const Value *V) const;
+ void dump() const;
+ void print(llvm::raw_ostream &OS, const ValueMapType &Map, const char *Name) const;
- unsigned getTypeID(Type *T) const {
+ unsigned getValueID(const llvm::Value *V) const;
+
+ unsigned getTypeID(llvm::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 getInstructionID(const llvm::Instruction *I) const;
+ void setInstructionID(const llvm::Instruction *I);
- unsigned getAttributeID(const AttrListPtr &PAL) const {
+ unsigned getAttributeID(const llvm::AttrListPtr &PAL) const {
if (PAL.isEmpty()) return 0; // Null maps to zero.
AttributeMapType::const_iterator I = AttributeMap.find(PAL.getRawPointer());
assert(I != AttributeMap.end() && "Attribute not in ValueEnumerator!");
@@ -110,44 +118,44 @@
const ValueList &getValues() const { return Values; }
const ValueList &getMDValues() const { return MDValues; }
- const SmallVector<const MDNode *, 8> &getFunctionLocalMDValues() const {
+ const llvm::SmallVector<const llvm::MDNode *, 8> &getFunctionLocalMDValues() const {
return FunctionLocalMDs;
}
const TypeList &getTypes() const { return Types; }
- const std::vector<const BasicBlock*> &getBasicBlocks() const {
+ const std::vector<const llvm::BasicBlock*> &getBasicBlocks() const {
return BasicBlocks;
}
- const std::vector<AttrListPtr> &getAttributes() const {
+ const std::vector<llvm::AttrListPtr> &getAttributes() const {
return Attributes;
}
/// 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;
+ unsigned getGlobalBasicBlockID(const llvm::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 incorporateFunction(const llvm::Function &F);
void purgeFunction();
private:
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
- void EnumerateMDNodeOperands(const MDNode *N);
- void EnumerateMetadata(const Value *MD);
- void EnumerateFunctionLocalMetadata(const MDNode *N);
- void EnumerateNamedMDNode(const NamedMDNode *NMD);
- void EnumerateValue(const Value *V);
- void EnumerateType(Type *T);
- void EnumerateOperandType(const Value *V);
- void EnumerateAttributes(const AttrListPtr &PAL);
+ void EnumerateMDNodeOperands(const llvm::MDNode *N);
+ void EnumerateMetadata(const llvm::Value *MD);
+ void EnumerateFunctionLocalMetadata(const llvm::MDNode *N);
+ void EnumerateNamedMDNode(const llvm::NamedMDNode *NMD);
+ void EnumerateValue(const llvm::Value *V);
+ void EnumerateType(llvm::Type *T);
+ void EnumerateOperandType(const llvm::Value *V);
+ void EnumerateAttributes(const llvm::AttrListPtr &PAL);
- void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
- void EnumerateNamedMetadata(const Module *M);
+ void EnumerateValueSymbolTable(const llvm::ValueSymbolTable &ST);
+ void EnumerateNamedMetadata(const llvm::Module *M);
};
-} // End llvm namespace
+} // end llvm_2_9 namespace
#endif
diff --git a/BitWriter_2_9_func/BitcodeWriter.cpp b/BitWriter_2_9_func/BitcodeWriter.cpp
index 9a224ea..9a37aab 100644
--- a/BitWriter_2_9_func/BitcodeWriter.cpp
+++ b/BitWriter_2_9_func/BitcodeWriter.cpp
@@ -154,7 +154,7 @@
}
// Emit information about parameter attributes.
-static void WriteAttributeTable(const ValueEnumerator &VE,
+static void WriteAttributeTable(const llvm_2_9_func::ValueEnumerator &VE,
BitstreamWriter &Stream) {
const std::vector<AttrListPtr> &Attrs = VE.getAttributes();
if (Attrs.empty()) return;
@@ -189,8 +189,9 @@
}
/// 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 llvm_2_9_func::ValueEnumerator &VE,
+ BitstreamWriter &Stream) {
+ const llvm_2_9_func::ValueEnumerator::TypeList &TypeList = VE.getTypes();
Stream.EnterSubblock(bitc::TYPE_BLOCK_ID_NEW, 4 /*count from # abbrevs */);
SmallVector<uint64_t, 64> TypeVals;
@@ -382,7 +383,8 @@
// 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,
+static void WriteModuleInfo(const Module *M,
+ const llvm_2_9_func::ValueEnumerator &VE,
BitstreamWriter &Stream) {
// Emit the list of dependent libraries for the Module.
for (Module::lib_iterator I = M->lib_begin(), E = M->lib_end(); I != E; ++I)
@@ -550,7 +552,7 @@
}
static void WriteMDNode(const MDNode *N,
- const ValueEnumerator &VE,
+ const llvm_2_9_func::ValueEnumerator &VE,
BitstreamWriter &Stream,
SmallVector<uint64_t, 64> &Record) {
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
@@ -569,9 +571,9 @@
}
static void WriteModuleMetadata(const Module *M,
- const ValueEnumerator &VE,
+ const llvm_2_9_func::ValueEnumerator &VE,
BitstreamWriter &Stream) {
- const ValueEnumerator::ValueList &Vals = VE.getMDValues();
+ const llvm_2_9_func::ValueEnumerator::ValueList &Vals = VE.getMDValues();
bool StartedMetadataBlock = false;
unsigned MDSAbbrev = 0;
SmallVector<uint64_t, 64> Record;
@@ -635,7 +637,7 @@
}
static void WriteFunctionLocalMetadata(const Function &F,
- const ValueEnumerator &VE,
+ const llvm_2_9_func::ValueEnumerator &VE,
BitstreamWriter &Stream) {
bool StartedMetadataBlock = false;
SmallVector<uint64_t, 64> Record;
@@ -655,7 +657,7 @@
}
static void WriteMetadataAttachment(const Function &F,
- const ValueEnumerator &VE,
+ const llvm_2_9_func::ValueEnumerator &VE,
BitstreamWriter &Stream) {
Stream.EnterSubblock(bitc::METADATA_ATTACHMENT_ID, 3);
@@ -712,7 +714,7 @@
}
static void WriteConstants(unsigned FirstVal, unsigned LastVal,
- const ValueEnumerator &VE,
+ const llvm_2_9_func::ValueEnumerator &VE,
BitstreamWriter &Stream, bool isGlobal) {
if (FirstVal == LastVal) return;
@@ -753,7 +755,7 @@
SmallVector<uint64_t, 64> Record;
- const ValueEnumerator::ValueList &Vals = VE.getValues();
+ const llvm_2_9_func::ValueEnumerator::ValueList &Vals = VE.getValues();
Type *LastTy = 0;
for (unsigned i = FirstVal; i != LastVal; ++i) {
const Value *V = Vals[i].first;
@@ -866,25 +868,14 @@
AbbrevToUse = CString7Abbrev;
} else if (const ConstantDataSequential *CDS =
dyn_cast<ConstantDataSequential>(C)) {
- Code = bitc::CST_CODE_DATA;
- Type *EltTy = CDS->getType()->getElementType();
- if (isa<IntegerType>(EltTy)) {
- for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
- Record.push_back(CDS->getElementAsInteger(i));
- } else if (EltTy->isFloatTy()) {
- for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
- union { float F; uint32_t I; };
- F = CDS->getElementAsFloat(i);
- Record.push_back(I);
- }
- } else {
- assert(EltTy->isDoubleTy() && "Unknown ConstantData element type");
- for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
- union { double F; uint64_t I; };
- F = CDS->getElementAsDouble(i);
- Record.push_back(I);
- }
- }
+ // We must replace ConstantDataSequential's representation with the
+ // legacy ConstantArray/ConstantVector/ConstantStruct version.
+ // ValueEnumerator is similarly modified to mark the appropriate
+ // Constants as used (so they are emitted).
+ Code = bitc::CST_CODE_AGGREGATE;
+ for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
+ Record.push_back(VE.getValueID(CDS->getElementAsConstant(i)));
+ AbbrevToUse = AggregateAbbrev;
} else if (isa<ConstantArray>(C) || isa<ConstantStruct>(C) ||
isa<ConstantVector>(C)) {
Code = bitc::CST_CODE_AGGREGATE;
@@ -980,9 +971,9 @@
Stream.ExitBlock();
}
-static void WriteModuleConstants(const ValueEnumerator &VE,
+static void WriteModuleConstants(const llvm_2_9_func::ValueEnumerator &VE,
BitstreamWriter &Stream) {
- const ValueEnumerator::ValueList &Vals = VE.getValues();
+ const llvm_2_9_func::ValueEnumerator::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.
@@ -1004,7 +995,7 @@
/// type ID.
static bool PushValueAndType(const Value *V, unsigned InstID,
SmallVector<unsigned, 64> &Vals,
- ValueEnumerator &VE) {
+ llvm_2_9_func::ValueEnumerator &VE) {
unsigned ValID = VE.getValueID(V);
Vals.push_back(ValID);
if (ValID >= InstID) {
@@ -1016,7 +1007,8 @@
/// WriteInstruction - Emit an instruction to the specified stream.
static void WriteInstruction(const Instruction &I, unsigned InstID,
- ValueEnumerator &VE, BitstreamWriter &Stream,
+ llvm_2_9_func::ValueEnumerator &VE,
+ BitstreamWriter &Stream,
SmallVector<unsigned, 64> &Vals) {
unsigned Code = 0;
unsigned AbbrevToUse = 0;
@@ -1304,7 +1296,7 @@
// Emit names for globals/functions etc.
static void WriteValueSymbolTable(const ValueSymbolTable &VST,
- const ValueEnumerator &VE,
+ const llvm_2_9_func::ValueEnumerator &VE,
BitstreamWriter &Stream) {
if (VST.empty()) return;
Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 4);
@@ -1361,7 +1353,7 @@
}
/// WriteFunction - Emit a function body to the module stream.
-static void WriteFunction(const Function &F, ValueEnumerator &VE,
+static void WriteFunction(const Function &F, llvm_2_9_func::ValueEnumerator &VE,
BitstreamWriter &Stream) {
Stream.EnterSubblock(bitc::FUNCTION_BLOCK_ID, 4);
VE.incorporateFunction(F);
@@ -1433,7 +1425,8 @@
}
// Emit blockinfo, which defines the standard abbreviations etc.
-static void WriteBlockInfo(const ValueEnumerator &VE, BitstreamWriter &Stream) {
+static void WriteBlockInfo(const llvm_2_9_func::ValueEnumerator &VE,
+ BitstreamWriter &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 defined their abbrevs inline.
@@ -1606,7 +1599,7 @@
}
// Analyze the module, enumerating globals, functions, etc.
- ValueEnumerator VE(M);
+ llvm_2_9_func::ValueEnumerator VE(M);
// Emit blockinfo, which defines the standard abbreviations etc.
WriteBlockInfo(VE, Stream);
diff --git a/BitWriter_2_9_func/ValueEnumerator.cpp b/BitWriter_2_9_func/ValueEnumerator.cpp
index 3764dec..88c406f 100644
--- a/BitWriter_2_9_func/ValueEnumerator.cpp
+++ b/BitWriter_2_9_func/ValueEnumerator.cpp
@@ -19,9 +19,13 @@
#include "llvm/Module.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/Instructions.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace llvm;
+namespace llvm_2_9_func {
+
static bool isIntegerValue(const std::pair<const Value*, unsigned> &V) {
return V.first->getType()->isIntegerTy();
}
@@ -107,7 +111,6 @@
OptimizeConstants(FirstConstant, Values.size());
}
-
unsigned ValueEnumerator::getInstructionID(const Instruction *Inst) const {
InstructionMapType::const_iterator I = InstructionMap.find(Inst);
assert(I != InstructionMap.end() && "Instruction is not mapped!");
@@ -130,6 +133,43 @@
return I->second-1;
}
+void ValueEnumerator::dump() const {
+ print(dbgs(), ValueMap, "Default");
+ dbgs() << '\n';
+ print(dbgs(), MDValueMap, "MetaData");
+ dbgs() << '\n';
+}
+
+void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,
+ const char *Name) const {
+
+ OS << "Map Name: " << Name << "\n";
+ OS << "Size: " << Map.size() << "\n";
+ for (ValueMapType::const_iterator I = Map.begin(),
+ E = Map.end(); I != E; ++I) {
+
+ const Value *V = I->first;
+ if (V->hasName())
+ OS << "Value: " << V->getName();
+ else
+ OS << "Value: [null]\n";
+ V->dump();
+
+ OS << " Uses(" << std::distance(V->use_begin(),V->use_end()) << "):";
+ for (Value::const_use_iterator UI = V->use_begin(), UE = V->use_end();
+ UI != UE; ++UI) {
+ if (UI != V->use_begin())
+ OS << ",";
+ if((*UI)->hasName())
+ OS << " " << (*UI)->getName();
+ else
+ OS << " [null]";
+
+ }
+ OS << "\n\n";
+ }
+}
+
// Optimize constant ordering.
namespace {
struct CstSortPredicate {
@@ -283,10 +323,6 @@
if (const Constant *C = dyn_cast<Constant>(V)) {
if (isa<GlobalValue>(C)) {
// Initializers for globals are handled explicitly elsewhere.
- //} else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {
- // Do not enumerate the initializers for an array of simple characters.
- // The initializers just pollute the value table, and we emit the strings
- // specially.
} else if (C->getNumOperands()) {
// If a constant has operands, enumerate them. This makes sure that if a
// constant has uses (for example an array of const ints), that they are
@@ -306,6 +342,16 @@
Values.push_back(std::make_pair(V, 1U));
ValueMap[V] = Values.size();
return;
+ } else if (const ConstantDataSequential *CDS =
+ dyn_cast<ConstantDataSequential>(C)) {
+ // For our legacy handling of the new ConstantDataSequential type, we
+ // need to enumerate the individual elements, as well as mark the
+ // outer constant as used.
+ for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
+ EnumerateValue(CDS->getElementAsConstant(i));
+ Values.push_back(std::make_pair(V, 1U));
+ ValueMap[V] = Values.size();
+ return;
}
}
@@ -492,3 +538,4 @@
return getGlobalBasicBlockID(BB);
}
+} // end llvm_2_9_func namespace
diff --git a/BitWriter_2_9_func/ValueEnumerator.h b/BitWriter_2_9_func/ValueEnumerator.h
index b6fc920..bfcc8da 100644
--- a/BitWriter_2_9_func/ValueEnumerator.h
+++ b/BitWriter_2_9_func/ValueEnumerator.h
@@ -32,40 +32,45 @@
class AttrListPtr;
class ValueSymbolTable;
class MDSymbolTable;
+class raw_ostream;
+
+} // end llvm namespace
+
+namespace llvm_2_9_func {
class ValueEnumerator {
public:
- typedef std::vector<Type*> TypeList;
+ typedef std::vector<llvm::Type*> TypeList;
// For each value, we remember its Value* and occurrence frequency.
- typedef std::vector<std::pair<const Value*, unsigned> > ValueList;
+ typedef std::vector<std::pair<const llvm::Value*, unsigned> > ValueList;
private:
- typedef DenseMap<Type*, unsigned> TypeMapType;
+ typedef llvm::DenseMap<llvm::Type*, unsigned> TypeMapType;
TypeMapType TypeMap;
TypeList Types;
- typedef DenseMap<const Value*, unsigned> ValueMapType;
+ typedef llvm::DenseMap<const llvm::Value*, unsigned> ValueMapType;
ValueMapType ValueMap;
ValueList Values;
ValueList MDValues;
- SmallVector<const MDNode *, 8> FunctionLocalMDs;
+ llvm::SmallVector<const llvm::MDNode *, 8> FunctionLocalMDs;
ValueMapType MDValueMap;
- typedef DenseMap<void*, unsigned> AttributeMapType;
+ typedef llvm::DenseMap<void*, unsigned> AttributeMapType;
AttributeMapType AttributeMap;
- std::vector<AttrListPtr> Attributes;
+ std::vector<llvm::AttrListPtr> Attributes;
/// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
/// the "getGlobalBasicBlockID" method.
- mutable DenseMap<const BasicBlock*, unsigned> GlobalBasicBlockIDs;
+ mutable llvm::DenseMap<const llvm::BasicBlock*, unsigned> GlobalBasicBlockIDs;
- typedef DenseMap<const Instruction*, unsigned> InstructionMapType;
+ typedef llvm::DenseMap<const llvm::Instruction*, unsigned> InstructionMapType;
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;
+ std::vector<const llvm::BasicBlock*> BasicBlocks;
/// When a function is incorporated, this is the size of the Values list
/// before incorporation.
@@ -81,20 +86,23 @@
ValueEnumerator(const ValueEnumerator &); // DO NOT IMPLEMENT
void operator=(const ValueEnumerator &); // DO NOT IMPLEMENT
public:
- ValueEnumerator(const Module *M);
+ ValueEnumerator(const llvm::Module *M);
- unsigned getValueID(const Value *V) const;
+ void dump() const;
+ void print(llvm::raw_ostream &OS, const ValueMapType &Map, const char *Name) const;
- unsigned getTypeID(Type *T) const {
+ unsigned getValueID(const llvm::Value *V) const;
+
+ unsigned getTypeID(llvm::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 getInstructionID(const llvm::Instruction *I) const;
+ void setInstructionID(const llvm::Instruction *I);
- unsigned getAttributeID(const AttrListPtr &PAL) const {
+ unsigned getAttributeID(const llvm::AttrListPtr &PAL) const {
if (PAL.isEmpty()) return 0; // Null maps to zero.
AttributeMapType::const_iterator I = AttributeMap.find(PAL.getRawPointer());
assert(I != AttributeMap.end() && "Attribute not in ValueEnumerator!");
@@ -110,44 +118,44 @@
const ValueList &getValues() const { return Values; }
const ValueList &getMDValues() const { return MDValues; }
- const SmallVector<const MDNode *, 8> &getFunctionLocalMDValues() const {
+ const llvm::SmallVector<const llvm::MDNode *, 8> &getFunctionLocalMDValues() const {
return FunctionLocalMDs;
}
const TypeList &getTypes() const { return Types; }
- const std::vector<const BasicBlock*> &getBasicBlocks() const {
+ const std::vector<const llvm::BasicBlock*> &getBasicBlocks() const {
return BasicBlocks;
}
- const std::vector<AttrListPtr> &getAttributes() const {
+ const std::vector<llvm::AttrListPtr> &getAttributes() const {
return Attributes;
}
/// 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;
+ unsigned getGlobalBasicBlockID(const llvm::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 incorporateFunction(const llvm::Function &F);
void purgeFunction();
private:
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
- void EnumerateMDNodeOperands(const MDNode *N);
- void EnumerateMetadata(const Value *MD);
- void EnumerateFunctionLocalMetadata(const MDNode *N);
- void EnumerateNamedMDNode(const NamedMDNode *NMD);
- void EnumerateValue(const Value *V);
- void EnumerateType(Type *T);
- void EnumerateOperandType(const Value *V);
- void EnumerateAttributes(const AttrListPtr &PAL);
+ void EnumerateMDNodeOperands(const llvm::MDNode *N);
+ void EnumerateMetadata(const llvm::Value *MD);
+ void EnumerateFunctionLocalMetadata(const llvm::MDNode *N);
+ void EnumerateNamedMDNode(const llvm::NamedMDNode *NMD);
+ void EnumerateValue(const llvm::Value *V);
+ void EnumerateType(llvm::Type *T);
+ void EnumerateOperandType(const llvm::Value *V);
+ void EnumerateAttributes(const llvm::AttrListPtr &PAL);
- void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
- void EnumerateNamedMetadata(const Module *M);
+ void EnumerateValueSymbolTable(const llvm::ValueSymbolTable &ST);
+ void EnumerateNamedMetadata(const llvm::Module *M);
};
-} // End llvm namespace
+} // End llvm_2_9_func namespace
#endif
diff --git a/slang_version.h b/slang_version.h
index ef390ea..07bd337 100644
--- a/slang_version.h
+++ b/slang_version.h
@@ -41,7 +41,8 @@
enum {
LEGACY = 0,
ICS = 1400,
- CURRENT = ICS
+ JB = 1600,
+ CURRENT = JB
};
} // namespace SlangVersion