1 //===-- M68kInstrInfo.h - M68k Instruction Information ----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This file contains the M68k implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_M68K_M68KINSTRINFO_H
15 #define LLVM_LIB_TARGET_M68K_M68KINSTRINFO_H
18 #include "M68kRegisterInfo.h"
20 #include "MCTargetDesc/M68kBaseInfo.h"
22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/TargetInstrInfo.h"
25 #define GET_INSTRINFO_HEADER
26 #include "M68kGenInstrInfo.inc"
33 // These MUST be kept in sync with codes definitions in M68kInstrInfo.td
38 COND_LS
= 3, // Less or Same
39 COND_CC
= 4, // Carry Clear
40 COND_CS
= 5, // Carry Set
41 COND_NE
= 6, // Not Equal
43 COND_VC
= 8, // Overflow Clear
44 COND_VS
= 9, // Overflow Set
46 COND_MI
= 11, // Minus
47 COND_GE
= 12, // Greater or Equal
48 COND_LT
= 13, // Less Than
49 COND_GT
= 14, // Greater Than
50 COND_LE
= 15, // Less or Equal
51 LAST_VALID_COND
= COND_LE
,
55 // FIXME would be nice tablegen to generate these predicates and converters
58 static inline M68k::CondCode
GetOppositeBranchCondition(M68k::CondCode CC
) {
61 llvm_unreachable("Illegal condition code!");
97 static inline unsigned GetCondBranchFromCond(M68k::CondCode CC
) {
100 llvm_unreachable("Illegal condition code!");
132 static inline M68k::CondCode
GetCondFromBranchOpc(unsigned Opcode
) {
135 return M68k::COND_INVALID
;
137 return M68k::COND_EQ
;
139 return M68k::COND_NE
;
141 return M68k::COND_LT
;
143 return M68k::COND_LE
;
145 return M68k::COND_GT
;
147 return M68k::COND_GE
;
149 return M68k::COND_CS
;
151 return M68k::COND_LS
;
153 return M68k::COND_HI
;
155 return M68k::COND_CC
;
157 return M68k::COND_MI
;
159 return M68k::COND_PL
;
161 return M68k::COND_VS
;
163 return M68k::COND_VC
;
167 static inline unsigned IsCMP(unsigned Op
) {
185 static inline bool IsSETCC(unsigned SETCC
) {
237 class M68kInstrInfo
: public M68kGenInstrInfo
{
238 virtual void anchor();
241 const M68kSubtarget
&Subtarget
;
242 const M68kRegisterInfo RI
;
245 explicit M68kInstrInfo(const M68kSubtarget
&STI
);
247 static const M68kInstrInfo
*create(M68kSubtarget
&STI
);
249 /// TargetInstrInfo is a superset of MRegister info. As such, whenever a
250 /// client has an instance of instruction info, it should always be able to
251 /// get register info as well (through this method).
252 const M68kRegisterInfo
&getRegisterInfo() const { return RI
; };
254 bool analyzeBranch(MachineBasicBlock
&MBB
, MachineBasicBlock
*&TBB
,
255 MachineBasicBlock
*&FBB
,
256 SmallVectorImpl
<MachineOperand
> &Cond
,
257 bool AllowModify
) const override
;
259 bool AnalyzeBranchImpl(MachineBasicBlock
&MBB
, MachineBasicBlock
*&TBB
,
260 MachineBasicBlock
*&FBB
,
261 SmallVectorImpl
<MachineOperand
> &Cond
,
262 bool AllowModify
) const;
264 unsigned removeBranch(MachineBasicBlock
&MBB
,
265 int *BytesRemoved
= nullptr) const override
;
267 unsigned insertBranch(MachineBasicBlock
&MBB
, MachineBasicBlock
*TBB
,
268 MachineBasicBlock
*FBB
, ArrayRef
<MachineOperand
> Cond
,
270 int *BytesAdded
= nullptr) const override
;
272 void copyPhysReg(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator MI
,
273 const DebugLoc
&DL
, MCRegister DestReg
, MCRegister SrcReg
,
274 bool KillSrc
) const override
;
276 bool getStackSlotRange(const TargetRegisterClass
*RC
, unsigned SubIdx
,
277 unsigned &Size
, unsigned &Offset
,
278 const MachineFunction
&MF
) const override
;
280 void storeRegToStackSlot(MachineBasicBlock
&MBB
,
281 MachineBasicBlock::iterator MI
, Register SrcReg
,
282 bool IsKill
, int FrameIndex
,
283 const TargetRegisterClass
*RC
,
284 const TargetRegisterInfo
*TRI
,
285 Register VReg
) const override
;
287 void loadRegFromStackSlot(MachineBasicBlock
&MBB
,
288 MachineBasicBlock::iterator MI
, Register DestReg
,
289 int FrameIndex
, const TargetRegisterClass
*RC
,
290 const TargetRegisterInfo
*TRI
,
291 Register VReg
) const override
;
293 bool expandPostRAPseudo(MachineInstr
&MI
) const override
;
295 bool isPCRelRegisterOperandLegal(const MachineOperand
&MO
) const override
;
297 /// Add appropriate SExt nodes
298 void AddSExt(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator I
,
299 DebugLoc DL
, unsigned Reg
, MVT From
, MVT To
) const;
301 /// Add appropriate ZExt nodes
302 void AddZExt(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator I
,
303 DebugLoc DL
, unsigned Reg
, MVT From
, MVT To
) const;
305 /// Move across register classes without extension
306 bool ExpandMOVX_RR(MachineInstrBuilder
&MIB
, MVT MVTDst
, MVT MVTSrc
) const;
308 /// Move from register and extend
309 bool ExpandMOVSZX_RR(MachineInstrBuilder
&MIB
, bool IsSigned
, MVT MVTDst
,
312 /// Move from memory and extend
313 bool ExpandMOVSZX_RM(MachineInstrBuilder
&MIB
, bool IsSigned
,
314 const MCInstrDesc
&Desc
, MVT MVTDst
, MVT MVTSrc
) const;
316 /// Push/Pop to/from stack
317 bool ExpandPUSH_POP(MachineInstrBuilder
&MIB
, const MCInstrDesc
&Desc
,
320 /// Moves to/from CCR
321 bool ExpandCCR(MachineInstrBuilder
&MIB
, bool IsToCCR
) const;
323 /// Expand all MOVEM pseudos into real MOVEMs
324 bool ExpandMOVEM(MachineInstrBuilder
&MIB
, const MCInstrDesc
&Desc
,
327 /// Return a virtual register initialized with the global base register
328 /// value. Output instructions required to initialize the register in the
329 /// function entry block, if necessary.
330 unsigned getGlobalBaseReg(MachineFunction
*MF
) const;
332 std::pair
<unsigned, unsigned>
333 decomposeMachineOperandsTargetFlags(unsigned TF
) const override
;
335 ArrayRef
<std::pair
<unsigned, const char *>>
336 getSerializableDirectMachineOperandTargetFlags() const override
;
341 #endif // LLVM_LIB_TARGET_M68K_M68KINSTRINFO_H