LLVM  15.0.0git
InstructionSelector.cpp
Go to the documentation of this file.
1 //===- llvm/CodeGen/GlobalISel/InstructionSelector.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 InstructionSelector class.
11 //
12 //===----------------------------------------------------------------------===//
13 
19 
20 #define DEBUG_TYPE "instructionselector"
21 
22 using namespace llvm;
23 
25  : Renderers(MaxRenderers) {}
26 
28 
30  const MachineOperand &MO, int64_t Value,
31  const MachineRegisterInfo &MRI) const {
32  if (MO.isReg() && MO.getReg())
33  if (auto VRegVal = getIConstantVRegValWithLookThrough(MO.getReg(), MRI))
34  return VRegVal->Value.getSExtValue() == Value;
35  return false;
36 }
37 
39  const MachineOperand &Root, const MachineRegisterInfo &MRI) const {
40  if (!Root.isReg())
41  return false;
42 
43  MachineInstr *RootI = MRI.getVRegDef(Root.getReg());
44  if (RootI->getOpcode() != TargetOpcode::G_PTR_ADD)
45  return false;
46 
47  MachineOperand &RHS = RootI->getOperand(2);
48  MachineInstr *RHSI = MRI.getVRegDef(RHS.getReg());
49  if (RHSI->getOpcode() != TargetOpcode::G_CONSTANT)
50  return false;
51 
52  return true;
53 }
54 
56  MachineInstr &IntoMI) const {
57  // Immediate neighbours are already folded.
58  if (MI.getParent() == IntoMI.getParent() &&
59  std::next(MI.getIterator()) == IntoMI.getIterator())
60  return true;
61 
62  return !MI.mayLoadOrStore() && !MI.mayRaiseFPException() &&
63  !MI.hasUnmodeledSideEffects() && MI.implicit_operands().empty();
64 }
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:104
MachineInstr.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:50
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
MachineRegisterInfo.h
llvm::MachineInstr::getOperand
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:501
Utils.h
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:48
llvm::InstructionSelector::InstructionSelector
InstructionSelector()
llvm::MachineRegisterInfo::getVRegDef
MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
Definition: MachineRegisterInfo.cpp:396
InstructionSelector.h
llvm::InstructionSelector::isOperandImmEqual
bool isOperandImmEqual(const MachineOperand &MO, int64_t Value, const MachineRegisterInfo &MRI) const
Definition: InstructionSelector.cpp:29
llvm::MachineOperand::isReg
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Definition: MachineOperand.h:320
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:359
llvm::InstructionSelector::MatcherState::MatcherState
MatcherState(unsigned MaxRenderers)
Definition: InstructionSelector.cpp:24
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:408
llvm::MachineInstr::getOpcode
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:491
llvm::InstructionSelector::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: InstructionSelector.cpp:38
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition: ilist_node.h:82
llvm::MachineInstr::getParent
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:288
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::InstructionSelector::isObviouslySafeToFold
bool isObviouslySafeToFold(MachineInstr &MI, MachineInstr &IntoMI) const
Return true if MI can obviously be folded into IntoMI.
Definition: InstructionSelector.cpp:55
MachineOperand.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74