IndirectCallVisitor.h 1.2 KB

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