[llvm] r289602 - Re-land "[SCEVExpander] Use llvm data structures; NFC"

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 13 14:04:58 PST 2016


Author: sanjoy
Date: Tue Dec 13 16:04:58 2016
New Revision: 289602

URL: http://llvm.org/viewvc/llvm-project?rev=289602&view=rev
Log:
Re-land "[SCEVExpander] Use llvm data structures; NFC"

This change re-lands r289215, by reverting r289482.  The underlying
issue that caused it to be reverted has been fixed by Tim Northover in
r289496.

Original commit message for r289215:

[SCEVExpander] Use llvm data structures; NFC

Original commit message for r289482:

Revert "[SCEVExpander] Use llvm data structures; NFC"

This reverts r289215 (git SHA1 cb7b86a1).  It breaks the ubsan build
because a DenseMap that keys off of `AssertingVH<T>` will hit UB when it
tries to cast the empty and tombstone keys to `T *` (due to insufficient
alignment).

This is the relevant stack trace (thanks to Mike Aizatsky):

    #0 0x25cf100 in llvm::AssertingVH<llvm::PHINode>::getValPtr() const llvm/include/llvm/IR/ValueHandle.h:212:39
    #1 0x25cea20 in llvm::AssertingVH<llvm::PHINode>::operator=(llvm::AssertingVH<llvm::PHINode> const&) llvm/include/llvm/IR/ValueHandle.h:234:19
    #2 0x25d0092 in llvm::DenseMapBase<llvm::DenseMap<llvm::AssertingVH<llvm::PHINode>, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::AssertingVH<llvm::PHINode> >, llvm::detail::DenseSetPair<llvm::AssertingVH<llvm::PHINode> > >, llvm::AssertingVH<llvm::PHINode>, llvm::detail::DenseSetEmpty, llvm::DenseMapInfo<llvm::AssertingVH<llvm::PHINode> >, llvm::detail::DenseSetPair<llvm::AssertingVH<llvm::PHINode> > >::clear() llvm/include/llvm/ADT/DenseMap.h:113:23

Modified:
    llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h

Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h?rev=289602&r1=289601&r2=289602&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h Tue Dec 13 16:04:58 2016
@@ -14,13 +14,14 @@
 #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONEXPANDER_H
 #define LLVM_ANALYSIS_SCALAREVOLUTIONEXPANDER_H
 
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
 #include "llvm/Analysis/ScalarEvolutionNormalization.h"
 #include "llvm/Analysis/TargetFolder.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/ValueHandle.h"
-#include <set>
 
 namespace llvm {
   class TargetTransformInfo;
@@ -43,11 +44,12 @@ namespace llvm {
     const char* IVName;
 
     // InsertedExpressions caches Values for reuse, so must track RAUW.
-    std::map<std::pair<const SCEV *, Instruction *>, TrackingVH<Value> >
-      InsertedExpressions;
+    DenseMap<std::pair<const SCEV *, Instruction *>, TrackingVH<Value>>
+        InsertedExpressions;
+
     // InsertedValues only flags inserted instructions so needs no RAUW.
-    std::set<AssertingVH<Value> > InsertedValues;
-    std::set<AssertingVH<Value> > InsertedPostIncValues;
+    DenseSet<AssertingVH<Value>> InsertedValues;
+    DenseSet<AssertingVH<Value>> InsertedPostIncValues;
 
     /// A memoization of the "relevant" loop for a given SCEV.
     DenseMap<const SCEV *, const Loop *> RelevantLoops;
@@ -67,7 +69,7 @@ namespace llvm {
     Instruction *IVIncInsertPos;
 
     /// Phis that complete an IV chain. Reuse
-    std::set<AssertingVH<PHINode> > ChainedPhis;
+    DenseSet<AssertingVH<PHINode>> ChainedPhis;
 
     /// When true, expressions are expanded in "canonical" form. In particular,
     /// addrecs are expanded as arithmetic based on a canonical induction




More information about the llvm-commits mailing list