1 //===- HexagonMCInstrInfo.cpp - Utility functions on Hexagon MCInsts ------===//
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 // Utility functions for Hexagon specific MCInst queries
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
15 #define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
17 #include "llvm/MC/MCInst.h"
25 class MCSubtargetInfo;
27 enum class MemAccessSize;
29 class DuplexCandidate {
31 unsigned packetIndexI, packetIndexJ, iClass;
32 DuplexCandidate(unsigned i, unsigned j, unsigned iClass)
33 : packetIndexI(i), packetIndexJ(j), iClass(iClass) {}
35 namespace HexagonMCInstrInfo {
36 size_t const innerLoopOffset = 0;
37 int64_t const innerLoopMask = 1 << innerLoopOffset;
39 size_t const outerLoopOffset = 1;
40 int64_t const outerLoopMask = 1 << outerLoopOffset;
42 size_t const bundleInstructionsOffset = 1;
44 // Returns the number of instructions in the bundle
45 size_t bundleSize(MCInst const &MCI);
47 // Returns a iterator range of instructions in this bundle
48 iterator_range<MCInst::const_iterator> bundleInstructions(MCInst const &MCI);
50 // Return the extender for instruction at Index or nullptr if none
51 MCInst const *extenderForIndex(MCInst const &MCB, size_t Index);
53 // Create a duplex instruction given the two subinsts
54 MCInst *deriveDuplex(MCContext &Context, unsigned iClass, MCInst const &inst0,
57 // Convert this instruction in to a duplex subinst
58 MCInst deriveSubInst(MCInst const &Inst);
60 // Return memory access size
61 HexagonII::MemAccessSize getAccessSize(MCInstrInfo const &MCII,
64 // Return number of bits in the constant extended operand.
65 unsigned getBitCount(MCInstrInfo const &MCII, MCInst const &MCI);
67 // Return constant extended operand number.
68 unsigned short getCExtOpNum(MCInstrInfo const &MCII, MCInst const &MCI);
70 MCInstrDesc const &getDesc(MCInstrInfo const &MCII, MCInst const &MCI);
72 // Return which duplex group this instruction belongs to
73 unsigned getDuplexCandidateGroup(MCInst const &MI);
75 // Return a list of all possible instruction duplex combinations
76 SmallVector<DuplexCandidate, 8> getDuplexPossibilties(MCInstrInfo const &MCII,
79 // Return the index of the extendable operand
80 unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI);
82 // Return a reference to the extendable operand
83 MCOperand const &getExtendableOperand(MCInstrInfo const &MCII,
86 // Return the implicit alignment of the extendable operand
87 unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI);
89 // Return the number of logical bits of the extendable operand
90 unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI);
92 // Return the max value that a constant extendable operand can have
93 // without being extended.
94 int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI);
96 // Return the min value that a constant extendable operand can have
97 // without being extended.
98 int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI);
100 // Return instruction name
101 char const *getName(MCInstrInfo const &MCII, MCInst const &MCI);
103 // Return the operand index for the new value.
104 unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI);
106 // Return the operand that consumes or produces a new value.
107 MCOperand const &getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI);
109 int getSubTarget(MCInstrInfo const &MCII, MCInst const &MCI);
111 // Return the Hexagon ISA class for the insn.
112 unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI);
114 /// Return the slots used by the insn.
115 unsigned getUnits(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
118 // Does the packet have an extender for the instruction at Index
119 bool hasExtenderForIndex(MCInst const &MCB, size_t Index);
121 bool hasImmExt(MCInst const &MCI);
123 // Return whether the instruction is a legal new-value producer.
124 bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
126 // Return the instruction at Index
127 MCInst const &instruction(MCInst const &MCB, size_t Index);
129 // Returns whether this MCInst is a wellformed bundle
130 bool isBundle(MCInst const &MCI);
132 // Return whether the insn is an actual insn.
133 bool isCanon(MCInstrInfo const &MCII, MCInst const &MCI);
135 // Return the duplex iclass given the two duplex classes
136 unsigned iClassOfDuplexPair(unsigned Ga, unsigned Gb);
138 // Return whether the instruction needs to be constant extended.
139 bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI);
141 // Is this double register suitable for use in a duplex subinst
142 bool isDblRegForSubInst(unsigned Reg);
144 // Is this a duplex instruction
145 bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI);
147 // Can these instructions be duplexed
148 bool isDuplexPair(MCInst const &MIa, MCInst const &MIb);
150 // Can these duplex classes be combine in to a duplex instruction
151 bool isDuplexPairMatch(unsigned Ga, unsigned Gb);
153 // Return true if the insn may be extended based on the operand value.
154 bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI);
156 // Return whether the instruction must be always extended.
157 bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI);
159 /// Return whether it is a floating-point insn.
160 bool isFloat(MCInstrInfo const &MCII, MCInst const &MCI);
162 // Returns whether this instruction is an immediate extender
163 bool isImmext(MCInst const &MCI);
165 // Returns whether this bundle is an endloop0
166 bool isInnerLoop(MCInst const &MCI);
168 // Is this an integer register
169 bool isIntReg(unsigned Reg);
171 // Is this register suitable for use in a duplex subinst
172 bool isIntRegForSubInst(unsigned Reg);
174 // Return whether the insn is a new-value consumer.
175 bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
177 // Return true if the operand can be constant extended.
178 bool isOperandExtended(MCInstrInfo const &MCII, MCInst const &MCI,
179 unsigned short OperandNum);
181 // Can these two instructions be duplexed
182 bool isOrderedDuplexPair(MCInstrInfo const &MCII, MCInst const &MIa,
183 bool ExtendedA, MCInst const &MIb, bool ExtendedB,
186 // Returns whether this bundle is an endloop1
187 bool isOuterLoop(MCInst const &MCI);
189 // Return whether this instruction is predicated
190 bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI);
192 // Return whether the predicate sense is true
193 bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI);
195 // Is this a predicate register
196 bool isPredReg(unsigned Reg);
198 // Return whether the insn is a prefix.
199 bool isPrefix(MCInstrInfo const &MCII, MCInst const &MCI);
201 // Return whether the insn is solo, i.e., cannot be in a packet.
202 bool isSolo(MCInstrInfo const &MCII, MCInst const &MCI);
204 /// Return whether the insn can be packaged only with A and X-type insns.
205 bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI);
207 /// Return whether the insn can be packaged only with an A-type insn in slot #1.
208 bool isSoloAin1(MCInstrInfo const &MCII, MCInst const &MCI);
210 // Pad the bundle with nops to satisfy endloop requirements
211 void padEndloop(MCInst &MCI);
213 bool prefersSlot3(MCInstrInfo const &MCII, MCInst const &MCI);
215 // Replace the instructions inside MCB, represented by Candidate
216 void replaceDuplex(MCContext &Context, MCInst &MCB, DuplexCandidate Candidate);
218 // Marks a bundle as endloop0
219 void setInnerLoop(MCInst &MCI);
221 // Marks a bundle as endloop1
222 void setOuterLoop(MCInst &MCI);
224 // Would duplexing this instruction create a requirement to extend
225 bool subInstWouldBeExtended(MCInst const &potentialDuplex);
229 #endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H