1//== llvm/CodeGen/GlobalISel/Legalizer.h ---------------- -*- C++ -*-==// 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 A pass to convert the target-illegal operations created by IR -> MIR 10/// translation into ones the target expects to be able to select. This may 11/// occur in multiple phases, for example G_ADD <2 x i8> -> G_ADD <2 x i16> -> 12/// G_ADD <4 x i16>. 13/// 14/// The LegalizeHelper class is where most of the work happens, and is designed 15/// to be callable from other passes that find themselves with an illegal 16/// instruction. 17// 18//===----------------------------------------------------------------------===// 19 20#ifndef LLVM_CODEGEN_GLOBALISEL_LEGALIZER_H 21#define LLVM_CODEGEN_GLOBALISEL_LEGALIZER_H 22 23#include "llvm/ADT/ArrayRef.h" 24#include "llvm/ADT/StringRef.h" 25#include "llvm/CodeGen/GlobalISel/GISelKnownBits.h" 26#include "llvm/CodeGen/MachineFunction.h" 27#include "llvm/CodeGen/MachineFunctionPass.h" 28 29namespace llvm { 30 31class LegalizerInfo; 32class MachineIRBuilder; 33class MachineInstr; 34class GISelChangeObserver; 35class LostDebugLocObserver; 36 37class Legalizer : public MachineFunctionPass { 38public: 39 static char ID; 40 41 struct MFResult { 42 bool Changed; 43 const MachineInstr *FailedOn; 44 }; 45 46private: 47 /// Initialize the field members using \p MF. 48 void init(MachineFunction &MF); 49 50public: 51 // Ctor, nothing fancy. 52 Legalizer(); 53 54 StringRef getPassName() const override { return "Legalizer"; } 55 56 void getAnalysisUsage(AnalysisUsage &AU) const override; 57 58 MachineFunctionProperties getRequiredProperties() const override { 59 return MachineFunctionProperties().set( 60 MachineFunctionProperties::Property::IsSSA); 61 } 62 63 MachineFunctionProperties getSetProperties() const override { 64 return MachineFunctionProperties().set( 65 MachineFunctionProperties::Property::Legalized); 66 } 67 68 MachineFunctionProperties getClearedProperties() const override { 69 return MachineFunctionProperties() 70 .set(MachineFunctionProperties::Property::NoPHIs) 71 .set(MachineFunctionProperties::Property::NoVRegs); 72 } 73 74 bool runOnMachineFunction(MachineFunction &MF) override; 75 76 static MFResult 77 legalizeMachineFunction(MachineFunction &MF, const LegalizerInfo &LI, 78 ArrayRef<GISelChangeObserver *> AuxObservers, 79 LostDebugLocObserver &LocObserver, 80 MachineIRBuilder &MIRBuilder, GISelKnownBits *KB); 81}; 82} // End namespace llvm. 83 84#endif 85