LLVM 24.0.0git
GIMatchTableExecutor.cpp
Go to the documentation of this file.
1//===- llvm/CodeGen/GlobalISel/GIMatchTableExecutor.cpp -------------------===//
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//
9/// \file
10/// This file implements the GIMatchTableExecutor class.
11//
12//===----------------------------------------------------------------------===//
13
20
21#define DEBUG_TYPE "gi-match-table-executor"
22
23using namespace llvm;
24using namespace MIPatternMatch;
25
27 : Renderers(MaxRenderers) {}
28
30
32 int64_t Value,
33 const MachineRegisterInfo &MRI,
34 bool Splat) const {
35 if (MO.isReg() && MO.getReg()) {
36 if (auto VRegVal = getIConstantVRegValWithLookThrough(MO.getReg(), MRI))
37 return VRegVal->Value.getSExtValue() == Value;
38
39 if (Splat) {
40 if (auto VRegVal = getIConstantSplatVal(MO.getReg(), MRI))
41 return VRegVal->getSExtValue() == Value;
42 }
43 }
44 return false;
45}
46
48 const MachineOperand &Root, const MachineRegisterInfo &MRI) const {
49 if (!Root.isReg())
50 return false;
51
52 GConstant *RHSI;
53 return mi_match(Root.getReg(), MRI, m_GPtrAdd(m_Reg(), m_GConstant(RHSI)));
54}
55
57 MachineInstr &IntoMI) const {
58 auto IntoMIIter = IntoMI.getIterator();
59
60 // Immediate neighbours are already folded.
61 if (MI.getParent() == IntoMI.getParent() &&
62 std::next(MI.getIterator()) == IntoMIIter)
63 return true;
64
65 // Convergent instructions cannot be moved in the CFG.
66 if (MI.isConvergent() && MI.getParent() != IntoMI.getParent())
67 return false;
68
69 if (MI.isLoadFoldBarrier())
70 return false;
71
72 // If the load is simple, check instructions between MI and IntoMI
73 if (MI.mayLoad() && MI.getParent() == IntoMI.getParent()) {
74 if (MI.memoperands_empty())
75 return false;
76 auto &MMO = **(MI.memoperands_begin());
77 if (MMO.isAtomic() || MMO.isVolatile())
78 return false;
79
80 // Ensure instructions between MI and IntoMI are not affected when combined
81 unsigned Iter = 0;
82 const unsigned MaxIter = 20;
83 for (auto &CurrMI :
84 instructionsWithoutDebug(MI.getIterator(), IntoMI.getIterator())) {
85 if (CurrMI.isLoadFoldBarrier())
86 return false;
87
88 if (Iter++ == MaxIter)
89 return false;
90 }
91
92 return true;
93 }
94
95 return !MI.mayLoad();
96}
IRTranslator LLVM IR MI
Contains matchers for matching SSA Machine Instructions.
Represents a G_CONSTANT.
LLVM_ABI bool isBaseWithConstantOffset(const MachineOperand &Root, const MachineRegisterInfo &MRI) const
Return true if the specified operand is a G_PTR_ADD with a G_CONSTANT on the right-hand side.
LLVM_ABI bool isOperandImmEqual(const MachineOperand &MO, int64_t Value, const MachineRegisterInfo &MRI, bool Splat=false) const
LLVM_ABI bool isObviouslySafeToFold(MachineInstr &MI, MachineInstr &IntoMI) const
Return true if MI can obviously be folded into IntoMI.
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM Value Representation.
Definition Value.h:75
self_iterator getIterator()
Definition ilist_node.h:123
operand_type_match m_Reg()
GInstrBind< GConstant > m_GConstant(GConstant *&Inst)
Match a literal G_CONSTANT instruction (no look-through of splats or copies).
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
BinaryOp_match< LHS, RHS, TargetOpcode::G_PTR_ADD, false > m_GPtrAdd(const LHS &L, const RHS &R)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::optional< APInt > getIConstantSplatVal(const Register Reg, const MachineRegisterInfo &MRI)
Definition Utils.cpp:1394
auto instructionsWithoutDebug(IterT It, IterT End, bool SkipPseudoOp=true)
Construct a range iterator which begins at It and moves forwards until End is reached,...
LLVM_ABI std::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:436
LLVM_ABI MatcherState(unsigned MaxRenderers)
std::vector< ComplexRendererFns::value_type > Renderers