]> granicus.if.org Git - llvm/commitdiff
[TBAAVerifier] Memoize validity of scalar tbaa nodes; NFCI
authorSanjoy Das <sanjoy@playingwithpointers.com>
Thu, 29 Dec 2016 15:46:57 +0000 (15:46 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Thu, 29 Dec 2016 15:46:57 +0000 (15:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290711 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Verifier.h
lib/IR/Verifier.cpp

index c074af1b173e8f04bb55ae5ce6f6801ad6e96ba5..7efca7865e65d6e1f8ebb80a1732dfbb6e2b01cf 100644 (file)
@@ -50,6 +50,10 @@ class TBAAVerifier {
   typedef std::pair<bool, unsigned> TBAABaseNodeSummary;
   DenseMap<MDNode *, TBAABaseNodeSummary> TBAABaseNodes;
 
+  /// Maps an alleged scalar TBAA node to a boolean that is true if the said
+  /// TBAA node is a valid scalar TBAA node or false otherwise.
+  DenseMap<const MDNode *, bool> TBAAScalarNodes;
+
   /// \name Helper functions used by \c visitTBAAMetadata.
   /// @{
   MDNode *getFieldNodeFromTBAABaseNode(Instruction &I, MDNode *BaseNode,
@@ -57,6 +61,8 @@ class TBAAVerifier {
   TBAAVerifier::TBAABaseNodeSummary verifyTBAABaseNode(Instruction &I,
                                                        MDNode *BaseNode);
   TBAABaseNodeSummary verifyTBAABaseNodeImpl(Instruction &I, MDNode *BaseNode);
+
+  bool isValidScalarTBAANode(const MDNode *MD);
   /// @}
 
 public:
index 8c91f1ee9e1bf10e94b6c19af0e222e4fe642f2a..d42f5d090d1fe1fa80b167b5bb71556f711dac63 100644 (file)
@@ -4655,9 +4655,18 @@ static bool IsScalarTBAANodeImpl(const MDNode *MD,
          (IsRootTBAANode(Parent) || IsScalarTBAANodeImpl(Parent, Visited));
 }
 
-static bool IsScalarTBAANode(const MDNode *MD) {
+bool TBAAVerifier::isValidScalarTBAANode(const MDNode *MD) {
+  auto ResultIt = TBAAScalarNodes.find(MD);
+  if (ResultIt != TBAAScalarNodes.end())
+    return ResultIt->second;
+
   SmallPtrSet<const MDNode *, 4> Visited;
-  return IsScalarTBAANodeImpl(MD, Visited);
+  bool Result = IsScalarTBAANodeImpl(MD, Visited);
+  auto InsertResult = TBAAScalarNodes.insert({MD, Result});
+  (void)InsertResult;
+  assert(InsertResult.second && "Just checked!");
+
+  return Result;
 }
 
 /// Returns the field node at the offset \p Offset in \p BaseNode.  Update \p
@@ -4735,8 +4744,8 @@ bool TBAAVerifier::visitTBAAMetadata(Instruction &I, MDNode *MD) {
              "should be non-null and point to Metadata nodes",
              &I, MD, BaseNode, AccessType);
 
-  AssertTBAA(IsScalarTBAANode(AccessType), "Access type node must be scalar",
-             &I, MD, AccessType);
+  AssertTBAA(isValidScalarTBAANode(AccessType),
+             "Access type node must be scalar", &I, MD, AccessType);
 
   auto *OffsetCI = mdconst::dyn_extract_or_null<ConstantInt>(MD->getOperand(2));
   AssertTBAA(OffsetCI, "Offset must be constant integer", &I, MD);
@@ -4764,7 +4773,7 @@ bool TBAAVerifier::visitTBAAMetadata(Instruction &I, MDNode *MD) {
 
     SeenAccessTypeInPath |= BaseNode == AccessType;
 
-    if (IsScalarTBAANode(BaseNode) || BaseNode == AccessType)
+    if (isValidScalarTBAANode(BaseNode) || BaseNode == AccessType)
       AssertTBAA(Offset == 0, "Offset not zero at the point of scalar access",
                  &I, MD, &Offset);