MachineSSAUpdater.h 4.9 KB

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