]> granicus.if.org Git - llvm/commitdiff
[Attributor] Only return attributes with a valid state
authorJohannes Doerfert <jdoerfert@anl.gov>
Sat, 13 Jul 2019 01:09:21 +0000 (01:09 +0000)
committerJohannes Doerfert <jdoerfert@anl.gov>
Sat, 13 Jul 2019 01:09:21 +0000 (01:09 +0000)
Attributor::getAAFor will now only return AbstractAttributes with a
valid AbstractState. This simplifies call sites as they only need to
check if the returned pointer is non-null. It also reduces the potential
for accidental misuse.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365983 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/IPO/Attributor.h
lib/Transforms/IPO/Attributor.cpp

index 0b72394e8e9ec055d557857a089210ca4d026564..435aaca75d1c2cfc62aabff21c1a2823b27a1c17 100644 (file)
@@ -199,8 +199,12 @@ struct Attributor {
     const auto &KindToAbstractAttributeMap = AAMap.lookup({&V, ArgNo});
     if (AAType *AA = static_cast<AAType *>(
             KindToAbstractAttributeMap.lookup(AAType::ID))) {
-      QueryMap[AA].insert(&QueryingAA);
-      return AA;
+      // Do not return an attribute with an invalid state. This minimizes checks
+      // at the calls sites and allows the fallback below to kick in.
+      if (AA->getState().isValidState()) {
+        QueryMap[AA].insert(&QueryingAA);
+        return AA;
+      }
     }
 
     // If no abstract attribute was found and we look for a call site argument,
index 85aa7a63ada57c55aa0f4f06bebca91453489bf6..5fea3d0b87a0921d080aa39bd1beb608723def0d 100644 (file)
@@ -655,7 +655,7 @@ ChangeStatus AAReturnedValuesImpl::updateImpl(Attributor &A) {
 
     // Try to find a assumed unique return value for the called function.
     auto *RetCSAA = A.getAAFor<AAReturnedValuesImpl>(*this, *RV);
-    if (!RetCSAA || !RetCSAA->isValidState()) {
+    if (!RetCSAA) {
       HasOverdefinedReturnedCalls = true;
       LLVM_DEBUG(dbgs() << "[AAReturnedValues] Returned call site (" << *RV
                         << ") with " << (RetCSAA ? "invalid" : "no")
@@ -965,8 +965,7 @@ ChangeStatus AANoFreeFunction::updateImpl(Attributor &A) {
       auto ICS = ImmutableCallSite(I);
       auto *NoFreeAA = A.getAAFor<AANoFreeFunction>(*this, *I);
 
-      if ((!NoFreeAA || !NoFreeAA->isValidState() ||
-           !NoFreeAA->isAssumedNoFree()) &&
+      if ((!NoFreeAA || !NoFreeAA->isAssumedNoFree()) &&
           !ICS.hasFnAttr(Attribute::NoFree)) {
         indicatePessimisticFixpoint();
         return ChangeStatus::CHANGED;