blob: 85e06f7287c642241f9162088e0c73ed1425c413 [file] [log] [blame]
Eugene Zelenko79220eae2017-08-03 22:12:30 +00001//===- Mips16InstrInfo.h - Mips16 Instruction Information -------*- C++ -*-===//
Akira Hatanakab7fa3c92012-07-31 21:49:49 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the Mips16 implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_MIPS_MIPS16INSTRINFO_H
15#define LLVM_LIB_TARGET_MIPS_MIPS16INSTRINFO_H
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000016
Akira Hatanakacb37e132012-07-31 23:41:32 +000017#include "Mips16RegisterInfo.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000018#include "MipsInstrInfo.h"
Eugene Zelenko79220eae2017-08-03 22:12:30 +000019#include "llvm/CodeGen/MachineBasicBlock.h"
20#include "llvm/Support/MathExtras.h"
21#include <cstdint>
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000022
23namespace llvm {
Eugene Zelenko79220eae2017-08-03 22:12:30 +000024
25class MCInstrDesc;
Eric Christophera20c3cf2015-03-12 05:43:57 +000026class MipsSubtarget;
Eugene Zelenko79220eae2017-08-03 22:12:30 +000027
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000028class Mips16InstrInfo : public MipsInstrInfo {
Akira Hatanakacb37e132012-07-31 23:41:32 +000029 const Mips16RegisterInfo RI;
30
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000031public:
Eric Christopher675cb4d2014-07-18 23:25:00 +000032 explicit Mips16InstrInfo(const MipsSubtarget &STI);
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000033
Craig Topper56c590a2014-04-29 07:58:02 +000034 const MipsRegisterInfo &getRegisterInfo() const override;
Akira Hatanakacb37e132012-07-31 23:41:32 +000035
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000036 /// isLoadFromStackSlot - If the specified machine instruction is a direct
37 /// load from a stack slot, return the virtual or physical register number of
38 /// the destination along with the FrameIndex of the loaded stack slot. If
39 /// not, return 0. This predicate must return 0 if the instruction has
40 /// any side effects other than loading from the stack slot.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +000041 unsigned isLoadFromStackSlot(const MachineInstr &MI,
Craig Topper56c590a2014-04-29 07:58:02 +000042 int &FrameIndex) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000043
44 /// isStoreToStackSlot - If the specified machine instruction is a direct
45 /// store to a stack slot, return the virtual or physical register number of
46 /// the source reg along with the FrameIndex of the loaded stack slot. If
47 /// not, return 0. This predicate must return 0 if the instruction has
48 /// any side effects other than storing to the stack slot.
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +000049 unsigned isStoreToStackSlot(const MachineInstr &MI,
Craig Topper56c590a2014-04-29 07:58:02 +000050 int &FrameIndex) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000051
Benjamin Kramerbdc49562016-06-12 15:39:02 +000052 void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
53 const DebugLoc &DL, unsigned DestReg, unsigned SrcReg,
Craig Topper56c590a2014-04-29 07:58:02 +000054 bool KillSrc) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000055
Petar Jovanovicc0510002018-05-23 15:28:28 +000056 bool isCopyInstr(const MachineInstr &MI, MachineOperand &Src,
57 MachineOperand &Dest) const override;
58
Craig Topper56c590a2014-04-29 07:58:02 +000059 void storeRegToStack(MachineBasicBlock &MBB,
60 MachineBasicBlock::iterator MBBI,
61 unsigned SrcReg, bool isKill, int FrameIndex,
62 const TargetRegisterClass *RC,
63 const TargetRegisterInfo *TRI,
64 int64_t Offset) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000065
Craig Topper56c590a2014-04-29 07:58:02 +000066 void loadRegFromStack(MachineBasicBlock &MBB,
67 MachineBasicBlock::iterator MBBI,
68 unsigned DestReg, int FrameIndex,
69 const TargetRegisterClass *RC,
70 const TargetRegisterInfo *TRI,
71 int64_t Offset) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000072
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +000073 bool expandPostRAPseudo(MachineInstr &MI) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000074
Craig Topper56c590a2014-04-29 07:58:02 +000075 unsigned getOppositeBranchOpc(unsigned Opc) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000076
Reed Kotlerd019dbf2012-12-20 04:07:42 +000077 // Adjust SP by FrameSize bytes. Save RA, S0, S1
78 void makeFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB,
Reed Kotler30cedf62013-08-04 01:13:25 +000079 MachineBasicBlock::iterator I) const;
Reed Kotlerd019dbf2012-12-20 04:07:42 +000080
81 // Adjust SP by FrameSize bytes. Restore RA, S0, S1
82 void restoreFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB,
83 MachineBasicBlock::iterator I) const;
84
Reed Kotler27a72292012-10-31 05:21:10 +000085 /// Adjust SP by Amount bytes.
86 void adjustStackPtr(unsigned SP, int64_t Amount, MachineBasicBlock &MBB,
Vasileios Kalintiris6d687782015-04-02 10:42:44 +000087 MachineBasicBlock::iterator I) const override;
Reed Kotler27a72292012-10-31 05:21:10 +000088
Reed Kotler66165c82013-02-08 03:57:41 +000089 /// Emit a series of instructions to load an immediate.
90 // This is to adjust some FrameReg. We return the new register to be used
91 // in place of FrameReg and the adjusted immediate field (&NewImm)
Benjamin Kramerbdc49562016-06-12 15:39:02 +000092 unsigned loadImmediate(unsigned FrameReg, int64_t Imm, MachineBasicBlock &MBB,
93 MachineBasicBlock::iterator II, const DebugLoc &DL,
Reed Kotler66165c82013-02-08 03:57:41 +000094 unsigned &NewImm) const;
Reed Kotlerd019dbf2012-12-20 04:07:42 +000095
Reed Kotler30cedf62013-08-04 01:13:25 +000096 static bool validImmediate(unsigned Opcode, unsigned Reg, int64_t Amount);
97
Reed Kotlerf662cff2013-02-13 20:28:27 +000098 static bool validSpImm8(int offset) {
99 return ((offset & 7) == 0) && isInt<11>(offset);
100 }
101
Reed Kotlerf662cff2013-02-13 20:28:27 +0000102 // build the proper one based on the Imm field
Reed Kotlerf662cff2013-02-13 20:28:27 +0000103
Reed Kotler8cf51032013-02-16 09:47:57 +0000104 const MCInstrDesc& AddiuSpImm(int64_t Imm) const;
Reed Kotlerf662cff2013-02-13 20:28:27 +0000105
Reed Kotler188dad02013-02-16 19:04:29 +0000106 void BuildAddiuSpImm
107 (MachineBasicBlock &MBB, MachineBasicBlock::iterator I, int64_t Imm) const;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000108private:
Craig Topper56c590a2014-04-29 07:58:02 +0000109 unsigned getAnalyzableBrOpc(unsigned Opc) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000110
111 void ExpandRetRA16(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
112 unsigned Opc) const;
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000113
114 // Adjust SP by Amount bytes where bytes can be up to 32bit number.
115 void adjustStackPtrBig(unsigned SP, int64_t Amount, MachineBasicBlock &MBB,
116 MachineBasicBlock::iterator I,
117 unsigned Reg1, unsigned Reg2) const;
118
119 // Adjust SP by Amount bytes where bytes can be up to 32bit number.
Akira Hatanakae067e5a2013-01-04 19:38:05 +0000120 void adjustStackPtrBigUnrestricted(unsigned SP, int64_t Amount,
121 MachineBasicBlock &MBB,
122 MachineBasicBlock::iterator I) const;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000123};
124
Eugene Zelenko79220eae2017-08-03 22:12:30 +0000125} // end namespace llvm
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000126
Eugene Zelenko79220eae2017-08-03 22:12:30 +0000127#endif // LLVM_LIB_TARGET_MIPS_MIPS16INSTRINFO_H