[LLVMdev] inefficiencies in ConstantUniqueMap ?

Jay Foad jay.foad at gmail.com
Fri Jun 24 08:28:52 PDT 2011


Hi,

Consider ConstantUniqueMap::getOrCreate() (in lib/VMCore/ConstantsContext.h):

  /// getOrCreate - Return the specified constant from the map, creating it if
  /// necessary.
  ConstantClass *getOrCreate(const TypeClass *Ty, ValRefType V) {
    MapKey Lookup(Ty, V);
    ConstantClass* Result = 0;
    ...

For array (or struct or vector) constants, typically:

ValType = vector<Constant*>
ValRefType = ArrayRef<Constant*>
MapKey = pair<ArrayType, vector<Constant*>>

So am I right in thinking that the line:

    MapKey Lookup(Ty, V);

is expensive because it has to copy a whole vector? It seems like this
should not be necessary, just to look something up in the map.

Further, if we don't find it in the map, we call Create(), which
constructs *another* copy of MapKey(Ty, V), which will be expensive
all over again.

Thanks,
Jay.



More information about the llvm-dev mailing list