Legalizer.h revision 360784
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_LEGALIZEMACHINEIRPASS_H
21#define LLVM_CODEGEN_GLOBALISEL_LEGALIZEMACHINEIRPASS_H
22
23#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
24#include "llvm/CodeGen/MachineFunctionPass.h"
25
26namespace llvm {
27
28class MachineRegisterInfo;
29
30class Legalizer : public MachineFunctionPass {
31public:
32  static char ID;
33
34  struct MFResult {
35    bool Changed;
36    const MachineInstr *FailedOn;
37  };
38
39private:
40  /// Initialize the field members using \p MF.
41  void init(MachineFunction &MF);
42
43public:
44  // Ctor, nothing fancy.
45  Legalizer();
46
47  StringRef getPassName() const override { return "Legalizer"; }
48
49  void getAnalysisUsage(AnalysisUsage &AU) const override;
50
51  MachineFunctionProperties getRequiredProperties() const override {
52    return MachineFunctionProperties().set(
53        MachineFunctionProperties::Property::IsSSA);
54  }
55
56  MachineFunctionProperties getSetProperties() const override {
57    return MachineFunctionProperties().set(
58        MachineFunctionProperties::Property::Legalized);
59  }
60
61  MachineFunctionProperties getClearedProperties() const override {
62    return MachineFunctionProperties().set(
63        MachineFunctionProperties::Property::NoPHIs);
64  }
65
66  bool combineExtracts(MachineInstr &MI, MachineRegisterInfo &MRI,
67                       const TargetInstrInfo &TII);
68
69  bool runOnMachineFunction(MachineFunction &MF) override;
70
71  static MFResult
72  legalizeMachineFunction(MachineFunction &MF, const LegalizerInfo &LI,
73                          ArrayRef<GISelChangeObserver *> AuxObservers,
74                          MachineIRBuilder &MIRBuilder);
75};
76} // End namespace llvm.
77
78#endif
79