<div>This patch adds a new method to DenseMap, "find_as()", which allows more efficient lookups in cases where the map keys are expensive to construct.</div><div><br></div><div>Motivation: There are several examples within LLVM of maps which have keys that contain instances of std::vector. Doing a find() on these maps requires allocating memory to construct a new key. The "find_as()" method is identical in behavior to "find()", except that the key type is a template parameter to the function, allowing the lookup key to have a different type than the keys stored in the map. This alternate key type can be one that is much cheaper to construct, such as an ArrayRef instead of a vector.</div>

<div><br></div><div>The alternate key type must be equality-comparable with the primary key type, and it must hash to the same value. This is handled by the DenseMapInfo for the map. For each alternate key type used, two additional methods must be defined in the DenseMapInfo:</div>

<div><br></div><div>  unsigned getHashValue(AltKeyType);</div><div>  bool isEqual(AltKeyType, PrimaryKeyType);</div><div><br></div><div>This also means that maps that use find_as() must use a custom DenseMapInfo, instead of the template default.</div>

<div><br></div><div>With this change, it will be possible to make some fairly significant optimizations in ConstantUniqueMap and other places.</div><div><br></div><div>Note that I didn't come up with the name "find_as", I got it from another STL implementation that I worked on while I was at Electronic Arts.</div>

<div><br></div>-- <br>-- Talin<br>