MachineBranchProbabilityInfo.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //=- MachineBranchProbabilityInfo.h - Branch Probability Analysis -*- C++ -*-=//
  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 pass is used to evaluate branch probabilties on machine basic blocks.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CODEGEN_MACHINEBRANCHPROBABILITYINFO_H
  18. #define LLVM_CODEGEN_MACHINEBRANCHPROBABILITYINFO_H
  19. #include "llvm/CodeGen/MachineBasicBlock.h"
  20. #include "llvm/Pass.h"
  21. #include "llvm/Support/BranchProbability.h"
  22. namespace llvm {
  23. class MachineBranchProbabilityInfo : public ImmutablePass {
  24. virtual void anchor();
  25. // Default weight value. Used when we don't have information about the edge.
  26. // TODO: DEFAULT_WEIGHT makes sense during static predication, when none of
  27. // the successors have a weight yet. But it doesn't make sense when providing
  28. // weight to an edge that may have siblings with non-zero weights. This can
  29. // be handled various ways, but it's probably fine for an edge with unknown
  30. // weight to just "inherit" the non-zero weight of an adjacent successor.
  31. static const uint32_t DEFAULT_WEIGHT = 16;
  32. public:
  33. static char ID;
  34. MachineBranchProbabilityInfo();
  35. void getAnalysisUsage(AnalysisUsage &AU) const override {
  36. AU.setPreservesAll();
  37. }
  38. // Return edge probability.
  39. BranchProbability getEdgeProbability(const MachineBasicBlock *Src,
  40. const MachineBasicBlock *Dst) const;
  41. // Same as above, but using a const_succ_iterator from Src. This is faster
  42. // when the iterator is already available.
  43. BranchProbability
  44. getEdgeProbability(const MachineBasicBlock *Src,
  45. MachineBasicBlock::const_succ_iterator Dst) const;
  46. // A 'Hot' edge is an edge which probability is >= 80%.
  47. bool isEdgeHot(const MachineBasicBlock *Src,
  48. const MachineBasicBlock *Dst) const;
  49. // Print value between 0 (0% probability) and 1 (100% probability),
  50. // however the value is never equal to 0, and can be 1 only iff SRC block
  51. // has only one successor.
  52. raw_ostream &printEdgeProbability(raw_ostream &OS,
  53. const MachineBasicBlock *Src,
  54. const MachineBasicBlock *Dst) const;
  55. };
  56. }
  57. #endif
  58. #ifdef __GNUC__
  59. #pragma GCC diagnostic pop
  60. #endif