1 //===- MipsLegalizerInfo.cpp ------------------------------------*- 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 /// \file
9 /// This file implements the targeting of the Machinelegalizer class for Mips.
10 /// \todo This should be generated by TableGen.
11 //===----------------------------------------------------------------------===//
12 
13 #include "MipsLegalizerInfo.h"
14 #include "MipsTargetMachine.h"
15 #include "llvm/CodeGen/GlobalISel/LegalizerHelper.h"
16 
17 using namespace llvm;
18 
19 MipsLegalizerInfo::MipsLegalizerInfo(const MipsSubtarget &ST) {
20   using namespace TargetOpcode;
21 
22   const LLT s1 = LLT::scalar(1);
23   const LLT s32 = LLT::scalar(32);
24   const LLT s64 = LLT::scalar(64);
25   const LLT p0 = LLT::pointer(0, 32);
26 
27   getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL})
28       .legalFor({s32})
29       .clampScalar(0, s32, s32);
30 
31   getActionDefinitionsBuilder({G_UADDO, G_UADDE, G_USUBO, G_USUBE, G_UMULO})
32       .lowerFor({{s32, s1}});
33 
34   getActionDefinitionsBuilder(G_UMULH)
35       .legalFor({s32})
36       .maxScalar(0, s32);
37 
38   getActionDefinitionsBuilder({G_LOAD, G_STORE})
39       .legalForTypesWithMemDesc({{s32, p0, 8, 8},
40                                  {s32, p0, 16, 8},
41                                  {s32, p0, 32, 8},
42                                  {s64, p0, 64, 8},
43                                  {p0, p0, 32, 8}})
44       .minScalar(0, s32);
45 
46   getActionDefinitionsBuilder(G_UNMERGE_VALUES)
47      .legalFor({{s32, s64}});
48 
49   getActionDefinitionsBuilder(G_MERGE_VALUES)
50      .legalFor({{s64, s32}});
51 
52   getActionDefinitionsBuilder({G_ZEXTLOAD, G_SEXTLOAD})
53     .legalForTypesWithMemDesc({{s32, p0, 8, 8},
54                                {s32, p0, 16, 8}})
55       .minScalar(0, s32);
56 
57   getActionDefinitionsBuilder(G_SELECT)
58       .legalForCartesianProduct({p0, s32, s64}, {s32})
59       .minScalar(0, s32)
60       .minScalar(1, s32);
61 
62   getActionDefinitionsBuilder(G_BRCOND)
63       .legalFor({s32})
64       .minScalar(0, s32);
65 
66   getActionDefinitionsBuilder(G_PHI)
67       .legalFor({p0, s32, s64})
68       .minScalar(0, s32);
69 
70   getActionDefinitionsBuilder({G_AND, G_OR, G_XOR})
71       .legalFor({s32})
72       .clampScalar(0, s32, s32);
73 
74   getActionDefinitionsBuilder({G_SDIV, G_SREM, G_UREM, G_UDIV})
75       .legalFor({s32})
76       .minScalar(0, s32)
77       .libcallFor({s64});
78 
79   getActionDefinitionsBuilder({G_SHL, G_ASHR, G_LSHR})
80     .legalFor({s32, s32})
81     .minScalar(1, s32);
82 
83   getActionDefinitionsBuilder(G_ICMP)
84       .legalFor({{s32, s32}})
85       .minScalar(0, s32);
86 
87   getActionDefinitionsBuilder(G_CONSTANT)
88       .legalFor({s32})
89       .clampScalar(0, s32, s32);
90 
91   getActionDefinitionsBuilder(G_GEP)
92       .legalFor({{p0, s32}});
93 
94   getActionDefinitionsBuilder(G_FRAME_INDEX)
95       .legalFor({p0});
96 
97   getActionDefinitionsBuilder(G_GLOBAL_VALUE)
98       .legalFor({p0});
99 
100   // FP instructions
101   getActionDefinitionsBuilder(G_FCONSTANT)
102       .legalFor({s32, s64});
103 
104   getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FABS, G_FSQRT})
105       .legalFor({s32, s64});
106 
107   getActionDefinitionsBuilder(G_FCMP)
108       .legalFor({{s32, s32}, {s32, s64}})
109       .minScalar(0, s32);
110 
111   getActionDefinitionsBuilder({G_FCEIL, G_FFLOOR})
112       .libcallFor({s32, s64});
113 
114   getActionDefinitionsBuilder(G_FPEXT)
115       .legalFor({{s64, s32}});
116 
117   getActionDefinitionsBuilder(G_FPTRUNC)
118       .legalFor({{s32, s64}});
119 
120   // FP to int conversion instructions
121   getActionDefinitionsBuilder(G_FPTOSI)
122       .legalForCartesianProduct({s32}, {s64, s32})
123       .libcallForCartesianProduct({s64}, {s64, s32})
124       .minScalar(0, s32);
125 
126   getActionDefinitionsBuilder(G_FPTOUI)
127       .libcallForCartesianProduct({s64}, {s64, s32})
128       .minScalar(0, s32);
129 
130   // Int to FP conversion instructions
131   getActionDefinitionsBuilder(G_SITOFP)
132       .legalForCartesianProduct({s64, s32}, {s32})
133       .libcallForCartesianProduct({s64, s32}, {s64})
134       .minScalar(1, s32);
135 
136   getActionDefinitionsBuilder(G_UITOFP)
137       .libcallForCartesianProduct({s64, s32}, {s64})
138       .minScalar(1, s32);
139 
140   computeTables();
141   verify(*ST.getInstrInfo());
142 }
143 
144 bool MipsLegalizerInfo::legalizeCustom(MachineInstr &MI,
145                                        MachineRegisterInfo &MRI,
146                                        MachineIRBuilder &MIRBuilder,
147                                        GISelChangeObserver &Observer) const {
148 
149   using namespace TargetOpcode;
150 
151   MIRBuilder.setInstr(MI);
152 
153   return false;
154 }
155