LLVM  14.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 
22 #include "llvm/MC/MCInstrDesc.h"
23 #include "llvm/Support/Debug.h"
25 #include <cassert>
26 
27 #define DEBUG_TYPE "instructionselector"
28 
29 using namespace llvm;
30 
32  : Renderers(MaxRenderers), MIs() {}
33 
35 
37  const MachineOperand &MO, int64_t Value,
38  const MachineRegisterInfo &MRI) const {
39  if (MO.isReg() && MO.getReg())
40  if (auto VRegVal = getIConstantVRegValWithLookThrough(MO.getReg(), MRI))
41  return VRegVal->Value.getSExtValue() == Value;
42  return false;
43 }
44 
46  const MachineOperand &Root, const MachineRegisterInfo &MRI) const {
47  if (!Root.isReg())
48  return false;
49 
50  MachineInstr *RootI = MRI.getVRegDef(Root.getReg());
51  if (RootI->getOpcode() != TargetOpcode::G_PTR_ADD)
52  return false;
53 
54  MachineOperand &RHS = RootI->getOperand(2);
55  MachineInstr *RHSI = MRI.getVRegDef(RHS.getReg());
56  if (RHSI->getOpcode() != TargetOpcode::G_CONSTANT)
57  return false;
58 
59  return true;
60 }
61 
63  MachineInstr &IntoMI) const {
64  // Immediate neighbours are already folded.
65  if (MI.getParent() == IntoMI.getParent() &&
66  std::next(MI.getIterator()) == IntoMI.getIterator())
67  return true;
68 
69  return !MI.mayLoadOrStore() && !MI.mayRaiseFPException() &&
70  !MI.hasUnmodeledSideEffects() && MI.implicit_operands().empty();
71 }
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
MachineInstr.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
MCInstrDesc.h
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
MachineBasicBlock.h
MachineRegisterInfo.h
llvm::MachineInstr::getOperand
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:499
Utils.h
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
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:400
InstructionSelector.h
llvm::InstructionSelector::isOperandImmEqual
bool isOperandImmEqual(const MachineOperand &MO, int64_t Value, const MachineRegisterInfo &MRI) const
Definition: InstructionSelector.cpp:36
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::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:360
llvm::InstructionSelector::MatcherState::MatcherState
MatcherState(unsigned MaxRenderers)
Definition: InstructionSelector.cpp:31
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:392
llvm::MachineInstr::getOpcode
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:489
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:45
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition: ilist_node.h:81
llvm::MachineInstr::getParent
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:286
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:62
MachineOperand.h
raw_ostream.h
MachineFunction.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
TargetRegisterInfo.h
Debug.h