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.

78 lines
2.6 KiB

  1. //===---------------- lib/CodeGen/CalcSpillWeights.h ------------*- 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. #ifndef LLVM_CODEGEN_CALCSPILLWEIGHTS_H
  10. #define LLVM_CODEGEN_CALCSPILLWEIGHTS_H
  11. #include "llvm/ADT/DenseMap.h"
  12. #include "llvm/CodeGen/SlotIndexes.h"
  13. namespace llvm {
  14. class LiveInterval;
  15. class LiveIntervals;
  16. class MachineLoopInfo;
  17. /// normalizeSpillWeight - The spill weight of a live interval is computed as:
  18. ///
  19. /// (sum(use freq) + sum(def freq)) / (K + size)
  20. ///
  21. /// @param UseDefFreq Expected number of executed use and def instructions
  22. /// per function call. Derived from block frequencies.
  23. /// @param Size Size of live interval as returnexd by getSize()
  24. ///
  25. static inline float normalizeSpillWeight(float UseDefFreq, unsigned Size) {
  26. // The constant 25 instructions is added to avoid depending too much on
  27. // accidental SlotIndex gaps for small intervals. The effect is that small
  28. // intervals have a spill weight that is mostly proportional to the number
  29. // of uses, while large intervals get a spill weight that is closer to a use
  30. // density.
  31. return UseDefFreq / (Size + 25*SlotIndex::InstrDist);
  32. }
  33. /// VirtRegAuxInfo - Calculate auxiliary information for a virtual
  34. /// register such as its spill weight and allocation hint.
  35. class VirtRegAuxInfo {
  36. MachineFunction &MF;
  37. LiveIntervals &LIS;
  38. const MachineLoopInfo &Loops;
  39. DenseMap<unsigned, float> Hint;
  40. public:
  41. VirtRegAuxInfo(MachineFunction &mf, LiveIntervals &lis,
  42. const MachineLoopInfo &loops) :
  43. MF(mf), LIS(lis), Loops(loops) {}
  44. /// CalculateWeightAndHint - (re)compute li's spill weight and allocation
  45. /// hint.
  46. void CalculateWeightAndHint(LiveInterval &li);
  47. };
  48. /// CalculateSpillWeights - Compute spill weights for all virtual register
  49. /// live intervals.
  50. class CalculateSpillWeights : public MachineFunctionPass {
  51. public:
  52. static char ID;
  53. CalculateSpillWeights() : MachineFunctionPass(ID) {
  54. initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry());
  55. }
  56. virtual void getAnalysisUsage(AnalysisUsage &au) const;
  57. virtual bool runOnMachineFunction(MachineFunction &fn);
  58. private:
  59. /// Returns true if the given live interval is zero length.
  60. bool isZeroLengthInterval(LiveInterval *li) const;
  61. };
  62. }
  63. #endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H