Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h
Line
Count
Source
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
24
#include "llvm/CodeGen/GlobalISel/CallLowering.h"
25
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
26
#include "llvm/CodeGen/LowLevelType.h"
27
#include "llvm/CodeGen/MachineFunctionPass.h"
28
#include "llvm/CodeGen/RuntimeLibcalls.h"
29
30
namespace llvm {
31
// Forward declarations.
32
class LegalizerInfo;
33
class Legalizer;
34
class MachineRegisterInfo;
35
36
class LegalizerHelper {
37
public:
38
  enum LegalizeResult {
39
    /// Instruction was already legal and no change was made to the
40
    /// MachineFunction.
41
    AlreadyLegal,
42
43
    /// Instruction has been legalized and the MachineFunction changed.
44
    Legalized,
45
46
    /// Some kind of error has occurred and we could not legalize this
47
    /// instruction.
48
    UnableToLegalize,
49
  };
50
51
  LegalizerHelper(MachineFunction &MF);
52
  LegalizerHelper(MachineFunction &MF, const LegalizerInfo &LI);
53
54
  /// Replace \p MI by a sequence of legal instructions that can implement the
55
  /// same operation. Note that this means \p MI may be deleted, so any iterator
56
  /// steps should be performed before calling this function. \p Helper should
57
  /// be initialized to the MachineFunction containing \p MI.
58
  ///
59
  /// Considered as an opaque blob, the legal code will use and define the same
60
  /// registers as \p MI.
61
  LegalizeResult legalizeInstrStep(MachineInstr &MI);
62
63
  /// Legalize an instruction by emiting a runtime library call instead.
64
  LegalizeResult libcall(MachineInstr &MI);
65
66
  /// Legalize an instruction by reducing the width of the underlying scalar
67
  /// type.
68
  LegalizeResult narrowScalar(MachineInstr &MI, unsigned TypeIdx, LLT NarrowTy);
69
70
  /// Legalize an instruction by performing the operation on a wider scalar type
71
  /// (for example a 16-bit addition can be safely performed at 32-bits
72
  /// precision, ignoring the unused bits).
73
  LegalizeResult widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy);
74
75
  /// Legalize an instruction by splitting it into simpler parts, hopefully
76
  /// understood by the target.
77
  LegalizeResult lower(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
78
79
  /// Legalize a vector instruction by splitting into multiple components, each
80
  /// acting on the same scalar type as the original but with fewer elements.
81
  LegalizeResult fewerElementsVector(MachineInstr &MI, unsigned TypeIdx,
82
                                     LLT NarrowTy);
83
84
  /// Legalize a vector instruction by increasing the number of vector elements
85
  /// involved and ignoring the added elements later.
86
  LegalizeResult moreElementsVector(MachineInstr &MI, unsigned TypeIdx,
87
                                    LLT WideTy);
88
89
  /// Expose MIRBuilder so clients can set their own RecordInsertInstruction
90
  /// functions
91
  MachineIRBuilder MIRBuilder;
92
93
  /// Expose LegalizerInfo so the clients can re-use.
94
234k
  const LegalizerInfo &getLegalizerInfo() const { return LI; }
95
96
private:
97
  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
98
  /// Use by extending the operand's type to \p WideTy using the specified \p
99
  /// ExtOpcode for the extension instruction, and replacing the vreg of the
100
  /// operand in place.
101
  void widenScalarSrc(MachineInstr &MI, LLT WideTy, unsigned OpIdx,
102
                      unsigned ExtOpcode);
103
104
  /// Legalize a single operand \p OpIdx of the machine instruction \p MI as a
105
  /// Def by extending the operand's type to \p WideTy and truncating it back
106
  /// with the \p TruncOpcode, and replacing the vreg of the operand in place.
107
  void widenScalarDst(MachineInstr &MI, LLT WideTy, unsigned OpIdx = 0,
108
                      unsigned TruncOpcode = TargetOpcode::G_TRUNC);
109
110
  /// Helper function to split a wide generic register into bitwise blocks with
111
  /// the given Type (which implies the number of blocks needed). The generic
112
  /// registers created are appended to Ops, starting at bit 0 of Reg.
113
  void extractParts(unsigned Reg, LLT Ty, int NumParts,
114
                    SmallVectorImpl<unsigned> &VRegs);
115
116
  LegalizeResult lowerBitCount(MachineInstr &MI, unsigned TypeIdx, LLT Ty);
117
118
  MachineRegisterInfo &MRI;
119
  const LegalizerInfo &LI;
120
};
121
122
/// Helper function that creates the given libcall.
123
LegalizerHelper::LegalizeResult
124
createLibcall(MachineIRBuilder &MIRBuilder, RTLIB::Libcall Libcall,
125
              const CallLowering::ArgInfo &Result,
126
              ArrayRef<CallLowering::ArgInfo> Args);
127
128
} // End namespace llvm.
129
130
#endif