[PATCH] [Review Request] Improve getVTList() in SelectionDAG

Wan, Xiaofei xiaofei.wan at intel.com
Thu Oct 10 22:26:32 PDT 2013


Owen:

Thanks for your comments. 
Patch updated http://llvm-reviews.chandlerc.com/D1127

SDVTList SelectionDAG::getVTList(EVT VT1, EVT VT2) {
  const EVT tmpVTs[2] = {VT1, VT2};
  return getVTList(tmpVTs, 2);
}
How does the lifetime of this array work out?  It looks like SDVTListInfo captures the pointer to the EVT array, which was stack allocated.  After this method returns, you're going to have a dangling pointer in the SDVTListInfo.
[Xiaofei] Yes, tmpVTs is an array on the stack, but it is just used temporally to determine whether this SDVTList  exist in the DenseMap, it won't be referenced anymore after that.

SDVTList SelectionDAG::getVTList(const EVT *VTs, unsigned NumVTs) {
  SDVTListInfo Key(VTs, NumVTs);
  if (VTListMap.count(Key))
    return VTListMap[Key];
  
  EVT *Array = Allocator.Allocate<EVT>(NumVTs);
  std::copy(VTs, VTs + NumVTs, Array); -------------------------------------------------VTs is copied out to Array which will be stored in the DenseMap
  SDVTList Result = makeVTList(Array, NumVTs);
  Key.pVTs = Array; --------------------------------------------------VTs is not used any more.
  VTListMap.insert(std::make_pair(Key, Result));

  return Result;
}

Thanks
Wan Xiaofei

-----Original Message-----
From: Owen Anderson [mailto:resistor at mac.com] 
Sent: Friday, October 11, 2013 1:30 AM
To: Wan, Xiaofei
Cc: llvm-commits at cs.uiuc.edu LLVM
Subject: Re: [PATCH] [Review Request] Improve getVTList() in SelectionDAG

Some feedback:

> +  /// getEmptyKey() - A private constructor that returns an unknown 
> + that is  /// not equal to the tombstone key or SDVTListInfo().
> +  static SDVTListInfo getEmptyKey() {
> +    SDVTListInfo SDVTInfo;
> +    SDVTInfo.NumVTs = 0;
> +    return SDVTInfo;
> +  }
> +
> +  /// getTombstoneKey() - A private constructor that returns an 
> + unknown that  /// is not equal to the empty key or SDVTListInfo().
> +  static SDVTListInfo getTombstoneKey() {
> +    SDVTListInfo SDVTInfo;
> +    SDVTInfo.NumVTs = 0;
> +    return SDVTInfo;
> +  }

I don't think this is a valid implementation of the DenseMapInfo callbacks.  getEmptyKey() and getTombstoneKey() have to return values that don't compare equal to each other.

> +  const EVT pVTs[2] = {VT1, VT2};
> +  return getVTList(pVTs, 2);

How does the lifetime of this array work out?  It looks like SDVTListInfo captures the pointer to the EVT array, which was stack allocated.  After this method returns, you're going to have a dangling pointer in the SDVTListInfo.

-Owen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1127.5.patch
Type: application/octet-stream
Size: 5893 bytes
Desc: D1127.5.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131011/57002ab2/attachment.obj>


More information about the llvm-commits mailing list