Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.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
14#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h"
15#include "llvm/CodeGen/GlobalISel/Utils.h"
16#include "llvm/CodeGen/MachineInstr.h"
17#include "llvm/CodeGen/MachineOperand.h"
18#include "llvm/CodeGen/MachineRegisterInfo.h"
19
20#define DEBUG_TYPE "gi-match-table-executor"
21
22using namespacellvm;
23
24GIMatchTableExecutor::MatcherState::MatcherState(unsigned MaxRenderers)
25 : Renderers(MaxRenderers) {}
26
27GIMatchTableExecutor::GIMatchTableExecutor() =default;
28
29boolGIMatchTableExecutor::isOperandImmEqual(constMachineOperand &MO,
30 int64_tValue,
31constMachineRegisterInfo &MRI,
32boolSplat) const{
33if (MO.isReg() && MO.getReg()) {
34if (auto VRegVal =getIConstantVRegValWithLookThrough(MO.getReg(),MRI))
35return VRegVal->Value.getSExtValue() ==Value;
36
37if (Splat) {
38if (auto VRegVal =getIConstantSplatVal(MO.getReg(),MRI))
39return VRegVal->getSExtValue() ==Value;
40 }
41 }
42returnfalse;
43}
44
45boolGIMatchTableExecutor::isBaseWithConstantOffset(
46constMachineOperand &Root,constMachineRegisterInfo &MRI) const{
47if (!Root.isReg())
48returnfalse;
49
50MachineInstr *RootI =MRI.getVRegDef(Root.getReg());
51if (RootI->getOpcode() != TargetOpcode::G_PTR_ADD)
52returnfalse;
53
54MachineOperand &RHS = RootI->getOperand(2);
55MachineInstr *RHSI =MRI.getVRegDef(RHS.getReg());
56if (RHSI->getOpcode() != TargetOpcode::G_CONSTANT)
57returnfalse;
58
59returntrue;
60}
61
62boolGIMatchTableExecutor::isObviouslySafeToFold(MachineInstr &MI,
63MachineInstr &IntoMI) const{
64auto IntoMIIter = IntoMI.getIterator();
65
66// Immediate neighbours are already folded.
67if (MI.getParent() == IntoMI.getParent() &&
68 std::next(MI.getIterator()) == IntoMIIter)
69returntrue;
70
71// Convergent instructions cannot be moved in the CFG.
72if (MI.isConvergent() &&MI.getParent() != IntoMI.getParent())
73returnfalse;
74
75if (MI.isLoadFoldBarrier())
76returnfalse;
77
78// If the load is simple, check instructions between MI and IntoMI
79if (MI.mayLoad() &&MI.getParent() == IntoMI.getParent()) {
80if (MI.memoperands_empty())
81returnfalse;
82auto &MMO = **(MI.memoperands_begin());
83if (MMO.isAtomic() || MMO.isVolatile())
84returnfalse;
85
86// Ensure instructions between MI and IntoMI are not affected when combined
87unsigned Iter = 0;
88constunsigned MaxIter = 20;
89for (auto &CurrMI :
90instructionsWithoutDebug(MI.getIterator(), IntoMI.getIterator())) {
91if (CurrMI.isLoadFoldBarrier())
92returnfalse;
93
94if (Iter++ == MaxIter)
95returnfalse;
96 }
97
98returntrue;
99 }
100
101return !MI.mayLoad();
102}
MRI
unsigned const MachineRegisterInfo * MRI
Definition:AArch64AdvSIMDScalarPass.cpp:105
Utils.h
GIMatchTableExecutor.h
MI
IRTranslator LLVM IR MI
Definition:IRTranslator.cpp:112
MachineInstr.h
MachineOperand.h
MachineRegisterInfo.h
RHS
Value * RHS
Definition:X86PartialReduction.cpp:74
llvm::GIMatchTableExecutor::GIMatchTableExecutor
GIMatchTableExecutor()
llvm::GIMatchTableExecutor::isBaseWithConstantOffset
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.
Definition:GIMatchTableExecutor.cpp:45
llvm::GIMatchTableExecutor::isOperandImmEqual
bool isOperandImmEqual(const MachineOperand &MO, int64_t Value, const MachineRegisterInfo &MRI, bool Splat=false) const
Definition:GIMatchTableExecutor.cpp:29
llvm::GIMatchTableExecutor::isObviouslySafeToFold
bool isObviouslySafeToFold(MachineInstr &MI, MachineInstr &IntoMI) const
Return true if MI can obviously be folded into IntoMI.
Definition:GIMatchTableExecutor.cpp:62
llvm::MachineInstr
Representation of each machine instruction.
Definition:MachineInstr.h:71
llvm::MachineInstr::getOpcode
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition:MachineInstr.h:577
llvm::MachineInstr::getParent
const MachineBasicBlock * getParent() const
Definition:MachineInstr.h:349
llvm::MachineInstr::getOperand
const MachineOperand & getOperand(unsigned i) const
Definition:MachineInstr.h:587
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition:MachineOperand.h:48
llvm::MachineOperand::isReg
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Definition:MachineOperand.h:329
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition:MachineOperand.h:369
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition:MachineRegisterInfo.h:51
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition:ilist_node.h:132
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::getIConstantSplatVal
std::optional< APInt > getIConstantSplatVal(const Register Reg, const MachineRegisterInfo &MRI)
Definition:Utils.cpp:1400
llvm::ComplexDeinterleavingOperation::Splat
@ Splat
llvm::instructionsWithoutDebug
auto instructionsWithoutDebug(IterT It, IterT End, bool SkipPseudoOp=true)
Construct a range iterator which begins at It and moves forwards until End is reached,...
Definition:MachineBasicBlock.h:1454
llvm::getIConstantVRegValWithLookThrough
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:433
llvm::GIMatchTableExecutor::MatcherState::MatcherState
MatcherState(unsigned MaxRenderers)
Definition:GIMatchTableExecutor.cpp:24

Generated on Fri Jul 18 2025 10:35:35 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp