1 //===- LanaiInstrInfo.h - Lanai Instruction Information ---------*- 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 // This file contains the Lanai implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H
15 #define LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H
17 #include "LanaiRegisterInfo.h"
18 #include "MCTargetDesc/LanaiMCTargetDesc.h"
19 #include "llvm/CodeGen/TargetInstrInfo.h"
21 #define GET_INSTRINFO_HEADER
22 #include "LanaiGenInstrInfo.inc"
26 class LanaiInstrInfo : public LanaiGenInstrInfo {
27 const LanaiRegisterInfo RegisterInfo;
32 // getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
33 // such, whenever a client has an instance of instruction info, it should
34 // always be able to get register info as well (through this method).
35 virtual const LanaiRegisterInfo &getRegisterInfo() const {
39 bool areMemAccessesTriviallyDisjoint(MachineInstr &MIa, MachineInstr &MIb,
40 AliasAnalysis *AA) const override;
42 unsigned isLoadFromStackSlot(const MachineInstr &MI,
43 int &FrameIndex) const override;
45 unsigned isLoadFromStackSlotPostFE(const MachineInstr &MI,
46 int &FrameIndex) const override;
48 unsigned isStoreToStackSlot(const MachineInstr &MI,
49 int &FrameIndex) const override;
51 void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position,
52 const DebugLoc &DL, unsigned DestinationRegister,
53 unsigned SourceRegister, bool KillSource) const override;
56 storeRegToStackSlot(MachineBasicBlock &MBB,
57 MachineBasicBlock::iterator Position,
58 unsigned SourceRegister, bool IsKill, int FrameIndex,
59 const TargetRegisterClass *RegisterClass,
60 const TargetRegisterInfo *RegisterInfo) const override;
63 loadRegFromStackSlot(MachineBasicBlock &MBB,
64 MachineBasicBlock::iterator Position,
65 unsigned DestinationRegister, int FrameIndex,
66 const TargetRegisterClass *RegisterClass,
67 const TargetRegisterInfo *RegisterInfo) const override;
69 bool expandPostRAPseudo(MachineInstr &MI) const override;
71 bool getMemOperandWithOffset(MachineInstr &LdSt, MachineOperand *&BaseOp,
73 const TargetRegisterInfo *TRI) const override;
75 bool getMemOperandWithOffsetWidth(MachineInstr &LdSt, MachineOperand *&BaseOp,
76 int64_t &Offset, unsigned &Width,
77 const TargetRegisterInfo *TRI) const;
79 std::pair<unsigned, unsigned>
80 decomposeMachineOperandsTargetFlags(unsigned TF) const override;
82 ArrayRef<std::pair<unsigned, const char *>>
83 getSerializableDirectMachineOperandTargetFlags() const override;
85 bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TrueBlock,
86 MachineBasicBlock *&FalseBlock,
87 SmallVectorImpl<MachineOperand> &Condition,
88 bool AllowModify) const override;
90 unsigned removeBranch(MachineBasicBlock &MBB,
91 int *BytesRemoved = nullptr) const override;
93 // For a comparison instruction, return the source registers in SrcReg and
94 // SrcReg2 if having two register operands, and the value it compares against
95 // in CmpValue. Return true if the comparison instruction can be analyzed.
96 bool analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
97 unsigned &SrcReg2, int &CmpMask,
98 int &CmpValue) const override;
100 // See if the comparison instruction can be converted into something more
101 // efficient. E.g., on Lanai register-register instructions can set the flag
102 // register, obviating the need for a separate compare.
103 bool optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
104 unsigned SrcReg2, int CmpMask, int CmpValue,
105 const MachineRegisterInfo *MRI) const override;
107 // Analyze the given select instruction, returning true if it cannot be
108 // understood. It is assumed that MI->isSelect() is true.
110 // When successful, return the controlling condition and the operands that
111 // determine the true and false result values.
113 // Result = SELECT Cond, TrueOp, FalseOp
115 // Lanai can optimize certain select instructions, for example by predicating
116 // the instruction defining one of the operands and sets Optimizable to true.
117 bool analyzeSelect(const MachineInstr &MI,
118 SmallVectorImpl<MachineOperand> &Cond, unsigned &TrueOp,
119 unsigned &FalseOp, bool &Optimizable) const override;
121 // Given a select instruction that was understood by analyzeSelect and
122 // returned Optimizable = true, attempt to optimize MI by merging it with one
123 // of its operands. Returns NULL on failure.
125 // When successful, returns the new select instruction. The client is
126 // responsible for deleting MI.
128 // If both sides of the select can be optimized, the TrueOp is modifed.
129 // PreferFalse is not used.
130 MachineInstr *optimizeSelect(MachineInstr &MI,
131 SmallPtrSetImpl<MachineInstr *> &SeenMIs,
132 bool PreferFalse) const override;
134 bool reverseBranchCondition(
135 SmallVectorImpl<MachineOperand> &Condition) const override;
137 unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TrueBlock,
138 MachineBasicBlock *FalseBlock,
139 ArrayRef<MachineOperand> Condition,
141 int *BytesAdded = nullptr) const override;
144 static inline bool isSPLSOpcode(unsigned Opcode) {
158 static inline bool isRMOpcode(unsigned Opcode) {
168 static inline bool isRRMOpcode(unsigned Opcode) {
187 #endif // LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H