[LLVMdev] compile error when using overloaded = operator of DenseMap

Benjamin Kramer benny.kra at gmail.com
Mon Nov 4 03:46:48 PST 2013


On Mon, Nov 4, 2013 at 10:35 AM, Rekha R <rekharamapai at nitc.ac.in> wrote:
> Hi,
>
> I am trying to implement Available Expressions data flow analysis. I created
> the following class (I am giving here code snippet.):
>
> namespace {
>   typedef DenseMap<Expression, uint32_t> DMTy;  //Expression is a class I
> defined.
>   struct DataFlowValue {
>     DMTy ExprMap;
>     llvm::BitVector* DFV;
>
>   // Functions operating on the data //
>     bool operator==(const DataFlowValue V) const;
>     void top();  /* set all elements */
>     void bot();  /* reset all elements */
>     void set(DMTy emap);
>     void merge(DataFlowValue V);  /* confluence operation  */
>   };
> }
>
> with the following function definition:
>
> void DataFlowValue::set(DMTy emap) {
>   ExprMap = *emap;    //Line153:
> }
>
> When I compile, I get the following error:
>
> /home/zeus/masterLLVM/llvm/include/llvm/ADT/DenseMap.h: In member function
> ‘void llvm::DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT>::destroyAll()
> [with DerivedT = llvm::DenseMap<{anonymous}::Expression, unsigned int>, KeyT
> = {anonymous}::Expression, ValueT = unsigned int, KeyInfoT =
> llvm::DenseMapInfo<{anonymous}::Expression>]’:
> /home/zeus/masterLLVM/llvm/include/llvm/ADT/DenseMap.h:600:5:   instantiated
> from ‘void llvm::DenseMap<KeyT, ValueT, KeyInfoT>::copyFrom(const
> llvm::DenseMap<KeyT, ValueT, KeyInfoT>&) [with KeyT =
> {anonymous}::Expression, ValueT = unsigned int, KeyInfoT =
> llvm::DenseMapInfo<{anonymous}::Expression>, llvm::DenseMap<KeyT, ValueT,
> KeyInfoT> = llvm::DenseMap<{anonymous}::Expression, unsigned int>]’
> /home/zeus/masterLLVM/llvm/include/llvm/ADT/DenseMap.h:585:5:   instantiated
> from ‘llvm::DenseMap<KeyT, ValueT, KeyInfoT>& llvm::DenseMap<KeyT, ValueT,
> KeyInfoT>::operator=(const llvm::DenseMap<KeyT, ValueT, KeyInfoT>&) [with
> KeyT = {anonymous}::Expression, ValueT = unsigned int, KeyInfoT =
> llvm::DenseMapInfo<{anonymous}::Expression>, llvm::DenseMap<KeyT, ValueT,
> KeyInfoT> = llvm::DenseMap<{anonymous}::Expression, unsigned int>]’
> /home/zeus/masterLLVM/llvm/lib/Analysis/AVEAnalysis.cpp:153:13:
> instantiated from here
> /home/zeus/masterLLVM/llvm/include/llvm/ADT/DenseMap.h:256:7: error:
> ‘isEqual’ is not a member of ‘llvm::DenseMapInfo<{anonymous}::Expression>’
> /home/zeus/masterLLVM/llvm/include/llvm/ADT/DenseMap.h:256:7: error:
> ‘isEqual’ is not a member of ‘llvm::DenseMapInfo<{anonymous}::Expression>’
>
> Can someone help me solve the error?

To use DenseMap with your own class as a key you have to specialize
DenseMapInfo first, DenseMapInfo.h has some examples.

In particular you have to set aside two special values as "empty" and
"tombstone" (deleted) keys that can not occur in normal Expressions.
Then you have to define a hash function for Expression and implement
isEqual, which will likely just call operator== on your objects.

See also http://llvm.org/docs/ProgrammersManual.html#llvm-adt-densemap-h

- Ben




More information about the llvm-dev mailing list