From e2f63174364087b019600f5a14587990bfcfb787 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 15 Jan 2004 18:45:25 +0000 Subject: [PATCH] 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. llvm-svn: 10883 --- llvm/lib/Bytecode/Reader/Reader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Bytecode/Reader/Reader.cpp b/llvm/lib/Bytecode/Reader/Reader.cpp index bc84135a96fa..9cc24b32cda0 100644 --- a/llvm/lib/Bytecode/Reader/Reader.cpp +++ b/llvm/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(V)) return C; // If we already have the value parsed, just return it + else if (GlobalValue *GV = dyn_cast(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(V)); + GV->setInitializer(CV); } else throw std::string("Cannot find initializer value."); }