annotate lib/Target/ARC/ARCInstrInfo.cpp @ 129:9ec641e857f8

Fix compile error to update llvm 5.0
author mir3636
date Tue, 12 Dec 2017 19:42:58 +0900
parents 803732b1fca8
children 3a76565eade5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- ARCInstrInfo.cpp - ARC Instruction Information -----------*- C++ -*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 // This file contains the ARC implementation of the TargetInstrInfo class.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "ARCInstrInfo.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #include "ARC.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #include "ARCMachineFunctionInfo.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include "ARCSubtarget.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 #include "MCTargetDesc/ARCInfo.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 #include "llvm/CodeGen/MachineFrameInfo.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 #include "llvm/CodeGen/MachineInstrBuilder.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 #include "llvm/CodeGen/MachineMemOperand.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 #include "llvm/Support/Debug.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 #include "llvm/Support/TargetRegistry.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 using namespace llvm;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 #define GET_INSTRINFO_CTOR_DTOR
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 #include "ARCGenInstrInfo.inc"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 #define DEBUG_TYPE "arc-inst-info"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 // Pin the vtable to this file.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 void ARCInstrInfo::anchor() {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 ARCInstrInfo::ARCInstrInfo()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 : ARCGenInstrInfo(ARC::ADJCALLSTACKDOWN, ARC::ADJCALLSTACKUP), RI() {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 static bool isZeroImm(const MachineOperand &Op) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 return Op.isImm() && Op.getImm() == 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 static bool isLoad(int Opcode) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 return Opcode == ARC::LD_rs9 || Opcode == ARC::LDH_rs9 ||
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 Opcode == ARC::LDB_rs9;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 static bool isStore(int Opcode) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 return Opcode == ARC::ST_rs9 || Opcode == ARC::STH_rs9 ||
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 Opcode == ARC::STB_rs9;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 /// If the specified machine instruction is a direct
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 /// load from a stack slot, return the virtual or physical register number of
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 /// the destination along with the FrameIndex of the loaded stack slot. If
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 /// not, return 0. This predicate must return 0 if the instruction has
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 /// any side effects other than loading from the stack slot.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 unsigned ARCInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 int &FrameIndex) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 int Opcode = MI.getOpcode();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 if (isLoad(Opcode)) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 if ((MI.getOperand(1).isFI()) && // is a stack slot
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 (MI.getOperand(2).isImm()) && // the imm is zero
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 (isZeroImm(MI.getOperand(2)))) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 FrameIndex = MI.getOperand(1).getIndex();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 return MI.getOperand(0).getReg();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 return 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 /// If the specified machine instruction is a direct
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 /// store to a stack slot, return the virtual or physical register number of
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 /// the source reg along with the FrameIndex of the loaded stack slot. If
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 /// not, return 0. This predicate must return 0 if the instruction has
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 /// any side effects other than storing to the stack slot.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 unsigned ARCInstrInfo::isStoreToStackSlot(const MachineInstr &MI,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 int &FrameIndex) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 int Opcode = MI.getOpcode();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 if (isStore(Opcode)) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 if ((MI.getOperand(1).isFI()) && // is a stack slot
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80 (MI.getOperand(2).isImm()) && // the imm is zero
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 (isZeroImm(MI.getOperand(2)))) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 FrameIndex = MI.getOperand(1).getIndex();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83 return MI.getOperand(0).getReg();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 return 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 /// Return the inverse of passed condition, i.e. turning COND_E to COND_NE.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 static ARCCC::CondCode GetOppositeBranchCondition(ARCCC::CondCode CC) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 switch (CC) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 default:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 llvm_unreachable("Illegal condition code!");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94 case ARCCC::EQ:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 return ARCCC::NE;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 case ARCCC::NE:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97 return ARCCC::EQ;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98 case ARCCC::LO:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99 return ARCCC::HS;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100 case ARCCC::HS:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101 return ARCCC::LO;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102 case ARCCC::GT:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
103 return ARCCC::LE;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
104 case ARCCC::GE:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
105 return ARCCC::LT;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
106 case ARCCC::LT:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
107 return ARCCC::GE;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
108 case ARCCC::LE:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
109 return ARCCC::GT;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
110 case ARCCC::HI:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
111 return ARCCC::LS;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
112 case ARCCC::LS:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
113 return ARCCC::HI;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
114 case ARCCC::NZ:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
115 return ARCCC::Z;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
116 case ARCCC::Z:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
117 return ARCCC::NZ;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
118 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
119 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
120
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
121 static bool isUncondBranchOpcode(int Opc) { return Opc == ARC::BR; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
122
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
123 static bool isCondBranchOpcode(int Opc) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
124 return Opc == ARC::BRcc_rr_p || Opc == ARC::BRcc_ru6_p;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
125 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
126
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
127 static bool isJumpOpcode(int Opc) { return Opc == ARC::J; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
128
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
129 /// Analyze the branching code at the end of MBB, returning
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
130 /// true if it cannot be understood (e.g. it's a switch dispatch or isn't
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
131 /// implemented for a target). Upon success, this returns false and returns
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
132 /// with the following information in various cases:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
133 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
134 /// 1. If this block ends with no branches (it just falls through to its succ)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
135 /// just return false, leaving TBB/FBB null.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
136 /// 2. If this block ends with only an unconditional branch, it sets TBB to be
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
137 /// the destination block.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
138 /// 3. If this block ends with a conditional branch and it falls through to a
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
139 /// successor block, it sets TBB to be the branch destination block and a
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
140 /// list of operands that evaluate the condition. These operands can be
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
141 /// passed to other TargetInstrInfo methods to create new branches.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
142 /// 4. If this block ends with a conditional branch followed by an
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
143 /// unconditional branch, it returns the 'true' destination in TBB, the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
144 /// 'false' destination in FBB, and a list of operands that evaluate the
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
145 /// condition. These operands can be passed to other TargetInstrInfo
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
146 /// methods to create new branches.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
147 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
148 /// Note that RemoveBranch and InsertBranch must be implemented to support
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
149 /// cases where this method returns success.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
150 ///
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
151 /// If AllowModify is true, then this routine is allowed to modify the basic
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
152 /// block (e.g. delete instructions after the unconditional branch).
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
153
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
154 bool ARCInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
155 MachineBasicBlock *&TBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
156 MachineBasicBlock *&FBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
157 SmallVectorImpl<MachineOperand> &Cond,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
158 bool AllowModify) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
159 TBB = FBB = nullptr;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
160 MachineBasicBlock::iterator I = MBB.end();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
161 if (I == MBB.begin())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
162 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
163 --I;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
164
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
165 while (isPredicated(*I) || I->isTerminator() || I->isDebugValue()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
166 // Flag to be raised on unanalyzeable instructions. This is useful in cases
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
167 // where we want to clean up on the end of the basic block before we bail
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
168 // out.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
169 bool CantAnalyze = false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
170
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
171 // Skip over DEBUG values and predicated nonterminators.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
172 while (I->isDebugValue() || !I->isTerminator()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
173 if (I == MBB.begin())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
174 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
175 --I;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
176 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
177
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
178 if (isJumpOpcode(I->getOpcode())) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
179 // Indirect branches and jump tables can't be analyzed, but we still want
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
180 // to clean up any instructions at the tail of the basic block.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
181 CantAnalyze = true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
182 } else if (isUncondBranchOpcode(I->getOpcode())) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
183 TBB = I->getOperand(0).getMBB();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
184 } else if (isCondBranchOpcode(I->getOpcode())) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
185 // Bail out if we encounter multiple conditional branches.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
186 if (!Cond.empty())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
187 return true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
188
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
189 assert(!FBB && "FBB should have been null.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
190 FBB = TBB;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
191 TBB = I->getOperand(0).getMBB();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
192 Cond.push_back(I->getOperand(1));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
193 Cond.push_back(I->getOperand(2));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
194 Cond.push_back(I->getOperand(3));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
195 } else if (I->isReturn()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
196 // Returns can't be analyzed, but we should run cleanup.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
197 CantAnalyze = !isPredicated(*I);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
198 } else {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
199 // We encountered other unrecognized terminator. Bail out immediately.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
200 return true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
201 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
202
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
203 // Cleanup code - to be run for unpredicated unconditional branches and
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
204 // returns.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
205 if (!isPredicated(*I) && (isUncondBranchOpcode(I->getOpcode()) ||
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
206 isJumpOpcode(I->getOpcode()) || I->isReturn())) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
207 // Forget any previous condition branch information - it no longer
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
208 // applies.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
209 Cond.clear();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
210 FBB = nullptr;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
211
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
212 // If we can modify the function, delete everything below this
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
213 // unconditional branch.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
214 if (AllowModify) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
215 MachineBasicBlock::iterator DI = std::next(I);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
216 while (DI != MBB.end()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
217 MachineInstr &InstToDelete = *DI;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
218 ++DI;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
219 InstToDelete.eraseFromParent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
220 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
221 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
222 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
223
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
224 if (CantAnalyze)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
225 return true;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
226
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
227 if (I == MBB.begin())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
228 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
229
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
230 --I;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
231 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
232
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
233 // We made it past the terminators without bailing out - we must have
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
234 // analyzed this branch successfully.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
235 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
236 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
237
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
238 unsigned ARCInstrInfo::removeBranch(MachineBasicBlock &MBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
239 int *BytesRemoved) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
240 assert(!BytesRemoved && "Code size not handled");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
241 MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
242 if (I == MBB.end())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
243 return 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
244
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
245 if (!isUncondBranchOpcode(I->getOpcode()) &&
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
246 !isCondBranchOpcode(I->getOpcode()))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
247 return 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
248
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
249 // Remove the branch.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
250 I->eraseFromParent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
251
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
252 I = MBB.end();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
253
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
254 if (I == MBB.begin())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
255 return 1;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
256 --I;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
257 if (!isCondBranchOpcode(I->getOpcode()))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
258 return 1;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
259
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
260 // Remove the branch.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
261 I->eraseFromParent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
262 return 2;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
263 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
264
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
265 void ARCInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
266 MachineBasicBlock::iterator I,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
267 const DebugLoc &dl, unsigned DestReg,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
268 unsigned SrcReg, bool KillSrc) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
269 assert(ARC::GPR32RegClass.contains(SrcReg) &&
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
270 "Only GPR32 src copy supported.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
271 assert(ARC::GPR32RegClass.contains(DestReg) &&
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
272 "Only GPR32 dest copy supported.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
273 BuildMI(MBB, I, dl, get(ARC::MOV_rr), DestReg)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
274 .addReg(SrcReg, getKillRegState(KillSrc));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
275 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
276
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
277 void ARCInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
278 MachineBasicBlock::iterator I,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
279 unsigned SrcReg, bool isKill,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
280 int FrameIndex,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
281 const TargetRegisterClass *RC,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
282 const TargetRegisterInfo *TRI) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
283 DebugLoc dl = MBB.findDebugLoc(I);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
284 MachineFunction &MF = *MBB.getParent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
285 MachineFrameInfo &MFI = MF.getFrameInfo();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
286 unsigned Align = MFI.getObjectAlignment(FrameIndex);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
287
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
288 MachineMemOperand *MMO = MF.getMachineMemOperand(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
289 MachinePointerInfo::getFixedStack(MF, FrameIndex),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
290 MachineMemOperand::MOStore, MFI.getObjectSize(FrameIndex), Align);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
291
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
292 assert(MMO && "Couldn't get MachineMemOperand for store to stack.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
293 assert(TRI->getSpillSize(*RC) == 4 &&
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
294 "Only support 4-byte stores to stack now.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
295 assert(ARC::GPR32RegClass.hasSubClassEq(RC) &&
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
296 "Only support GPR32 stores to stack now.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
297 DEBUG(dbgs() << "Created store reg=" << PrintReg(SrcReg, TRI)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
298 << " to FrameIndex=" << FrameIndex << "\n");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
299 BuildMI(MBB, I, dl, get(ARC::ST_rs9))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
300 .addReg(SrcReg, getKillRegState(isKill))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
301 .addFrameIndex(FrameIndex)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
302 .addImm(0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
303 .addMemOperand(MMO);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
304 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
305
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
306 void ARCInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
307 MachineBasicBlock::iterator I,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
308 unsigned DestReg, int FrameIndex,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
309 const TargetRegisterClass *RC,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
310 const TargetRegisterInfo *TRI) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
311 DebugLoc dl = MBB.findDebugLoc(I);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
312 MachineFunction &MF = *MBB.getParent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
313 MachineFrameInfo &MFI = MF.getFrameInfo();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
314 unsigned Align = MFI.getObjectAlignment(FrameIndex);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
315 MachineMemOperand *MMO = MF.getMachineMemOperand(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
316 MachinePointerInfo::getFixedStack(MF, FrameIndex),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
317 MachineMemOperand::MOLoad, MFI.getObjectSize(FrameIndex), Align);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
318
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
319 assert(MMO && "Couldn't get MachineMemOperand for store to stack.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
320 assert(TRI->getSpillSize(*RC) == 4 &&
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
321 "Only support 4-byte loads from stack now.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
322 assert(ARC::GPR32RegClass.hasSubClassEq(RC) &&
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
323 "Only support GPR32 stores to stack now.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
324 DEBUG(dbgs() << "Created load reg=" << PrintReg(DestReg, TRI)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
325 << " from FrameIndex=" << FrameIndex << "\n");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
326 BuildMI(MBB, I, dl, get(ARC::LD_rs9))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
327 .addReg(DestReg, RegState::Define)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
328 .addFrameIndex(FrameIndex)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
329 .addImm(0)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
330 .addMemOperand(MMO);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
331 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
332
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
333 /// Return the inverse opcode of the specified Branch instruction.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
334 bool ARCInstrInfo::reverseBranchCondition(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
335 SmallVectorImpl<MachineOperand> &Cond) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
336 assert((Cond.size() == 3) && "Invalid ARC branch condition!");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
337 Cond[2].setImm(GetOppositeBranchCondition((ARCCC::CondCode)Cond[2].getImm()));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
338 return false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
339 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
340
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
341 MachineBasicBlock::iterator
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
342 ARCInstrInfo::loadImmediate(MachineBasicBlock &MBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
343 MachineBasicBlock::iterator MI, unsigned Reg,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
344 uint64_t Value) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
345 DebugLoc dl = MBB.findDebugLoc(MI);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
346 if (isInt<12>(Value)) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
347 return BuildMI(MBB, MI, dl, get(ARC::MOV_rs12), Reg)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
348 .addImm(Value)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
349 .getInstr();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
350 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
351 llvm_unreachable("Need Arc long immediate instructions.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
352 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
353
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
354 unsigned ARCInstrInfo::insertBranch(MachineBasicBlock &MBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
355 MachineBasicBlock *TBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
356 MachineBasicBlock *FBB,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
357 ArrayRef<MachineOperand> Cond,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
358 const DebugLoc &dl, int *BytesAdded) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
359 assert(!BytesAdded && "Code size not handled.");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
360
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
361 // Shouldn't be a fall through.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
362 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
363 assert((Cond.size() == 3 || Cond.size() == 0) &&
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
364 "ARC branch conditions have two components!");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
365
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
366 if (Cond.empty()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
367 BuildMI(&MBB, dl, get(ARC::BR)).addMBB(TBB);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
368 return 1;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
369 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
370 int BccOpc = Cond[1].isImm() ? ARC::BRcc_ru6_p : ARC::BRcc_rr_p;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
371 MachineInstrBuilder MIB = BuildMI(&MBB, dl, get(BccOpc));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
372 MIB.addMBB(TBB);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
373 for (unsigned i = 0; i < 3; i++) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
374 MIB.add(Cond[i]);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
375 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
376
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
377 // One-way conditional branch.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
378 if (!FBB) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
379 return 1;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
380 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
381
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
382 // Two-way conditional branch.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
383 BuildMI(&MBB, dl, get(ARC::BR)).addMBB(FBB);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
384 return 2;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
385 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
386
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
387 unsigned ARCInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
388 if (MI.getOpcode() == TargetOpcode::INLINEASM) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
389 const MachineFunction *MF = MI.getParent()->getParent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
390 const char *AsmStr = MI.getOperand(0).getSymbolName();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
391 return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
392 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
393 return MI.getDesc().getSize();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
394 }