[llvm-commits] [llvm] r122720 - in /llvm/trunk/lib/Transforms/Scalar: EarlyCSE.cpp LoopIdiomRecognize.cpp

Chris Lattner clattner at apple.com
Sun Jan 2 19:09:16 PST 2011


On Jan 2, 2011, at 6:15 PM, Nick Lewycky wrote:

> On 01/02/2011 05:46 PM, Chris Lattner wrote:
>> 
>> On Jan 2, 2011, at 5:21 PM, Nick Lewycky wrote:
>> 
>>>> +           "Invalid/unknown instruction");
>>>>    }
>>>> -
>>>> +
>>>> +  // Mix in the opcode.
>>>>    return (Res<<   1) ^ Inst->getOpcode();
>>> 
>>> Chris, did you consider using a FoldingSetNodeID to calculate your hash?
>>> I think it would end up cleaner.
>> 
>> How would it help?
> 
> Mostly it just hides the hashing math. You'd end up with:
> 
>  unsigned DenseMapInfo<InstValue>::getHashValue(InstValue Val) {
>    FoldingSetNodeID Res;
>    for (unsigned i = 0, e = Inst->getNumOperands(); i != e; ++i)
>      Res.AddPointer(Inst->getOperand(i));
> 
>    if (CastInst *CI = dyn_cast<CastInst>(Inst))
>      Res.AddPointer(CI->getType());
>    else if (CmpInst *CI = dyn_cast<CmpInst>(Inst))
>      Res.AddInteger(CI->getPredicate());
>    else if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(Inst)) {
>      for (ExtractValueInst::idx_iterator I = EVI->idx_begin(),
>           E = EVI->idx_end(); I != E; ++I)
>        Res.AddInteger(*I);
>    } else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(Inst)) {
>      for (InsertValueInst::idx_iterator I = IVI->idx_begin(),
>           E = IVI->idx_end(); I != E; ++I)
>        Res.AddInteger(*I);
>  [...]
>    Res.AddInteger(I->getOpcode());
>    return Res.ComputeHash();
>  }
> 
> It's nice in that you don't have to worry about how much you're shifting and whether you're going to be mixing the bits properly, etc. It doesn't do anything to reduce the number of lines.

I'd rather not pull in FoldingSet.h.  Thanks for the idea though,

-Chris



More information about the llvm-commits mailing list