|
| 1 | +//== llvm/CodeGen/GlobalISel/MachineLegalizeHelper.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 MachineLegalizeHelper 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 | + |
| 24 | +#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" |
| 25 | +#include "llvm/CodeGen/MachineFunctionPass.h" |
| 26 | +#include "llvm/CodeGen/LowLevelType.h" |
| 27 | + |
| 28 | +namespace llvm { |
| 29 | +// Forward declarations. |
| 30 | +class MachineLegalizeInfo; |
| 31 | +class MachineLegalizer; |
| 32 | +class MachineRegisterInfo; |
| 33 | + |
| 34 | +class MachineLegalizeHelper { |
| 35 | +public: |
| 36 | + enum LegalizeResult { |
| 37 | + /// Instruction was already legal and no change was made to the |
| 38 | + /// MachineFunction. |
| 39 | + AlreadyLegal, |
| 40 | + |
| 41 | + /// Instruction has been legalized and the MachineFunction changed. |
| 42 | + Legalized, |
| 43 | + |
| 44 | + /// Some kind of error has occurred and we could not legalize this |
| 45 | + /// instruction. |
| 46 | + UnableToLegalize, |
| 47 | + }; |
| 48 | + |
| 49 | + MachineLegalizeHelper(MachineFunction &MF); |
| 50 | + |
| 51 | + /// Replace \p MI by a sequence of legal instructions that can implement the |
| 52 | + /// same operation. Note that this means \p MI may be deleted, so any iterator |
| 53 | + /// steps should be performed before calling this function. \p Helper should |
| 54 | + /// be initialized to the MachineFunction containing \p MI. |
| 55 | + /// |
| 56 | + /// Considered as an opaque blob, the legal code will use and define the same |
| 57 | + /// registers as \p MI. |
| 58 | + LegalizeResult legalizeInstr(MachineInstr &MI, |
| 59 | + const MachineLegalizer &Legalizer); |
| 60 | + |
| 61 | + /// Legalize an instruction by reducing the width of the underlying scalar |
| 62 | + /// type. |
| 63 | + LegalizeResult narrowScalar(MachineInstr &MI, LLT NarrowTy); |
| 64 | + |
| 65 | + /// Legalize an instruction by performing the operation on a wider scalar type |
| 66 | + /// (for example a 16-bit addition can be safely performed at 32-bits |
| 67 | + /// precision, ignoring the unused bits). |
| 68 | + LegalizeResult widenScalar(MachineInstr &MI, LLT WideTy); |
| 69 | + |
| 70 | + /// Legalize a vector instruction by splitting into multiple components, each |
| 71 | + /// acting on the same scalar type as the original but with fewer elements. |
| 72 | + LegalizeResult fewerElementsVector(MachineInstr &MI, LLT NarrowTy); |
| 73 | + |
| 74 | + /// Legalize a vector instruction by increasing the number of vector elements |
| 75 | + /// involved and ignoring the added elements later. |
| 76 | + LegalizeResult moreElementsVector(MachineInstr &MI, LLT WideTy); |
| 77 | + |
| 78 | +private: |
| 79 | + |
| 80 | + /// Helper function to split a wide generic register into bitwise blocks with |
| 81 | + /// the given Type (which implies the number of blocks needed). The generic |
| 82 | + /// registers created are appended to Ops, starting at bit 0 of Reg. |
| 83 | + void extractParts(unsigned Reg, LLT Ty, int NumParts, |
| 84 | + SmallVectorImpl<unsigned> &Ops); |
| 85 | + |
| 86 | + MachineIRBuilder MIRBuilder; |
| 87 | + MachineRegisterInfo &MRI; |
| 88 | +}; |
| 89 | + |
| 90 | +} // End namespace llvm. |
| 91 | + |
| 92 | +#endif |
0 commit comments