LLVM  7.0.0
LegalizerHelper.h
Go to the documentation of this file.
1 //== llvm/CodeGen/GlobalISel/LegalizerHelper.h ---------------- -*- C++ -*-==//
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 A pass to convert the target-illegal operations created by IR -> MIR
11 /// translation into ones the target expects to be able to select. This may
12 /// occur in multiple phases, for example G_ADD <2 x i8> -> G_ADD <2 x i16> ->
13 /// G_ADD <4 x i16>.
14 ///
15 /// The LegalizerHelper class is where most of the work happens, and is
16 /// designed to be callable from other passes that find themselves with an
17 /// illegal instruction.
18 //
19 //===----------------------------------------------------------------------===//
20 
21 #ifndef LLVM_CODEGEN_GLOBALISEL_MACHINELEGALIZEHELPER_H
22 #define LLVM_CODEGEN_GLOBALISEL_MACHINELEGALIZEHELPER_H
23 
29 
30 namespace llvm {
31 // Forward declarations.
32 class LegalizerInfo;
33 class Legalizer;
34 class MachineRegisterInfo;
35 
37 public:
39  /// Instruction was already legal and no change was made to the
40  /// MachineFunction.
42 
43  /// Instruction has been legalized and the MachineFunction changed.
45 
46  /// Some kind of error has occurred and we could not legalize this
47  /// instruction.
49  };
50 
52 
53  /// Replace \p MI by a sequence of legal instructions that can implement the
54  /// same operation. Note that this means \p MI may be deleted, so any iterator
55  /// steps should be performed before calling this function. \p Helper should
56  /// be initialized to the MachineFunction containing \p MI.
57  ///
58  /// Considered as an opaque blob, the legal code will use and define the same
59  /// registers as \p MI.
61 
62  /// Legalize an instruction by emiting a runtime library call instead.
64 
65  /// Legalize an instruction by reducing the width of the underlying scalar
66  /// type.
67  LegalizeResult narrowScalar(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy);
68 
69  /// Legalize an instruction by performing the operation on a wider scalar type
70  /// (for example a 16-bit addition can be safely performed at 32-bits
71  /// precision, ignoring the unused bits).
72  LegalizeResult widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
73 
74  /// Legalize an instruction by splitting it into simpler parts, hopefully
75  /// understood by the target.
76  LegalizeResult lower(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
77 
78  /// Legalize a vector instruction by splitting into multiple components, each
79  /// acting on the same scalar type as the original but with fewer elements.
81  LLT NarrowTy);
82 
83  /// Legalize a vector instruction by increasing the number of vector elements
84  /// involved and ignoring the added elements later.
86  LLT WideTy);
87 
88  /// Expose MIRBuilder so clients can set their own RecordInsertInstruction
89  /// functions
91 
92  /// Expose LegalizerInfo so the clients can re-use.
93  const LegalizerInfo &getLegalizerInfo() const { return LI; }
94 
95 private:
96  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
97  /// Use by extending the operand's type to \p WideTy using the specified \p
98  /// ExtOpcode for the extension instruction, and replacing the vreg of the
99  /// operand in place.
100  void widenScalarSrc(MachineInstr &MI, LLT WideTy, unsigned OpIdx,
101  unsigned ExtOpcode);
102 
103  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
104  /// Def by extending the operand's type to \p WideTy and truncating it back
105  /// with the \p TruncOpcode, and replacing the vreg of the operand in place.
106  void widenScalarDst(MachineInstr &MI, LLT WideTy, unsigned OpIdx = 0,
107  unsigned TruncOpcode = TargetOpcode::G_TRUNC);
108 
109  /// Helper function to split a wide generic register into bitwise blocks with
110  /// the given Type (which implies the number of blocks needed). The generic
111  /// registers created are appended to Ops, starting at bit 0 of Reg.
112  void extractParts(unsigned Reg, LLT Ty, int NumParts,
114 
115  MachineRegisterInfo &MRI;
116  const LegalizerInfo &LI;
117 };
118 
119 /// Helper function that creates the given libcall.
124 
125 } // End namespace llvm.
126 
127 #endif
const LegalizerInfo & getLegalizerInfo() const
Expose LegalizerInfo so the clients can re-use.
MachineIRBuilder MIRBuilder
Expose MIRBuilder so clients can set their own RecordInsertInstruction functions. ...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
unsigned Reg
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit...
static const MCPhysReg VRegs[32]
LegalizerHelper(MachineFunction &MF)
LegalizeResult widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy)
Legalize an instruction by performing the operation on a wider scalar type (for example a 16-bit addi...
LegalizerHelper::LegalizeResult createLibcall(MachineIRBuilder &MIRBuilder, RTLIB::Libcall Libcall, const CallLowering::ArgInfo &Result, ArrayRef< CallLowering::ArgInfo > Args)
Helper function that creates the given libcall.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
LegalizeResult legalizeInstrStep(MachineInstr &MI)
Replace MI by a sequence of legal instructions that can implement the same operation.
Some kind of error has occurred and we could not legalize this instruction.
Instruction was already legal and no change was made to the MachineFunction.
LegalizeResult moreElementsVector(MachineInstr &MI, unsigned TypeIdx, LLT WideTy)
Legalize a vector instruction by increasing the number of vector elements involved and ignoring the a...
LegalizeResult libcall(MachineInstr &MI)
Legalize an instruction by emiting a runtime library call instead.
LegalizeResult lower(MachineInstr &MI, unsigned TypeIdx, LLT Ty)
Legalize an instruction by splitting it into simpler parts, hopefully understood by the target...
LegalizeResult fewerElementsVector(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Legalize a vector instruction by splitting into multiple components, each acting on the same scalar t...
This file declares the MachineIRBuilder class.
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:60
Instruction has been legalized and the MachineFunction changed.
LegalizeResult narrowScalar(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy)
Legalize an instruction by reducing the width of the underlying scalar type.
This file describes how to lower LLVM calls to machine code calls.
IRTranslator LLVM IR MI
constexpr char Args[]
Key for Kernel::Metadata::mArgs.