[polly] r249544 - IRBuilder: Ensure we do not add empty map elements

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 7 06:20:15 PDT 2015


What about if(Map.lookup(Key))?

If nullptr is an invalid value that works and is shorter/easier than find/end.

On 10/07, Tobias Grosser via llvm-commits wrote:
> Author: grosser
> Date: Wed Oct  7 08:19:06 2015
> New Revision: 249544
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=249544&view=rev
> Log:
> IRBuilder: Ensure we do not add empty map elements
> 
> Do not use "Map[Key] == nullptr" to check if a Key is in the map, but use
> "Map.find(Key) == Map.end()". Map[Key] always adds Key into the map, a
> side-effect we do not want.
> 
> Found by inspection. This is hard to test outside of a targetted unit test,
> which seems too much overhead for this individual issue.
> 
> Modified:
>     polly/trunk/lib/CodeGen/IRBuilder.cpp
> 
> Modified: polly/trunk/lib/CodeGen/IRBuilder.cpp
> URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IRBuilder.cpp?rev=249544&r1=249543&r2=249544&view=diff
> ==============================================================================
> --- polly/trunk/lib/CodeGen/IRBuilder.cpp (original)
> +++ polly/trunk/lib/CodeGen/IRBuilder.cpp Wed Oct  7 08:19:06 2015
> @@ -146,12 +146,22 @@ void ScopAnnotator::annotate(Instruction
>    if (!BasePtr)
>      return;
>  
> -  auto *AliasScope = AliasScopeMap[BasePtr];
> +  auto AliasScopeIterator = AliasScopeMap.find(BasePtr);
>  
> -  if (!AliasScope)
> -    BasePtr = AlternativeAliasBases[BasePtr];
> +  if (AliasScopeIterator == AliasScopeMap.end()) {
> +    auto I = AlternativeAliasBases.find(BasePtr);
> +    if (I == AlternativeAliasBases.end())
> +      return;
>  
> -  AliasScope = AliasScopeMap[BasePtr];
> +    BasePtr = I->second;
> +    AliasScopeIterator = AliasScopeMap.find(BasePtr);
> +    if (AliasScopeIterator == AliasScopeMap.end())
> +      return;
> +  }
> +
> +  auto AliasScope = AliasScopeIterator->second;
> +  assert(OtherAliasScopeListMap.count(BasePtr) &&
> +         "BasePtr either expected in AliasScopeMap and OtherAlias...Map");
>    auto *OtherAliasScopeList = OtherAliasScopeListMap[BasePtr];
>  
>    Inst->setMetadata("alias.scope", AliasScope);
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits

-- 

Johannes Doerfert
Researcher / PhD Student

Compiler Design Lab (Prof. Hack)
Saarland University, Computer Science
Building E1.3, Room 4.31

Tel. +49 (0)681 302-57521 : doerfert at cs.uni-saarland.de
Fax. +49 (0)681 302-3065  : http://www.cdl.uni-saarland.de/people/doerfert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151007/a4c70779/attachment.sig>


More information about the llvm-commits mailing list