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"
18 #include "llvm/MC/MCInstrInfo.h"
28 enum class MemAccessSize;
30 class DuplexCandidate {
32 unsigned packetIndexI, packetIndexJ, iClass;
33 DuplexCandidate(unsigned i, unsigned j, unsigned iClass)
34 : packetIndexI(i), packetIndexJ(j), iClass(iClass) {}
36 namespace HexagonMCInstrInfo {
37 size_t const innerLoopOffset = 0;
38 int64_t const innerLoopMask = 1 << innerLoopOffset;
40 size_t const outerLoopOffset = 1;
41 int64_t const outerLoopMask = 1 << outerLoopOffset;
43 size_t const bundleInstructionsOffset = 1;
45 // Returns the number of instructions in the bundle
46 size_t bundleSize(MCInst const &MCI);
48 // Returns a iterator range of instructions in this bundle
49 iterator_range<MCInst::const_iterator> bundleInstructions(MCInst const &MCI);
51 // Return memory access size
52 HexagonII::MemAccessSize getAccessSize(MCInstrInfo const &MCII,
55 // Return number of bits in the constant extended operand.
56 unsigned getBitCount(MCInstrInfo const &MCII, MCInst const &MCI);
58 // Return constant extended operand number.
59 unsigned short getCExtOpNum(MCInstrInfo const &MCII, MCInst const &MCI);
61 MCInstrDesc const &getDesc(MCInstrInfo const &MCII, MCInst const &MCI);
63 // Return the index of the extendable operand
64 unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI);
66 // Return a reference to the extendable operand
67 MCOperand const &getExtendableOperand(MCInstrInfo const &MCII,
70 // Return the implicit alignment of the extendable operand
71 unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI);
73 // Return the number of logical bits of the extendable operand
74 unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI);
76 // Return the max value that a constant extendable operand can have
77 // without being extended.
78 int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI);
80 // Return the min value that a constant extendable operand can have
81 // without being extended.
82 int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI);
84 // Return instruction name
85 char const *getName(MCInstrInfo const &MCII, MCInst const &MCI);
87 // Return the operand index for the new value.
88 unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI);
90 // Return the operand that consumes or produces a new value.
91 MCOperand const &getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI);
93 int getSubTarget(MCInstrInfo const &MCII, MCInst const &MCI);
95 // Return the Hexagon ISA class for the insn.
96 unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI);
98 /// Return the slots used by the insn.
99 unsigned getUnits(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
102 bool hasImmExt(MCInst const &MCI);
104 // Return whether the instruction is a legal new-value producer.
105 bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
107 // Return the instruction at Index
108 MCInst const &instruction(MCInst const &MCB, size_t Index);
110 // Returns whether this MCInst is a wellformed bundle
111 bool isBundle(MCInst const &MCI);
113 // Return whether the insn is an actual insn.
114 bool isCanon(MCInstrInfo const &MCII, MCInst const &MCI);
116 // Return whether the instruction needs to be constant extended.
117 bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI);
119 // Return true if the insn may be extended based on the operand value.
120 bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI);
122 // Return whether the instruction must be always extended.
123 bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI);
125 /// Return whether it is a floating-point insn.
126 bool isFloat(MCInstrInfo const &MCII, MCInst const &MCI);
128 // Returns whether this instruction is an immediate extender
129 bool isImmext(MCInst const &MCI);
131 // Returns whether this bundle is an endloop0
132 bool isInnerLoop(MCInst const &MCI);
134 // Return whether the insn is a new-value consumer.
135 bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
137 // Return true if the operand can be constant extended.
138 bool isOperandExtended(MCInstrInfo const &MCII, MCInst const &MCI,
139 unsigned short OperandNum);
141 // Returns whether this bundle is an endloop1
142 bool isOuterLoop(MCInst const &MCI);
144 // Return whether this instruction is predicated
145 bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI);
147 // Return whether the predicate sense is true
148 bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI);
150 // Return whether the insn is a prefix.
151 bool isPrefix(MCInstrInfo const &MCII, MCInst const &MCI);
153 // Return whether the insn is solo, i.e., cannot be in a packet.
154 bool isSolo(MCInstrInfo const &MCII, MCInst const &MCI);
156 /// Return whether the insn can be packaged only with A and X-type insns.
157 bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI);
159 /// Return whether the insn can be packaged only with an A-type insn in slot #1.
160 bool isSoloAin1(MCInstrInfo const &MCII, MCInst const &MCI);
162 // Pad the bundle with nops to satisfy endloop requirements
163 void padEndloop(MCInst &MCI);
165 bool prefersSlot3(MCInstrInfo const &MCII, MCInst const &MCI);
167 // Marks a bundle as endloop0
168 void setInnerLoop(MCInst &MCI);
170 // Marks a bundle as endloop1
171 void setOuterLoop(MCInst &MCI);
175 #endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H