1 //===- BlackfinInstrInfo.cpp - Blackfin Instruction Information -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the Blackfin implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #include "BlackfinInstrInfo.h"
15 #include "BlackfinSubtarget.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/CodeGen/MachineRegisterInfo.h"
20 #include "llvm/CodeGen/MachineInstrBuilder.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "BlackfinGenInstrInfo.inc"
26 BlackfinInstrInfo::BlackfinInstrInfo(BlackfinSubtarget
&ST
)
27 : TargetInstrInfoImpl(BlackfinInsts
, array_lengthof(BlackfinInsts
)),
31 /// isLoadFromStackSlot - If the specified machine instruction is a direct
32 /// load from a stack slot, return the virtual or physical register number of
33 /// the destination along with the FrameIndex of the loaded stack slot. If
34 /// not, return 0. This predicate must return 0 if the instruction has
35 /// any side effects other than loading from the stack slot.
36 unsigned BlackfinInstrInfo::isLoadFromStackSlot(const MachineInstr
*MI
,
37 int &FrameIndex
) const {
38 switch (MI
->getOpcode()) {
42 if (MI
->getOperand(1).isFI() &&
43 MI
->getOperand(2).isImm() &&
44 MI
->getOperand(2).getImm() == 0) {
45 FrameIndex
= MI
->getOperand(1).getIndex();
46 return MI
->getOperand(0).getReg();
53 /// isStoreToStackSlot - If the specified machine instruction is a direct
54 /// store to a stack slot, return the virtual or physical register number of
55 /// the source reg along with the FrameIndex of the loaded stack slot. If
56 /// not, return 0. This predicate must return 0 if the instruction has
57 /// any side effects other than storing to the stack slot.
58 unsigned BlackfinInstrInfo::isStoreToStackSlot(const MachineInstr
*MI
,
59 int &FrameIndex
) const {
60 switch (MI
->getOpcode()) {
64 if (MI
->getOperand(1).isFI() &&
65 MI
->getOperand(2).isImm() &&
66 MI
->getOperand(2).getImm() == 0) {
67 FrameIndex
= MI
->getOperand(1).getIndex();
68 return MI
->getOperand(0).getReg();
75 unsigned BlackfinInstrInfo::
76 InsertBranch(MachineBasicBlock
&MBB
,
77 MachineBasicBlock
*TBB
,
78 MachineBasicBlock
*FBB
,
79 const SmallVectorImpl
<MachineOperand
> &Cond
,
81 // Shouldn't be a fall through.
82 assert(TBB
&& "InsertBranch must not be told to insert a fallthrough");
83 assert((Cond
.size() == 1 || Cond
.size() == 0) &&
84 "Branch conditions have one component!");
87 // Unconditional branch?
88 assert(!FBB
&& "Unconditional branch with multiple successors!");
89 BuildMI(&MBB
, DL
, get(BF::JUMPa
)).addMBB(TBB
);
93 // Conditional branch.
94 llvm_unreachable("Implement conditional branches!");
97 void BlackfinInstrInfo::copyPhysReg(MachineBasicBlock
&MBB
,
98 MachineBasicBlock::iterator I
, DebugLoc DL
,
99 unsigned DestReg
, unsigned SrcReg
,
100 bool KillSrc
) const {
101 if (BF::ALLRegClass
.contains(DestReg
, SrcReg
)) {
102 BuildMI(MBB
, I
, DL
, get(BF::MOVE
), DestReg
)
103 .addReg(SrcReg
, getKillRegState(KillSrc
));
107 if (BF::D16RegClass
.contains(DestReg
, SrcReg
)) {
108 BuildMI(MBB
, I
, DL
, get(BF::SLL16i
), DestReg
)
109 .addReg(SrcReg
, getKillRegState(KillSrc
))
114 if (BF::DRegClass
.contains(DestReg
)) {
115 if (SrcReg
== BF::NCC
) {
116 BuildMI(MBB
, I
, DL
, get(BF::MOVENCC_z
), DestReg
)
117 .addReg(SrcReg
, getKillRegState(KillSrc
));
118 BuildMI(MBB
, I
, DL
, get(BF::BITTGL
), DestReg
).addReg(DestReg
).addImm(0);
121 if (SrcReg
== BF::CC
) {
122 BuildMI(MBB
, I
, DL
, get(BF::MOVECC_zext
), DestReg
)
123 .addReg(SrcReg
, getKillRegState(KillSrc
));
128 if (BF::DRegClass
.contains(SrcReg
)) {
129 if (DestReg
== BF::NCC
) {
130 BuildMI(MBB
, I
, DL
, get(BF::SETEQri_not
), DestReg
)
131 .addReg(SrcReg
, getKillRegState(KillSrc
)).addImm(0);
134 if (DestReg
== BF::CC
) {
135 BuildMI(MBB
, I
, DL
, get(BF::MOVECC_nz
), DestReg
)
136 .addReg(SrcReg
, getKillRegState(KillSrc
));
142 if (DestReg
== BF::NCC
&& SrcReg
== BF::CC
) {
143 BuildMI(MBB
, I
, DL
, get(BF::MOVE_ncccc
), DestReg
)
144 .addReg(SrcReg
, getKillRegState(KillSrc
));
148 if (DestReg
== BF::CC
&& SrcReg
== BF::NCC
) {
149 BuildMI(MBB
, I
, DL
, get(BF::MOVE_ccncc
), DestReg
)
150 .addReg(SrcReg
, getKillRegState(KillSrc
));
154 llvm_unreachable("Bad reg-to-reg copy");
157 static bool inClass(const TargetRegisterClass
&Test
,
159 const TargetRegisterClass
*RC
) {
160 if (TargetRegisterInfo::isPhysicalRegister(Reg
))
161 return Test
.contains(Reg
);
163 return &Test
==RC
|| Test
.hasSubClass(RC
);
167 BlackfinInstrInfo::storeRegToStackSlot(MachineBasicBlock
&MBB
,
168 MachineBasicBlock::iterator I
,
172 const TargetRegisterClass
*RC
,
173 const TargetRegisterInfo
*TRI
) const {
174 DebugLoc DL
= I
!= MBB
.end() ? I
->getDebugLoc() : DebugLoc();
176 if (inClass(BF::DPRegClass
, SrcReg
, RC
)) {
177 BuildMI(MBB
, I
, DL
, get(BF::STORE32fi
))
178 .addReg(SrcReg
, getKillRegState(isKill
))
184 if (inClass(BF::D16RegClass
, SrcReg
, RC
)) {
185 BuildMI(MBB
, I
, DL
, get(BF::STORE16fi
))
186 .addReg(SrcReg
, getKillRegState(isKill
))
192 if (inClass(BF::AnyCCRegClass
, SrcReg
, RC
)) {
193 BuildMI(MBB
, I
, DL
, get(BF::STORE8fi
))
194 .addReg(SrcReg
, getKillRegState(isKill
))
200 llvm_unreachable((std::string("Cannot store regclass to stack slot: ")+
201 RC
->getName()).c_str());
204 void BlackfinInstrInfo::
205 storeRegToAddr(MachineFunction
&MF
,
208 SmallVectorImpl
<MachineOperand
> &Addr
,
209 const TargetRegisterClass
*RC
,
210 SmallVectorImpl
<MachineInstr
*> &NewMIs
) const {
211 llvm_unreachable("storeRegToAddr not implemented");
215 BlackfinInstrInfo::loadRegFromStackSlot(MachineBasicBlock
&MBB
,
216 MachineBasicBlock::iterator I
,
219 const TargetRegisterClass
*RC
,
220 const TargetRegisterInfo
*TRI
) const {
221 DebugLoc DL
= I
!= MBB
.end() ? I
->getDebugLoc() : DebugLoc();
222 if (inClass(BF::DPRegClass
, DestReg
, RC
)) {
223 BuildMI(MBB
, I
, DL
, get(BF::LOAD32fi
), DestReg
)
229 if (inClass(BF::D16RegClass
, DestReg
, RC
)) {
230 BuildMI(MBB
, I
, DL
, get(BF::LOAD16fi
), DestReg
)
236 if (inClass(BF::AnyCCRegClass
, DestReg
, RC
)) {
237 BuildMI(MBB
, I
, DL
, get(BF::LOAD8fi
), DestReg
)
243 llvm_unreachable("Cannot load regclass from stack slot");
246 void BlackfinInstrInfo::
247 loadRegFromAddr(MachineFunction
&MF
,
249 SmallVectorImpl
<MachineOperand
> &Addr
,
250 const TargetRegisterClass
*RC
,
251 SmallVectorImpl
<MachineInstr
*> &NewMIs
) const {
252 llvm_unreachable("loadRegFromAddr not implemented");