1 //===- AddrModeMatcher.h - Addressing mode matching facility ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_TRANSFORMS_UTILS_ADDRMODEMATCHER_H
20 #define LLVM_TRANSFORMS_UTILS_ADDRMODEMATCHER_H
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/Support/Streams.h"
24 #include "llvm/Target/TargetLowering.h"
34 /// ExtAddrMode - This is an extended version of TargetLowering::AddrMode
35 /// which holds actual Value*'s for register values.
36 struct ExtAddrMode : public TargetLowering::AddrMode {
39 ExtAddrMode() : BaseReg(0), ScaledReg(0) {}
40 void print(OStream &OS) const;
44 static inline OStream &operator<<(OStream &OS, const ExtAddrMode &AM) {
49 class AddressingModeMatcher {
50 SmallVectorImpl<Instruction*> &AddrModeInsts;
51 const TargetLowering &TLI;
53 /// AccessTy/MemoryInst - This is the type for the access (e.g. double) and
54 /// the memory instruction that we're computing this address for.
56 Instruction *MemoryInst;
58 /// AddrMode - This is the addressing mode that we're building up. This is
59 /// part of the return value of this addressing mode matching stuff.
60 ExtAddrMode &AddrMode;
62 /// IgnoreProfitability - This is set to true when we should not do
63 /// profitability checks. When true, IsProfitableToFoldIntoAddressingMode
64 /// always returns true.
65 bool IgnoreProfitability;
67 AddressingModeMatcher(SmallVectorImpl<Instruction*> &AMI,
68 const TargetLowering &T, const Type *AT,
69 Instruction *MI, ExtAddrMode &AM)
70 : AddrModeInsts(AMI), TLI(T), AccessTy(AT), MemoryInst(MI), AddrMode(AM) {
71 IgnoreProfitability = false;
75 /// Match - Find the maximal addressing mode that a load/store of V can fold,
76 /// give an access type of AccessTy. This returns a list of involved
77 /// instructions in AddrModeInsts.
78 static ExtAddrMode Match(Value *V, const Type *AccessTy,
79 Instruction *MemoryInst,
80 SmallVectorImpl<Instruction*> &AddrModeInsts,
81 const TargetLowering &TLI) {
85 AddressingModeMatcher(AddrModeInsts, TLI, AccessTy,
86 MemoryInst, Result).MatchAddr(V, 0);
87 Success = Success; assert(Success && "Couldn't select *anything*?");
91 bool MatchScaledValue(Value *ScaleReg, int64_t Scale, unsigned Depth);
92 bool MatchAddr(Value *V, unsigned Depth);
93 bool MatchOperationAddr(User *Operation, unsigned Opcode, unsigned Depth);
94 bool IsProfitableToFoldIntoAddressingMode(Instruction *I,
95 ExtAddrMode &AMBefore,
96 ExtAddrMode &AMAfter);
97 bool ValueAlreadyLiveAtInst(Value *Val, Value *KnownLive1, Value *KnownLive2);
100 } // End llvm namespace