LLVM 20.0.0git
LanaiInstrInfo.h
Go to the documentation of this file.
1//===- LanaiInstrInfo.h - Lanai Instruction Information ---------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the Lanai implementation of the TargetInstrInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H
14#define LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H
15
16#include "LanaiRegisterInfo.h"
19
20#define GET_INSTRINFO_HEADER
21#include "LanaiGenInstrInfo.inc"
22
23namespace llvm {
24
26 const LanaiRegisterInfo RegisterInfo;
27
28public:
30
31 // getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
32 // such, whenever a client has an instance of instruction info, it should
33 // always be able to get register info as well (through this method).
34 virtual const LanaiRegisterInfo &getRegisterInfo() const {
35 return RegisterInfo;
36 }
37
39 const MachineInstr &MIb) const override;
40
42 int &FrameIndex) const override;
43
45 int &FrameIndex) const override;
46
48 int &FrameIndex) const override;
49
51 const DebugLoc &DL, MCRegister DestinationRegister,
52 MCRegister SourceRegister, bool KillSource,
53 bool RenamableDest = false,
54 bool RenamableSrc = false) const override;
55
58 Register SourceRegister, bool IsKill, int FrameIndex,
59 const TargetRegisterClass *RegisterClass,
60 const TargetRegisterInfo *RegisterInfo,
61 Register VReg) const override;
62
65 Register DestinationRegister, int FrameIndex,
66 const TargetRegisterClass *RegisterClass,
67 const TargetRegisterInfo *RegisterInfo,
68 Register VReg) const override;
69
70 bool expandPostRAPseudo(MachineInstr &MI) const override;
71
73 const MachineInstr &LdSt,
75 bool &OffsetIsScalable, LocationSize &Width,
76 const TargetRegisterInfo *TRI) const override;
77
79 const MachineOperand *&BaseOp,
80 int64_t &Offset, LocationSize &Width,
81 const TargetRegisterInfo *TRI) const;
82
83 std::pair<unsigned, unsigned>
84 decomposeMachineOperandsTargetFlags(unsigned TF) const override;
85
88
90 MachineBasicBlock *&FalseBlock,
92 bool AllowModify) const override;
93
95 int *BytesRemoved = nullptr) const override;
96
97 // For a comparison instruction, return the source registers in SrcReg and
98 // SrcReg2 if having two register operands, and the value it compares against
99 // in CmpValue. Return true if the comparison instruction can be analyzed.
100 bool analyzeCompare(const MachineInstr &MI, Register &SrcReg,
101 Register &SrcReg2, int64_t &CmpMask,
102 int64_t &CmpValue) const override;
103
104 // See if the comparison instruction can be converted into something more
105 // efficient. E.g., on Lanai register-register instructions can set the flag
106 // register, obviating the need for a separate compare.
107 bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
108 Register SrcReg2, int64_t CmpMask, int64_t CmpValue,
109 const MachineRegisterInfo *MRI) const override;
110
111 // Analyze the given select instruction, returning true if it cannot be
112 // understood. It is assumed that MI->isSelect() is true.
113 //
114 // When successful, return the controlling condition and the operands that
115 // determine the true and false result values.
116 //
117 // Result = SELECT Cond, TrueOp, FalseOp
118 //
119 // Lanai can optimize certain select instructions, for example by predicating
120 // the instruction defining one of the operands and sets Optimizable to true.
121 bool analyzeSelect(const MachineInstr &MI,
122 SmallVectorImpl<MachineOperand> &Cond, unsigned &TrueOp,
123 unsigned &FalseOp, bool &Optimizable) const override;
124
125 // Given a select instruction that was understood by analyzeSelect and
126 // returned Optimizable = true, attempt to optimize MI by merging it with one
127 // of its operands. Returns NULL on failure.
128 //
129 // When successful, returns the new select instruction. The client is
130 // responsible for deleting MI.
131 //
132 // If both sides of the select can be optimized, the TrueOp is modifed.
133 // PreferFalse is not used.
136 bool PreferFalse) const override;
137
139 SmallVectorImpl<MachineOperand> &Condition) const override;
140
142 MachineBasicBlock *FalseBlock,
143 ArrayRef<MachineOperand> Condition,
144 const DebugLoc &DL,
145 int *BytesAdded = nullptr) const override;
146};
147
148static inline bool isSPLSOpcode(unsigned Opcode) {
149 switch (Opcode) {
150 case Lanai::LDBs_RI:
151 case Lanai::LDBz_RI:
152 case Lanai::LDHs_RI:
153 case Lanai::LDHz_RI:
154 case Lanai::STB_RI:
155 case Lanai::STH_RI:
156 return true;
157 default:
158 return false;
159 }
160}
161
162static inline bool isRMOpcode(unsigned Opcode) {
163 switch (Opcode) {
164 case Lanai::LDW_RI:
165 case Lanai::SW_RI:
166 return true;
167 default:
168 return false;
169 }
170}
171
172static inline bool isRRMOpcode(unsigned Opcode) {
173 switch (Opcode) {
174 case Lanai::LDBs_RR:
175 case Lanai::LDBz_RR:
176 case Lanai::LDHs_RR:
177 case Lanai::LDHz_RR:
178 case Lanai::LDWz_RR:
179 case Lanai::LDW_RR:
180 case Lanai::STB_RR:
181 case Lanai::STH_RR:
182 case Lanai::SW_RR:
183 return true;
184 default:
185 return false;
186 }
187}
188
189} // namespace llvm
190
191#endif // LLVM_LIB_TARGET_LANAI_LANAIINSTRINFO_H
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
IRTranslator LLVM IR MI
unsigned const TargetRegisterInfo * TRI
const SmallVectorImpl< MachineOperand > & Cond
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
A debug info location.
Definition: DebugLoc.h:33
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TrueBlock, MachineBasicBlock *FalseBlock, ArrayRef< MachineOperand > Condition, const DebugLoc &DL, int *BytesAdded=nullptr) const override
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
bool analyzeSelect(const MachineInstr &MI, SmallVectorImpl< MachineOperand > &Cond, unsigned &TrueOp, unsigned &FalseOp, bool &Optimizable) const override
Register isLoadFromStackSlotPostFE(const MachineInstr &MI, int &FrameIndex) const override
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TrueBlock, MachineBasicBlock *&FalseBlock, SmallVectorImpl< MachineOperand > &Condition, bool AllowModify) const override
virtual const LanaiRegisterInfo & getRegisterInfo() const
MachineInstr * optimizeSelect(MachineInstr &MI, SmallPtrSetImpl< MachineInstr * > &SeenMIs, bool PreferFalse) const override
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position, Register DestinationRegister, int FrameIndex, const TargetRegisterClass *RegisterClass, const TargetRegisterInfo *RegisterInfo, Register VReg) const override
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position, const DebugLoc &DL, MCRegister DestinationRegister, MCRegister SourceRegister, bool KillSource, bool RenamableDest=false, bool RenamableSrc=false) const override
bool expandPostRAPseudo(MachineInstr &MI) const override
bool getMemOperandWithOffsetWidth(const MachineInstr &LdSt, const MachineOperand *&BaseOp, int64_t &Offset, LocationSize &Width, const TargetRegisterInfo *TRI) const
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
bool optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg, Register SrcReg2, int64_t CmpMask, int64_t CmpValue, const MachineRegisterInfo *MRI) const override
bool analyzeCompare(const MachineInstr &MI, Register &SrcReg, Register &SrcReg2, int64_t &CmpMask, int64_t &CmpValue) const override
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
bool getMemOperandsWithOffsetWidth(const MachineInstr &LdSt, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width, const TargetRegisterInfo *TRI) const override
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Condition) const override
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator Position, Register SourceRegister, bool IsKill, int FrameIndex, const TargetRegisterClass *RegisterClass, const TargetRegisterInfo *RegisterInfo, Register VReg) const override
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:363
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
static bool isRMOpcode(unsigned Opcode)
static bool isRRMOpcode(unsigned Opcode)
static bool isSPLSOpcode(unsigned Opcode)