aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bytecode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-01-15 18:45:25 +0000
committerChris Lattner <sabre@nondot.org>2004-01-15 18:45:25 +0000
commit933619912bf7af3f226871387902245d91df2e21 (patch)
tree1e305d3d833d7ec16c2b45fec15b3468e0356fa0 /lib/Bytecode
parentff47e7d02ecbd4fc88ce02b952f3f021d9f4d9b5 (diff)
downloadexternal_llvm-933619912bf7af3f226871387902245d91df2e21.zip
external_llvm-933619912bf7af3f226871387902245d91df2e21.tar.gz
external_llvm-933619912bf7af3f226871387902245d91df2e21.tar.bz2
Allow bytecode files to refer directly to global values as constants, instead
of forcing them to go through ConstantPointerRef's. This allows bytecode files to mirror .ll files, allows more efficient encoding, and makes it easier to eventually eliminate CPR's. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10883 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode')
-rw-r--r--lib/Bytecode/Reader/Reader.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index bc84135..9cc24b3 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -151,6 +151,10 @@ Constant *BytecodeParser::getConstantValue(unsigned TypeSlot, unsigned Slot) {
if (Value *V = getValue(TypeSlot, Slot, false))
if (Constant *C = dyn_cast<Constant>(V))
return C; // If we already have the value parsed, just return it
+ else if (GlobalValue *GV = dyn_cast<GlobalValue>(V))
+ // ConstantPointerRef's are an abomination, but at least they don't have
+ // to infest bytecode files.
+ return ConstantPointerRef::get(GV);
else
throw std::string("Reference of a value is expected to be a constant!");
@@ -637,10 +641,10 @@ void BytecodeParser::ParseModule(const unsigned char *Buf,
// Look up the initializer value...
// FIXME: Preserve this type ID!
unsigned TypeSlot = getTypeSlot(GV->getType()->getElementType());
- if (Value *V = getValue(TypeSlot, Slot, false)) {
+ if (Constant *CV = getConstantValue(TypeSlot, Slot)) {
if (GV->hasInitializer())
throw std::string("Global *already* has an initializer?!");
- GV->setInitializer(cast<Constant>(V));
+ GV->setInitializer(CV);
} else
throw std::string("Cannot find initializer value.");
}