LLVM  14.0.0git
MIPatternMatch.h
Go to the documentation of this file.
1 //==------ llvm/CodeGen/GlobalISel/MIPatternMatch.h -------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// Contains matchers for matching SSA Machine Instructions.
10 ///
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CODEGEN_GLOBALISEL_MIPATTERNMATCH_H
14 #define LLVM_CODEGEN_GLOBALISEL_MIPATTERNMATCH_H
15 
18 #include "llvm/IR/InstrTypes.h"
19 
20 namespace llvm {
21 namespace MIPatternMatch {
22 
23 template <typename Reg, typename Pattern>
25  return P.match(MRI, R);
26 }
27 
28 template <typename Pattern>
30  return P.match(MRI, &MI);
31 }
32 
33 // TODO: Extend for N use.
34 template <typename SubPatternT> struct OneUse_match {
35  SubPatternT SubPat;
36  OneUse_match(const SubPatternT &SP) : SubPat(SP) {}
37 
39  return MRI.hasOneUse(Reg) && SubPat.match(MRI, Reg);
40  }
41 };
42 
43 template <typename SubPat>
44 inline OneUse_match<SubPat> m_OneUse(const SubPat &SP) {
45  return SP;
46 }
47 
48 template <typename SubPatternT> struct OneNonDBGUse_match {
49  SubPatternT SubPat;
50  OneNonDBGUse_match(const SubPatternT &SP) : SubPat(SP) {}
51 
53  return MRI.hasOneNonDBGUse(Reg) && SubPat.match(MRI, Reg);
54  }
55 };
56 
57 template <typename SubPat>
58 inline OneNonDBGUse_match<SubPat> m_OneNonDBGUse(const SubPat &SP) {
59  return SP;
60 }
61 
62 struct ConstantMatch {
63  int64_t &CR;
64  ConstantMatch(int64_t &C) : CR(C) {}
66  if (auto MaybeCst = getIConstantVRegSExtVal(Reg, MRI)) {
67  CR = *MaybeCst;
68  return true;
69  }
70  return false;
71  }
72 };
73 
74 inline ConstantMatch m_ICst(int64_t &Cst) { return ConstantMatch(Cst); }
75 
81  return ValReg ? true : false;
82  }
83 };
84 
86  return GCstAndRegMatch(ValReg);
87 }
88 
94  return FPValReg ? true : false;
95  }
96 };
97 
99  return GFCstAndRegMatch(FPValReg);
100 }
101 
105  : FPValReg(FPValReg) {}
107  return (FPValReg = getFConstantSplat(Reg, MRI)) ||
109  };
110 };
111 
112 inline GFCstOrSplatGFCstMatch
114  return GFCstOrSplatGFCstMatch(FPValReg);
115 }
116 
117 /// Matcher for a specific constant value.
119  int64_t RequestedVal;
122  int64_t MatchedVal;
123  return mi_match(Reg, MRI, m_ICst(MatchedVal)) && MatchedVal == RequestedVal;
124  }
125 };
126 
127 /// Matches a constant equal to \p RequestedValue.
128 inline SpecificConstantMatch m_SpecificICst(int64_t RequestedValue) {
129  return SpecificConstantMatch(RequestedValue);
130 }
131 
132 ///{
133 /// Convenience matchers for specific integer values.
136  return SpecificConstantMatch(-1);
137 }
138 ///}
139 
140 // TODO: Rework this for different kinds of MachineOperand.
141 // Currently assumes the Src for a match is a register.
142 // We might want to support taking in some MachineOperands and call getReg on
143 // that.
144 
146  bool match(const MachineRegisterInfo &MRI, Register Reg) { return true; }
148  return MO->isReg();
149  }
150 };
151 
153 
154 /// Matching combinators.
155 template <typename... Preds> struct And {
156  template <typename MatchSrc>
157  bool match(const MachineRegisterInfo &MRI, MatchSrc &&src) {
158  return true;
159  }
160 };
161 
162 template <typename Pred, typename... Preds>
163 struct And<Pred, Preds...> : And<Preds...> {
164  Pred P;
165  And(Pred &&p, Preds &&... preds)
166  : And<Preds...>(std::forward<Preds>(preds)...), P(std::forward<Pred>(p)) {
167  }
168  template <typename MatchSrc>
169  bool match(const MachineRegisterInfo &MRI, MatchSrc &&src) {
170  return P.match(MRI, src) && And<Preds...>::match(MRI, src);
171  }
172 };
173 
174 template <typename... Preds> struct Or {
175  template <typename MatchSrc>
176  bool match(const MachineRegisterInfo &MRI, MatchSrc &&src) {
177  return false;
178  }
179 };
180 
181 template <typename Pred, typename... Preds>
182 struct Or<Pred, Preds...> : Or<Preds...> {
183  Pred P;
184  Or(Pred &&p, Preds &&... preds)
185  : Or<Preds...>(std::forward<Preds>(preds)...), P(std::forward<Pred>(p)) {}
186  template <typename MatchSrc>
187  bool match(const MachineRegisterInfo &MRI, MatchSrc &&src) {
188  return P.match(MRI, src) || Or<Preds...>::match(MRI, src);
189  }
190 };
191 
192 template <typename... Preds> And<Preds...> m_all_of(Preds &&... preds) {
193  return And<Preds...>(std::forward<Preds>(preds)...);
194 }
195 
196 template <typename... Preds> Or<Preds...> m_any_of(Preds &&... preds) {
197  return Or<Preds...>(std::forward<Preds>(preds)...);
198 }
199 
200 template <typename BindTy> struct bind_helper {
201  static bool bind(const MachineRegisterInfo &MRI, BindTy &VR, BindTy &V) {
202  VR = V;
203  return true;
204  }
205 };
206 
207 template <> struct bind_helper<MachineInstr *> {
208  static bool bind(const MachineRegisterInfo &MRI, MachineInstr *&MI,
209  Register Reg) {
210  MI = MRI.getVRegDef(Reg);
211  if (MI)
212  return true;
213  return false;
214  }
215  static bool bind(const MachineRegisterInfo &MRI, MachineInstr *&MI,
216  MachineInstr *Inst) {
217  MI = Inst;
218  return MI;
219  }
220 };
221 
222 template <> struct bind_helper<LLT> {
223  static bool bind(const MachineRegisterInfo &MRI, LLT Ty, Register Reg) {
224  Ty = MRI.getType(Reg);
225  if (Ty.isValid())
226  return true;
227  return false;
228  }
229 };
230 
231 template <> struct bind_helper<const ConstantFP *> {
232  static bool bind(const MachineRegisterInfo &MRI, const ConstantFP *&F,
233  Register Reg) {
235  if (F)
236  return true;
237  return false;
238  }
239 };
240 
241 template <typename Class> struct bind_ty {
242  Class &VR;
243 
244  bind_ty(Class &V) : VR(V) {}
245 
246  template <typename ITy> bool match(const MachineRegisterInfo &MRI, ITy &&V) {
247  return bind_helper<Class>::bind(MRI, VR, V);
248  }
249 };
250 
251 inline bind_ty<Register> m_Reg(Register &R) { return R; }
253 inline bind_ty<LLT> m_Type(LLT Ty) { return Ty; }
256 
257 // Helper for matching G_FCONSTANT
258 inline bind_ty<const ConstantFP *> m_GFCst(const ConstantFP *&C) { return C; }
259 
260 // General helper for all the binary generic MI such as G_ADD/G_SUB etc
261 template <typename LHS_P, typename RHS_P, unsigned Opcode,
262  bool Commutable = false>
264  LHS_P L;
265  RHS_P R;
266 
267  BinaryOp_match(const LHS_P &LHS, const RHS_P &RHS) : L(LHS), R(RHS) {}
268  template <typename OpTy>
269  bool match(const MachineRegisterInfo &MRI, OpTy &&Op) {
270  MachineInstr *TmpMI;
271  if (mi_match(Op, MRI, m_MInstr(TmpMI))) {
272  if (TmpMI->getOpcode() == Opcode && TmpMI->getNumOperands() == 3) {
273  return (L.match(MRI, TmpMI->getOperand(1).getReg()) &&
274  R.match(MRI, TmpMI->getOperand(2).getReg())) ||
275  (Commutable && (R.match(MRI, TmpMI->getOperand(1).getReg()) &&
276  L.match(MRI, TmpMI->getOperand(2).getReg())));
277  }
278  }
279  return false;
280  }
281 };
282 
283 // Helper for (commutative) binary generic MI that checks Opcode.
284 template <typename LHS_P, typename RHS_P, bool Commutable = false>
286  unsigned Opc;
287  LHS_P L;
288  RHS_P R;
289 
290  BinaryOpc_match(unsigned Opcode, const LHS_P &LHS, const RHS_P &RHS)
291  : Opc(Opcode), L(LHS), R(RHS) {}
292  template <typename OpTy>
293  bool match(const MachineRegisterInfo &MRI, OpTy &&Op) {
294  MachineInstr *TmpMI;
295  if (mi_match(Op, MRI, m_MInstr(TmpMI))) {
296  if (TmpMI->getOpcode() == Opc && TmpMI->getNumDefs() == 1 &&
297  TmpMI->getNumOperands() == 3) {
298  return (L.match(MRI, TmpMI->getOperand(1).getReg()) &&
299  R.match(MRI, TmpMI->getOperand(2).getReg())) ||
300  (Commutable && (R.match(MRI, TmpMI->getOperand(1).getReg()) &&
301  L.match(MRI, TmpMI->getOperand(2).getReg())));
302  }
303  }
304  return false;
305  }
306 };
307 
308 template <typename LHS, typename RHS>
309 inline BinaryOpc_match<LHS, RHS, false> m_BinOp(unsigned Opcode, const LHS &L,
310  const RHS &R) {
311  return BinaryOpc_match<LHS, RHS, false>(Opcode, L, R);
312 }
313 
314 template <typename LHS, typename RHS>
315 inline BinaryOpc_match<LHS, RHS, true>
316 m_CommutativeBinOp(unsigned Opcode, const LHS &L, const RHS &R) {
317  return BinaryOpc_match<LHS, RHS, true>(Opcode, L, R);
318 }
319 
320 template <typename LHS, typename RHS>
322 m_GAdd(const LHS &L, const RHS &R) {
324 }
325 
326 template <typename LHS, typename RHS>
328 m_GPtrAdd(const LHS &L, const RHS &R) {
330 }
331 
332 template <typename LHS, typename RHS>
334  const RHS &R) {
336 }
337 
338 template <typename LHS, typename RHS>
340 m_GMul(const LHS &L, const RHS &R) {
342 }
343 
344 template <typename LHS, typename RHS>
346 m_GFAdd(const LHS &L, const RHS &R) {
348 }
349 
350 template <typename LHS, typename RHS>
352 m_GFMul(const LHS &L, const RHS &R) {
354 }
355 
356 template <typename LHS, typename RHS>
358 m_GFSub(const LHS &L, const RHS &R) {
360 }
361 
362 template <typename LHS, typename RHS>
364 m_GAnd(const LHS &L, const RHS &R) {
366 }
367 
368 template <typename LHS, typename RHS>
370 m_GXor(const LHS &L, const RHS &R) {
372 }
373 
374 template <typename LHS, typename RHS>
376  const RHS &R) {
378 }
379 
380 template <typename LHS, typename RHS>
382 m_GShl(const LHS &L, const RHS &R) {
384 }
385 
386 template <typename LHS, typename RHS>
388 m_GLShr(const LHS &L, const RHS &R) {
390 }
391 
392 template <typename LHS, typename RHS>
394 m_GAShr(const LHS &L, const RHS &R) {
396 }
397 
398 template <typename LHS, typename RHS>
400 m_GSMax(const LHS &L, const RHS &R) {
402 }
403 
404 template <typename LHS, typename RHS>
406 m_GSMin(const LHS &L, const RHS &R) {
408 }
409 
410 // Helper for unary instructions (G_[ZSA]EXT/G_TRUNC) etc
411 template <typename SrcTy, unsigned Opcode> struct UnaryOp_match {
412  SrcTy L;
413 
414  UnaryOp_match(const SrcTy &LHS) : L(LHS) {}
415  template <typename OpTy>
416  bool match(const MachineRegisterInfo &MRI, OpTy &&Op) {
417  MachineInstr *TmpMI;
418  if (mi_match(Op, MRI, m_MInstr(TmpMI))) {
419  if (TmpMI->getOpcode() == Opcode && TmpMI->getNumOperands() == 2) {
420  return L.match(MRI, TmpMI->getOperand(1).getReg());
421  }
422  }
423  return false;
424  }
425 };
426 
427 template <typename SrcTy>
428 inline UnaryOp_match<SrcTy, TargetOpcode::G_ANYEXT>
429 m_GAnyExt(const SrcTy &Src) {
431 }
432 
433 template <typename SrcTy>
436 }
437 
438 template <typename SrcTy>
441 }
442 
443 template <typename SrcTy>
446 }
447 
448 template <typename SrcTy>
451 }
452 
453 template <typename SrcTy>
454 inline UnaryOp_match<SrcTy, TargetOpcode::G_BITCAST>
455 m_GBitcast(const SrcTy &Src) {
457 }
458 
459 template <typename SrcTy>
460 inline UnaryOp_match<SrcTy, TargetOpcode::G_PTRTOINT>
461 m_GPtrToInt(const SrcTy &Src) {
463 }
464 
465 template <typename SrcTy>
466 inline UnaryOp_match<SrcTy, TargetOpcode::G_INTTOPTR>
467 m_GIntToPtr(const SrcTy &Src) {
469 }
470 
471 template <typename SrcTy>
472 inline UnaryOp_match<SrcTy, TargetOpcode::G_FPTRUNC>
473 m_GFPTrunc(const SrcTy &Src) {
475 }
476 
477 template <typename SrcTy>
480 }
481 
482 template <typename SrcTy>
485 }
486 
487 template <typename SrcTy>
489  return UnaryOp_match<SrcTy, TargetOpcode::COPY>(std::forward<SrcTy>(Src));
490 }
491 
492 // General helper for generic MI compares, i.e. G_ICMP and G_FCMP
493 // TODO: Allow checking a specific predicate.
494 template <typename Pred_P, typename LHS_P, typename RHS_P, unsigned Opcode>
496  Pred_P P;
497  LHS_P L;
498  RHS_P R;
499 
500  CompareOp_match(const Pred_P &Pred, const LHS_P &LHS, const RHS_P &RHS)
501  : P(Pred), L(LHS), R(RHS) {}
502 
503  template <typename OpTy>
504  bool match(const MachineRegisterInfo &MRI, OpTy &&Op) {
505  MachineInstr *TmpMI;
506  if (!mi_match(Op, MRI, m_MInstr(TmpMI)) || TmpMI->getOpcode() != Opcode)
507  return false;
508 
509  auto TmpPred =
510  static_cast<CmpInst::Predicate>(TmpMI->getOperand(1).getPredicate());
511  if (!P.match(MRI, TmpPred))
512  return false;
513 
514  return L.match(MRI, TmpMI->getOperand(2).getReg()) &&
515  R.match(MRI, TmpMI->getOperand(3).getReg());
516  }
517 };
518 
519 template <typename Pred, typename LHS, typename RHS>
520 inline CompareOp_match<Pred, LHS, RHS, TargetOpcode::G_ICMP>
521 m_GICmp(const Pred &P, const LHS &L, const RHS &R) {
523 }
524 
525 template <typename Pred, typename LHS, typename RHS>
526 inline CompareOp_match<Pred, LHS, RHS, TargetOpcode::G_FCMP>
527 m_GFCmp(const Pred &P, const LHS &L, const RHS &R) {
529 }
530 
531 // Helper for checking if a Reg is of specific type.
532 struct CheckType {
534  CheckType(const LLT Ty) : Ty(Ty) {}
535 
537  return MRI.getType(Reg) == Ty;
538  }
539 };
540 
541 inline CheckType m_SpecificType(LLT Ty) { return Ty; }
542 
543 template <typename Src0Ty, typename Src1Ty, typename Src2Ty, unsigned Opcode>
545  Src0Ty Src0;
546  Src1Ty Src1;
547  Src2Ty Src2;
548 
549  TernaryOp_match(const Src0Ty &Src0, const Src1Ty &Src1, const Src2Ty &Src2)
550  : Src0(Src0), Src1(Src1), Src2(Src2) {}
551  template <typename OpTy>
552  bool match(const MachineRegisterInfo &MRI, OpTy &&Op) {
553  MachineInstr *TmpMI;
554  if (mi_match(Op, MRI, m_MInstr(TmpMI))) {
555  if (TmpMI->getOpcode() == Opcode && TmpMI->getNumOperands() == 4) {
556  return (Src0.match(MRI, TmpMI->getOperand(1).getReg()) &&
557  Src1.match(MRI, TmpMI->getOperand(2).getReg()) &&
558  Src2.match(MRI, TmpMI->getOperand(3).getReg()));
559  }
560  }
561  return false;
562  }
563 };
564 template <typename Src0Ty, typename Src1Ty, typename Src2Ty>
565 inline TernaryOp_match<Src0Ty, Src1Ty, Src2Ty,
566  TargetOpcode::G_INSERT_VECTOR_ELT>
567 m_GInsertVecElt(const Src0Ty &Src0, const Src1Ty &Src1, const Src2Ty &Src2) {
568  return TernaryOp_match<Src0Ty, Src1Ty, Src2Ty,
569  TargetOpcode::G_INSERT_VECTOR_ELT>(Src0, Src1, Src2);
570 }
571 
572 template <typename Src0Ty, typename Src1Ty, typename Src2Ty>
573 inline TernaryOp_match<Src0Ty, Src1Ty, Src2Ty, TargetOpcode::G_SELECT>
574 m_GISelect(const Src0Ty &Src0, const Src1Ty &Src1, const Src2Ty &Src2) {
576  Src0, Src1, Src2);
577 }
578 
579 /// Matches a register negated by a G_SUB.
580 /// G_SUB 0, %negated_reg
581 template <typename SrcTy>
583 m_Neg(const SrcTy &&Src) {
584  return m_GSub(m_ZeroInt(), Src);
585 }
586 
587 /// Matches a register not-ed by a G_XOR.
588 /// G_XOR %not_reg, -1
589 template <typename SrcTy>
591 m_Not(const SrcTy &&Src) {
592  return m_GXor(Src, m_AllOnesInt());
593 }
594 
595 } // namespace MIPatternMatch
596 } // namespace llvm
597 
598 #endif
llvm::MIPatternMatch::CheckType
Definition: MIPatternMatch.h:532
llvm::getIConstantVRegSExtVal
Optional< int64_t > getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT fits in int64_t returns it.
Definition: Utils.cpp:284
llvm::MIPatternMatch::operand_type_match::match
bool match(const MachineRegisterInfo &MRI, MachineOperand *MO)
Definition: MIPatternMatch.h:147
llvm::MIPatternMatch::TernaryOp_match::match
bool match(const MachineRegisterInfo &MRI, OpTy &&Op)
Definition: MIPatternMatch.h:552
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::PatternMatch::BinaryOp_match
Definition: PatternMatch.h:983
llvm::MIPatternMatch::bind_helper< LLT >::bind
static bool bind(const MachineRegisterInfo &MRI, LLT Ty, Register Reg)
Definition: MIPatternMatch.h:223
llvm::MIPatternMatch::UnaryOp_match::UnaryOp_match
UnaryOp_match(const SrcTy &LHS)
Definition: MIPatternMatch.h:414
llvm::MIPatternMatch::GFCstAndRegMatch::FPValReg
Optional< FPValueAndVReg > & FPValReg
Definition: MIPatternMatch.h:90
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:720
llvm::MIPatternMatch::m_GFPExt
UnaryOp_match< SrcTy, TargetOpcode::G_FPEXT > m_GFPExt(const SrcTy &Src)
Definition: MIPatternMatch.h:444
llvm::MIPatternMatch::m_GFNeg
UnaryOp_match< SrcTy, TargetOpcode::G_FNEG > m_GFNeg(const SrcTy &Src)
Definition: MIPatternMatch.h:483
llvm::MIPatternMatch::m_Reg
operand_type_match m_Reg()
Definition: MIPatternMatch.h:152
llvm::MIPatternMatch::ConstantMatch::ConstantMatch
ConstantMatch(int64_t &C)
Definition: MIPatternMatch.h:64
llvm::MIPatternMatch::m_GAnd
BinaryOp_match< LHS, RHS, TargetOpcode::G_AND, true > m_GAnd(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:364
llvm::MIPatternMatch::m_GShl
BinaryOp_match< LHS, RHS, TargetOpcode::G_SHL, false > m_GShl(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:382
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::MIPatternMatch::Or< Pred, Preds... >::P
Pred P
Definition: MIPatternMatch.h:183
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::MIPatternMatch::m_GLShr
BinaryOp_match< LHS, RHS, TargetOpcode::G_LSHR, false > m_GLShr(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:388
llvm::MIPatternMatch::BinaryOpc_match::Opc
unsigned Opc
Definition: MIPatternMatch.h:286
llvm::MIPatternMatch::UnaryOp_match::L
SrcTy L
Definition: MIPatternMatch.h:412
llvm::MCID::Commutable
@ Commutable
Definition: MCInstrDesc.h:171
llvm::MIPatternMatch::m_OneNonDBGUse
OneNonDBGUse_match< SubPat > m_OneNonDBGUse(const SubPat &SP)
Definition: MIPatternMatch.h:58
llvm::MIPatternMatch::GCstAndRegMatch::GCstAndRegMatch
GCstAndRegMatch(Optional< ValueAndVReg > &ValReg)
Definition: MIPatternMatch.h:78
llvm::MIPatternMatch::m_GSub
BinaryOp_match< LHS, RHS, TargetOpcode::G_SUB > m_GSub(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:333
llvm::MIPatternMatch::BinaryOpc_match::L
LHS_P L
Definition: MIPatternMatch.h:287
llvm::MIPatternMatch::m_GTrunc
UnaryOp_match< SrcTy, TargetOpcode::G_TRUNC > m_GTrunc(const SrcTy &Src)
Definition: MIPatternMatch.h:449
llvm::MIPatternMatch::BinaryOpc_match::R
RHS_P R
Definition: MIPatternMatch.h:288
llvm::MIPatternMatch::m_GFSub
BinaryOp_match< LHS, RHS, TargetOpcode::G_FSUB, false > m_GFSub(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:358
llvm::MIPatternMatch::m_GSMax
BinaryOp_match< LHS, RHS, TargetOpcode::G_SMAX, false > m_GSMax(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:400
llvm::MIPatternMatch::CheckType::CheckType
CheckType(const LLT Ty)
Definition: MIPatternMatch.h:534
llvm::MIPatternMatch::m_GICmp
CompareOp_match< Pred, LHS, RHS, TargetOpcode::G_ICMP > m_GICmp(const Pred &P, const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:521
llvm::LLT::isValid
bool isValid() const
Definition: LowLevelTypeImpl.h:117
llvm::MIPatternMatch::m_GFAdd
BinaryOp_match< LHS, RHS, TargetOpcode::G_FADD, true > m_GFAdd(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:346
llvm::Optional
Definition: APInt.h:33
llvm::MIPatternMatch::BinaryOpc_match::match
bool match(const MachineRegisterInfo &MRI, OpTy &&Op)
Definition: MIPatternMatch.h:293
llvm::MIPatternMatch::m_GSMin
BinaryOp_match< LHS, RHS, TargetOpcode::G_SMIN, false > m_GSMin(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:406
llvm::MIPatternMatch::bind_ty::match
bool match(const MachineRegisterInfo &MRI, ITy &&V)
Definition: MIPatternMatch.h:246
llvm::MIPatternMatch::SpecificConstantMatch::RequestedVal
int64_t RequestedVal
Definition: MIPatternMatch.h:119
preds
preds
Definition: README.txt:340
p
the resulting code requires compare and branches when and if * p
Definition: README.txt:396
llvm::MIPatternMatch::BinaryOpc_match::BinaryOpc_match
BinaryOpc_match(unsigned Opcode, const LHS_P &LHS, const RHS_P &RHS)
Definition: MIPatternMatch.h:290
llvm::MIPatternMatch::BinaryOp_match::R
RHS_P R
Definition: MIPatternMatch.h:265
llvm::MIPatternMatch::BinaryOp_match::L
LHS_P L
Definition: MIPatternMatch.h:264
llvm::MIPatternMatch::m_GPtrToInt
UnaryOp_match< SrcTy, TargetOpcode::G_PTRTOINT > m_GPtrToInt(const SrcTy &Src)
Definition: MIPatternMatch.h:461
llvm::MIPatternMatch::m_GFabs
UnaryOp_match< SrcTy, TargetOpcode::G_FABS > m_GFabs(const SrcTy &Src)
Definition: MIPatternMatch.h:478
F
#define F(x, y, z)
Definition: MD5.cpp:56
MachineRegisterInfo.h
llvm::MachineInstr::getNumDefs
unsigned getNumDefs() const
Returns the total number of definitions.
Definition: MachineInstr.h:567
llvm::MIPatternMatch::operand_type_match::match
bool match(const MachineRegisterInfo &MRI, Register Reg)
Definition: MIPatternMatch.h:146
llvm::MIPatternMatch::OneNonDBGUse_match
Definition: MIPatternMatch.h:48
llvm::MIPatternMatch::m_GFCst
GFCstAndRegMatch m_GFCst(Optional< FPValueAndVReg > &FPValReg)
Definition: MIPatternMatch.h:98
llvm::MIPatternMatch::ConstantMatch::match
bool match(const MachineRegisterInfo &MRI, Register Reg)
Definition: MIPatternMatch.h:65
llvm::MIPatternMatch::m_GSExt
UnaryOp_match< SrcTy, TargetOpcode::G_SEXT > m_GSExt(const SrcTy &Src)
Definition: MIPatternMatch.h:434
llvm::MIPatternMatch::m_GMul
BinaryOp_match< LHS, RHS, TargetOpcode::G_MUL, true > m_GMul(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:340
llvm::MIPatternMatch::ConstantMatch
Definition: MIPatternMatch.h:62
llvm::MIPatternMatch::TernaryOp_match::TernaryOp_match
TernaryOp_match(const Src0Ty &Src0, const Src1Ty &Src1, const Src2Ty &Src2)
Definition: MIPatternMatch.h:549
llvm::MIPatternMatch::m_GZExt
UnaryOp_match< SrcTy, TargetOpcode::G_ZEXT > m_GZExt(const SrcTy &Src)
Definition: MIPatternMatch.h:439
llvm::MIPatternMatch::OneNonDBGUse_match::OneNonDBGUse_match
OneNonDBGUse_match(const SubPatternT &SP)
Definition: MIPatternMatch.h:50
llvm::MIPatternMatch::GFCstOrSplatGFCstMatch
Definition: MIPatternMatch.h:102
llvm::MIPatternMatch::m_GPtrAdd
BinaryOp_match< LHS, RHS, TargetOpcode::G_PTR_ADD, true > m_GPtrAdd(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:328
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::MachineInstr::getOperand
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:499
llvm::MIPatternMatch::Or::match
bool match(const MachineRegisterInfo &MRI, MatchSrc &&src)
Definition: MIPatternMatch.h:176
llvm::MIPatternMatch::GCstAndRegMatch
Definition: MIPatternMatch.h:76
llvm::MIPatternMatch::SpecificConstantMatch::match
bool match(const MachineRegisterInfo &MRI, Register Reg)
Definition: MIPatternMatch.h:121
InstrTypes.h
Utils.h
llvm::MIPatternMatch::bind_ty
Definition: MIPatternMatch.h:241
llvm::MIPatternMatch::m_GIntToPtr
UnaryOp_match< SrcTy, TargetOpcode::G_INTTOPTR > m_GIntToPtr(const SrcTy &Src)
Definition: MIPatternMatch.h:467
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::MIPatternMatch::m_ZeroInt
SpecificConstantMatch m_ZeroInt()
{ Convenience matchers for specific integer values.
Definition: MIPatternMatch.h:134
llvm::MIPatternMatch::Or< Pred, Preds... >::match
bool match(const MachineRegisterInfo &MRI, MatchSrc &&src)
Definition: MIPatternMatch.h:187
llvm::MIPatternMatch::m_GFCstOrSplat
GFCstOrSplatGFCstMatch m_GFCstOrSplat(Optional< FPValueAndVReg > &FPValReg)
Definition: MIPatternMatch.h:113
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:257
llvm::MIPatternMatch::BinaryOpc_match
Definition: MIPatternMatch.h:285
llvm::MIPatternMatch::Or< Pred, Preds... >::Or
Or(Pred &&p, Preds &&... preds)
Definition: MIPatternMatch.h:184
llvm::MIPatternMatch::bind_helper< MachineInstr * >::bind
static bool bind(const MachineRegisterInfo &MRI, MachineInstr *&MI, Register Reg)
Definition: MIPatternMatch.h:208
llvm::MIPatternMatch::m_SpecificICst
SpecificConstantMatch m_SpecificICst(int64_t RequestedValue)
Matches a constant equal to RequestedValue.
Definition: MIPatternMatch.h:128
llvm::MIPatternMatch::OneUse_match::OneUse_match
OneUse_match(const SubPatternT &SP)
Definition: MIPatternMatch.h:36
llvm::MIPatternMatch::UnaryOp_match::match
bool match(const MachineRegisterInfo &MRI, OpTy &&Op)
Definition: MIPatternMatch.h:416
llvm::MIPatternMatch::m_MInstr
bind_ty< MachineInstr * > m_MInstr(MachineInstr *&MI)
Definition: MIPatternMatch.h:252
llvm::MIPatternMatch::m_Pred
bind_ty< CmpInst::Predicate > m_Pred(CmpInst::Predicate &P)
Definition: MIPatternMatch.h:254
llvm::MIPatternMatch::m_SpecificType
CheckType m_SpecificType(LLT Ty)
Definition: MIPatternMatch.h:541
llvm::MIPatternMatch::GFCstOrSplatGFCstMatch::FPValReg
Optional< FPValueAndVReg > & FPValReg
Definition: MIPatternMatch.h:103
llvm::MIPatternMatch::UnaryOp_match
Definition: MIPatternMatch.h:411
llvm::MIPatternMatch::m_GAnyExt
UnaryOp_match< SrcTy, TargetOpcode::G_ANYEXT > m_GAnyExt(const SrcTy &Src)
Definition: MIPatternMatch.h:429
llvm::MIPatternMatch::CompareOp_match::match
bool match(const MachineRegisterInfo &MRI, OpTy &&Op)
Definition: MIPatternMatch.h:504
llvm::MIPatternMatch::SpecificConstantMatch::SpecificConstantMatch
SpecificConstantMatch(int64_t RequestedVal)
Definition: MIPatternMatch.h:120
llvm::MIPatternMatch::m_GOr
BinaryOp_match< LHS, RHS, TargetOpcode::G_OR, true > m_GOr(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:375
llvm::MachineOperand::isReg
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Definition: MachineOperand.h:321
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MIPatternMatch::BinaryOp_match
Definition: MIPatternMatch.h:263
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::MIPatternMatch::OneNonDBGUse_match::SubPat
SubPatternT SubPat
Definition: MIPatternMatch.h:49
llvm::MIPatternMatch::And< Pred, Preds... >::match
bool match(const MachineRegisterInfo &MRI, MatchSrc &&src)
Definition: MIPatternMatch.h:169
llvm::MIPatternMatch::bind_ty::VR
Class & VR
Definition: MIPatternMatch.h:242
llvm::MIPatternMatch::Or
Definition: MIPatternMatch.h:174
llvm::MIPatternMatch::m_CommutativeBinOp
BinaryOpc_match< LHS, RHS, true > m_CommutativeBinOp(unsigned Opcode, const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:316
llvm::MIPatternMatch::m_AllOnesInt
SpecificConstantMatch m_AllOnesInt()
Definition: MIPatternMatch.h:135
llvm::MIPatternMatch::And
Matching combinators.
Definition: MIPatternMatch.h:155
llvm::MIPatternMatch::CheckType::match
bool match(const MachineRegisterInfo &MRI, Register Reg)
Definition: MIPatternMatch.h:536
llvm::MachineOperand::getPredicate
unsigned getPredicate() const
Definition: MachineOperand.h:588
llvm::MIPatternMatch::GFCstOrSplatGFCstMatch::match
bool match(const MachineRegisterInfo &MRI, Register Reg)
Definition: MIPatternMatch.h:106
llvm::MIPatternMatch::m_Type
bind_ty< LLT > m_Type(LLT Ty)
Definition: MIPatternMatch.h:253
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:360
llvm::MIPatternMatch::OneNonDBGUse_match::match
bool match(const MachineRegisterInfo &MRI, Register Reg)
Definition: MIPatternMatch.h:52
llvm::MIPatternMatch::bind_ty::bind_ty
bind_ty(Class &V)
Definition: MIPatternMatch.h:244
llvm::MIPatternMatch::TernaryOp_match::Src2
Src2Ty Src2
Definition: MIPatternMatch.h:547
llvm::MIPatternMatch::BinaryOp_match::match
bool match(const MachineRegisterInfo &MRI, OpTy &&Op)
Definition: MIPatternMatch.h:269
llvm::MIPatternMatch::GCstAndRegMatch::match
bool match(const MachineRegisterInfo &MRI, Register Reg)
Definition: MIPatternMatch.h:79
llvm::MIPatternMatch::GFCstAndRegMatch::GFCstAndRegMatch
GFCstAndRegMatch(Optional< FPValueAndVReg > &FPValReg)
Definition: MIPatternMatch.h:91
llvm::getIConstantVRegValWithLookThrough
Optional< ValueAndVReg > getIConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_CONSTANT returns its...
Definition: Utils.cpp:393
llvm::MachineInstr::getOpcode
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:489
llvm::MIPatternMatch::m_any_of
Or< Preds... > m_any_of(Preds &&... preds)
Definition: MIPatternMatch.h:196
llvm::MIPatternMatch::m_GXor
BinaryOp_match< LHS, RHS, TargetOpcode::G_XOR, true > m_GXor(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:370
llvm::MIPatternMatch::TernaryOp_match::Src1
Src1Ty Src1
Definition: MIPatternMatch.h:546
llvm::MIPatternMatch::bind_helper::bind
static bool bind(const MachineRegisterInfo &MRI, BindTy &VR, BindTy &V)
Definition: MIPatternMatch.h:201
llvm::MIPatternMatch::m_Copy
UnaryOp_match< SrcTy, TargetOpcode::COPY > m_Copy(SrcTy &&Src)
Definition: MIPatternMatch.h:488
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::MIPatternMatch::m_GAShr
BinaryOp_match< LHS, RHS, TargetOpcode::G_ASHR, false > m_GAShr(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:394
llvm::MIPatternMatch::And::match
bool match(const MachineRegisterInfo &MRI, MatchSrc &&src)
Definition: MIPatternMatch.h:157
std
Definition: BitVector.h:838
llvm::MIPatternMatch::m_GFCmp
CompareOp_match< Pred, LHS, RHS, TargetOpcode::G_FCMP > m_GFCmp(const Pred &P, const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:527
llvm::MIPatternMatch::m_GAdd
BinaryOp_match< LHS, RHS, TargetOpcode::G_ADD, true > m_GAdd(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:322
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:324
llvm::MIPatternMatch::m_GCst
GCstAndRegMatch m_GCst(Optional< ValueAndVReg > &ValReg)
Definition: MIPatternMatch.h:85
llvm::MIPatternMatch::CompareOp_match::P
Pred_P P
Definition: MIPatternMatch.h:496
llvm::MIPatternMatch::CompareOp_match
Definition: MIPatternMatch.h:495
llvm::MIPatternMatch::And< Pred, Preds... >::P
Pred P
Definition: MIPatternMatch.h:164
llvm::MIPatternMatch::GFCstAndRegMatch::match
bool match(const MachineRegisterInfo &MRI, Register Reg)
Definition: MIPatternMatch.h:92
llvm::MIPatternMatch::m_GISelect
TernaryOp_match< Src0Ty, Src1Ty, Src2Ty, TargetOpcode::G_SELECT > m_GISelect(const Src0Ty &Src0, const Src1Ty &Src1, const Src2Ty &Src2)
Definition: MIPatternMatch.h:574
llvm::getFConstantVRegValWithLookThrough
Optional< FPValueAndVReg > getFConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_FCONSTANT returns it...
Definition: Utils.cpp:407
llvm::MIPatternMatch::CompareOp_match::L
LHS_P L
Definition: MIPatternMatch.h:497
llvm::MIPatternMatch::m_ICst
ConstantMatch m_ICst(int64_t &Cst)
Definition: MIPatternMatch.h:74
llvm::MIPatternMatch::bind_helper
Definition: MIPatternMatch.h:200
llvm::MIPatternMatch::OneUse_match::SubPat
SubPatternT SubPat
Definition: MIPatternMatch.h:35
llvm::MIPatternMatch::CompareOp_match::CompareOp_match
CompareOp_match(const Pred_P &Pred, const LHS_P &LHS, const RHS_P &RHS)
Definition: MIPatternMatch.h:500
llvm::Pattern
Definition: FileCheckImpl.h:614
llvm::MIPatternMatch::bind_helper< const ConstantFP * >::bind
static bool bind(const MachineRegisterInfo &MRI, const ConstantFP *&F, Register Reg)
Definition: MIPatternMatch.h:232
llvm::MIPatternMatch::m_GFPTrunc
UnaryOp_match< SrcTy, TargetOpcode::G_FPTRUNC > m_GFPTrunc(const SrcTy &Src)
Definition: MIPatternMatch.h:473
llvm::MIPatternMatch::m_GBitcast
UnaryOp_match< SrcTy, TargetOpcode::G_BITCAST > m_GBitcast(const SrcTy &Src)
Definition: MIPatternMatch.h:455
llvm::MIPatternMatch::operand_type_match
}
Definition: MIPatternMatch.h:145
llvm::getFConstantSplat
Optional< FPValueAndVReg > getFConstantSplat(Register VReg, const MachineRegisterInfo &MRI, bool AllowUndef=true)
Returns a floating point scalar constant of a build vector splat if it exists.
Definition: Utils.cpp:1046
llvm::MachineInstr::getNumOperands
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:492
llvm::MIPatternMatch::m_GFMul
BinaryOp_match< LHS, RHS, TargetOpcode::G_FMUL, true > m_GFMul(const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:352
llvm::MIPatternMatch::m_Neg
BinaryOp_match< SpecificConstantMatch, SrcTy, TargetOpcode::G_SUB > m_Neg(const SrcTy &&Src)
Matches a register negated by a G_SUB.
Definition: MIPatternMatch.h:583
llvm::MIPatternMatch::OneUse_match
Definition: MIPatternMatch.h:34
llvm::MIPatternMatch::GFCstOrSplatGFCstMatch::GFCstOrSplatGFCstMatch
GFCstOrSplatGFCstMatch(Optional< FPValueAndVReg > &FPValReg)
Definition: MIPatternMatch.h:104
llvm::MIPatternMatch::BinaryOp_match::BinaryOp_match
BinaryOp_match(const LHS_P &LHS, const RHS_P &RHS)
Definition: MIPatternMatch.h:267
llvm::MIPatternMatch::bind_helper< MachineInstr * >::bind
static bool bind(const MachineRegisterInfo &MRI, MachineInstr *&MI, MachineInstr *Inst)
Definition: MIPatternMatch.h:215
llvm::getConstantFPVRegVal
const ConstantFP * getConstantFPVRegVal(Register VReg, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:418
llvm::MIPatternMatch::m_all_of
And< Preds... > m_all_of(Preds &&... preds)
Definition: MIPatternMatch.h:192
llvm::MIPatternMatch::CheckType::Ty
LLT Ty
Definition: MIPatternMatch.h:533
llvm::MIPatternMatch::GCstAndRegMatch::ValReg
Optional< ValueAndVReg > & ValReg
Definition: MIPatternMatch.h:77
llvm::MIPatternMatch::m_Not
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
Definition: MIPatternMatch.h:591
llvm::MIPatternMatch::OneUse_match::match
bool match(const MachineRegisterInfo &MRI, Register Reg)
Definition: MIPatternMatch.h:38
llvm::MIPatternMatch::mi_match
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
Definition: MIPatternMatch.h:24
llvm::MIPatternMatch::TernaryOp_match
Definition: MIPatternMatch.h:544
llvm::MIPatternMatch::m_BinOp
BinaryOpc_match< LHS, RHS, false > m_BinOp(unsigned Opcode, const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:309
llvm::MIPatternMatch::TernaryOp_match::Src0
Src0Ty Src0
Definition: MIPatternMatch.h:545
llvm::MIPatternMatch::m_GInsertVecElt
TernaryOp_match< Src0Ty, Src1Ty, Src2Ty, TargetOpcode::G_INSERT_VECTOR_ELT > m_GInsertVecElt(const Src0Ty &Src0, const Src1Ty &Src1, const Src2Ty &Src2)
Definition: MIPatternMatch.h:567
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1903
llvm::MIPatternMatch::GFCstAndRegMatch
Definition: MIPatternMatch.h:89
llvm::MIPatternMatch::m_OneUse
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
Definition: MIPatternMatch.h:44
llvm::MIPatternMatch::SpecificConstantMatch
Matcher for a specific constant value.
Definition: MIPatternMatch.h:118
llvm::MIPatternMatch::ConstantMatch::CR
int64_t & CR
Definition: MIPatternMatch.h:63
llvm::MIPatternMatch::And< Pred, Preds... >::And
And(Pred &&p, Preds &&... preds)
Definition: MIPatternMatch.h:165
llvm::MIPatternMatch::CompareOp_match::R
RHS_P R
Definition: MIPatternMatch.h:498
llvm::LLT
Definition: LowLevelTypeImpl.h:40