/3rd_party/llvm/include/llvm/Transforms/Utils/AddrModeMatcher.h

https://code.google.com/p/softart/ · C++ Header · 108 lines · 63 code · 16 blank · 29 comment · 10 complexity · 75a3c8515307bcc34c4850c8a7b36b5e MD5 · raw file

  1. //===- AddrModeMatcher.h - Addressing mode matching facility ----*- 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. // AddressingModeMatcher - This class exposes a single public method, which is
  11. // used to construct a "maximal munch" of the addressing mode for the target
  12. // specified by TLI for an access to "V" with an access type of AccessTy. This
  13. // returns the addressing mode that is actually matched by value, but also
  14. // returns the list of instructions involved in that addressing computation in
  15. // AddrModeInsts.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_TRANSFORMS_UTILS_ADDRMODEMATCHER_H
  19. #define LLVM_TRANSFORMS_UTILS_ADDRMODEMATCHER_H
  20. #include "llvm/ADT/SmallVector.h"
  21. #include "llvm/Target/TargetLowering.h"
  22. namespace llvm {
  23. class GlobalValue;
  24. class Instruction;
  25. class Value;
  26. class Type;
  27. class User;
  28. class raw_ostream;
  29. /// ExtAddrMode - This is an extended version of TargetLowering::AddrMode
  30. /// which holds actual Value*'s for register values.
  31. struct ExtAddrMode : public TargetLowering::AddrMode {
  32. Value *BaseReg;
  33. Value *ScaledReg;
  34. ExtAddrMode() : BaseReg(0), ScaledReg(0) {}
  35. void print(raw_ostream &OS) const;
  36. void dump() const;
  37. bool operator==(const ExtAddrMode& O) const {
  38. return (BaseReg == O.BaseReg) && (ScaledReg == O.ScaledReg) &&
  39. (BaseGV == O.BaseGV) && (BaseOffs == O.BaseOffs) &&
  40. (HasBaseReg == O.HasBaseReg) && (Scale == O.Scale);
  41. }
  42. };
  43. static inline raw_ostream &operator<<(raw_ostream &OS, const ExtAddrMode &AM) {
  44. AM.print(OS);
  45. return OS;
  46. }
  47. class AddressingModeMatcher {
  48. SmallVectorImpl<Instruction*> &AddrModeInsts;
  49. const TargetLowering &TLI;
  50. /// AccessTy/MemoryInst - This is the type for the access (e.g. double) and
  51. /// the memory instruction that we're computing this address for.
  52. Type *AccessTy;
  53. Instruction *MemoryInst;
  54. /// AddrMode - This is the addressing mode that we're building up. This is
  55. /// part of the return value of this addressing mode matching stuff.
  56. ExtAddrMode &AddrMode;
  57. /// IgnoreProfitability - This is set to true when we should not do
  58. /// profitability checks. When true, IsProfitableToFoldIntoAddressingMode
  59. /// always returns true.
  60. bool IgnoreProfitability;
  61. AddressingModeMatcher(SmallVectorImpl<Instruction*> &AMI,
  62. const TargetLowering &T, Type *AT,
  63. Instruction *MI, ExtAddrMode &AM)
  64. : AddrModeInsts(AMI), TLI(T), AccessTy(AT), MemoryInst(MI), AddrMode(AM) {
  65. IgnoreProfitability = false;
  66. }
  67. public:
  68. /// Match - Find the maximal addressing mode that a load/store of V can fold,
  69. /// give an access type of AccessTy. This returns a list of involved
  70. /// instructions in AddrModeInsts.
  71. static ExtAddrMode Match(Value *V, Type *AccessTy,
  72. Instruction *MemoryInst,
  73. SmallVectorImpl<Instruction*> &AddrModeInsts,
  74. const TargetLowering &TLI) {
  75. ExtAddrMode Result;
  76. bool Success =
  77. AddressingModeMatcher(AddrModeInsts, TLI, AccessTy,
  78. MemoryInst, Result).MatchAddr(V, 0);
  79. (void)Success; assert(Success && "Couldn't select *anything*?");
  80. return Result;
  81. }
  82. private:
  83. bool MatchScaledValue(Value *ScaleReg, int64_t Scale, unsigned Depth);
  84. bool MatchAddr(Value *V, unsigned Depth);
  85. bool MatchOperationAddr(User *Operation, unsigned Opcode, unsigned Depth);
  86. bool IsProfitableToFoldIntoAddressingMode(Instruction *I,
  87. ExtAddrMode &AMBefore,
  88. ExtAddrMode &AMAfter);
  89. bool ValueAlreadyLiveAtInst(Value *Val, Value *KnownLive1, Value *KnownLive2);
  90. };
  91. } // End llvm namespace
  92. #endif