[Hexagon] Adding MC packet shuffler.
[oota-llvm.git] / lib / Target / Hexagon / MCTargetDesc / HexagonMCInstrInfo.h
1 //===- HexagonMCInstrInfo.cpp - Utility functions on Hexagon MCInsts ------===//
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 // Utility functions for Hexagon specific MCInst queries
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
15 #define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
16
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCInstrInfo.h"
19
20 #include <bitset>
21
22 namespace llvm {
23 class MCInstrDesc;
24 class MCInstrInfo;
25 class MCInst;
26 class MCOperand;
27 namespace HexagonII {
28 enum class MemAccessSize;
29 }
30 class DuplexCandidate {
31 public:
32   unsigned packetIndexI, packetIndexJ, iClass;
33   DuplexCandidate(unsigned i, unsigned j, unsigned iClass)
34       : packetIndexI(i), packetIndexJ(j), iClass(iClass) {}
35 };
36 namespace HexagonMCInstrInfo {
37 size_t const innerLoopOffset = 0;
38 int64_t const innerLoopMask = 1 << innerLoopOffset;
39
40 size_t const outerLoopOffset = 1;
41 int64_t const outerLoopMask = 1 << outerLoopOffset;
42
43 size_t const bundleInstructionsOffset = 1;
44
45 // Returns the number of instructions in the bundle
46 size_t bundleSize(MCInst const &MCI);
47
48 // Returns a iterator range of instructions in this bundle
49 iterator_range<MCInst::const_iterator> bundleInstructions(MCInst const &MCI);
50
51 // Return memory access size
52 HexagonII::MemAccessSize getAccessSize(MCInstrInfo const &MCII,
53                                        MCInst const &MCI);
54
55 // Return number of bits in the constant extended operand.
56 unsigned getBitCount(MCInstrInfo const &MCII, MCInst const &MCI);
57
58 // Return constant extended operand number.
59 unsigned short getCExtOpNum(MCInstrInfo const &MCII, MCInst const &MCI);
60
61 MCInstrDesc const &getDesc(MCInstrInfo const &MCII, MCInst const &MCI);
62
63 // Return the index of the extendable operand
64 unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI);
65
66 // Return a reference to the extendable operand
67 MCOperand const &getExtendableOperand(MCInstrInfo const &MCII,
68                                       MCInst const &MCI);
69
70 // Return the implicit alignment of the extendable operand
71 unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI);
72
73 // Return the number of logical bits of the extendable operand
74 unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI);
75
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);
79
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);
83
84 // Return instruction name
85 char const *getName(MCInstrInfo const &MCII, MCInst const &MCI);
86
87 // Return the operand index for the new value.
88 unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI);
89
90 // Return the operand that consumes or produces a new value.
91 MCOperand const &getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI);
92
93 int getSubTarget(MCInstrInfo const &MCII, MCInst const &MCI);
94
95 // Return the Hexagon ISA class for the insn.
96 unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI);
97
98 /// Return the slots used by the insn.
99 unsigned getUnits(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
100                   MCInst const &MCI);
101
102 bool hasImmExt(MCInst const &MCI);
103
104 // Return whether the instruction is a legal new-value producer.
105 bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
106
107 // Return the instruction at Index
108 MCInst const &instruction(MCInst const &MCB, size_t Index);
109
110 // Returns whether this MCInst is a wellformed bundle
111 bool isBundle(MCInst const &MCI);
112
113 // Return whether the insn is an actual insn.
114 bool isCanon(MCInstrInfo const &MCII, MCInst const &MCI);
115
116 // Return whether the instruction needs to be constant extended.
117 bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI);
118
119 // Return true if the insn may be extended based on the operand value.
120 bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI);
121
122 // Return whether the instruction must be always extended.
123 bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI);
124
125 /// Return whether it is a floating-point insn.
126 bool isFloat(MCInstrInfo const &MCII, MCInst const &MCI);
127
128 // Returns whether this instruction is an immediate extender
129 bool isImmext(MCInst const &MCI);
130
131 // Returns whether this bundle is an endloop0
132 bool isInnerLoop(MCInst const &MCI);
133
134 // Return whether the insn is a new-value consumer.
135 bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
136
137 // Return true if the operand can be constant extended.
138 bool isOperandExtended(MCInstrInfo const &MCII, MCInst const &MCI,
139                        unsigned short OperandNum);
140
141 // Returns whether this bundle is an endloop1
142 bool isOuterLoop(MCInst const &MCI);
143
144 // Return whether this instruction is predicated
145 bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI);
146
147 // Return whether the predicate sense is true
148 bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI);
149
150 // Return whether the insn is a prefix.
151 bool isPrefix(MCInstrInfo const &MCII, MCInst const &MCI);
152
153 // Return whether the insn is solo, i.e., cannot be in a packet.
154 bool isSolo(MCInstrInfo const &MCII, MCInst const &MCI);
155
156 /// Return whether the insn can be packaged only with A and X-type insns.
157 bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI);
158
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);
161
162 // Pad the bundle with nops to satisfy endloop requirements
163 void padEndloop(MCInst &MCI);
164
165 bool prefersSlot3(MCInstrInfo const &MCII, MCInst const &MCI);
166
167 // Marks a bundle as endloop0
168 void setInnerLoop(MCInst &MCI);
169
170 // Marks a bundle as endloop1
171 void setOuterLoop(MCInst &MCI);
172 }
173 }
174
175 #endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H