1*9880d681SAndroid Build Coastguard Worker //===- LanaiInstrInfo.h - Lanai Instruction Information ---------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file contains the Lanai implementation of the TargetInstrInfo class.
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H
15*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker #include "LanaiRegisterInfo.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetInstrInfo.h"
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Worker #define GET_INSTRINFO_HEADER
21*9880d681SAndroid Build Coastguard Worker #include "LanaiGenInstrInfo.inc"
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Worker namespace llvm {
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker class LanaiInstrInfo : public LanaiGenInstrInfo {
26*9880d681SAndroid Build Coastguard Worker const LanaiRegisterInfo RegisterInfo;
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Worker public:
29*9880d681SAndroid Build Coastguard Worker LanaiInstrInfo();
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Worker // getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
32*9880d681SAndroid Build Coastguard Worker // such, whenever a client has an instance of instruction info, it should
33*9880d681SAndroid Build Coastguard Worker // always be able to get register info as well (through this method).
getRegisterInfo()34*9880d681SAndroid Build Coastguard Worker virtual const LanaiRegisterInfo &getRegisterInfo() const {
35*9880d681SAndroid Build Coastguard Worker return RegisterInfo;
36*9880d681SAndroid Build Coastguard Worker }
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Worker bool areMemAccessesTriviallyDisjoint(MachineInstr &MIa, MachineInstr &MIb,
39*9880d681SAndroid Build Coastguard Worker AliasAnalysis *AA) const override;
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Worker unsigned isLoadFromStackSlot(const MachineInstr &MI,
42*9880d681SAndroid Build Coastguard Worker int &FrameIndex) const override;
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker unsigned isLoadFromStackSlotPostFE(const MachineInstr &MI,
45*9880d681SAndroid Build Coastguard Worker int &FrameIndex) const override;
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker unsigned isStoreToStackSlot(const MachineInstr &MI,
48*9880d681SAndroid Build Coastguard Worker int &FrameIndex) const override;
49*9880d681SAndroid Build Coastguard Worker
50*9880d681SAndroid Build Coastguard Worker void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position,
51*9880d681SAndroid Build Coastguard Worker const DebugLoc &DL, unsigned DestinationRegister,
52*9880d681SAndroid Build Coastguard Worker unsigned SourceRegister, bool KillSource) const override;
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Worker void
55*9880d681SAndroid Build Coastguard Worker storeRegToStackSlot(MachineBasicBlock &MBB,
56*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator Position,
57*9880d681SAndroid Build Coastguard Worker unsigned SourceRegister, bool IsKill, int FrameIndex,
58*9880d681SAndroid Build Coastguard Worker const TargetRegisterClass *RegisterClass,
59*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *RegisterInfo) const override;
60*9880d681SAndroid Build Coastguard Worker
61*9880d681SAndroid Build Coastguard Worker void
62*9880d681SAndroid Build Coastguard Worker loadRegFromStackSlot(MachineBasicBlock &MBB,
63*9880d681SAndroid Build Coastguard Worker MachineBasicBlock::iterator Position,
64*9880d681SAndroid Build Coastguard Worker unsigned DestinationRegister, int FrameIndex,
65*9880d681SAndroid Build Coastguard Worker const TargetRegisterClass *RegisterClass,
66*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *RegisterInfo) const override;
67*9880d681SAndroid Build Coastguard Worker
68*9880d681SAndroid Build Coastguard Worker bool expandPostRAPseudo(MachineInstr &MI) const override;
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Worker bool getMemOpBaseRegImmOfs(MachineInstr &LdSt, unsigned &BaseReg,
71*9880d681SAndroid Build Coastguard Worker int64_t &Offset,
72*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI) const override;
73*9880d681SAndroid Build Coastguard Worker
74*9880d681SAndroid Build Coastguard Worker bool getMemOpBaseRegImmOfsWidth(MachineInstr &LdSt, unsigned &BaseReg,
75*9880d681SAndroid Build Coastguard Worker int64_t &Offset, unsigned &Width,
76*9880d681SAndroid Build Coastguard Worker const TargetRegisterInfo *TRI) const;
77*9880d681SAndroid Build Coastguard Worker
78*9880d681SAndroid Build Coastguard Worker std::pair<unsigned, unsigned>
79*9880d681SAndroid Build Coastguard Worker decomposeMachineOperandsTargetFlags(unsigned TF) const override;
80*9880d681SAndroid Build Coastguard Worker
81*9880d681SAndroid Build Coastguard Worker ArrayRef<std::pair<unsigned, const char *>>
82*9880d681SAndroid Build Coastguard Worker getSerializableDirectMachineOperandTargetFlags() const override;
83*9880d681SAndroid Build Coastguard Worker
84*9880d681SAndroid Build Coastguard Worker bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TrueBlock,
85*9880d681SAndroid Build Coastguard Worker MachineBasicBlock *&FalseBlock,
86*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineOperand> &Condition,
87*9880d681SAndroid Build Coastguard Worker bool AllowModify) const override;
88*9880d681SAndroid Build Coastguard Worker
89*9880d681SAndroid Build Coastguard Worker unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
90*9880d681SAndroid Build Coastguard Worker
91*9880d681SAndroid Build Coastguard Worker // For a comparison instruction, return the source registers in SrcReg and
92*9880d681SAndroid Build Coastguard Worker // SrcReg2 if having two register operands, and the value it compares against
93*9880d681SAndroid Build Coastguard Worker // in CmpValue. Return true if the comparison instruction can be analyzed.
94*9880d681SAndroid Build Coastguard Worker bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
95*9880d681SAndroid Build Coastguard Worker unsigned &SrcReg2, int &CmpMask,
96*9880d681SAndroid Build Coastguard Worker int &CmpValue) const override;
97*9880d681SAndroid Build Coastguard Worker
98*9880d681SAndroid Build Coastguard Worker // See if the comparison instruction can be converted into something more
99*9880d681SAndroid Build Coastguard Worker // efficient. E.g., on Lanai register-register instructions can set the flag
100*9880d681SAndroid Build Coastguard Worker // register, obviating the need for a separate compare.
101*9880d681SAndroid Build Coastguard Worker bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
102*9880d681SAndroid Build Coastguard Worker unsigned SrcReg2, int CmpMask, int CmpValue,
103*9880d681SAndroid Build Coastguard Worker const MachineRegisterInfo *MRI) const override;
104*9880d681SAndroid Build Coastguard Worker
105*9880d681SAndroid Build Coastguard Worker // Analyze the given select instruction, returning true if it cannot be
106*9880d681SAndroid Build Coastguard Worker // understood. It is assumed that MI->isSelect() is true.
107*9880d681SAndroid Build Coastguard Worker //
108*9880d681SAndroid Build Coastguard Worker // When successful, return the controlling condition and the operands that
109*9880d681SAndroid Build Coastguard Worker // determine the true and false result values.
110*9880d681SAndroid Build Coastguard Worker //
111*9880d681SAndroid Build Coastguard Worker // Result = SELECT Cond, TrueOp, FalseOp
112*9880d681SAndroid Build Coastguard Worker //
113*9880d681SAndroid Build Coastguard Worker // Lanai can optimize certain select instructions, for example by predicating
114*9880d681SAndroid Build Coastguard Worker // the instruction defining one of the operands and sets Optimizable to true.
115*9880d681SAndroid Build Coastguard Worker bool analyzeSelect(const MachineInstr &MI,
116*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineOperand> &Cond, unsigned &TrueOp,
117*9880d681SAndroid Build Coastguard Worker unsigned &FalseOp, bool &Optimizable) const override;
118*9880d681SAndroid Build Coastguard Worker
119*9880d681SAndroid Build Coastguard Worker // Given a select instruction that was understood by analyzeSelect and
120*9880d681SAndroid Build Coastguard Worker // returned Optimizable = true, attempt to optimize MI by merging it with one
121*9880d681SAndroid Build Coastguard Worker // of its operands. Returns NULL on failure.
122*9880d681SAndroid Build Coastguard Worker //
123*9880d681SAndroid Build Coastguard Worker // When successful, returns the new select instruction. The client is
124*9880d681SAndroid Build Coastguard Worker // responsible for deleting MI.
125*9880d681SAndroid Build Coastguard Worker //
126*9880d681SAndroid Build Coastguard Worker // If both sides of the select can be optimized, the TrueOp is modifed.
127*9880d681SAndroid Build Coastguard Worker // PreferFalse is not used.
128*9880d681SAndroid Build Coastguard Worker MachineInstr *optimizeSelect(MachineInstr &MI,
129*9880d681SAndroid Build Coastguard Worker SmallPtrSetImpl<MachineInstr *> &SeenMIs,
130*9880d681SAndroid Build Coastguard Worker bool PreferFalse) const override;
131*9880d681SAndroid Build Coastguard Worker
132*9880d681SAndroid Build Coastguard Worker bool ReverseBranchCondition(
133*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<MachineOperand> &Condition) const override;
134*9880d681SAndroid Build Coastguard Worker
135*9880d681SAndroid Build Coastguard Worker unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TrueBlock,
136*9880d681SAndroid Build Coastguard Worker MachineBasicBlock *FalseBlock,
137*9880d681SAndroid Build Coastguard Worker ArrayRef<MachineOperand> Condition,
138*9880d681SAndroid Build Coastguard Worker const DebugLoc &DL) const override;
139*9880d681SAndroid Build Coastguard Worker };
140*9880d681SAndroid Build Coastguard Worker
isSPLSOpcode(unsigned Opcode)141*9880d681SAndroid Build Coastguard Worker static inline bool isSPLSOpcode(unsigned Opcode) {
142*9880d681SAndroid Build Coastguard Worker switch (Opcode) {
143*9880d681SAndroid Build Coastguard Worker case Lanai::LDBs_RI:
144*9880d681SAndroid Build Coastguard Worker case Lanai::LDBz_RI:
145*9880d681SAndroid Build Coastguard Worker case Lanai::LDHs_RI:
146*9880d681SAndroid Build Coastguard Worker case Lanai::LDHz_RI:
147*9880d681SAndroid Build Coastguard Worker case Lanai::STB_RI:
148*9880d681SAndroid Build Coastguard Worker case Lanai::STH_RI:
149*9880d681SAndroid Build Coastguard Worker return true;
150*9880d681SAndroid Build Coastguard Worker default:
151*9880d681SAndroid Build Coastguard Worker return false;
152*9880d681SAndroid Build Coastguard Worker }
153*9880d681SAndroid Build Coastguard Worker }
154*9880d681SAndroid Build Coastguard Worker
isRMOpcode(unsigned Opcode)155*9880d681SAndroid Build Coastguard Worker static inline bool isRMOpcode(unsigned Opcode) {
156*9880d681SAndroid Build Coastguard Worker switch (Opcode) {
157*9880d681SAndroid Build Coastguard Worker case Lanai::LDW_RI:
158*9880d681SAndroid Build Coastguard Worker case Lanai::SW_RI:
159*9880d681SAndroid Build Coastguard Worker return true;
160*9880d681SAndroid Build Coastguard Worker default:
161*9880d681SAndroid Build Coastguard Worker return false;
162*9880d681SAndroid Build Coastguard Worker }
163*9880d681SAndroid Build Coastguard Worker }
164*9880d681SAndroid Build Coastguard Worker
isRRMOpcode(unsigned Opcode)165*9880d681SAndroid Build Coastguard Worker static inline bool isRRMOpcode(unsigned Opcode) {
166*9880d681SAndroid Build Coastguard Worker switch (Opcode) {
167*9880d681SAndroid Build Coastguard Worker case Lanai::LDBs_RR:
168*9880d681SAndroid Build Coastguard Worker case Lanai::LDBz_RR:
169*9880d681SAndroid Build Coastguard Worker case Lanai::LDHs_RR:
170*9880d681SAndroid Build Coastguard Worker case Lanai::LDHz_RR:
171*9880d681SAndroid Build Coastguard Worker case Lanai::LDWz_RR:
172*9880d681SAndroid Build Coastguard Worker case Lanai::LDW_RR:
173*9880d681SAndroid Build Coastguard Worker case Lanai::STB_RR:
174*9880d681SAndroid Build Coastguard Worker case Lanai::STH_RR:
175*9880d681SAndroid Build Coastguard Worker case Lanai::SW_RR:
176*9880d681SAndroid Build Coastguard Worker return true;
177*9880d681SAndroid Build Coastguard Worker default:
178*9880d681SAndroid Build Coastguard Worker return false;
179*9880d681SAndroid Build Coastguard Worker }
180*9880d681SAndroid Build Coastguard Worker }
181*9880d681SAndroid Build Coastguard Worker
182*9880d681SAndroid Build Coastguard Worker } // namespace llvm
183*9880d681SAndroid Build Coastguard Worker
184*9880d681SAndroid Build Coastguard Worker #endif // LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H
185