blob: 6540b40bc9abfb59887f388c8a010ec7d2606e4d [file] [log] [blame]
Akira Hatanakab7fa3c92012-07-31 21:49:49 +00001//===-- Mips16InstrInfo.h - Mips16 Instruction Information ------*- C++ -*-===//
2//
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"
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000019
20namespace llvm {
Eric Christophera20c3cf2015-03-12 05:43:57 +000021class MipsSubtarget;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000022class Mips16InstrInfo : public MipsInstrInfo {
Akira Hatanakacb37e132012-07-31 23:41:32 +000023 const Mips16RegisterInfo RI;
24
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000025public:
Eric Christopher675cb4d2014-07-18 23:25:00 +000026 explicit Mips16InstrInfo(const MipsSubtarget &STI);
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000027
Craig Topper56c590a2014-04-29 07:58:02 +000028 const MipsRegisterInfo &getRegisterInfo() const override;
Akira Hatanakacb37e132012-07-31 23:41:32 +000029
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000030 /// isLoadFromStackSlot - If the specified machine instruction is a direct
31 /// load from a stack slot, return the virtual or physical register number of
32 /// the destination along with the FrameIndex of the loaded stack slot. If
33 /// not, return 0. This predicate must return 0 if the instruction has
34 /// any side effects other than loading from the stack slot.
Craig Topper56c590a2014-04-29 07:58:02 +000035 unsigned isLoadFromStackSlot(const MachineInstr *MI,
36 int &FrameIndex) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000037
38 /// isStoreToStackSlot - If the specified machine instruction is a direct
39 /// store to a stack slot, return the virtual or physical register number of
40 /// the source reg along with the FrameIndex of the loaded stack slot. If
41 /// not, return 0. This predicate must return 0 if the instruction has
42 /// any side effects other than storing to the stack slot.
Craig Topper56c590a2014-04-29 07:58:02 +000043 unsigned isStoreToStackSlot(const MachineInstr *MI,
44 int &FrameIndex) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000045
Craig Topper56c590a2014-04-29 07:58:02 +000046 void copyPhysReg(MachineBasicBlock &MBB,
47 MachineBasicBlock::iterator MI, DebugLoc DL,
48 unsigned DestReg, unsigned SrcReg,
49 bool KillSrc) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000050
Craig Topper56c590a2014-04-29 07:58:02 +000051 void storeRegToStack(MachineBasicBlock &MBB,
52 MachineBasicBlock::iterator MBBI,
53 unsigned SrcReg, bool isKill, int FrameIndex,
54 const TargetRegisterClass *RC,
55 const TargetRegisterInfo *TRI,
56 int64_t Offset) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000057
Craig Topper56c590a2014-04-29 07:58:02 +000058 void loadRegFromStack(MachineBasicBlock &MBB,
59 MachineBasicBlock::iterator MBBI,
60 unsigned DestReg, int FrameIndex,
61 const TargetRegisterClass *RC,
62 const TargetRegisterInfo *TRI,
63 int64_t Offset) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000064
Craig Topper56c590a2014-04-29 07:58:02 +000065 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000066
Craig Topper56c590a2014-04-29 07:58:02 +000067 unsigned getOppositeBranchOpc(unsigned Opc) const override;
Akira Hatanakab7fa3c92012-07-31 21:49:49 +000068
Reed Kotlerd019dbf2012-12-20 04:07:42 +000069 // Adjust SP by FrameSize bytes. Save RA, S0, S1
70 void makeFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB,
Reed Kotler30cedf62013-08-04 01:13:25 +000071 MachineBasicBlock::iterator I) const;
Reed Kotlerd019dbf2012-12-20 04:07:42 +000072
73 // Adjust SP by FrameSize bytes. Restore RA, S0, S1
74 void restoreFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB,
75 MachineBasicBlock::iterator I) const;
76
77
Reed Kotler27a72292012-10-31 05:21:10 +000078 /// Adjust SP by Amount bytes.
79 void adjustStackPtr(unsigned SP, int64_t Amount, MachineBasicBlock &MBB,
Vasileios Kalintiris6d687782015-04-02 10:42:44 +000080 MachineBasicBlock::iterator I) const override;
Reed Kotler27a72292012-10-31 05:21:10 +000081
Reed Kotler66165c82013-02-08 03:57:41 +000082 /// Emit a series of instructions to load an immediate.
83 // This is to adjust some FrameReg. We return the new register to be used
84 // in place of FrameReg and the adjusted immediate field (&NewImm)
85 //
86 unsigned loadImmediate(unsigned FrameReg,
87 int64_t Imm, MachineBasicBlock &MBB,
Reed Kotlerd019dbf2012-12-20 04:07:42 +000088 MachineBasicBlock::iterator II, DebugLoc DL,
Reed Kotler66165c82013-02-08 03:57:41 +000089 unsigned &NewImm) const;
Reed Kotlerd019dbf2012-12-20 04:07:42 +000090
Reed Kotler30cedf62013-08-04 01:13:25 +000091 static bool validImmediate(unsigned Opcode, unsigned Reg, int64_t Amount);
92
Reed Kotlerf662cff2013-02-13 20:28:27 +000093 static bool validSpImm8(int offset) {
94 return ((offset & 7) == 0) && isInt<11>(offset);
95 }
96
97 //
98 // build the proper one based on the Imm field
99 //
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;
105
Reed Kotler5c8ae092013-11-13 04:37:52 +0000106 unsigned getInlineAsmLength(const char *Str,
Craig Topper56c590a2014-04-29 07:58:02 +0000107 const MCAsmInfo &MAI) const override;
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;
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000123
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000124};
125
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000126}
Akira Hatanakab7fa3c92012-07-31 21:49:49 +0000127
128#endif