Skip to content

Commit

Permalink
[Passes] Use llvm::any_cast instead of any_cast (NFC)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
kazutakahirata committed Sep 30, 2023
1 parent 4909e7c commit d408770
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions llvm/lib/Passes/StandardInstrumentations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d408770

Please sign in to comment.