16 #ifndef LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTORIMPL_H
17 #define LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTORIMPL_H
20 template <
class TgtInstructionSelector,
class PredicateBitset,
21 class ComplexMatcherMemFn>
28 const PredicateBitset &AvailableFeatures)
const {
29 const int64_t *Command = MatchTable;
33 int64_t NewInsnID = *Command++;
34 int64_t InsnID = *Command++;
35 int64_t OpIdx = *Command++;
39 assert(NewInsnID != 0 &&
"Refusing to modify MIs[0]");
44 DEBUG(
dbgs() <<
"Rejected (not a register)\n");
48 DEBUG(
dbgs() <<
"Rejected (is a physical register)\n");
53 "Expected to store MIs in order");
55 DEBUG(
dbgs() <<
"MIs[" << NewInsnID <<
"] = GIM_RecordInsn(" << InsnID
56 <<
", " << OpIdx <<
")\n");
61 int64_t ExpectedBitsetID = *Command++;
62 DEBUG(
dbgs() <<
"GIM_CheckFeatures(ExpectedBitsetID=" << ExpectedBitsetID
64 if ((AvailableFeatures & MatcherInfo.
FeatureBitsets[ExpectedBitsetID]) !=
73 int64_t InsnID = *Command++;
76 unsigned Opcode = State.
MIs[InsnID]->getOpcode();
77 DEBUG(
dbgs() <<
"GIM_CheckOpcode(MIs[" << InsnID <<
"], ExpectedOpcode="
78 << Expected <<
") // Got=" << Opcode <<
"\n");
79 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
80 if (Opcode != Expected)
85 int64_t InsnID = *Command++;
87 DEBUG(
dbgs() <<
"GIM_CheckNumOperands(MIs[" << InsnID
88 <<
"], Expected=" << Expected <<
")\n");
89 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
90 if (State.
MIs[InsnID]->getNumOperands() != Expected)
96 int64_t InsnID = *Command++;
97 int64_t OpIdx = *Command++;
98 int64_t
TypeID = *Command++;
99 DEBUG(
dbgs() <<
"GIM_CheckType(MIs[" << InsnID <<
"]->getOperand("
100 << OpIdx <<
"), TypeID=" << TypeID <<
")\n");
101 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
102 if (MRI.
getType(State.
MIs[InsnID]->getOperand(OpIdx).getReg()) !=
108 int64_t InsnID = *Command++;
109 int64_t OpIdx = *Command++;
110 int64_t RCEnum = *Command++;
111 DEBUG(
dbgs() <<
"GIM_CheckRegBankForClass(MIs[" << InsnID
112 <<
"]->getOperand(" << OpIdx <<
"), RCEnum=" << RCEnum
114 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
121 int64_t InsnID = *Command++;
122 int64_t OpIdx = *Command++;
123 int64_t RendererID = *Command++;
124 int64_t ComplexPredicateID = *Command++;
125 DEBUG(
dbgs() <<
"State.Renderers[" << RendererID
126 <<
"] = GIM_CheckComplexPattern(MIs[" << InsnID
127 <<
"]->getOperand(" << OpIdx
128 <<
"), ComplexPredicateID=" << ComplexPredicateID <<
")\n");
129 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
133 State.
MIs[InsnID]->getOperand(OpIdx))))
138 int64_t InsnID = *Command++;
139 int64_t OpIdx = *Command++;
140 int64_t
Value = *Command++;
141 DEBUG(
dbgs() <<
"GIM_CheckConstantInt(MIs[" << InsnID <<
"]->getOperand("
142 << OpIdx <<
"), Value=" << Value <<
")\n");
143 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
149 int64_t InsnID = *Command++;
150 int64_t OpIdx = *Command++;
151 int64_t
Value = *Command++;
152 DEBUG(
dbgs() <<
"GIM_CheckLiteralInt(MIs[" << InsnID <<
"]->getOperand(" << OpIdx
153 <<
"), Value=" << Value <<
")\n");
154 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
161 int64_t InsnID = *Command++;
162 int64_t OpIdx = *Command++;
163 int64_t
Value = *Command++;
164 DEBUG(
dbgs() <<
"GIM_CheckIntrinsicID(MIs[" << InsnID <<
"]->getOperand(" << OpIdx
165 <<
"), Value=" << Value <<
")\n");
166 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
173 int64_t InsnID = *Command++;
174 int64_t OpIdx = *Command++;
175 DEBUG(
dbgs() <<
"GIM_CheckIsMBB(MIs[" << InsnID <<
"]->getOperand("
177 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
178 if (!State.
MIs[InsnID]->getOperand(OpIdx).isMBB())
184 int64_t InsnID = *Command++;
185 DEBUG(
dbgs() <<
"GIM_CheckIsSafeToFold(MIs[" << InsnID <<
"])\n");
186 assert(State.
MIs[InsnID] !=
nullptr &&
"Used insn before defined");
193 int64_t OldInsnID = *Command++;
194 int64_t NewInsnID = *Command++;
195 int64_t NewOpcode = *Command++;
197 "Expected to store MIs in order");
200 State.
MIs[OldInsnID]));
201 OutMIs[NewInsnID]->setDesc(TII.
get(NewOpcode));
202 DEBUG(
dbgs() <<
"GIR_MutateOpcode(OutMIs[" << NewInsnID <<
"], MIs["
203 << OldInsnID <<
"], " << NewOpcode <<
")\n");
207 int64_t InsnID = *Command++;
208 int64_t Opcode = *Command++;
210 "Expected to store MIs in order");
213 State.
MIs[0]->getDebugLoc(), TII.
get(Opcode)));
214 DEBUG(
dbgs() <<
"GIR_BuildMI(OutMIs[" << InsnID <<
"], " << Opcode
220 int64_t NewInsnID = *Command++;
221 int64_t OldInsnID = *Command++;
222 int64_t OpIdx = *Command++;
223 assert(OutMIs[NewInsnID] &&
"Attempted to add to undefined instruction");
224 OutMIs[NewInsnID].add(State.
MIs[OldInsnID]->getOperand(OpIdx));
225 DEBUG(
dbgs() <<
"GIR_Copy(OutMIs[" << NewInsnID <<
"], MIs[" << OldInsnID
226 <<
"], " << OpIdx <<
")\n");
230 int64_t NewInsnID = *Command++;
231 int64_t OldInsnID = *Command++;
232 int64_t OpIdx = *Command++;
233 int64_t SubRegIdx = *Command++;
234 assert(OutMIs[NewInsnID] &&
"Attempted to add to undefined instruction");
235 OutMIs[NewInsnID].addReg(State.
MIs[OldInsnID]->getOperand(OpIdx).getReg(),
237 DEBUG(
dbgs() <<
"GIR_CopySubReg(OutMIs[" << NewInsnID <<
"], MIs["
238 << OldInsnID <<
"], " << OpIdx <<
", " << SubRegIdx
243 int64_t InsnID = *Command++;
244 int64_t RegNum = *Command++;
245 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
247 DEBUG(
dbgs() <<
"GIR_AddImplicitDef(OutMIs[" << InsnID <<
"], " << RegNum
252 int64_t InsnID = *Command++;
253 int64_t RegNum = *Command++;
254 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
256 DEBUG(
dbgs() <<
"GIR_AddImplicitUse(OutMIs[" << InsnID <<
"], " << RegNum
261 int64_t InsnID = *Command++;
262 int64_t RegNum = *Command++;
263 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
264 OutMIs[InsnID].addReg(RegNum);
265 DEBUG(
dbgs() <<
"GIR_AddRegister(OutMIs[" << InsnID <<
"], " << RegNum
270 int64_t InsnID = *Command++;
271 int64_t Imm = *Command++;
272 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
273 OutMIs[InsnID].addImm(Imm);
274 DEBUG(
dbgs() <<
"GIR_AddImm(OutMIs[" << InsnID <<
"], " << Imm <<
")\n");
278 int64_t InsnID = *Command++;
279 int64_t RendererID = *Command++;
280 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
281 State.
Renderers[RendererID](OutMIs[InsnID]);
282 DEBUG(
dbgs() <<
"GIR_ComplexRenderer(OutMIs[" << InsnID <<
"], "
283 << RendererID <<
")\n");
288 int64_t InsnID = *Command++;
289 int64_t OpIdx = *Command++;
290 int64_t RCEnum = *Command++;
291 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
294 DEBUG(
dbgs() <<
"GIR_ConstrainOperandRC(OutMIs[" << InsnID <<
"], "
295 << OpIdx <<
", " << RCEnum <<
")\n");
299 int64_t InsnID = *Command++;
300 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
303 DEBUG(
dbgs() <<
"GIR_ConstrainSelectedInstOperands(OutMIs[" << InsnID
308 int64_t InsnID = *Command++;
309 assert(OutMIs[InsnID] &&
"Attempted to add to undefined instruction");
310 for (
const auto *FromMI : State.
MIs)
311 for (
const auto &MMO : FromMI->memoperands())
312 OutMIs[InsnID].addMemOperand(MMO);
313 DEBUG(
dbgs() <<
"GIR_MergeMemOperands(OutMIs[" << InsnID <<
"])\n");
317 int64_t InsnID = *Command++;
319 "Attempted to erase an undefined instruction");
320 State.
MIs[InsnID]->eraseFromParent();
321 DEBUG(
dbgs() <<
"GIR_EraseFromParent(MIs[" << InsnID <<
"])\n");
337 #endif // LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECTORIMPL_H
void push_back(const T &Elt)
virtual const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC) const
Get a register bank that covers RC.
LLT getType(unsigned VReg) const
Get the low-level type of VReg or LLT{} if VReg is not a generic (target independent) virtual registe...
Check the register bank for the specified operand.
const std::vector< ComplexMatcherMemFn > ComplexPredicates
Merge all memory operands into instruction.
bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
Add an immediate to the specified instruction.
Copy an operand to the specified instruction.
Add an implicit register def to the specified instruction.
Holds all the information related to register banks.
const HexagonInstrInfo * TII
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Check the operand is a specific intrinsic ID.
Tagged union holding either a T or a Error.
Constrain an instructions operands according to the instruction description.
Check the instruction has the right number of operands.
Check the operand matches a complex predicate.
TargetInstrInfo - Interface to description of machine instruction set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool isIntrinsicID() const
Intrinsic::ID getIntrinsicID() const
unsigned const MachineRegisterInfo * MRI
Record the specified instruction.
bool executeMatchTable(TgtInstructionSelector &ISel, NewMIVector &OutMIs, MatcherState &State, const MatcherInfoTy< PredicateBitset, ComplexMatcherMemFn > &MatcherInfo, const int64_t *MatchTable, const TargetInstrInfo &TII, MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI, const PredicateBitset &AvailableFeatures) const
Execute a given matcher table and return true if the match was successful and false otherwise...
std::vector< ComplexRendererFn > Renderers
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
bool isOperandImmEqual(const MachineOperand &MO, int64_t Value, const MachineRegisterInfo &MRI) const
Check if the specified operand is safe to fold into the current instruction.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Check the specified operand is an MBB.
bool equalsInt(uint64_t V) const
A helper method that can be used to determine if the constant contained within is equal to a constant...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const ConstantInt * getCImm() const
Render complex operands to the specified instruction.
bool isObviouslySafeToFold(MachineInstr &MI) const
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Check the operand is a specific integer.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Constrain an instruction operand to a register class.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
const PredicateBitset * FeatureBitsets
unsigned getReg() const
getReg - Returns the register number.
Add an implicit register use to the specified instruction.
Check the opcode on the specified instruction.
Check the operand is a specific literal integer (i.e.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
bool constrainOperandRegToRegClass(MachineInstr &I, unsigned OpIdx, const TargetRegisterClass &RC, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
Constrain a register operand of an instruction I to a specified register class.
Copy an operand to the specified instruction.
Add an register to the specified instruction.
Check the type for the specified operand.