forked from OSchip/llvm-project
BitcodeWriter: Refactor common computation of bits required for a type index.
Suggested by Duncan. Happy to bikeshed the name, cache the result, etc. llvm-svn: 230410
This commit is contained in:
parent
efa60dfd34
commit
7b0281089e
|
@ -323,7 +323,7 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) {
|
|||
Stream.EnterSubblock(bitc::TYPE_BLOCK_ID_NEW, 4 /*count from # abbrevs */);
|
||||
SmallVector<uint64_t, 64> TypeVals;
|
||||
|
||||
uint64_t NumBits = Log2_32_Ceil(VE.getTypes().size()+1);
|
||||
uint64_t NumBits = VE.computeBitsRequiredForTypeIndicies();
|
||||
|
||||
// Abbrev for TYPE_CODE_POINTER.
|
||||
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
|
||||
|
@ -2182,7 +2182,7 @@ static void WriteBlockInfo(const ValueEnumerator &VE, BitstreamWriter &Stream) {
|
|||
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
|
||||
Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_SETTYPE));
|
||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
|
||||
Log2_32_Ceil(VE.getTypes().size()+1)));
|
||||
VE.computeBitsRequiredForTypeIndicies()));
|
||||
if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID,
|
||||
Abbv) != CONSTANTS_SETTYPE_ABBREV)
|
||||
llvm_unreachable("Unexpected abbrev ordering!");
|
||||
|
@ -2202,7 +2202,7 @@ static void WriteBlockInfo(const ValueEnumerator &VE, BitstreamWriter &Stream) {
|
|||
Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_CE_CAST));
|
||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // cast opc
|
||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // typeid
|
||||
Log2_32_Ceil(VE.getTypes().size()+1)));
|
||||
VE.computeBitsRequiredForTypeIndicies()));
|
||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // value id
|
||||
|
||||
if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID,
|
||||
|
@ -2255,7 +2255,7 @@ static void WriteBlockInfo(const ValueEnumerator &VE, BitstreamWriter &Stream) {
|
|||
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_CAST));
|
||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpVal
|
||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
|
||||
Log2_32_Ceil(VE.getTypes().size()+1)));
|
||||
VE.computeBitsRequiredForTypeIndicies()));
|
||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
|
||||
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID,
|
||||
Abbv) != FUNCTION_INST_CAST_ABBREV)
|
||||
|
|
|
@ -803,3 +803,7 @@ unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const {
|
|||
IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs);
|
||||
return getGlobalBasicBlockID(BB);
|
||||
}
|
||||
|
||||
uint64_t ValueEnumerator::computeBitsRequiredForTypeIndicies() const {
|
||||
return Log2_32_Ceil(getTypes().size() + 1);
|
||||
}
|
||||
|
|
|
@ -182,6 +182,7 @@ public:
|
|||
///
|
||||
void incorporateFunction(const Function &F);
|
||||
void purgeFunction();
|
||||
uint64_t computeBitsRequiredForTypeIndicies() const;
|
||||
|
||||
private:
|
||||
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
|
||||
|
|
Loading…
Reference in New Issue