diff options
| author | Chris Lattner <sabre@nondot.org> | 2002-10-14 03:33:02 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2002-10-14 03:33:02 +0000 |
| commit | 2862d2ec711cb77a954f313f11e280280691c895 (patch) | |
| tree | 6932a5cbe8738c79ab55e80108515b4718aa0758 /llvm/lib/Bytecode/Reader/Reader.cpp | |
| parent | 163b890dfb7811e2ff473d548570823c63d4d598 (diff) | |
| download | bcm5719-llvm-2862d2ec711cb77a954f313f11e280280691c895.tar.gz bcm5719-llvm-2862d2ec711cb77a954f313f11e280280691c895.zip | |
There is no way to guarantee that constants are not forward referenced.
Handle forward referenced constants in a general way. This fixes bug:
Assembler/2002-10-13-ConstantEncodingProblem.llx and allows the SPEC
197.parser benchmark to be built
llvm-svn: 4161
Diffstat (limited to 'llvm/lib/Bytecode/Reader/Reader.cpp')
| -rw-r--r-- | llvm/lib/Bytecode/Reader/Reader.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Bytecode/Reader/Reader.cpp b/llvm/lib/Bytecode/Reader/Reader.cpp index 9898af93187..9aa54552110 100644 --- a/llvm/lib/Bytecode/Reader/Reader.cpp +++ b/llvm/lib/Bytecode/Reader/Reader.cpp @@ -132,6 +132,34 @@ Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) { return d; } +/// getConstantValue - Just like getValue, except that it returns a null pointer +/// only on error. It always returns a constant (meaning that if the value is +/// defined, but is not a constant, that is an error). If the specified +/// constant hasn't been parsed yet, a placeholder is defined and used. Later, +/// after the real value is parsed, the placeholder is eliminated. +/// +Constant *BytecodeParser::getConstantValue(const Type *Ty, unsigned Slot) { + if (Value *V = getValue(Ty, Slot, false)) + return dyn_cast<Constant>(V); // If we already have the value parsed... + + GlobalRefsType::iterator I = GlobalRefs.find(make_pair(Ty, Slot)); + if (I != GlobalRefs.end()) { + BCR_TRACE(5, "Previous forward ref found!\n"); + return cast<Constant>(I->second); + } else { + // Create a placeholder for the constant reference and + // keep track of the fact that we have a forward ref to recycle it + BCR_TRACE(5, "Creating new forward ref to a constant!\n"); + Constant *C = new ConstPHolder(Ty, Slot); + + // Keep track of the fact that we have a forward ref to recycle it + GlobalRefs.insert(make_pair(make_pair(Ty, Slot), C)); + return C; + } +} + + + bool BytecodeParser::postResolveValues(ValueTable &ValTab) { bool Error = false; for (unsigned ty = 0; ty < ValTab.size(); ++ty) { |

