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})
28       .legalFor({s32})
29       .clampScalar(0, s32, s32);
30 
31   getActionDefinitionsBuilder(G_MUL)
32       .legalFor({s32})
33       .minScalar(0, s32);
34 
35   getActionDefinitionsBuilder({G_UADDE, G_USUBO, G_USUBE})
36       .lowerFor({{s32, s1}});
37 
38   getActionDefinitionsBuilder({G_LOAD, G_STORE})
39       .legalForTypesWithMemSize({{s32, p0, 8},
40                                  {s32, p0, 16},
41                                  {s32, p0, 32},
42                                  {p0, p0, 32}})
43       .minScalar(0, s32);
44 
45   getActionDefinitionsBuilder({G_ZEXTLOAD, G_SEXTLOAD})
46       .legalForTypesWithMemSize({{s32, p0, 8},
47                                  {s32, p0, 16}})
48       .minScalar(0, s32);
49 
50   getActionDefinitionsBuilder(G_SELECT)
51       .legalForCartesianProduct({p0, s32}, {s32})
52       .minScalar(0, s32)
53       .minScalar(1, s32);
54 
55   getActionDefinitionsBuilder({G_AND, G_OR, G_XOR})
56       .legalFor({s32})
57       .clampScalar(0, s32, s32);
58 
59   getActionDefinitionsBuilder({G_SDIV, G_SREM, G_UREM, G_UDIV})
60       .legalFor({s32})
61       .minScalar(0, s32)
62       .libcallFor({s64});
63 
64   getActionDefinitionsBuilder({G_SHL, G_ASHR, G_LSHR})
65     .legalFor({s32, s32})
66     .minScalar(1, s32);
67 
68   getActionDefinitionsBuilder(G_ICMP)
69       .legalFor({{s32, s32}})
70       .minScalar(0, s32);
71 
72   getActionDefinitionsBuilder(G_CONSTANT)
73       .legalFor({s32})
74       .clampScalar(0, s32, s32);
75 
76   getActionDefinitionsBuilder(G_GEP)
77       .legalFor({{p0, s32}});
78 
79   getActionDefinitionsBuilder(G_FRAME_INDEX)
80       .legalFor({p0});
81 
82   getActionDefinitionsBuilder(G_GLOBAL_VALUE)
83       .legalFor({p0});
84 
85   computeTables();
86   verify(*ST.getInstrInfo());
87 }
88 
89 bool MipsLegalizerInfo::legalizeCustom(MachineInstr &MI,
90                                        MachineRegisterInfo &MRI,
91                                        MachineIRBuilder &MIRBuilder,
92                                        GISelChangeObserver &Observer) const {
93 
94   using namespace TargetOpcode;
95 
96   MIRBuilder.setInstr(MI);
97 
98   return false;
99 }
100