IndirectCallVisitor.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- IndirectCallVisitor.h - indirect call visitor ---------------------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file implements defines a visitor class and a helper function that find
  15. // all indirect call-sites in a function.
  16. #ifndef LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
  17. #define LLVM_ANALYSIS_INDIRECTCALLVISITOR_H
  18. #include "llvm/IR/InstVisitor.h"
  19. #include <vector>
  20. namespace llvm {
  21. // Visitor class that finds all indirect call.
  22. struct PGOIndirectCallVisitor : public InstVisitor<PGOIndirectCallVisitor> {
  23. std::vector<CallBase *> IndirectCalls;
  24. PGOIndirectCallVisitor() {}
  25. void visitCallBase(CallBase &Call) {
  26. if (Call.isIndirectCall())
  27. IndirectCalls.push_back(&Call);
  28. }
  29. };
  30. // Helper function that finds all indirect call sites.
  31. inline std::vector<CallBase *> findIndirectCalls(Function &F) {
  32. PGOIndirectCallVisitor ICV;
  33. ICV.visit(F);
  34. return ICV.IndirectCalls;
  35. }
  36. } // namespace llvm
  37. #endif
  38. #ifdef __GNUC__
  39. #pragma GCC diagnostic pop
  40. #endif