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 .legalForCartesianProduct({s32}, {s32, p0}) 85 .clampScalar(1, s32, s32) 86 .minScalar(0, s32); 87 88 getActionDefinitionsBuilder(G_CONSTANT) 89 .legalFor({s32}) 90 .clampScalar(0, s32, s32); 91 92 getActionDefinitionsBuilder({G_GEP, G_INTTOPTR}) 93 .legalFor({{p0, s32}}); 94 95 getActionDefinitionsBuilder(G_PTRTOINT) 96 .legalFor({{s32, p0}}); 97 98 getActionDefinitionsBuilder(G_FRAME_INDEX) 99 .legalFor({p0}); 100 101 getActionDefinitionsBuilder(G_GLOBAL_VALUE) 102 .legalFor({p0}); 103 104 // FP instructions 105 getActionDefinitionsBuilder(G_FCONSTANT) 106 .legalFor({s32, s64}); 107 108 getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FABS, G_FSQRT}) 109 .legalFor({s32, s64}); 110 111 getActionDefinitionsBuilder(G_FCMP) 112 .legalFor({{s32, s32}, {s32, s64}}) 113 .minScalar(0, s32); 114 115 getActionDefinitionsBuilder({G_FCEIL, G_FFLOOR}) 116 .libcallFor({s32, s64}); 117 118 getActionDefinitionsBuilder(G_FPEXT) 119 .legalFor({{s64, s32}}); 120 121 getActionDefinitionsBuilder(G_FPTRUNC) 122 .legalFor({{s32, s64}}); 123 124 // FP to int conversion instructions 125 getActionDefinitionsBuilder(G_FPTOSI) 126 .legalForCartesianProduct({s32}, {s64, s32}) 127 .libcallForCartesianProduct({s64}, {s64, s32}) 128 .minScalar(0, s32); 129 130 getActionDefinitionsBuilder(G_FPTOUI) 131 .libcallForCartesianProduct({s64}, {s64, s32}) 132 .minScalar(0, s32); 133 134 // Int to FP conversion instructions 135 getActionDefinitionsBuilder(G_SITOFP) 136 .legalForCartesianProduct({s64, s32}, {s32}) 137 .libcallForCartesianProduct({s64, s32}, {s64}) 138 .minScalar(1, s32); 139 140 getActionDefinitionsBuilder(G_UITOFP) 141 .libcallForCartesianProduct({s64, s32}, {s64}) 142 .minScalar(1, s32); 143 144 computeTables(); 145 verify(*ST.getInstrInfo()); 146 } 147 148 bool MipsLegalizerInfo::legalizeCustom(MachineInstr &MI, 149 MachineRegisterInfo &MRI, 150 MachineIRBuilder &MIRBuilder, 151 GISelChangeObserver &Observer) const { 152 153 using namespace TargetOpcode; 154 155 MIRBuilder.setInstr(MI); 156 157 return false; 158 } 159 160 bool MipsLegalizerInfo::legalizeIntrinsic(MachineInstr &MI, MachineRegisterInfo &MRI, 161 MachineIRBuilder &MIRBuilder) const { 162 switch (MI.getIntrinsicID()) { 163 case Intrinsic::memcpy: 164 case Intrinsic::memset: 165 case Intrinsic::memmove: 166 if (createMemLibcall(MIRBuilder, MRI, MI) == 167 LegalizerHelper::UnableToLegalize) 168 return false; 169 MI.eraseFromParent(); 170 return true; 171 default: 172 break; 173 } 174 return true; 175 } 176