]> granicus.if.org Git - llvm/commitdiff
[Instruction] Add hasMetadata(Kind) helper [NFC]
authorPhilip Reames <listmail@philipreames.com>
Wed, 4 Sep 2019 17:28:48 +0000 (17:28 +0000)
committerPhilip Reames <listmail@philipreames.com>
Wed, 4 Sep 2019 17:28:48 +0000 (17:28 +0000)
It's a common idiom, so let's add the obvious wrapper for metadata kinds which are basically booleans.

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

include/llvm/IR/Instruction.h
lib/Analysis/MemoryDependenceAnalysis.cpp
lib/Transforms/Instrumentation/AddressSanitizer.cpp
lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
lib/Transforms/Scalar/EarlyCSE.cpp
lib/Transforms/Scalar/LoopPredication.cpp
lib/Transforms/Utils/ImportedFunctionsInliningStatistics.cpp

index 6a9a74bd16f0f5f708d40b68bd6090f78fed2570..803f6977b32c09ffa3b5a4e93f95d2b8e5ca114d 100644 (file)
@@ -229,6 +229,16 @@ public:
     return hasMetadataHashEntry();
   }
 
+  /// Return true if this instruction has the given type of metadata attached.
+  bool hasMetadata(unsigned KindID) const {
+    return getMetadata(KindID) != nullptr;
+  }
+
+  /// Return true if this instruction has the given type of metadata attached.
+  bool hasMetadata(StringRef Kind) const {
+    return getMetadata(Kind) != nullptr;
+  }
+
   /// Get the metadata of given kind attached to this Instruction.
   /// If the metadata is not found then return null.
   MDNode *getMetadata(unsigned KindID) const {
index 8ee2c6455e8647b7b85ff0cb27e3cdd8f3fd0111..89f30240e8ed4c7eff43110d4080de2bff8bfb0c 100644 (file)
@@ -356,7 +356,7 @@ MemDepResult
 MemoryDependenceResults::getInvariantGroupPointerDependency(LoadInst *LI,
                                                             BasicBlock *BB) {
 
-  if (!LI->getMetadata(LLVMContext::MD_invariant_group))
+  if (!LI->hasMetadata(LLVMContext::MD_invariant_group))
     return MemDepResult::getUnknown();
 
   // Take the ptr operand after all casts and geps 0. This way we can search
@@ -417,7 +417,7 @@ MemoryDependenceResults::getInvariantGroupPointerDependency(LoadInst *LI,
       // same pointer operand) we can assume that value pointed by pointer
       // operand didn't change.
       if ((isa<LoadInst>(U) || isa<StoreInst>(U)) &&
-          U->getMetadata(LLVMContext::MD_invariant_group) != nullptr)
+          U->hasMetadata(LLVMContext::MD_invariant_group))
         ClosestDependency = GetClosestDependency(ClosestDependency, U);
     }
   }
@@ -481,7 +481,7 @@ MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom(
   // Arguably, this logic should be pushed inside AliasAnalysis itself.
   if (isLoad && QueryInst) {
     LoadInst *LI = dyn_cast<LoadInst>(QueryInst);
-    if (LI && LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr)
+    if (LI && LI->hasMetadata(LLVMContext::MD_invariant_load))
       isInvariantLoad = true;
   }
 
index a4cdc4f27c4dac0353413253f5cfb4d54fee3a61..7dcab7a49650f397ae35f3d80216dc707e5218a7 100644 (file)
@@ -1346,7 +1346,7 @@ Value *AddressSanitizer::isInterestingMemoryAccess(Instruction *I,
                                                    unsigned *Alignment,
                                                    Value **MaybeMask) {
   // Skip memory accesses inserted by another instrumentation.
-  if (I->getMetadata("nosanitize")) return nullptr;
+  if (I->hasMetadata("nosanitize")) return nullptr;
 
   // Do not instrument the load fetching the dynamic shadow address.
   if (LocalDynamicShadow == I)
@@ -2686,7 +2686,7 @@ bool AddressSanitizer::instrumentFunction(Function &F,
         if (CS) {
           // A call inside BB.
           TempsToInstrument.clear();
-          if (CS.doesNotReturn() && !CS->getMetadata("nosanitize"))
+          if (CS.doesNotReturn() && !CS->hasMetadata("nosanitize"))
             NoReturnCalls.push_back(CS.getInstruction());
         }
         if (CallInst *CI = dyn_cast<CallInst>(&Inst))
index ca67eee1bef9f2a5d8eb132eb9e7f2232fb9b76a..df7606dfa247de9f1213413a30453c82e612f013 100644 (file)
@@ -500,7 +500,7 @@ Value *HWAddressSanitizer::isInterestingMemoryAccess(Instruction *I,
                                                      unsigned *Alignment,
                                                      Value **MaybeMask) {
   // Skip memory accesses inserted by another instrumentation.
-  if (I->getMetadata("nosanitize")) return nullptr;
+  if (I->hasMetadata("nosanitize")) return nullptr;
 
   // Do not instrument the load fetching the dynamic shadow address.
   if (LocalDynamicShadow == I)
index 829f310b6fb005bb8e911a81c4a503f3395dbbf4..09530a6a5aedbe7b6169216eb266f56fcacb78b7 100644 (file)
@@ -652,7 +652,7 @@ private:
 
     bool isInvariantLoad() const {
       if (auto *LI = dyn_cast<LoadInst>(Inst))
-        return LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr;
+        return LI->hasMetadata(LLVMContext::MD_invariant_load);
       return false;
     }
 
index 507a1e251ca657cfe34f7c2d0e72365c9011a931..885c0e8f4b8b8fc04e6d5cc121b0148a69866e47 100644 (file)
@@ -543,7 +543,7 @@ bool LoopPredication::isLoopInvariantValue(const SCEV* S) {
     if (const auto *LI = dyn_cast<LoadInst>(U->getValue()))
       if (LI->isUnordered() && L->hasLoopInvariantOperands(LI))
         if (AA->pointsToConstantMemory(LI->getOperand(0)) ||
-            LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr)
+            LI->hasMetadata(LLVMContext::MD_invariant_load))
           return true;
   return false;
 }
index 1e9864a12d1b55effa59de040cf94bc66b9ed4a0..ea93f99d69e34b39a89a7ca2e7e3ab71de67737d 100644 (file)
@@ -26,7 +26,7 @@ ImportedFunctionsInliningStatistics::createInlineGraphNode(const Function &F) {
   auto &ValueLookup = NodesMap[F.getName()];
   if (!ValueLookup) {
     ValueLookup = std::make_unique<InlineGraphNode>();
-    ValueLookup->Imported = F.getMetadata("thinlto_src_module") != nullptr;
+    ValueLookup->Imported = F.hasMetadata("thinlto_src_module");
   }
   return *ValueLookup;
 }
@@ -64,7 +64,7 @@ void ImportedFunctionsInliningStatistics::setModuleInfo(const Module &M) {
     if (F.isDeclaration())
       continue;
     AllFunctions++;
-    ImportedFunctions += int(F.getMetadata("thinlto_src_module") != nullptr);
+    ImportedFunctions += int(F.hasMetadata("thinlto_src_module"));
   }
 }
 static std::string getStatString(const char *Msg, int32_t Fraction, int32_t All,