compile error when using overloaded = operator of DenseMap

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

compile error when using overloaded = operator of DenseMap

Rekha R
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?

--
Rekha

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: compile error when using overloaded = operator of DenseMap

Benjamin Kramer
On Mon, Nov 4, 2013 at 10:35 AM, Rekha R <[hidden email]> 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

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: compile error when using overloaded = operator of DenseMap

Rekha R
Thank you Benjamin. I did what you suggested and got the code working.
But this I did mechanically, by looking at some example code.

Could you explain the functions - getEmptyKey, getTombstoneKey, getHashValue, and isEqual?
Also, the need for redefining them.

Regards,
Rekha


On Mon, Nov 4, 2013 at 5:16 PM, Benjamin Kramer <[hidden email]> wrote:
On Mon, Nov 4, 2013 at 10:35 AM, Rekha R <[hidden email]> 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



--
Rekha

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev