LLVM  8.0.1
InstructionSelector.cpp
Go to the documentation of this file.
1 //===- llvm/CodeGen/GlobalISel/InstructionSelector.cpp --------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// This file implements the InstructionSelector class.
12 //
13 //===----------------------------------------------------------------------===//
14 
23 #include "llvm/MC/MCInstrDesc.h"
24 #include "llvm/Support/Debug.h"
26 #include <cassert>
27 
28 #define DEBUG_TYPE "instructionselector"
29 
30 using namespace llvm;
31 
33  : Renderers(MaxRenderers), MIs() {}
34 
36 
38  MachineInstr &I, unsigned OpIdx, const TargetRegisterClass &RC,
40  const RegisterBankInfo &RBI) const {
41  MachineBasicBlock &MBB = *I.getParent();
42  MachineFunction &MF = *MBB.getParent();
44 
45  return
46  constrainRegToClass(MRI, TII, RBI, I, I.getOperand(OpIdx).getReg(), RC);
47 }
48 
50  const MachineOperand &MO, int64_t Value,
51  const MachineRegisterInfo &MRI) const {
52  if (MO.isReg() && MO.getReg())
53  if (auto VRegVal = getConstantVRegVal(MO.getReg(), MRI))
54  return *VRegVal == Value;
55  return false;
56 }
57 
59  const MachineOperand &Root, const MachineRegisterInfo &MRI) const {
60  if (!Root.isReg())
61  return false;
62 
63  MachineInstr *RootI = MRI.getVRegDef(Root.getReg());
64  if (RootI->getOpcode() != TargetOpcode::G_GEP)
65  return false;
66 
67  MachineOperand &RHS = RootI->getOperand(2);
68  MachineInstr *RHSI = MRI.getVRegDef(RHS.getReg());
69  if (RHSI->getOpcode() != TargetOpcode::G_CONSTANT)
70  return false;
71 
72  return true;
73 }
74 
76  MachineInstr &IntoMI) const {
77  // Immediate neighbours are already folded.
78  if (MI.getParent() == IntoMI.getParent() &&
79  std::next(MI.getIterator()) == IntoMI.getIterator())
80  return true;
81 
82  return !MI.mayLoadOrStore() && !MI.hasUnmodeledSideEffects() &&
84 }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
unsigned getReg() const
getReg - Returns the register number.
bool constrainOperandRegToRegClass(MachineInstr &I, unsigned OpIdx, const TargetRegisterClass &RC, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
Constrain a register operand of an instruction I to a specified register class.
bool mayLoadOrStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read or modify memory.
Definition: MachineInstr.h:830
unsigned const TargetRegisterInfo * TRI
Holds all the information related to register banks.
bool isBaseWithConstantOffset(const MachineOperand &Root, const MachineRegisterInfo &MRI) const
Return true if the specified operand is a G_GEP with a G_CONSTANT on the right-hand side...
const HexagonInstrInfo * TII
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:409
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
TargetInstrInfo - Interface to description of machine instruction set.
unsigned const MachineRegisterInfo * MRI
self_iterator getIterator()
Definition: ilist_node.h:82
unsigned constrainRegToClass(MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, unsigned Reg, const TargetRegisterClass &RegClass)
Try to constrain Reg to the specified register class.
Definition: Utils.cpp:31
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Definition: STLExtras.h:210
bool isOperandImmEqual(const MachineOperand &MO, int64_t Value, const MachineRegisterInfo &MRI) const
MachineOperand class - Representation of each machine instruction operand.
iterator_range< mop_iterator > implicit_operands()
Definition: MachineInstr.h:473
Optional< int64_t > getConstantVRegVal(unsigned VReg, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:185
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:254
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Definition: MachineInstr.h:64
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
#define I(x, y, z)
Definition: MD5.cpp:58
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LLVM Value Representation.
Definition: Value.h:73
bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore...
IRTranslator LLVM IR MI
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:414
bool isObviouslySafeToFold(MachineInstr &MI, MachineInstr &IntoMI) const
Return true if MI can obviously be folded into IntoMI.