aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode/Reader
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2007-04-28 13:45:00 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2007-04-28 13:45:00 +0000
commita80e1181b78183dc36ec6568559d38faa86981f0 (patch)
tree88ca9bd2f28f363e50add28297f6220ac8e09fc1 /lib/Bytecode/Reader
parent44b2c5098f5cf766b4eff43d9eb0d8a9a143e7d8 (diff)
Implement review feedback. Aliasees can be either GlobalValue's or
bitcasts of them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36537 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader')
-rw-r--r--lib/Bytecode/Reader/Analyzer.cpp21
-rw-r--r--lib/Bytecode/Reader/Reader.cpp41
-rw-r--r--lib/Bytecode/Reader/Reader.h9
3 files changed, 61 insertions, 10 deletions
diff --git a/lib/Bytecode/Reader/Analyzer.cpp b/lib/Bytecode/Reader/Analyzer.cpp
index dde73dfb1a..2d90c93826 100644
--- a/lib/Bytecode/Reader/Analyzer.cpp
+++ b/lib/Bytecode/Reader/Analyzer.cpp
@@ -179,6 +179,27 @@ public:
}
+ virtual void handleGlobalAlias(
+ const Type* ElemType,
+ GlobalValue::LinkageTypes Linkage,
+ unsigned TypeSlotNum,
+ unsigned AliaseeSlot) {
+ if (os) {
+ *os << " GA: "
+ << " Linkage=" << Linkage
+ << " Type=";
+ //WriteTypeSymbolic(*os, ElemType, M);
+ *os << " Slot=" << TypeSlotNum << " AliaseeSlot=" << AliaseeSlot
+ << "\n";
+ }
+
+ bca.numValues++;
+ if (TypeSlotNum > bca.maxValueSlot)
+ bca.maxValueSlot = TypeSlotNum;
+ if (AliaseeSlot > bca.maxValueSlot)
+ bca.maxValueSlot = AliaseeSlot;
+ }
+
virtual void handleTypeList(unsigned numEntries) {
bca.maxTypeSlot = numEntries - 1;
}
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index f7606c6e5a..99aac056ff 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -1923,12 +1923,10 @@ void BytecodeReader::ParseModuleGlobalInfo() {
// Read aliases...
unsigned VarType = read_vbr_uint();
while (VarType != Type::VoidTyID) { // List is terminated by Void
- unsigned TypeSlotNo = VarType >> 2;
+ unsigned TypeSlotNo = VarType >> 3;
unsigned EncodedLinkage = VarType & 3;
- unsigned AliaseeTypeSlotNo, AliaseeSlotNo;
-
- AliaseeTypeSlotNo = read_vbr_uint();
- AliaseeSlotNo = read_vbr_uint();
+ bool isConstantAliasee = (VarType >> 2) & 1;
+ unsigned AliaseeSlotNo = read_vbr_uint();
const Type *Ty = getType(TypeSlotNo);
if (!Ty)
@@ -1937,11 +1935,11 @@ void BytecodeReader::ParseModuleGlobalInfo() {
if (!isa<PointerType>(Ty))
error("Alias not a pointer type! Ty= " + Ty->getDescription());
- Value* V = getValue(AliaseeTypeSlotNo, AliaseeSlotNo, false);
- if (!V)
- error("Invalid aliasee! TypeSlotNo=" + utostr(AliaseeTypeSlotNo) +
+ Value* V = getValue(TypeSlotNo, AliaseeSlotNo, false);
+ if (!V && !isConstantAliasee)
+ error("Invalid aliasee! TypeSlotNo=" + utostr(TypeSlotNo) +
" SlotNo=" + utostr(AliaseeSlotNo));
- if (!isa<GlobalValue>(V))
+ if (!isConstantAliasee && !isa<GlobalValue>(V))
error("Aliasee is not global value! SlotNo=" + utostr(AliaseeSlotNo));
GlobalValue::LinkageTypes Linkage;
@@ -1960,8 +1958,14 @@ void BytecodeReader::ParseModuleGlobalInfo() {
}
GlobalAlias *GA = new GlobalAlias(Ty, Linkage, "",
- dyn_cast<GlobalValue>(V), TheModule);
+ dyn_cast_or_null<Constant>(V),
+ TheModule);
insertValue(GA, TypeSlotNo, ModuleValues);
+ if (!V && isConstantAliasee)
+ Aliasees.push_back(std::make_pair(GA, AliaseeSlotNo));
+
+ if (Handler) Handler->handleGlobalAlias(Ty, Linkage,
+ TypeSlotNo, AliaseeSlotNo);
VarType = read_vbr_uint();
}
}
@@ -2068,6 +2072,23 @@ void BytecodeReader::ParseModule() {
error("Cannot find initializer value.");
}
+ // And aliasees
+ while (!Aliasees.empty()) {
+ GlobalAlias *GA = Aliasees.back().first;
+ unsigned Slot = Aliasees.back().second;
+ Aliasees.pop_back();
+
+ // Look up the aliasee value...
+ const llvm::PointerType* GAType = GA->getType();
+ unsigned TypeSlot = getTypeSlot(GAType);
+ if (Constant *CV = getConstantValue(TypeSlot, Slot)) {
+ if (GA->getAliasee())
+ error("Aliasee was *already* set?!");
+ GA->setAliasee(CV);
+ } else
+ error("Cannot find aliasee value.");
+ }
+
if (!ConstantFwdRefs.empty())
error("Use of undefined constants in a module");
diff --git a/lib/Bytecode/Reader/Reader.h b/lib/Bytecode/Reader/Reader.h
index c852cce6ba..95cf58c2b3 100644
--- a/lib/Bytecode/Reader/Reader.h
+++ b/lib/Bytecode/Reader/Reader.h
@@ -129,6 +129,9 @@ public:
/// them.
typedef std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInitsList;
+ /// @brief A list of global aliases and the slot number for constant aliasees
+ typedef std::vector<std::pair<GlobalAlias*, unsigned> > AliaseeList;
+
/// This type maps a typeslot/valueslot pair to the corresponding Value*.
/// It is used for dealing with forward references as values are read in.
/// @brief A map for dealing with forward references of values.
@@ -338,6 +341,12 @@ private:
/// of what we must do.
GlobalInitsList GlobalInits;
+ /// Constant values are read in after global aliases. Because of this, we must
+ /// defer setting the constant aliasees until after module level constants
+ /// have been read. In the mean time, this list keeps track of what we must
+ /// do.
+ AliaseeList Aliasees;
+
// For lazy reading-in of functions, we need to save away several pieces of
// information about each function: its begin and end pointer in the buffer
// and its FunctionSlot.