Bug Summary

File:lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp
Warning:line 200, column 3
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name HexagonMCInstrInfo.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/lib/Target/Hexagon/MCTargetDesc -I /build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc -I /build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/lib/Target/Hexagon -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn329677/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/lib/Target/Hexagon/MCTargetDesc -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-04-11-031539-24776-1 -x c++ /build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp
1//===- HexagonMCInstrInfo.cpp - Hexagon sub-class of MCInst ---------------===//
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 class extends MCInstrInfo to allow Hexagon specific MCInstr queries
11//
12//===----------------------------------------------------------------------===//
13
14#include "MCTargetDesc/HexagonMCInstrInfo.h"
15#include "Hexagon.h"
16#include "MCTargetDesc/HexagonBaseInfo.h"
17#include "MCTargetDesc/HexagonMCChecker.h"
18#include "MCTargetDesc/HexagonMCExpr.h"
19#include "MCTargetDesc/HexagonMCShuffler.h"
20#include "MCTargetDesc/HexagonMCTargetDesc.h"
21#include "llvm/ADT/SmallVector.h"
22#include "llvm/MC/MCContext.h"
23#include "llvm/MC/MCExpr.h"
24#include "llvm/MC/MCInst.h"
25#include "llvm/MC/MCInstrInfo.h"
26#include "llvm/MC/MCInstrItineraries.h"
27#include "llvm/MC/MCSubtargetInfo.h"
28#include "llvm/Support/Casting.h"
29#include "llvm/Support/ErrorHandling.h"
30#include <cassert>
31#include <cstdint>
32#include <limits>
33
34using namespace llvm;
35
36bool HexagonMCInstrInfo::PredicateInfo::isPredicated() const {
37 return Register != Hexagon::NoRegister;
38}
39
40Hexagon::PacketIterator::PacketIterator(MCInstrInfo const &MCII,
41 MCInst const &Inst)
42 : MCII(MCII), BundleCurrent(Inst.begin() +
43 HexagonMCInstrInfo::bundleInstructionsOffset),
44 BundleEnd(Inst.end()), DuplexCurrent(Inst.end()), DuplexEnd(Inst.end()) {}
45
46Hexagon::PacketIterator::PacketIterator(MCInstrInfo const &MCII,
47 MCInst const &Inst, std::nullptr_t)
48 : MCII(MCII), BundleCurrent(Inst.end()), BundleEnd(Inst.end()),
49 DuplexCurrent(Inst.end()), DuplexEnd(Inst.end()) {}
50
51Hexagon::PacketIterator &Hexagon::PacketIterator::operator++() {
52 if (DuplexCurrent != DuplexEnd) {
53 ++DuplexCurrent;
54 if (DuplexCurrent == DuplexEnd) {
55 DuplexCurrent = BundleEnd;
56 DuplexEnd = BundleEnd;
57 ++BundleCurrent;
58 }
59 return *this;
60 }
61 ++BundleCurrent;
62 if (BundleCurrent != BundleEnd) {
63 MCInst const &Inst = *BundleCurrent->getInst();
64 if (HexagonMCInstrInfo::isDuplex(MCII, Inst)) {
65 DuplexCurrent = Inst.begin();
66 DuplexEnd = Inst.end();
67 }
68 }
69 return *this;
70}
71
72MCInst const &Hexagon::PacketIterator::operator*() const {
73 if (DuplexCurrent != DuplexEnd)
74 return *DuplexCurrent->getInst();
75 return *BundleCurrent->getInst();
76}
77
78bool Hexagon::PacketIterator::operator==(PacketIterator const &Other) const {
79 return BundleCurrent == Other.BundleCurrent && BundleEnd == Other.BundleEnd &&
80 DuplexCurrent == Other.DuplexCurrent && DuplexEnd == Other.DuplexEnd;
81}
82
83void HexagonMCInstrInfo::addConstant(MCInst &MI, uint64_t Value,
84 MCContext &Context) {
85 MI.addOperand(MCOperand::createExpr(MCConstantExpr::create(Value, Context)));
86}
87
88void HexagonMCInstrInfo::addConstExtender(MCContext &Context,
89 MCInstrInfo const &MCII, MCInst &MCB,
90 MCInst const &MCI) {
91 assert(HexagonMCInstrInfo::isBundle(MCB))(static_cast <bool> (HexagonMCInstrInfo::isBundle(MCB))
? void (0) : __assert_fail ("HexagonMCInstrInfo::isBundle(MCB)"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 91, __extension__ __PRETTY_FUNCTION__))
;
92 MCOperand const &exOp =
93 MCI.getOperand(HexagonMCInstrInfo::getExtendableOp(MCII, MCI));
94
95 // Create the extender.
96 MCInst *XMCI =
97 new (Context) MCInst(HexagonMCInstrInfo::deriveExtender(MCII, MCI, exOp));
98 XMCI->setLoc(MCI.getLoc());
99
100 MCB.addOperand(MCOperand::createInst(XMCI));
101}
102
103iterator_range<Hexagon::PacketIterator>
104HexagonMCInstrInfo::bundleInstructions(MCInstrInfo const &MCII,
105 MCInst const &MCI) {
106 assert(isBundle(MCI))(static_cast <bool> (isBundle(MCI)) ? void (0) : __assert_fail
("isBundle(MCI)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 return make_range(Hexagon::PacketIterator(MCII, MCI),
108 Hexagon::PacketIterator(MCII, MCI, nullptr));
109}
110
111iterator_range<MCInst::const_iterator>
112HexagonMCInstrInfo::bundleInstructions(MCInst const &MCI) {
113 assert(isBundle(MCI))(static_cast <bool> (isBundle(MCI)) ? void (0) : __assert_fail
("isBundle(MCI)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 113, __extension__ __PRETTY_FUNCTION__))
;
114 return make_range(MCI.begin() + bundleInstructionsOffset, MCI.end());
115}
116
117size_t HexagonMCInstrInfo::bundleSize(MCInst const &MCI) {
118 if (HexagonMCInstrInfo::isBundle(MCI))
119 return (MCI.size() - bundleInstructionsOffset);
120 else
121 return (1);
122}
123
124bool HexagonMCInstrInfo::canonicalizePacket(MCInstrInfo const &MCII,
125 MCSubtargetInfo const &STI,
126 MCContext &Context, MCInst &MCB,
127 HexagonMCChecker *Check) {
128 // Check the bundle for errors.
129 bool CheckOk = Check ? Check->check(false) : true;
130 if (!CheckOk)
131 return false;
132 // Examine the packet and convert pairs of instructions to compound
133 // instructions when possible.
134 if (!HexagonDisableCompound)
135 HexagonMCInstrInfo::tryCompound(MCII, STI, Context, MCB);
136 HexagonMCShuffle(Context, false, MCII, STI, MCB);
137 // Examine the packet and convert pairs of instructions to duplex
138 // instructions when possible.
139 MCInst InstBundlePreDuplex = MCInst(MCB);
140 if (STI.getFeatureBits() [Hexagon::FeatureDuplex]) {
141 SmallVector<DuplexCandidate, 8> possibleDuplexes;
142 possibleDuplexes =
143 HexagonMCInstrInfo::getDuplexPossibilties(MCII, STI, MCB);
144 HexagonMCShuffle(Context, MCII, STI, MCB, possibleDuplexes);
145 }
146 // Examines packet and pad the packet, if needed, when an
147 // end-loop is in the bundle.
148 HexagonMCInstrInfo::padEndloop(MCB, Context);
149 // If compounding and duplexing didn't reduce the size below
150 // 4 or less we have a packet that is too big.
151 if (HexagonMCInstrInfo::bundleSize(MCB) > HEXAGON_PACKET_SIZE4)
152 return false;
153 // Check the bundle for errors.
154 CheckOk = Check ? Check->check(true) : true;
155 if (!CheckOk)
156 return false;
157 HexagonMCShuffle(Context, true, MCII, STI, MCB);
158 return true;
159}
160
161void HexagonMCInstrInfo::clampExtended(MCInstrInfo const &MCII,
162 MCContext &Context, MCInst &MCI) {
163 assert(HexagonMCInstrInfo::isExtendable(MCII, MCI) ||(static_cast <bool> (HexagonMCInstrInfo::isExtendable(MCII
, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) ? void (
0) : __assert_fail ("HexagonMCInstrInfo::isExtendable(MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 164, __extension__ __PRETTY_FUNCTION__))
164 HexagonMCInstrInfo::isExtended(MCII, MCI))(static_cast <bool> (HexagonMCInstrInfo::isExtendable(MCII
, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) ? void (
0) : __assert_fail ("HexagonMCInstrInfo::isExtendable(MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 164, __extension__ __PRETTY_FUNCTION__))
;
165 MCOperand &exOp =
166 MCI.getOperand(HexagonMCInstrInfo::getExtendableOp(MCII, MCI));
167 // If the extended value is a constant, then use it for the extended and
168 // for the extender instructions, masking off the lower 6 bits and
169 // including the assumed bits.
170 int64_t Value;
171 if (exOp.getExpr()->evaluateAsAbsolute(Value)) {
172 unsigned Shift = HexagonMCInstrInfo::getExtentAlignment(MCII, MCI);
173 exOp.setExpr(HexagonMCExpr::create(
174 MCConstantExpr::create((Value & 0x3f) << Shift, Context), Context));
175 }
176}
177
178MCInst HexagonMCInstrInfo::deriveExtender(MCInstrInfo const &MCII,
179 MCInst const &Inst,
180 MCOperand const &MO) {
181 assert(HexagonMCInstrInfo::isExtendable(MCII, Inst) ||(static_cast <bool> (HexagonMCInstrInfo::isExtendable(MCII
, Inst) || HexagonMCInstrInfo::isExtended(MCII, Inst)) ? void
(0) : __assert_fail ("HexagonMCInstrInfo::isExtendable(MCII, Inst) || HexagonMCInstrInfo::isExtended(MCII, Inst)"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 182, __extension__ __PRETTY_FUNCTION__))
182 HexagonMCInstrInfo::isExtended(MCII, Inst))(static_cast <bool> (HexagonMCInstrInfo::isExtendable(MCII
, Inst) || HexagonMCInstrInfo::isExtended(MCII, Inst)) ? void
(0) : __assert_fail ("HexagonMCInstrInfo::isExtendable(MCII, Inst) || HexagonMCInstrInfo::isExtended(MCII, Inst)"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 182, __extension__ __PRETTY_FUNCTION__))
;
183
184 MCInst XMI;
185 XMI.setOpcode(Hexagon::A4_ext);
186 if (MO.isImm())
187 XMI.addOperand(MCOperand::createImm(MO.getImm() & (~0x3f)));
188 else if (MO.isExpr())
189 XMI.addOperand(MCOperand::createExpr(MO.getExpr()));
190 else
191 llvm_unreachable("invalid extendable operand")::llvm::llvm_unreachable_internal("invalid extendable operand"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 191)
;
192 return XMI;
193}
194
195MCInst *HexagonMCInstrInfo::deriveDuplex(MCContext &Context, unsigned iClass,
196 MCInst const &inst0,
197 MCInst const &inst1) {
198 assert((iClass <= 0xf) && "iClass must have range of 0 to 0xf")(static_cast <bool> ((iClass <= 0xf) && "iClass must have range of 0 to 0xf"
) ? void (0) : __assert_fail ("(iClass <= 0xf) && \"iClass must have range of 0 to 0xf\""
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 198, __extension__ __PRETTY_FUNCTION__))
;
199 MCInst *duplexInst = new (Context) MCInst;
1
'duplexInst' initialized to a null pointer value
200 duplexInst->setOpcode(Hexagon::DuplexIClass0 + iClass);
2
Called C++ object pointer is null
201
202 MCInst *SubInst0 = new (Context) MCInst(deriveSubInst(inst0));
203 MCInst *SubInst1 = new (Context) MCInst(deriveSubInst(inst1));
204 duplexInst->addOperand(MCOperand::createInst(SubInst0));
205 duplexInst->addOperand(MCOperand::createInst(SubInst1));
206 return duplexInst;
207}
208
209MCInst const *HexagonMCInstrInfo::extenderForIndex(MCInst const &MCB,
210 size_t Index) {
211 assert(Index <= bundleSize(MCB))(static_cast <bool> (Index <= bundleSize(MCB)) ? void
(0) : __assert_fail ("Index <= bundleSize(MCB)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 211, __extension__ __PRETTY_FUNCTION__))
;
212 if (Index == 0)
213 return nullptr;
214 MCInst const *Inst =
215 MCB.getOperand(Index + bundleInstructionsOffset - 1).getInst();
216 if (isImmext(*Inst))
217 return Inst;
218 return nullptr;
219}
220
221void HexagonMCInstrInfo::extendIfNeeded(MCContext &Context,
222 MCInstrInfo const &MCII, MCInst &MCB,
223 MCInst const &MCI) {
224 if (isConstExtended(MCII, MCI))
225 addConstExtender(Context, MCII, MCB, MCI);
226}
227
228unsigned HexagonMCInstrInfo::getMemAccessSize(MCInstrInfo const &MCII,
229 MCInst const &MCI) {
230 uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
231 unsigned S = (F >> HexagonII::MemAccessSizePos) & HexagonII::MemAccesSizeMask;
232 return HexagonII::getMemAccessSizeInBytes(HexagonII::MemAccessSize(S));
233}
234
235unsigned HexagonMCInstrInfo::getAddrMode(MCInstrInfo const &MCII,
236 MCInst const &MCI) {
237 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
238 return static_cast<unsigned>((F >> HexagonII::AddrModePos) &
239 HexagonII::AddrModeMask);
240}
241
242MCInstrDesc const &HexagonMCInstrInfo::getDesc(MCInstrInfo const &MCII,
243 MCInst const &MCI) {
244 return MCII.get(MCI.getOpcode());
245}
246
247unsigned HexagonMCInstrInfo::getDuplexRegisterNumbering(unsigned Reg) {
248 using namespace Hexagon;
249
250 switch (Reg) {
251 default:
252 llvm_unreachable("unknown duplex register")::llvm::llvm_unreachable_internal("unknown duplex register", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 252)
;
253 // Rs Rss
254 case R0:
255 case D0:
256 return 0;
257 case R1:
258 case D1:
259 return 1;
260 case R2:
261 case D2:
262 return 2;
263 case R3:
264 case D3:
265 return 3;
266 case R4:
267 case D8:
268 return 4;
269 case R5:
270 case D9:
271 return 5;
272 case R6:
273 case D10:
274 return 6;
275 case R7:
276 case D11:
277 return 7;
278 case R16:
279 return 8;
280 case R17:
281 return 9;
282 case R18:
283 return 10;
284 case R19:
285 return 11;
286 case R20:
287 return 12;
288 case R21:
289 return 13;
290 case R22:
291 return 14;
292 case R23:
293 return 15;
294 }
295}
296
297MCExpr const &HexagonMCInstrInfo::getExpr(MCExpr const &Expr) {
298 const auto &HExpr = cast<HexagonMCExpr>(Expr);
299 assert(HExpr.getExpr())(static_cast <bool> (HExpr.getExpr()) ? void (0) : __assert_fail
("HExpr.getExpr()", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 299, __extension__ __PRETTY_FUNCTION__))
;
300 return *HExpr.getExpr();
301}
302
303unsigned short HexagonMCInstrInfo::getExtendableOp(MCInstrInfo const &MCII,
304 MCInst const &MCI) {
305 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
306 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
307}
308
309MCOperand const &
310HexagonMCInstrInfo::getExtendableOperand(MCInstrInfo const &MCII,
311 MCInst const &MCI) {
312 unsigned O = HexagonMCInstrInfo::getExtendableOp(MCII, MCI);
313 MCOperand const &MO = MCI.getOperand(O);
314
315 assert((HexagonMCInstrInfo::isExtendable(MCII, MCI) ||(static_cast <bool> ((HexagonMCInstrInfo::isExtendable(
MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) &&
(MO.isImm() || MO.isExpr())) ? void (0) : __assert_fail ("(HexagonMCInstrInfo::isExtendable(MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) && (MO.isImm() || MO.isExpr())"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 317, __extension__ __PRETTY_FUNCTION__))
316 HexagonMCInstrInfo::isExtended(MCII, MCI)) &&(static_cast <bool> ((HexagonMCInstrInfo::isExtendable(
MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) &&
(MO.isImm() || MO.isExpr())) ? void (0) : __assert_fail ("(HexagonMCInstrInfo::isExtendable(MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) && (MO.isImm() || MO.isExpr())"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 317, __extension__ __PRETTY_FUNCTION__))
317 (MO.isImm() || MO.isExpr()))(static_cast <bool> ((HexagonMCInstrInfo::isExtendable(
MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) &&
(MO.isImm() || MO.isExpr())) ? void (0) : __assert_fail ("(HexagonMCInstrInfo::isExtendable(MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) && (MO.isImm() || MO.isExpr())"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 317, __extension__ __PRETTY_FUNCTION__))
;
318 return (MO);
319}
320
321unsigned HexagonMCInstrInfo::getExtentAlignment(MCInstrInfo const &MCII,
322 MCInst const &MCI) {
323 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
324 return ((F >> HexagonII::ExtentAlignPos) & HexagonII::ExtentAlignMask);
325}
326
327unsigned HexagonMCInstrInfo::getExtentBits(MCInstrInfo const &MCII,
328 MCInst const &MCI) {
329 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
330 return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask);
331}
332
333/// Return the maximum value of an extendable operand.
334int HexagonMCInstrInfo::getMaxValue(MCInstrInfo const &MCII,
335 MCInst const &MCI) {
336 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
337 bool S = (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask;
338
339 assert(HexagonMCInstrInfo::isExtendable(MCII, MCI) ||(static_cast <bool> (HexagonMCInstrInfo::isExtendable(MCII
, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) ? void (
0) : __assert_fail ("HexagonMCInstrInfo::isExtendable(MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 340, __extension__ __PRETTY_FUNCTION__))
340 HexagonMCInstrInfo::isExtended(MCII, MCI))(static_cast <bool> (HexagonMCInstrInfo::isExtendable(MCII
, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) ? void (
0) : __assert_fail ("HexagonMCInstrInfo::isExtendable(MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 340, __extension__ __PRETTY_FUNCTION__))
;
341
342 if (S) // if value is signed
343 return (1 << (HexagonMCInstrInfo::getExtentBits(MCII, MCI) - 1)) - 1;
344 return (1 << HexagonMCInstrInfo::getExtentBits(MCII, MCI)) - 1;
345}
346
347/// Return the minimum value of an extendable operand.
348int HexagonMCInstrInfo::getMinValue(MCInstrInfo const &MCII,
349 MCInst const &MCI) {
350 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
351 bool S = (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask;
352
353 assert(HexagonMCInstrInfo::isExtendable(MCII, MCI) ||(static_cast <bool> (HexagonMCInstrInfo::isExtendable(MCII
, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) ? void (
0) : __assert_fail ("HexagonMCInstrInfo::isExtendable(MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 354, __extension__ __PRETTY_FUNCTION__))
354 HexagonMCInstrInfo::isExtended(MCII, MCI))(static_cast <bool> (HexagonMCInstrInfo::isExtendable(MCII
, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)) ? void (
0) : __assert_fail ("HexagonMCInstrInfo::isExtendable(MCII, MCI) || HexagonMCInstrInfo::isExtended(MCII, MCI)"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 354, __extension__ __PRETTY_FUNCTION__))
;
355
356 if (S) // if value is signed
357 return -(1 << (HexagonMCInstrInfo::getExtentBits(MCII, MCI) - 1));
358 return 0;
359}
360
361StringRef HexagonMCInstrInfo::getName(MCInstrInfo const &MCII,
362 MCInst const &MCI) {
363 return MCII.getName(MCI.getOpcode());
364}
365
366unsigned short HexagonMCInstrInfo::getNewValueOp(MCInstrInfo const &MCII,
367 MCInst const &MCI) {
368 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
369 return ((F >> HexagonII::NewValueOpPos) & HexagonII::NewValueOpMask);
370}
371
372MCOperand const &HexagonMCInstrInfo::getNewValueOperand(MCInstrInfo const &MCII,
373 MCInst const &MCI) {
374 if (HexagonMCInstrInfo::hasTmpDst(MCII, MCI)) {
375 // VTMP doesn't actually exist in the encodings for these 184
376 // 3 instructions so go ahead and create it here.
377 static MCOperand MCO = MCOperand::createReg(Hexagon::VTMP);
378 return (MCO);
379 } else {
380 unsigned O = HexagonMCInstrInfo::getNewValueOp(MCII, MCI);
381 MCOperand const &MCO = MCI.getOperand(O);
382
383 assert((HexagonMCInstrInfo::isNewValue(MCII, MCI) ||(static_cast <bool> ((HexagonMCInstrInfo::isNewValue(MCII
, MCI) || HexagonMCInstrInfo::hasNewValue(MCII, MCI)) &&
MCO.isReg()) ? void (0) : __assert_fail ("(HexagonMCInstrInfo::isNewValue(MCII, MCI) || HexagonMCInstrInfo::hasNewValue(MCII, MCI)) && MCO.isReg()"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 385, __extension__ __PRETTY_FUNCTION__))
384 HexagonMCInstrInfo::hasNewValue(MCII, MCI)) &&(static_cast <bool> ((HexagonMCInstrInfo::isNewValue(MCII
, MCI) || HexagonMCInstrInfo::hasNewValue(MCII, MCI)) &&
MCO.isReg()) ? void (0) : __assert_fail ("(HexagonMCInstrInfo::isNewValue(MCII, MCI) || HexagonMCInstrInfo::hasNewValue(MCII, MCI)) && MCO.isReg()"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 385, __extension__ __PRETTY_FUNCTION__))
385 MCO.isReg())(static_cast <bool> ((HexagonMCInstrInfo::isNewValue(MCII
, MCI) || HexagonMCInstrInfo::hasNewValue(MCII, MCI)) &&
MCO.isReg()) ? void (0) : __assert_fail ("(HexagonMCInstrInfo::isNewValue(MCII, MCI) || HexagonMCInstrInfo::hasNewValue(MCII, MCI)) && MCO.isReg()"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 385, __extension__ __PRETTY_FUNCTION__))
;
386 return (MCO);
387 }
388}
389
390/// Return the new value or the newly produced value.
391unsigned short HexagonMCInstrInfo::getNewValueOp2(MCInstrInfo const &MCII,
392 MCInst const &MCI) {
393 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
394 return ((F >> HexagonII::NewValueOpPos2) & HexagonII::NewValueOpMask2);
395}
396
397MCOperand const &
398HexagonMCInstrInfo::getNewValueOperand2(MCInstrInfo const &MCII,
399 MCInst const &MCI) {
400 unsigned O = HexagonMCInstrInfo::getNewValueOp2(MCII, MCI);
401 MCOperand const &MCO = MCI.getOperand(O);
402
403 assert((HexagonMCInstrInfo::isNewValue(MCII, MCI) ||(static_cast <bool> ((HexagonMCInstrInfo::isNewValue(MCII
, MCI) || HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) &&
MCO.isReg()) ? void (0) : __assert_fail ("(HexagonMCInstrInfo::isNewValue(MCII, MCI) || HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) && MCO.isReg()"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 405, __extension__ __PRETTY_FUNCTION__))
404 HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) &&(static_cast <bool> ((HexagonMCInstrInfo::isNewValue(MCII
, MCI) || HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) &&
MCO.isReg()) ? void (0) : __assert_fail ("(HexagonMCInstrInfo::isNewValue(MCII, MCI) || HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) && MCO.isReg()"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 405, __extension__ __PRETTY_FUNCTION__))
405 MCO.isReg())(static_cast <bool> ((HexagonMCInstrInfo::isNewValue(MCII
, MCI) || HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) &&
MCO.isReg()) ? void (0) : __assert_fail ("(HexagonMCInstrInfo::isNewValue(MCII, MCI) || HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) && MCO.isReg()"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 405, __extension__ __PRETTY_FUNCTION__))
;
406 return (MCO);
407}
408
409/// Return the Hexagon ISA class for the insn.
410unsigned HexagonMCInstrInfo::getType(MCInstrInfo const &MCII,
411 MCInst const &MCI) {
412 const uint64_t F = MCII.get(MCI.getOpcode()).TSFlags;
413 return ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
414}
415
416/// Return the slots this instruction can execute out of
417unsigned HexagonMCInstrInfo::getUnits(MCInstrInfo const &MCII,
418 MCSubtargetInfo const &STI,
419 MCInst const &MCI) {
420 const InstrItinerary *II = STI.getSchedModel().InstrItineraries;
421 int SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
422 return ((II[SchedClass].FirstStage + HexagonStages)->getUnits());
423}
424
425/// Return the slots this instruction consumes in addition to
426/// the slot(s) it can execute out of
427
428unsigned HexagonMCInstrInfo::getOtherReservedSlots(MCInstrInfo const &MCII,
429 MCSubtargetInfo const &STI,
430 MCInst const &MCI) {
431 const InstrItinerary *II = STI.getSchedModel().InstrItineraries;
432 int SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
433 unsigned Slots = 0;
434
435 // FirstStage are slots that this instruction can execute in.
436 // FirstStage+1 are slots that are also consumed by this instruction.
437 // For example: vmemu can only execute in slot 0 but also consumes slot 1.
438 for (unsigned Stage = II[SchedClass].FirstStage + 1;
439 Stage < II[SchedClass].LastStage; ++Stage) {
440 unsigned Units = (Stage + HexagonStages)->getUnits();
441 if (Units > HexagonGetLastSlot())
442 break;
443 // fyi: getUnits() will return 0x1, 0x2, 0x4 or 0x8
444 Slots |= Units;
445 }
446
447 // if 0 is returned, then no additional slots are consumed by this inst.
448 return Slots;
449}
450
451bool HexagonMCInstrInfo::hasDuplex(MCInstrInfo const &MCII, MCInst const &MCI) {
452 if (!HexagonMCInstrInfo::isBundle(MCI))
453 return false;
454
455 for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCI)) {
456 if (HexagonMCInstrInfo::isDuplex(MCII, *I.getInst()))
457 return true;
458 }
459
460 return false;
461}
462
463bool HexagonMCInstrInfo::hasExtenderForIndex(MCInst const &MCB, size_t Index) {
464 return extenderForIndex(MCB, Index) != nullptr;
465}
466
467bool HexagonMCInstrInfo::hasImmExt(MCInst const &MCI) {
468 if (!HexagonMCInstrInfo::isBundle(MCI))
469 return false;
470
471 for (const auto &I : HexagonMCInstrInfo::bundleInstructions(MCI)) {
472 if (isImmext(*I.getInst()))
473 return true;
474 }
475
476 return false;
477}
478
479/// Return whether the insn produces a value.
480bool HexagonMCInstrInfo::hasNewValue(MCInstrInfo const &MCII,
481 MCInst const &MCI) {
482 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
483 return ((F >> HexagonII::hasNewValuePos) & HexagonII::hasNewValueMask);
484}
485
486/// Return whether the insn produces a second value.
487bool HexagonMCInstrInfo::hasNewValue2(MCInstrInfo const &MCII,
488 MCInst const &MCI) {
489 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
490 return ((F >> HexagonII::hasNewValuePos2) & HexagonII::hasNewValueMask2);
491}
492
493MCInst const &HexagonMCInstrInfo::instruction(MCInst const &MCB, size_t Index) {
494 assert(isBundle(MCB))(static_cast <bool> (isBundle(MCB)) ? void (0) : __assert_fail
("isBundle(MCB)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 494, __extension__ __PRETTY_FUNCTION__))
;
495 assert(Index < HEXAGON_PACKET_SIZE)(static_cast <bool> (Index < 4) ? void (0) : __assert_fail
("Index < HEXAGON_PACKET_SIZE", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 495, __extension__ __PRETTY_FUNCTION__))
;
496 return *MCB.getOperand(bundleInstructionsOffset + Index).getInst();
497}
498
499/// Return where the instruction is an accumulator.
500bool HexagonMCInstrInfo::isAccumulator(MCInstrInfo const &MCII,
501 MCInst const &MCI) {
502 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
503 return ((F >> HexagonII::AccumulatorPos) & HexagonII::AccumulatorMask);
504}
505
506bool HexagonMCInstrInfo::isBundle(MCInst const &MCI) {
507 auto Result = Hexagon::BUNDLE == MCI.getOpcode();
508 assert(!Result || (MCI.size() > 0 && MCI.getOperand(0).isImm()))(static_cast <bool> (!Result || (MCI.size() > 0 &&
MCI.getOperand(0).isImm())) ? void (0) : __assert_fail ("!Result || (MCI.size() > 0 && MCI.getOperand(0).isImm())"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 508, __extension__ __PRETTY_FUNCTION__))
;
509 return Result;
510}
511
512bool HexagonMCInstrInfo::isConstExtended(MCInstrInfo const &MCII,
513 MCInst const &MCI) {
514 if (HexagonMCInstrInfo::isExtended(MCII, MCI))
515 return true;
516 if (!HexagonMCInstrInfo::isExtendable(MCII, MCI))
517 return false;
518 MCOperand const &MO = HexagonMCInstrInfo::getExtendableOperand(MCII, MCI);
519 if (isa<HexagonMCExpr>(MO.getExpr()) &&
520 HexagonMCInstrInfo::mustExtend(*MO.getExpr()))
521 return true;
522 // Branch insns are handled as necessary by relaxation.
523 if ((HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeJ) ||
524 (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCJ &&
525 HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch()) ||
526 (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeNCJ &&
527 HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch()))
528 return false;
529 // Otherwise loop instructions and other CR insts are handled by relaxation
530 else if ((HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCR) &&
531 (MCI.getOpcode() != Hexagon::C4_addipc))
532 return false;
533
534 assert(!MO.isImm())(static_cast <bool> (!MO.isImm()) ? void (0) : __assert_fail
("!MO.isImm()", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 534, __extension__ __PRETTY_FUNCTION__))
;
535 if (isa<HexagonMCExpr>(MO.getExpr()) &&
536 HexagonMCInstrInfo::mustNotExtend(*MO.getExpr()))
537 return false;
538 int64_t Value;
539 if (!MO.getExpr()->evaluateAsAbsolute(Value))
540 return true;
541 int MinValue = HexagonMCInstrInfo::getMinValue(MCII, MCI);
542 int MaxValue = HexagonMCInstrInfo::getMaxValue(MCII, MCI);
543 return (MinValue > Value || Value > MaxValue);
544}
545
546bool HexagonMCInstrInfo::isCanon(MCInstrInfo const &MCII, MCInst const &MCI) {
547 return !HexagonMCInstrInfo::getDesc(MCII, MCI).isPseudo() &&
548 !HexagonMCInstrInfo::isPrefix(MCII, MCI);
549}
550
551bool HexagonMCInstrInfo::isCofMax1(MCInstrInfo const &MCII, MCInst const &MCI) {
552 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
553 return ((F >> HexagonII::CofMax1Pos) & HexagonII::CofMax1Mask);
554}
555
556bool HexagonMCInstrInfo::isCofRelax1(MCInstrInfo const &MCII,
557 MCInst const &MCI) {
558 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
559 return ((F >> HexagonII::CofRelax1Pos) & HexagonII::CofRelax1Mask);
560}
561
562bool HexagonMCInstrInfo::isCofRelax2(MCInstrInfo const &MCII,
563 MCInst const &MCI) {
564 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
565 return ((F >> HexagonII::CofRelax2Pos) & HexagonII::CofRelax2Mask);
566}
567
568bool HexagonMCInstrInfo::isCompound(MCInstrInfo const &MCII,
569 MCInst const &MCI) {
570 return (getType(MCII, MCI) == HexagonII::TypeCJ);
571}
572
573bool HexagonMCInstrInfo::isCVINew(MCInstrInfo const &MCII, MCInst const &MCI) {
574 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
575 return ((F >> HexagonII::CVINewPos) & HexagonII::CVINewMask);
576}
577
578bool HexagonMCInstrInfo::isDblRegForSubInst(unsigned Reg) {
579 return ((Reg >= Hexagon::D0 && Reg <= Hexagon::D3) ||
580 (Reg >= Hexagon::D8 && Reg <= Hexagon::D11));
581}
582
583bool HexagonMCInstrInfo::isDuplex(MCInstrInfo const &MCII, MCInst const &MCI) {
584 return HexagonII::TypeDUPLEX == HexagonMCInstrInfo::getType(MCII, MCI);
585}
586
587bool HexagonMCInstrInfo::isExtendable(MCInstrInfo const &MCII,
588 MCInst const &MCI) {
589 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
590 return (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask;
591}
592
593bool HexagonMCInstrInfo::isExtended(MCInstrInfo const &MCII,
594 MCInst const &MCI) {
595 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
596 return (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
597}
598
599bool HexagonMCInstrInfo::isFloat(MCInstrInfo const &MCII, MCInst const &MCI) {
600 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
601 return ((F >> HexagonII::FPPos) & HexagonII::FPMask);
602}
603
604bool HexagonMCInstrInfo::isHVX(MCInstrInfo const &MCII, MCInst const &MCI) {
605 const uint64_t V = getType(MCII, MCI);
606 return HexagonII::TypeCVI_FIRST <= V && V <= HexagonII::TypeCVI_LAST;
607}
608
609bool HexagonMCInstrInfo::isImmext(MCInst const &MCI) {
610 return MCI.getOpcode() == Hexagon::A4_ext;
611}
612
613bool HexagonMCInstrInfo::isInnerLoop(MCInst const &MCI) {
614 assert(isBundle(MCI))(static_cast <bool> (isBundle(MCI)) ? void (0) : __assert_fail
("isBundle(MCI)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 614, __extension__ __PRETTY_FUNCTION__))
;
615 int64_t Flags = MCI.getOperand(0).getImm();
616 return (Flags & innerLoopMask) != 0;
617}
618
619bool HexagonMCInstrInfo::isIntReg(unsigned Reg) {
620 return (Reg >= Hexagon::R0 && Reg <= Hexagon::R31);
621}
622
623bool HexagonMCInstrInfo::isIntRegForSubInst(unsigned Reg) {
624 return ((Reg >= Hexagon::R0 && Reg <= Hexagon::R7) ||
625 (Reg >= Hexagon::R16 && Reg <= Hexagon::R23));
626}
627
628/// Return whether the insn expects newly produced value.
629bool HexagonMCInstrInfo::isNewValue(MCInstrInfo const &MCII,
630 MCInst const &MCI) {
631 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
632 return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask);
633}
634
635/// Return whether the operand is extendable.
636bool HexagonMCInstrInfo::isOpExtendable(MCInstrInfo const &MCII,
637 MCInst const &MCI, unsigned short O) {
638 return (O == HexagonMCInstrInfo::getExtendableOp(MCII, MCI));
639}
640
641bool HexagonMCInstrInfo::isOuterLoop(MCInst const &MCI) {
642 assert(isBundle(MCI))(static_cast <bool> (isBundle(MCI)) ? void (0) : __assert_fail
("isBundle(MCI)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 642, __extension__ __PRETTY_FUNCTION__))
;
643 int64_t Flags = MCI.getOperand(0).getImm();
644 return (Flags & outerLoopMask) != 0;
645}
646
647bool HexagonMCInstrInfo::isPredicated(MCInstrInfo const &MCII,
648 MCInst const &MCI) {
649 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
650 return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
651}
652
653bool HexagonMCInstrInfo::isPrefix(MCInstrInfo const &MCII, MCInst const &MCI) {
654 return HexagonII::TypeEXTENDER == HexagonMCInstrInfo::getType(MCII, MCI);
655}
656
657bool HexagonMCInstrInfo::isPredicateLate(MCInstrInfo const &MCII,
658 MCInst const &MCI) {
659 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
660 return (F >> HexagonII::PredicateLatePos & HexagonII::PredicateLateMask);
661}
662
663/// Return whether the insn is newly predicated.
664bool HexagonMCInstrInfo::isPredicatedNew(MCInstrInfo const &MCII,
665 MCInst const &MCI) {
666 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
667 return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask);
668}
669
670bool HexagonMCInstrInfo::isPredicatedTrue(MCInstrInfo const &MCII,
671 MCInst const &MCI) {
672 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
673 return (
674 !((F >> HexagonII::PredicatedFalsePos) & HexagonII::PredicatedFalseMask));
675}
676
677bool HexagonMCInstrInfo::isPredReg(unsigned Reg) {
678 return (Reg >= Hexagon::P0 && Reg <= Hexagon::P3_0);
679}
680
681/// Return whether the insn can be packaged only with A and X-type insns.
682bool HexagonMCInstrInfo::isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI) {
683 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
684 return ((F >> HexagonII::SoloAXPos) & HexagonII::SoloAXMask);
685}
686
687/// Return whether the insn can be packaged only with an A-type insn in slot #1.
688bool HexagonMCInstrInfo::isRestrictSlot1AOK(MCInstrInfo const &MCII,
689 MCInst const &MCI) {
690 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
691 return ((F >> HexagonII::RestrictSlot1AOKPos) &
692 HexagonII::RestrictSlot1AOKMask);
693}
694
695bool HexagonMCInstrInfo::isRestrictNoSlot1Store(MCInstrInfo const &MCII,
696 MCInst const &MCI) {
697 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
698 return ((F >> HexagonII::RestrictNoSlot1StorePos) &
699 HexagonII::RestrictNoSlot1StoreMask);
700}
701
702/// Return whether the insn is solo, i.e., cannot be in a packet.
703bool HexagonMCInstrInfo::isSolo(MCInstrInfo const &MCII, MCInst const &MCI) {
704 const uint64_t F = MCII.get(MCI.getOpcode()).TSFlags;
705 return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask);
706}
707
708bool HexagonMCInstrInfo::isMemReorderDisabled(MCInst const &MCI) {
709 assert(isBundle(MCI))(static_cast <bool> (isBundle(MCI)) ? void (0) : __assert_fail
("isBundle(MCI)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 709, __extension__ __PRETTY_FUNCTION__))
;
710 auto Flags = MCI.getOperand(0).getImm();
711 return (Flags & memReorderDisabledMask) != 0;
712}
713
714bool HexagonMCInstrInfo::isSubInstruction(MCInst const &MCI) {
715 switch (MCI.getOpcode()) {
716 default:
717 return false;
718 case Hexagon::SA1_addi:
719 case Hexagon::SA1_addrx:
720 case Hexagon::SA1_addsp:
721 case Hexagon::SA1_and1:
722 case Hexagon::SA1_clrf:
723 case Hexagon::SA1_clrfnew:
724 case Hexagon::SA1_clrt:
725 case Hexagon::SA1_clrtnew:
726 case Hexagon::SA1_cmpeqi:
727 case Hexagon::SA1_combine0i:
728 case Hexagon::SA1_combine1i:
729 case Hexagon::SA1_combine2i:
730 case Hexagon::SA1_combine3i:
731 case Hexagon::SA1_combinerz:
732 case Hexagon::SA1_combinezr:
733 case Hexagon::SA1_dec:
734 case Hexagon::SA1_inc:
735 case Hexagon::SA1_seti:
736 case Hexagon::SA1_setin1:
737 case Hexagon::SA1_sxtb:
738 case Hexagon::SA1_sxth:
739 case Hexagon::SA1_tfr:
740 case Hexagon::SA1_zxtb:
741 case Hexagon::SA1_zxth:
742 case Hexagon::SL1_loadri_io:
743 case Hexagon::SL1_loadrub_io:
744 case Hexagon::SL2_deallocframe:
745 case Hexagon::SL2_jumpr31:
746 case Hexagon::SL2_jumpr31_f:
747 case Hexagon::SL2_jumpr31_fnew:
748 case Hexagon::SL2_jumpr31_t:
749 case Hexagon::SL2_jumpr31_tnew:
750 case Hexagon::SL2_loadrb_io:
751 case Hexagon::SL2_loadrd_sp:
752 case Hexagon::SL2_loadrh_io:
753 case Hexagon::SL2_loadri_sp:
754 case Hexagon::SL2_loadruh_io:
755 case Hexagon::SL2_return:
756 case Hexagon::SL2_return_f:
757 case Hexagon::SL2_return_fnew:
758 case Hexagon::SL2_return_t:
759 case Hexagon::SL2_return_tnew:
760 case Hexagon::SS1_storeb_io:
761 case Hexagon::SS1_storew_io:
762 case Hexagon::SS2_allocframe:
763 case Hexagon::SS2_storebi0:
764 case Hexagon::SS2_storebi1:
765 case Hexagon::SS2_stored_sp:
766 case Hexagon::SS2_storeh_io:
767 case Hexagon::SS2_storew_sp:
768 case Hexagon::SS2_storewi0:
769 case Hexagon::SS2_storewi1:
770 return true;
771 }
772}
773
774bool HexagonMCInstrInfo::isVector(MCInstrInfo const &MCII, MCInst const &MCI) {
775 if ((getType(MCII, MCI) <= HexagonII::TypeCVI_LAST) &&
776 (getType(MCII, MCI) >= HexagonII::TypeCVI_FIRST))
777 return true;
778 return false;
779}
780
781int64_t HexagonMCInstrInfo::minConstant(MCInst const &MCI, size_t Index) {
782 auto Sentinal = static_cast<int64_t>(std::numeric_limits<uint32_t>::max())
783 << 8;
784 if (MCI.size() <= Index)
785 return Sentinal;
786 MCOperand const &MCO = MCI.getOperand(Index);
787 if (!MCO.isExpr())
788 return Sentinal;
789 int64_t Value;
790 if (!MCO.getExpr()->evaluateAsAbsolute(Value))
791 return Sentinal;
792 return Value;
793}
794
795void HexagonMCInstrInfo::setMustExtend(MCExpr const &Expr, bool Val) {
796 HexagonMCExpr &HExpr = const_cast<HexagonMCExpr &>(cast<HexagonMCExpr>(Expr));
797 HExpr.setMustExtend(Val);
798}
799
800bool HexagonMCInstrInfo::mustExtend(MCExpr const &Expr) {
801 HexagonMCExpr const &HExpr = cast<HexagonMCExpr>(Expr);
802 return HExpr.mustExtend();
803}
804void HexagonMCInstrInfo::setMustNotExtend(MCExpr const &Expr, bool Val) {
805 HexagonMCExpr &HExpr = const_cast<HexagonMCExpr &>(cast<HexagonMCExpr>(Expr));
806 HExpr.setMustNotExtend(Val);
807}
808bool HexagonMCInstrInfo::mustNotExtend(MCExpr const &Expr) {
809 HexagonMCExpr const &HExpr = cast<HexagonMCExpr>(Expr);
810 return HExpr.mustNotExtend();
811}
812void HexagonMCInstrInfo::setS27_2_reloc(MCExpr const &Expr, bool Val) {
813 HexagonMCExpr &HExpr =
814 const_cast<HexagonMCExpr &>(*cast<HexagonMCExpr>(&Expr));
815 HExpr.setS27_2_reloc(Val);
816}
817bool HexagonMCInstrInfo::s27_2_reloc(MCExpr const &Expr) {
818 HexagonMCExpr const *HExpr = dyn_cast<HexagonMCExpr>(&Expr);
819 if (!HExpr)
820 return false;
821 return HExpr->s27_2_reloc();
822}
823
824void HexagonMCInstrInfo::padEndloop(MCInst &MCB, MCContext &Context) {
825 MCInst Nop;
826 Nop.setOpcode(Hexagon::A2_nop);
827 assert(isBundle(MCB))(static_cast <bool> (isBundle(MCB)) ? void (0) : __assert_fail
("isBundle(MCB)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 827, __extension__ __PRETTY_FUNCTION__))
;
828 while ((HexagonMCInstrInfo::isInnerLoop(MCB) &&
829 (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_INNER_SIZE2)) ||
830 ((HexagonMCInstrInfo::isOuterLoop(MCB) &&
831 (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_OUTER_SIZE3))))
832 MCB.addOperand(MCOperand::createInst(new (Context) MCInst(Nop)));
833}
834
835HexagonMCInstrInfo::PredicateInfo
836HexagonMCInstrInfo::predicateInfo(MCInstrInfo const &MCII, MCInst const &MCI) {
837 if (!isPredicated(MCII, MCI))
838 return {0, 0, false};
839 MCInstrDesc const &Desc = getDesc(MCII, MCI);
840 for (auto I = Desc.getNumDefs(), N = Desc.getNumOperands(); I != N; ++I)
841 if (Desc.OpInfo[I].RegClass == Hexagon::PredRegsRegClassID)
842 return {MCI.getOperand(I).getReg(), I, isPredicatedTrue(MCII, MCI)};
843 return {0, 0, false};
844}
845
846bool HexagonMCInstrInfo::prefersSlot3(MCInstrInfo const &MCII,
847 MCInst const &MCI) {
848 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
849 return (F >> HexagonII::PrefersSlot3Pos) & HexagonII::PrefersSlot3Mask;
850}
851
852/// return true if instruction has hasTmpDst attribute.
853bool HexagonMCInstrInfo::hasTmpDst(MCInstrInfo const &MCII, MCInst const &MCI) {
854 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
855 return (F >> HexagonII::HasTmpDstPos) & HexagonII::HasTmpDstMask;
856}
857
858void HexagonMCInstrInfo::replaceDuplex(MCContext &Context, MCInst &MCB,
859 DuplexCandidate Candidate) {
860 assert(Candidate.packetIndexI < MCB.size())(static_cast <bool> (Candidate.packetIndexI < MCB.size
()) ? void (0) : __assert_fail ("Candidate.packetIndexI < MCB.size()"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 860, __extension__ __PRETTY_FUNCTION__))
;
861 assert(Candidate.packetIndexJ < MCB.size())(static_cast <bool> (Candidate.packetIndexJ < MCB.size
()) ? void (0) : __assert_fail ("Candidate.packetIndexJ < MCB.size()"
, "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 861, __extension__ __PRETTY_FUNCTION__))
;
862 assert(isBundle(MCB))(static_cast <bool> (isBundle(MCB)) ? void (0) : __assert_fail
("isBundle(MCB)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 862, __extension__ __PRETTY_FUNCTION__))
;
863 MCInst *Duplex =
864 deriveDuplex(Context, Candidate.iClass,
865 *MCB.getOperand(Candidate.packetIndexJ).getInst(),
866 *MCB.getOperand(Candidate.packetIndexI).getInst());
867 assert(Duplex != nullptr)(static_cast <bool> (Duplex != nullptr) ? void (0) : __assert_fail
("Duplex != nullptr", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 867, __extension__ __PRETTY_FUNCTION__))
;
868 MCB.getOperand(Candidate.packetIndexI).setInst(Duplex);
869 MCB.erase(MCB.begin() + Candidate.packetIndexJ);
870}
871
872void HexagonMCInstrInfo::setInnerLoop(MCInst &MCI) {
873 assert(isBundle(MCI))(static_cast <bool> (isBundle(MCI)) ? void (0) : __assert_fail
("isBundle(MCI)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 873, __extension__ __PRETTY_FUNCTION__))
;
874 MCOperand &Operand = MCI.getOperand(0);
875 Operand.setImm(Operand.getImm() | innerLoopMask);
876}
877
878void HexagonMCInstrInfo::setMemReorderDisabled(MCInst &MCI) {
879 assert(isBundle(MCI))(static_cast <bool> (isBundle(MCI)) ? void (0) : __assert_fail
("isBundle(MCI)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 879, __extension__ __PRETTY_FUNCTION__))
;
880 MCOperand &Operand = MCI.getOperand(0);
881 Operand.setImm(Operand.getImm() | memReorderDisabledMask);
882 assert(isMemReorderDisabled(MCI))(static_cast <bool> (isMemReorderDisabled(MCI)) ? void (
0) : __assert_fail ("isMemReorderDisabled(MCI)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 882, __extension__ __PRETTY_FUNCTION__))
;
883}
884
885void HexagonMCInstrInfo::setOuterLoop(MCInst &MCI) {
886 assert(isBundle(MCI))(static_cast <bool> (isBundle(MCI)) ? void (0) : __assert_fail
("isBundle(MCI)", "/build/llvm-toolchain-snapshot-7~svn329677/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp"
, 886, __extension__ __PRETTY_FUNCTION__))
;
887 MCOperand &Operand = MCI.getOperand(0);
888 Operand.setImm(Operand.getImm() | outerLoopMask);
889}
890
891unsigned HexagonMCInstrInfo::SubregisterBit(unsigned Consumer,
892 unsigned Producer,
893 unsigned Producer2) {
894 // If we're a single vector consumer of a double producer, set subreg bit
895 // based on if we're accessing the lower or upper register component
896 if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15)
897 if (Consumer >= Hexagon::V0 && Consumer <= Hexagon::V31)
898 return (Consumer - Hexagon::V0) & 0x1;
899 if (Producer2 != Hexagon::NoRegister)
900 return Consumer == Producer;
901 return 0;
902}