blob: ffdd4728c8cb71aaa414e3dd6676838cd2fed8ae [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
Craig Topper56c590a2014-04-29 07:58:02 +000056 void storeRegToStack(MachineBasicBlock &MBB,
57 MachineBasicBlock::iterator MBBI,
58 unsigned SrcReg, bool isKill, int FrameIndex,
59 const TargetRegisterClass *RC,
60 const TargetRegisterInfo *TRI,
61 int64_t Offset) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000062
Craig Topper56c590a2014-04-29 07:58:02 +000063 void loadRegFromStack(MachineBasicBlock &MBB,
64 MachineBasicBlock::iterator MBBI,
65 unsigned DestReg, int FrameIndex,
66 const TargetRegisterClass *RC,
67 const TargetRegisterInfo *TRI,
68 int64_t Offset) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000069
Duncan P. N. Exon Smith9cfc75c2016-06-30 00:01:54 +000070 bool expandPostRAPseudo(MachineInstr &MI) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000071
Craig Topper56c590a2014-04-29 07:58:02 +000072 unsigned getOppositeBranchOpc(unsigned Opc) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000073
Reed Kotlerd019dbf2012-12-20 04:07:42 +000074 // Adjust SP by FrameSize bytes. Save RA, S0, S1
75 void makeFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB,
Reed Kotler30cedf62013-08-04 01:13:25 +000076 MachineBasicBlock::iterator I) const;
Reed Kotlerd019dbf2012-12-20 04:07:42 +000077
78 // Adjust SP by FrameSize bytes. Restore RA, S0, S1
79 void restoreFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB,
80 MachineBasicBlock::iterator I) const;
81
Reed Kotler27a72292012-10-31 05:21:10 +000082 /// Adjust SP by Amount bytes.
83 void adjustStackPtr(unsigned SP, int64_t Amount, MachineBasicBlock &MBB,
Vasileios Kalintiris6d687782015-04-02 10:42:44 +000084 MachineBasicBlock::iterator I) const override;
Reed Kotler27a72292012-10-31 05:21:10 +000085
Reed Kotler66165c82013-02-08 03:57:41 +000086 /// Emit a series of instructions to load an immediate.
87 // This is to adjust some FrameReg. We return the new register to be used
88 // in place of FrameReg and the adjusted immediate field (&NewImm)
Benjamin Kramerbdc49562016-06-12 15:39:02 +000089 unsigned loadImmediate(unsigned FrameReg, int64_t Imm, MachineBasicBlock &MBB,
90 MachineBasicBlock::iterator II, const DebugLoc &DL,
Reed Kotler66165c82013-02-08 03:57:41 +000091 unsigned &NewImm) const;
Reed Kotlerd019dbf2012-12-20 04:07:42 +000092
Reed Kotler30cedf62013-08-04 01:13:25 +000093 static bool validImmediate(unsigned Opcode, unsigned Reg, int64_t Amount);
94
Reed Kotlerf662cff2013-02-13 20:28:27 +000095 static bool validSpImm8(int offset) {
96 return ((offset & 7) == 0) && isInt<11>(offset);
97 }
98
Reed Kotlerf662cff2013-02-13 20:28:27 +000099 // build the proper one based on the Imm field
Reed Kotlerf662cff2013-02-13 20:28:27 +0000100
Reed Kotler8cf51032013-02-16 09:47:57 +0000101 const MCInstrDesc& AddiuSpImm(int64_t Imm) const;
Reed Kotlerf662cff2013-02-13 20:28:27 +0000102
Reed Kotler188dad02013-02-16 19:04:29 +0000103 void BuildAddiuSpImm
104 (MachineBasicBlock &MBB, MachineBasicBlock::iterator I, int64_t Imm) const;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000105private:
Craig Topper56c590a2014-04-29 07:58:02 +0000106 unsigned getAnalyzableBrOpc(unsigned Opc) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000107
108 void ExpandRetRA16(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
109 unsigned Opc) const;
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000110
111 // Adjust SP by Amount bytes where bytes can be up to 32bit number.
112 void adjustStackPtrBig(unsigned SP, int64_t Amount, MachineBasicBlock &MBB,
113 MachineBasicBlock::iterator I,
114 unsigned Reg1, unsigned Reg2) const;
115
116 // Adjust SP by Amount bytes where bytes can be up to 32bit number.
Akira Hatanakae067e5a2013-01-04 19:38:05 +0000117 void adjustStackPtrBigUnrestricted(unsigned SP, int64_t Amount,
118 MachineBasicBlock &MBB,
119 MachineBasicBlock::iterator I) const;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000120};
121
Eugene Zelenko79220eae2017-08-03 22:12:30 +0000122} // end namespace llvm
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000123
Eugene Zelenko79220eae2017-08-03 22:12:30 +0000124#endif // LLVM_LIB_TARGET_MIPS_MIPS16INSTRINFO_H