aboutsummaryrefslogtreecommitdiff
path: root/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h
diff options
context:
space:
mode:
authorKarl Schimpf <kschimpf@google.com>2013-06-24 12:12:38 -0700
committerKarl Schimpf <kschimpf@google.com>2013-06-24 12:12:38 -0700
commit9bdedeb556e162cecaa79aff339150ea53aae99f (patch)
tree9a8440ecdfd3c06d74e2627c9a4aee2b144de006 /lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h
parent41dd5ede22556305aed7ea2184a2905f187db78c (diff)
Simplify representation of forward value references in bitcode.
Simplify instruction records by adding concept of a forward type reference map that maps ValueID's to types. Used to generate forward reference types for instruction arguments that need a type because the forward reference has not yet been generated. BUG= https://code.google.com/p/nativeclient/issues/detail?id=3507 R=jvoung@chromium.org, mseaborn@chromium.org Review URL: https://codereview.chromium.org/16963004
Diffstat (limited to 'lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h')
-rw-r--r--lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h44
1 files changed, 23 insertions, 21 deletions
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h
index a426c22f1d..57757e7ded 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h
+++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h
@@ -77,8 +77,13 @@ public:
ValuePtrs.resize(N);
}
+ // Gets or creates the forward reference value for Idx with the given type.
+ Value *getOrCreateValueFwdRef(unsigned Idx, Type *Ty);
+
Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
- Value *getValueFwdRef(unsigned Idx, Type *Ty);
+
+ // Gets the forward reference value for Idx.
+ Value *getValueFwdRef(unsigned Idx);
void AssignValue(Value *V, unsigned Idx);
@@ -240,37 +245,34 @@ private:
(!AcceptSupportedBitcodeOnly && Header.IsReadable()));
}
Type *getTypeByID(unsigned ID);
- Value *getFnValueByID(unsigned ID, Type *Ty) {
+ // Gets or creates the (function-level) forward referenced value for
+ // ID with the given type.
+ Value *getOrCreateFnValueByID(unsigned ID, Type *Ty) {
if (Ty && Ty->isMetadataTy())
return MDValueList.getValueFwdRef(ID);
- return ValueList.getValueFwdRef(ID, Ty);
+ return ValueList.getOrCreateValueFwdRef(ID, Ty);
+ }
+ // Returns the value associated with ID. The value must already exist,
+ // or a forward referenced value created by getOrCreateFnVaueByID.
+ Value *getFnValueByID(unsigned ID) {
+ return ValueList.getValueFwdRef(ID);
}
BasicBlock *getBasicBlock(unsigned ID) const {
if (ID >= FunctionBBs.size()) return 0; // Invalid ID
return FunctionBBs[ID];
}
- /// getValueTypePair - Read a value/type pair out of the specified record from
- /// slot 'Slot'. Increment Slot past the number of slots used in the record.
- /// Return true on failure.
- bool getValueTypePair(SmallVector<uint64_t, 64> &Record, unsigned &Slot,
- unsigned InstNum, Value *&ResVal) {
+ /// \brief Read a value out of the specified record from slot 'Slot'.
+ /// Increment Slot past the number of slots used by the value in the record.
+ /// Return true if there is an error.
+ bool getValue(SmallVector<uint64_t, 64> &Record, unsigned &Slot,
+ unsigned InstNum, Value *&ResVal) {
if (Slot == Record.size()) return true;
unsigned ValNo = (unsigned)Record[Slot++];
// Adjust the ValNo, if it was encoded relative to the InstNum.
if (UseRelativeIDs)
ValNo = InstNum - ValNo;
- if (ValNo < InstNum) {
- // If this is not a forward reference, just return the value we already
- // have.
- ResVal = getFnValueByID(ValNo, 0);
- return ResVal == 0;
- } else if (Slot == Record.size()) {
- return true;
- }
-
- unsigned TypeNo = (unsigned)Record[Slot++];
- ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
+ ResVal = getFnValueByID(ValNo);
return ResVal == 0;
}
@@ -302,7 +304,7 @@ private:
// Adjust the ValNo, if it was encoded relative to the InstNum.
if (UseRelativeIDs)
ValNo = InstNum - ValNo;
- return getFnValueByID(ValNo, Ty);
+ return getOrCreateFnValueByID(ValNo, Ty);
}
/// getValueSigned -- Like getValue, but decodes signed VBRs.
@@ -313,7 +315,7 @@ private:
// Adjust the ValNo, if it was encoded relative to the InstNum.
if (UseRelativeIDs)
ValNo = InstNum - ValNo;
- return getFnValueByID(ValNo, Ty);
+ return getOrCreateFnValueByID(ValNo, Ty);
}
bool ParseModule(bool Resume);