Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.0 KiB

  1. //===- CodeMetrics.h - Code cost measurements -------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements various weight measurements for code, helping
  11. // the Inliner and other passes decide whether to duplicate its contents.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_ANALYSIS_CODEMETRICS_H
  15. #define LLVM_ANALYSIS_CODEMETRICS_H
  16. #include "llvm/ADT/DenseMap.h"
  17. #include "llvm/Support/CallSite.h"
  18. namespace llvm {
  19. class BasicBlock;
  20. class Function;
  21. class Instruction;
  22. class DataLayout;
  23. class TargetTransformInfo;
  24. class Value;
  25. /// \brief Check whether a call will lower to something small.
  26. ///
  27. /// This tests checks whether this callsite will lower to something
  28. /// significantly cheaper than a traditional call, often a single
  29. /// instruction. Note that if isInstructionFree(CS.getInstruction()) would
  30. /// return true, so will this function.
  31. bool callIsSmall(ImmutableCallSite CS);
  32. /// \brief Utility to calculate the size and a few similar metrics for a set
  33. /// of basic blocks.
  34. struct CodeMetrics {
  35. /// \brief True if this function contains a call to setjmp or other functions
  36. /// with attribute "returns twice" without having the attribute itself.
  37. bool exposesReturnsTwice;
  38. /// \brief True if this function calls itself.
  39. bool isRecursive;
  40. /// \brief True if this function cannot be duplicated.
  41. ///
  42. /// True if this function contains one or more indirect branches, or it contains
  43. /// one or more 'noduplicate' instructions.
  44. bool notDuplicatable;
  45. /// \brief True if this function calls alloca (in the C sense).
  46. bool usesDynamicAlloca;
  47. /// \brief Number of instructions in the analyzed blocks.
  48. unsigned NumInsts;
  49. /// \brief Number of analyzed blocks.
  50. unsigned NumBlocks;
  51. /// \brief Keeps track of basic block code size estimates.
  52. DenseMap<const BasicBlock *, unsigned> NumBBInsts;
  53. /// \brief Keep track of the number of calls to 'big' functions.
  54. unsigned NumCalls;
  55. /// \brief The number of calls to internal functions with a single caller.
  56. ///
  57. /// These are likely targets for future inlining, likely exposed by
  58. /// interleaved devirtualization.
  59. unsigned NumInlineCandidates;
  60. /// \brief How many instructions produce vector values.
  61. ///
  62. /// The inliner is more aggressive with inlining vector kernels.
  63. unsigned NumVectorInsts;
  64. /// \brief How many 'ret' instructions the blocks contain.
  65. unsigned NumRets;
  66. CodeMetrics()
  67. : exposesReturnsTwice(false), isRecursive(false), notDuplicatable(false),
  68. usesDynamicAlloca(false), NumInsts(0), NumBlocks(0), NumCalls(0),
  69. NumInlineCandidates(0), NumVectorInsts(0), NumRets(0) {}
  70. /// \brief Add information about a block to the current state.
  71. void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI);
  72. };
  73. }
  74. #endif