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.

117 lines
4.4 KiB

  1. //===-- MachineSSAUpdater.h - Unstructured SSA Update Tool ------*- 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 declares the MachineSSAUpdater class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CODEGEN_MACHINESSAUPDATER_H
  14. #define LLVM_CODEGEN_MACHINESSAUPDATER_H
  15. #include "llvm/Support/Compiler.h"
  16. namespace llvm {
  17. class MachineBasicBlock;
  18. class MachineFunction;
  19. class MachineInstr;
  20. class MachineOperand;
  21. class MachineRegisterInfo;
  22. class TargetInstrInfo;
  23. class TargetRegisterClass;
  24. template<typename T> class SmallVectorImpl;
  25. template<typename T> class SSAUpdaterTraits;
  26. class BumpPtrAllocator;
  27. /// MachineSSAUpdater - This class updates SSA form for a set of virtual
  28. /// registers defined in multiple blocks. This is used when code duplication
  29. /// or another unstructured transformation wants to rewrite a set of uses of one
  30. /// vreg with uses of a set of vregs.
  31. class MachineSSAUpdater {
  32. friend class SSAUpdaterTraits<MachineSSAUpdater>;
  33. private:
  34. /// AvailableVals - This keeps track of which value to use on a per-block
  35. /// basis. When we insert PHI nodes, we keep track of them here.
  36. //typedef DenseMap<MachineBasicBlock*, unsigned > AvailableValsTy;
  37. void *AV;
  38. /// VR - Current virtual register whose uses are being updated.
  39. unsigned VR;
  40. /// VRC - Register class of the current virtual register.
  41. const TargetRegisterClass *VRC;
  42. /// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI
  43. /// nodes that it creates to the vector.
  44. SmallVectorImpl<MachineInstr*> *InsertedPHIs;
  45. const TargetInstrInfo *TII;
  46. MachineRegisterInfo *MRI;
  47. public:
  48. /// MachineSSAUpdater constructor. If InsertedPHIs is specified, it will be
  49. /// filled in with all PHI Nodes created by rewriting.
  50. explicit MachineSSAUpdater(MachineFunction &MF,
  51. SmallVectorImpl<MachineInstr*> *InsertedPHIs = 0);
  52. ~MachineSSAUpdater();
  53. /// Initialize - Reset this object to get ready for a new set of SSA
  54. /// updates.
  55. void Initialize(unsigned V);
  56. /// AddAvailableValue - Indicate that a rewritten value is available at the
  57. /// end of the specified block with the specified value.
  58. void AddAvailableValue(MachineBasicBlock *BB, unsigned V);
  59. /// HasValueForBlock - Return true if the MachineSSAUpdater already has a
  60. /// value for the specified block.
  61. bool HasValueForBlock(MachineBasicBlock *BB) const;
  62. /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is
  63. /// live at the end of the specified block.
  64. unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB);
  65. /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that
  66. /// is live in the middle of the specified block.
  67. ///
  68. /// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one
  69. /// important case: if there is a definition of the rewritten value after the
  70. /// 'use' in BB. Consider code like this:
  71. ///
  72. /// X1 = ...
  73. /// SomeBB:
  74. /// use(X)
  75. /// X2 = ...
  76. /// br Cond, SomeBB, OutBB
  77. ///
  78. /// In this case, there are two values (X1 and X2) added to the AvailableVals
  79. /// set by the client of the rewriter, and those values are both live out of
  80. /// their respective blocks. However, the use of X happens in the *middle* of
  81. /// a block. Because of this, we need to insert a new PHI node in SomeBB to
  82. /// merge the appropriate values, and this value isn't live out of the block.
  83. ///
  84. unsigned GetValueInMiddleOfBlock(MachineBasicBlock *BB);
  85. /// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes,
  86. /// which use their value in the corresponding predecessor. Note that this
  87. /// will not work if the use is supposed to be rewritten to a value defined in
  88. /// the same block as the use, but above it. Any 'AddAvailableValue's added
  89. /// for the use's block will be considered to be below it.
  90. void RewriteUse(MachineOperand &U);
  91. private:
  92. void ReplaceRegWith(unsigned OldReg, unsigned NewReg);
  93. unsigned GetValueAtEndOfBlockInternal(MachineBasicBlock *BB);
  94. void operator=(const MachineSSAUpdater&) LLVM_DELETED_FUNCTION;
  95. MachineSSAUpdater(const MachineSSAUpdater&) LLVM_DELETED_FUNCTION;
  96. };
  97. } // End llvm namespace
  98. #endif