[llvm-commits] [PATCH] Make Inits FoldingSetNodes
Chris Lattner
clattner at apple.com
Thu Jul 14 20:43:25 PDT 2011
On Jul 14, 2011, at 2:47 PM, David A. Greene wrote:
> Chris Lattner <clattner at apple.com> writes:
>
>> On Jul 13, 2011, at 3:33 PM, David Greene wrote:
>> @@ -530,6 +629,23 @@ const Init *OpInit::resolveListElementReference(Record &R, const
>> +const UnOpInit *UnOpInit::get(UnaryOp opc, const Init *lhs, RecTy *Type) {
>> + FoldingSetNodeID ID;
>> + ID.AddInteger(initUnOp);
>> + ID.AddInteger(opc);
>> + ID.AddString(Type->getAsString());
>> + ID.AddPointer(lhs);
>>
>> DenseMap makes sense here.
>>
>> +const BinOpInit *BinOpInit::get(BinaryOp opc, const Init *lhs,
>> + const Init *rhs, RecTy *Type) {
>>
>> and here.
>>
>> +const TernOpInit *TernOpInit::get(TernaryOp opc, const Init *lhs,
>> + const Init *mhs, const Init *rhs,
>> + RecTy *Type) {
>>
>> and here.
>
> I am going through and uniquing Inits in their own unique ways.
>
> Question on these three. DenseMap of what? There's an opcode, multiple
> operands and a type. What's the Key, a struct of these items? Is a
> DenseMap much more efficient than a FoldingSetNode when string
> comparison/hash is involved? Wouldn't hashing a struct of these and
> putting them in a DenseMap basically be equivalent to a FoldingSet?
FoldingSet is only efficient for very large and heterogenous objects. Its constant factor is really very very high, so densemap is almost always a win for something with a few elements.
-Chris
More information about the llvm-commits
mailing list