aboutsummaryrefslogtreecommitdiff
path: root/BitWriter_2_9_func
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2012-07-12 20:13:42 -0700
committerStephen Hines <srhines@google.com>2012-07-13 15:18:03 -0700
commit9937d116e09feb32d46a4c76eca1be6afcd3bed5 (patch)
tree525da4558c744fb410306b250ee1c13b855428d2 /BitWriter_2_9_func
parent0d26cef64debfaa6862a27587c1fd0d30baa3b1d (diff)
downloadslang-9937d116e09feb32d46a4c76eca1be6afcd3bed5.tar.gz
Place each ValueEnumerator in its own namespace.
Without this change, we are actually picking up llvm::ValueEnumerator, which is improper for our specialized writers. Change-Id: I95990f592524293ce40092e069437febc5b2c49a
Diffstat (limited to 'BitWriter_2_9_func')
-rw-r--r--BitWriter_2_9_func/BitcodeWriter.cpp42
-rw-r--r--BitWriter_2_9_func/ValueEnumerator.cpp3
-rw-r--r--BitWriter_2_9_func/ValueEnumerator.h68
3 files changed, 62 insertions, 51 deletions
diff --git a/BitWriter_2_9_func/BitcodeWriter.cpp b/BitWriter_2_9_func/BitcodeWriter.cpp
index 9a224ea..fa3c8eb 100644
--- a/BitWriter_2_9_func/BitcodeWriter.cpp
+++ b/BitWriter_2_9_func/BitcodeWriter.cpp
@@ -154,7 +154,7 @@ static void WriteStringRecord(unsigned Code, StringRef Str,
}
// 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 @@ 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 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 @@ static unsigned getEncodedVisibility(const GlobalValue *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,
+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 uint64_t GetOptimizationFlags(const Value *V) {
}
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 WriteMDNode(const MDNode *N,
}
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 WriteModuleMetadata(const Module *M,
}
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 WriteFunctionLocalMetadata(const Function &F,
}
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 WriteModuleMetadataStore(const Module *M, BitstreamWriter &Stream) {
}
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 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
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;
@@ -980,9 +982,9 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
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 +1006,7 @@ static void WriteModuleConstants(const ValueEnumerator &VE,
/// 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 +1018,8 @@ static bool PushValueAndType(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,
+ llvm_2_9_func::ValueEnumerator &VE,
+ BitstreamWriter &Stream,
SmallVector<unsigned, 64> &Vals) {
unsigned Code = 0;
unsigned AbbrevToUse = 0;
@@ -1304,7 +1307,7 @@ static void WriteInstruction(const Instruction &I, unsigned InstID,
// 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 +1364,7 @@ static void WriteValueSymbolTable(const ValueSymbolTable &VST,
}
/// 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 +1436,8 @@ 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 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 +1610,7 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) {
}
// 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..b7e6c88 100644
--- a/BitWriter_2_9_func/ValueEnumerator.cpp
+++ b/BitWriter_2_9_func/ValueEnumerator.cpp
@@ -22,6 +22,8 @@
#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();
}
@@ -492,3 +494,4 @@ unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
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..f400e75 100644
--- a/BitWriter_2_9_func/ValueEnumerator.h
+++ b/BitWriter_2_9_func/ValueEnumerator.h
@@ -33,39 +33,43 @@ class AttrListPtr;
class ValueSymbolTable;
class MDSymbolTable;
+} // 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 +85,20 @@ private:
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;
+ unsigned getValueID(const llvm::Value *V) const;
- unsigned getTypeID(Type *T) 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 +114,44 @@ public:
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