[llvm] d408770 - [Passes] Use llvm::any_cast instead of any_cast (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 30 00:02:10 PDT 2023


Author: Kazu Hirata
Date: 2023-09-30T00:02:03-07:00
New Revision: d408770c007896d84c3e8d80351bc0d4aeb4e229

URL: https://github.com/llvm/llvm-project/commit/d408770c007896d84c3e8d80351bc0d4aeb4e229
DIFF: https://github.com/llvm/llvm-project/commit/d408770c007896d84c3e8d80351bc0d4aeb4e229.diff

LOG: [Passes] Use llvm::any_cast instead of any_cast (NFC)

This patch replaces any_cast with llvm::any_cast. This in turn allows
us to gracefully switch to std::any in future by forwarding llvm::Any
and llvm::any_cast to:

  using Any = std::any;

  template <class T> T *any_cast(Any *Value) {
    return std::any_cast<T>(Value);
  }

respectively.

Without this patch, it's ambiguous whether any_cast refers to
std::any_cast or llvm::any_cast.

As an added bonus, this patch makes it easier to mechanically replace
llvm::any_cast with std::any_cast without affecting other occurrences of
any_cast (e.g. in libcxx).

Added: 
    

Modified: 
    llvm/lib/Passes/StandardInstrumentations.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 64df3c06bb61242..879a5bd805363b6 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -702,19 +702,19 @@ static SmallString<32> getIRFileDisplayName(Any IR) {
   stable_hash NameHash = stable_hash_combine_string(M->getName());
   unsigned int MaxHashWidth = sizeof(stable_hash) * 8 / 4;
   write_hex(ResultStream, NameHash, HexPrintStyle::Lower, MaxHashWidth);
-  if (any_cast<const Module *>(&IR)) {
+  if (llvm::any_cast<const Module *>(&IR)) {
     ResultStream << "-module";
-  } else if (const Function **F = any_cast<const Function *>(&IR)) {
+  } else if (const Function **F = llvm::any_cast<const Function *>(&IR)) {
     ResultStream << "-function-";
     stable_hash FunctionNameHash = stable_hash_combine_string((*F)->getName());
     write_hex(ResultStream, FunctionNameHash, HexPrintStyle::Lower,
               MaxHashWidth);
   } else if (const LazyCallGraph::SCC **C =
-                 any_cast<const LazyCallGraph::SCC *>(&IR)) {
+                 llvm::any_cast<const LazyCallGraph::SCC *>(&IR)) {
     ResultStream << "-scc-";
     stable_hash SCCNameHash = stable_hash_combine_string((*C)->getName());
     write_hex(ResultStream, SCCNameHash, HexPrintStyle::Lower, MaxHashWidth);
-  } else if (const Loop **L = any_cast<const Loop *>(&IR)) {
+  } else if (const Loop **L = llvm::any_cast<const Loop *>(&IR)) {
     ResultStream << "-loop-";
     stable_hash LoopNameHash = stable_hash_combine_string((*L)->getName());
     write_hex(ResultStream, LoopNameHash, HexPrintStyle::Lower, MaxHashWidth);


        


More information about the llvm-commits mailing list