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.

121 lines
4.6 KiB

  1. //===- PHITransAddr.h - PHI Translation for Addresses -----------*- 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 PHITransAddr class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_ANALYSIS_PHITRANSADDR_H
  14. #define LLVM_ANALYSIS_PHITRANSADDR_H
  15. #include "llvm/ADT/SmallVector.h"
  16. #include "llvm/IR/Instruction.h"
  17. namespace llvm {
  18. class DominatorTree;
  19. class DataLayout;
  20. class TargetLibraryInfo;
  21. /// PHITransAddr - An address value which tracks and handles phi translation.
  22. /// As we walk "up" the CFG through predecessors, we need to ensure that the
  23. /// address we're tracking is kept up to date. For example, if we're analyzing
  24. /// an address of "&A[i]" and walk through the definition of 'i' which is a PHI
  25. /// node, we *must* phi translate i to get "&A[j]" or else we will analyze an
  26. /// incorrect pointer in the predecessor block.
  27. ///
  28. /// This is designed to be a relatively small object that lives on the stack and
  29. /// is copyable.
  30. ///
  31. class PHITransAddr {
  32. /// Addr - The actual address we're analyzing.
  33. Value *Addr;
  34. /// TD - The target data we are playing with if known, otherwise null.
  35. const DataLayout *TD;
  36. /// TLI - The target library info if known, otherwise null.
  37. const TargetLibraryInfo *TLI;
  38. /// InstInputs - The inputs for our symbolic address.
  39. SmallVector<Instruction*, 4> InstInputs;
  40. public:
  41. PHITransAddr(Value *addr, const DataLayout *td) : Addr(addr), TD(td), TLI(0) {
  42. // If the address is an instruction, the whole thing is considered an input.
  43. if (Instruction *I = dyn_cast<Instruction>(Addr))
  44. InstInputs.push_back(I);
  45. }
  46. Value *getAddr() const { return Addr; }
  47. /// NeedsPHITranslationFromBlock - Return true if moving from the specified
  48. /// BasicBlock to its predecessors requires PHI translation.
  49. bool NeedsPHITranslationFromBlock(BasicBlock *BB) const {
  50. // We do need translation if one of our input instructions is defined in
  51. // this block.
  52. for (unsigned i = 0, e = InstInputs.size(); i != e; ++i)
  53. if (InstInputs[i]->getParent() == BB)
  54. return true;
  55. return false;
  56. }
  57. /// IsPotentiallyPHITranslatable - If this needs PHI translation, return true
  58. /// if we have some hope of doing it. This should be used as a filter to
  59. /// avoid calling PHITranslateValue in hopeless situations.
  60. bool IsPotentiallyPHITranslatable() const;
  61. /// PHITranslateValue - PHI translate the current address up the CFG from
  62. /// CurBB to Pred, updating our state to reflect any needed changes. If the
  63. /// dominator tree DT is non-null, the translated value must dominate
  64. /// PredBB. This returns true on failure and sets Addr to null.
  65. bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB,
  66. const DominatorTree *DT);
  67. /// PHITranslateWithInsertion - PHI translate this value into the specified
  68. /// predecessor block, inserting a computation of the value if it is
  69. /// unavailable.
  70. ///
  71. /// All newly created instructions are added to the NewInsts list. This
  72. /// returns null on failure.
  73. ///
  74. Value *PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB,
  75. const DominatorTree &DT,
  76. SmallVectorImpl<Instruction*> &NewInsts);
  77. void dump() const;
  78. /// Verify - Check internal consistency of this data structure. If the
  79. /// structure is valid, it returns true. If invalid, it prints errors and
  80. /// returns false.
  81. bool Verify() const;
  82. private:
  83. Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB,
  84. const DominatorTree *DT);
  85. /// InsertPHITranslatedSubExpr - Insert a computation of the PHI translated
  86. /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
  87. /// block. All newly created instructions are added to the NewInsts list.
  88. /// This returns null on failure.
  89. ///
  90. Value *InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB,
  91. BasicBlock *PredBB, const DominatorTree &DT,
  92. SmallVectorImpl<Instruction*> &NewInsts);
  93. /// AddAsInput - If the specified value is an instruction, add it as an input.
  94. Value *AddAsInput(Value *V) {
  95. // If V is an instruction, it is now an input.
  96. if (Instruction *VI = dyn_cast<Instruction>(V))
  97. InstInputs.push_back(VI);
  98. return V;
  99. }
  100. };
  101. } // end namespace llvm
  102. #endif