MipsSEISelLowering.cpp revision 4e812c1f4a723f0fa0e8714610e08be593c759b8
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===-- MipsSEISelLowering.cpp - MipsSE DAG Lowering Interface --*- C++ -*-===// 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The LLVM Compiler Infrastructure 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// License. See LICENSE.TXT for details. 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Subclass of MipsTargetLowering specialized for mips32/64. 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "MipsSEISelLowering.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "MipsRegisterInfo.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "MipsTargetMachine.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/CodeGen/MachineInstrBuilder.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/CodeGen/MachineRegisterInfo.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/IR/Intrinsics.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/Support/CommandLine.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/Target/TargetInstrInfo.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using namespace llvm; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static cl::opt<bool> 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)EnableMipsTailCalls("enable-mips-tail-calls", cl::Hidden, 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cl::desc("MIPS: Enable tail calls."), cl::init(false)); 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static cl::opt<bool> NoDPLoadStore("mno-ldc1-sdc1", cl::init(false), 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cl::desc("Expand double precision loads and " 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "stores to their single precision " 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "counterparts")); 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MipsSETargetLowering::MipsSETargetLowering(MipsTargetMachine &TM) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : MipsTargetLowering(TM) { 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set up the register classes 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) clearRegisterClasses(); 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addRegisterClass(MVT::i32, &Mips::GPR32RegClass); 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (HasMips64) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addRegisterClass(MVT::i64, &Mips::GPR64RegClass); 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (Subtarget->hasDSP()) { 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MVT::SimpleValueType VecTys[2] = {MVT::v2i16, MVT::v4i8}; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (unsigned i = 0; i < array_lengthof(VecTys); ++i) { 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addRegisterClass(VecTys[i], &Mips::DSPRRegClass); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Expand all builtin opcodes. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(Opc, VecTys[i], Expand); 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::ADD, VecTys[i], Legal); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::SUB, VecTys[i], Legal); 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::LOAD, VecTys[i], Legal); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::STORE, VecTys[i], Legal); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::BITCAST, VecTys[i], Legal); 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Expand all truncating stores and extending loads. 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned FirstVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned LastVT = (unsigned)MVT::LAST_VECTOR_VALUETYPE; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (unsigned VT0 = FirstVT; VT0 <= LastVT; ++VT0) { 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (unsigned VT1 = FirstVT; VT1 <= LastVT; ++VT1) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setTruncStoreAction((MVT::SimpleValueType)VT0, 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (MVT::SimpleValueType)VT1, Expand); 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setLoadExtAction(ISD::SEXTLOAD, (MVT::SimpleValueType)VT0, Expand); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setLoadExtAction(ISD::ZEXTLOAD, (MVT::SimpleValueType)VT0, Expand); 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setLoadExtAction(ISD::EXTLOAD, (MVT::SimpleValueType)VT0, Expand); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setTargetDAGCombine(ISD::SHL); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setTargetDAGCombine(ISD::SRA); 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setTargetDAGCombine(ISD::SRL); 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setTargetDAGCombine(ISD::SETCC); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setTargetDAGCombine(ISD::VSELECT); 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (Subtarget->hasDSPR2()) 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::MUL, MVT::v2i16, Legal); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (Subtarget->hasMSA()) { 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addMSAIntType(MVT::v16i8, &Mips::MSA128BRegClass); 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addMSAIntType(MVT::v8i16, &Mips::MSA128HRegClass); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addMSAIntType(MVT::v4i32, &Mips::MSA128WRegClass); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addMSAIntType(MVT::v2i64, &Mips::MSA128DRegClass); 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addMSAFloatType(MVT::v8f16, &Mips::MSA128HRegClass); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addMSAFloatType(MVT::v4f32, &Mips::MSA128WRegClass); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addMSAFloatType(MVT::v2f64, &Mips::MSA128DRegClass); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!Subtarget->mipsSEUsesSoftFloat()) { 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addRegisterClass(MVT::f32, &Mips::FGR32RegClass); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When dealing with single precision only, use libcalls 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!Subtarget->isSingleFloat()) { 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (Subtarget->isFP64bit()) 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addRegisterClass(MVT::f64, &Mips::FGR64RegClass); 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addRegisterClass(MVT::f64, &Mips::AFGR64RegClass); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::SMUL_LOHI, MVT::i32, Custom); 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::UMUL_LOHI, MVT::i32, Custom); 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::MULHS, MVT::i32, Custom); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::MULHU, MVT::i32, Custom); 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (HasMips64) { 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::MULHS, MVT::i64, Custom); 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::MULHU, MVT::i64, Custom); 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::MUL, MVT::i64, Custom); 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i64, Custom); 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i64, Custom); 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::SDIVREM, MVT::i32, Custom); 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::UDIVREM, MVT::i32, Custom); 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::SDIVREM, MVT::i64, Custom); 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::UDIVREM, MVT::i64, Custom); 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::LOAD, MVT::i32, Custom); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::STORE, MVT::i32, Custom); 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setTargetDAGCombine(ISD::ADDE); 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setTargetDAGCombine(ISD::SUBE); 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setTargetDAGCombine(ISD::MUL); 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom); 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::INTRINSIC_VOID, MVT::Other, Custom); 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (NoDPLoadStore) { 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::LOAD, MVT::f64, Custom); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::STORE, MVT::f64, Custom); 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) computeRegisterProperties(); 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const MipsTargetLowering * 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)llvm::createMipsSETargetLowering(MipsTargetMachine &TM) { 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return new MipsSETargetLowering(TM); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Enable MSA support for the given integer type and Register class. 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void MipsSETargetLowering:: 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)addMSAIntType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC) { 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addRegisterClass(Ty, RC); 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Expand all builtin opcodes. 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(Opc, Ty, Expand); 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::BITCAST, Ty, Legal); 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::LOAD, Ty, Legal); 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::STORE, Ty, Legal); 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::BUILD_VECTOR, Ty, Custom); 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::ADD, Ty, Legal); 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::AND, Ty, Legal); 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::CTLZ, Ty, Legal); 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::MUL, Ty, Legal); 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::OR, Ty, Legal); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::SDIV, Ty, Legal); 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::SHL, Ty, Legal); 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::SRA, Ty, Legal); 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::SRL, Ty, Legal); 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::SUB, Ty, Legal); 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::UDIV, Ty, Legal); 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::XOR, Ty, Legal); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Enable MSA support for the given floating-point type and Register class. 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void MipsSETargetLowering:: 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)addMSAFloatType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC) { 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) addRegisterClass(Ty, RC); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Expand all builtin opcodes. 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc) 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(Opc, Ty, Expand); 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::LOAD, Ty, Legal); 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::STORE, Ty, Legal); 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::BITCAST, Ty, Legal); 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (Ty != MVT::v8f16) { 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::FADD, Ty, Legal); 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::FDIV, Ty, Legal); 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::FLOG2, Ty, Legal); 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::FMUL, Ty, Legal); 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::FRINT, Ty, Legal); 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::FSQRT, Ty, Legal); 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) setOperationAction(ISD::FSUB, Ty, Legal); 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MipsSETargetLowering::allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const { 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MVT::SimpleValueType SVT = VT.getSimpleVT().SimpleTy; 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (SVT) { 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case MVT::i64: 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case MVT::i32: 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (Fast) 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *Fast = true; 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)SDValue MipsSETargetLowering::LowerOperation(SDValue Op, 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SelectionDAG &DAG) const { 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch(Op.getOpcode()) { 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::LOAD: return lowerLOAD(Op, DAG); 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::STORE: return lowerSTORE(Op, DAG); 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::SMUL_LOHI: return lowerMulDiv(Op, MipsISD::Mult, true, true, DAG); 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::UMUL_LOHI: return lowerMulDiv(Op, MipsISD::Multu, true, true, DAG); 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::MULHS: return lowerMulDiv(Op, MipsISD::Mult, false, true, DAG); 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::MULHU: return lowerMulDiv(Op, MipsISD::Multu, false, true, DAG); 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::MUL: return lowerMulDiv(Op, MipsISD::Mult, true, false, DAG); 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::SDIVREM: return lowerMulDiv(Op, MipsISD::DivRem, true, true, DAG); 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::UDIVREM: return lowerMulDiv(Op, MipsISD::DivRemU, true, true, 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DAG); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::INTRINSIC_WO_CHAIN: return lowerINTRINSIC_WO_CHAIN(Op, DAG); 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::INTRINSIC_W_CHAIN: return lowerINTRINSIC_W_CHAIN(Op, DAG); 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::INTRINSIC_VOID: return lowerINTRINSIC_VOID(Op, DAG); 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ISD::BUILD_VECTOR: return lowerBUILD_VECTOR(Op, DAG); 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return MipsTargetLowering::LowerOperation(Op, DAG); 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// selectMADD - 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Transforms a subgraph in CurDAG if the following pattern is found: 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (addc multLo, Lo0), (adde multHi, Hi0), 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// where, 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// multHi/Lo: product of multiplication 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Lo0: initial value of Lo register 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Hi0: initial value of Hi register 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Return true if pattern matching was successful. 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static bool selectMADD(SDNode *ADDENode, SelectionDAG *CurDAG) { 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ADDENode's second operand must be a flag output of an ADDC node in order 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the matching to be successful. 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDNode *ADDCNode = ADDENode->getOperand(2).getNode(); 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (ADDCNode->getOpcode() != ISD::ADDC) 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue MultHi = ADDENode->getOperand(0); 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue MultLo = ADDCNode->getOperand(0); 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDNode *MultNode = MultHi.getNode(); 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned MultOpc = MultHi.getOpcode(); 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // MultHi and MultLo must be generated by the same node, 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (MultLo.getNode() != MultNode) 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and it must be a multiplication. 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI) 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // MultLo amd MultHi must be the first and second output of MultNode 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // respectively. 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0) 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Transform this to a MADD only if ADDENode and ADDCNode are the only users 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of the values of MultNode, in which case MultNode will be removed in later 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // phases. 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If there exist users other than ADDENode or ADDCNode, this function returns 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // here, which will result in MultNode being mapped to a single MULT 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // instruction node rather than a pair of MULT and MADD instructions being 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // produced. 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!MultHi.hasOneUse() || !MultLo.hasOneUse()) 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDLoc DL(ADDENode); 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initialize accumulator. 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue ACCIn = CurDAG->getNode(MipsISD::InsertLOHI, DL, MVT::Untyped, 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ADDCNode->getOperand(1), 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ADDENode->getOperand(1)); 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // create MipsMAdd(u) node 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MAddu : MipsISD::MAdd; 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue MAdd = CurDAG->getNode(MultOpc, DL, MVT::Untyped, 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MultNode->getOperand(0),// Factor 0 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MultNode->getOperand(1),// Factor 1 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACCIn); 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // replace uses of adde and addc here 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!SDValue(ADDCNode, 0).use_empty()) { 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue LoIdx = CurDAG->getConstant(Mips::sub_lo, MVT::i32); 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue LoOut = CurDAG->getNode(MipsISD::ExtractLOHI, DL, MVT::i32, MAdd, 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoIdx); 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDCNode, 0), LoOut); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!SDValue(ADDENode, 0).use_empty()) { 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue HiIdx = CurDAG->getConstant(Mips::sub_hi, MVT::i32); 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue HiOut = CurDAG->getNode(MipsISD::ExtractLOHI, DL, MVT::i32, MAdd, 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HiIdx); 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDENode, 0), HiOut); 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// selectMSUB - 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Transforms a subgraph in CurDAG if the following pattern is found: 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (addc Lo0, multLo), (sube Hi0, multHi), 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// where, 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// multHi/Lo: product of multiplication 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Lo0: initial value of Lo register 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Hi0: initial value of Hi register 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Return true if pattern matching was successful. 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static bool selectMSUB(SDNode *SUBENode, SelectionDAG *CurDAG) { 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SUBENode's second operand must be a flag output of an SUBC node in order 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the matching to be successful. 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDNode *SUBCNode = SUBENode->getOperand(2).getNode(); 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (SUBCNode->getOpcode() != ISD::SUBC) 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue MultHi = SUBENode->getOperand(1); 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue MultLo = SUBCNode->getOperand(1); 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDNode *MultNode = MultHi.getNode(); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) unsigned MultOpc = MultHi.getOpcode(); 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // MultHi and MultLo must be generated by the same node, 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (MultLo.getNode() != MultNode) 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and it must be a multiplication. 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI) 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // MultLo amd MultHi must be the first and second output of MultNode 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // respectively. 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0) 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Transform this to a MSUB only if SUBENode and SUBCNode are the only users 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of the values of MultNode, in which case MultNode will be removed in later 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // phases. 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If there exist users other than SUBENode or SUBCNode, this function returns 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // here, which will result in MultNode being mapped to a single MULT 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // instruction node rather than a pair of MULT and MSUB instructions being 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // produced. 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!MultHi.hasOneUse() || !MultLo.hasOneUse()) 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDLoc DL(SUBENode); 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initialize accumulator. 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue ACCIn = CurDAG->getNode(MipsISD::InsertLOHI, DL, MVT::Untyped, 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SUBCNode->getOperand(0), 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SUBENode->getOperand(0)); 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // create MipsSub(u) node 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MSubu : MipsISD::MSub; 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue MSub = CurDAG->getNode(MultOpc, DL, MVT::Glue, 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MultNode->getOperand(0),// Factor 0 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MultNode->getOperand(1),// Factor 1 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ACCIn); 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // replace uses of sube and subc here 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!SDValue(SUBCNode, 0).use_empty()) { 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue LoIdx = CurDAG->getConstant(Mips::sub_lo, MVT::i32); 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue LoOut = CurDAG->getNode(MipsISD::ExtractLOHI, DL, MVT::i32, MSub, 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoIdx); 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBCNode, 0), LoOut); 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!SDValue(SUBENode, 0).use_empty()) { 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue HiIdx = CurDAG->getConstant(Mips::sub_hi, MVT::i32); 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SDValue HiOut = CurDAG->getNode(MipsISD::ExtractLOHI, DL, MVT::i32, MSub, 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HiIdx); 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBENode, 0), HiOut); 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static SDValue performADDECombine(SDNode *N, SelectionDAG &DAG, 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TargetLowering::DAGCombinerInfo &DCI, 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const MipsSubtarget *Subtarget) { 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (DCI.isBeforeLegalize()) 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return SDValue(); 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (Subtarget->hasMips32() && N->getValueType(0) == MVT::i32 && 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) selectMADD(N, &DAG)) 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return SDValue(N, 0); 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return SDValue(); 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static SDValue performSUBECombine(SDNode *N, SelectionDAG &DAG, 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TargetLowering::DAGCombinerInfo &DCI, 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const MipsSubtarget *Subtarget) { 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (DCI.isBeforeLegalize()) 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return SDValue(); 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 410 if (Subtarget->hasMips32() && N->getValueType(0) == MVT::i32 && 411 selectMSUB(N, &DAG)) 412 return SDValue(N, 0); 413 414 return SDValue(); 415} 416 417static SDValue genConstMult(SDValue X, uint64_t C, SDLoc DL, EVT VT, 418 EVT ShiftTy, SelectionDAG &DAG) { 419 // Clear the upper (64 - VT.sizeInBits) bits. 420 C &= ((uint64_t)-1) >> (64 - VT.getSizeInBits()); 421 422 // Return 0. 423 if (C == 0) 424 return DAG.getConstant(0, VT); 425 426 // Return x. 427 if (C == 1) 428 return X; 429 430 // If c is power of 2, return (shl x, log2(c)). 431 if (isPowerOf2_64(C)) 432 return DAG.getNode(ISD::SHL, DL, VT, X, 433 DAG.getConstant(Log2_64(C), ShiftTy)); 434 435 unsigned Log2Ceil = Log2_64_Ceil(C); 436 uint64_t Floor = 1LL << Log2_64(C); 437 uint64_t Ceil = Log2Ceil == 64 ? 0LL : 1LL << Log2Ceil; 438 439 // If |c - floor_c| <= |c - ceil_c|, 440 // where floor_c = pow(2, floor(log2(c))) and ceil_c = pow(2, ceil(log2(c))), 441 // return (add constMult(x, floor_c), constMult(x, c - floor_c)). 442 if (C - Floor <= Ceil - C) { 443 SDValue Op0 = genConstMult(X, Floor, DL, VT, ShiftTy, DAG); 444 SDValue Op1 = genConstMult(X, C - Floor, DL, VT, ShiftTy, DAG); 445 return DAG.getNode(ISD::ADD, DL, VT, Op0, Op1); 446 } 447 448 // If |c - floor_c| > |c - ceil_c|, 449 // return (sub constMult(x, ceil_c), constMult(x, ceil_c - c)). 450 SDValue Op0 = genConstMult(X, Ceil, DL, VT, ShiftTy, DAG); 451 SDValue Op1 = genConstMult(X, Ceil - C, DL, VT, ShiftTy, DAG); 452 return DAG.getNode(ISD::SUB, DL, VT, Op0, Op1); 453} 454 455static SDValue performMULCombine(SDNode *N, SelectionDAG &DAG, 456 const TargetLowering::DAGCombinerInfo &DCI, 457 const MipsSETargetLowering *TL) { 458 EVT VT = N->getValueType(0); 459 460 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) 461 if (!VT.isVector()) 462 return genConstMult(N->getOperand(0), C->getZExtValue(), SDLoc(N), 463 VT, TL->getScalarShiftAmountTy(VT), DAG); 464 465 return SDValue(N, 0); 466} 467 468static SDValue performDSPShiftCombine(unsigned Opc, SDNode *N, EVT Ty, 469 SelectionDAG &DAG, 470 const MipsSubtarget *Subtarget) { 471 // See if this is a vector splat immediate node. 472 APInt SplatValue, SplatUndef; 473 unsigned SplatBitSize; 474 bool HasAnyUndefs; 475 unsigned EltSize = Ty.getVectorElementType().getSizeInBits(); 476 BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); 477 478 if (!BV || 479 !BV->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs, 480 EltSize, !Subtarget->isLittle()) || 481 (SplatBitSize != EltSize) || 482 (SplatValue.getZExtValue() >= EltSize)) 483 return SDValue(); 484 485 return DAG.getNode(Opc, SDLoc(N), Ty, N->getOperand(0), 486 DAG.getConstant(SplatValue.getZExtValue(), MVT::i32)); 487} 488 489static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG, 490 TargetLowering::DAGCombinerInfo &DCI, 491 const MipsSubtarget *Subtarget) { 492 EVT Ty = N->getValueType(0); 493 494 if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8)) 495 return SDValue(); 496 497 return performDSPShiftCombine(MipsISD::SHLL_DSP, N, Ty, DAG, Subtarget); 498} 499 500static SDValue performSRACombine(SDNode *N, SelectionDAG &DAG, 501 TargetLowering::DAGCombinerInfo &DCI, 502 const MipsSubtarget *Subtarget) { 503 EVT Ty = N->getValueType(0); 504 505 if ((Ty != MVT::v2i16) && ((Ty != MVT::v4i8) || !Subtarget->hasDSPR2())) 506 return SDValue(); 507 508 return performDSPShiftCombine(MipsISD::SHRA_DSP, N, Ty, DAG, Subtarget); 509} 510 511 512static SDValue performSRLCombine(SDNode *N, SelectionDAG &DAG, 513 TargetLowering::DAGCombinerInfo &DCI, 514 const MipsSubtarget *Subtarget) { 515 EVT Ty = N->getValueType(0); 516 517 if (((Ty != MVT::v2i16) || !Subtarget->hasDSPR2()) && (Ty != MVT::v4i8)) 518 return SDValue(); 519 520 return performDSPShiftCombine(MipsISD::SHRL_DSP, N, Ty, DAG, Subtarget); 521} 522 523static bool isLegalDSPCondCode(EVT Ty, ISD::CondCode CC) { 524 bool IsV216 = (Ty == MVT::v2i16); 525 526 switch (CC) { 527 case ISD::SETEQ: 528 case ISD::SETNE: return true; 529 case ISD::SETLT: 530 case ISD::SETLE: 531 case ISD::SETGT: 532 case ISD::SETGE: return IsV216; 533 case ISD::SETULT: 534 case ISD::SETULE: 535 case ISD::SETUGT: 536 case ISD::SETUGE: return !IsV216; 537 default: return false; 538 } 539} 540 541static SDValue performSETCCCombine(SDNode *N, SelectionDAG &DAG) { 542 EVT Ty = N->getValueType(0); 543 544 if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8)) 545 return SDValue(); 546 547 if (!isLegalDSPCondCode(Ty, cast<CondCodeSDNode>(N->getOperand(2))->get())) 548 return SDValue(); 549 550 return DAG.getNode(MipsISD::SETCC_DSP, SDLoc(N), Ty, N->getOperand(0), 551 N->getOperand(1), N->getOperand(2)); 552} 553 554static SDValue performVSELECTCombine(SDNode *N, SelectionDAG &DAG) { 555 EVT Ty = N->getValueType(0); 556 557 if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8)) 558 return SDValue(); 559 560 SDValue SetCC = N->getOperand(0); 561 562 if (SetCC.getOpcode() != MipsISD::SETCC_DSP) 563 return SDValue(); 564 565 return DAG.getNode(MipsISD::SELECT_CC_DSP, SDLoc(N), Ty, 566 SetCC.getOperand(0), SetCC.getOperand(1), N->getOperand(1), 567 N->getOperand(2), SetCC.getOperand(2)); 568} 569 570SDValue 571MipsSETargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const { 572 SelectionDAG &DAG = DCI.DAG; 573 SDValue Val; 574 575 switch (N->getOpcode()) { 576 case ISD::ADDE: 577 return performADDECombine(N, DAG, DCI, Subtarget); 578 case ISD::SUBE: 579 return performSUBECombine(N, DAG, DCI, Subtarget); 580 case ISD::MUL: 581 return performMULCombine(N, DAG, DCI, this); 582 case ISD::SHL: 583 return performSHLCombine(N, DAG, DCI, Subtarget); 584 case ISD::SRA: 585 return performSRACombine(N, DAG, DCI, Subtarget); 586 case ISD::SRL: 587 return performSRLCombine(N, DAG, DCI, Subtarget); 588 case ISD::VSELECT: 589 return performVSELECTCombine(N, DAG); 590 case ISD::SETCC: { 591 Val = performSETCCCombine(N, DAG); 592 break; 593 } 594 } 595 596 if (Val.getNode()) 597 return Val; 598 599 return MipsTargetLowering::PerformDAGCombine(N, DCI); 600} 601 602MachineBasicBlock * 603MipsSETargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, 604 MachineBasicBlock *BB) const { 605 switch (MI->getOpcode()) { 606 default: 607 return MipsTargetLowering::EmitInstrWithCustomInserter(MI, BB); 608 case Mips::BPOSGE32_PSEUDO: 609 return emitBPOSGE32(MI, BB); 610 case Mips::SNZ_B_PSEUDO: 611 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_B); 612 case Mips::SNZ_H_PSEUDO: 613 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_H); 614 case Mips::SNZ_W_PSEUDO: 615 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_W); 616 case Mips::SNZ_D_PSEUDO: 617 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_D); 618 case Mips::SNZ_V_PSEUDO: 619 return emitMSACBranchPseudo(MI, BB, Mips::BNZ_V); 620 case Mips::SZ_B_PSEUDO: 621 return emitMSACBranchPseudo(MI, BB, Mips::BZ_B); 622 case Mips::SZ_H_PSEUDO: 623 return emitMSACBranchPseudo(MI, BB, Mips::BZ_H); 624 case Mips::SZ_W_PSEUDO: 625 return emitMSACBranchPseudo(MI, BB, Mips::BZ_W); 626 case Mips::SZ_D_PSEUDO: 627 return emitMSACBranchPseudo(MI, BB, Mips::BZ_D); 628 case Mips::SZ_V_PSEUDO: 629 return emitMSACBranchPseudo(MI, BB, Mips::BZ_V); 630 } 631} 632 633bool MipsSETargetLowering:: 634isEligibleForTailCallOptimization(const MipsCC &MipsCCInfo, 635 unsigned NextStackOffset, 636 const MipsFunctionInfo& FI) const { 637 if (!EnableMipsTailCalls) 638 return false; 639 640 // Return false if either the callee or caller has a byval argument. 641 if (MipsCCInfo.hasByValArg() || FI.hasByvalArg()) 642 return false; 643 644 // Return true if the callee's argument area is no larger than the 645 // caller's. 646 return NextStackOffset <= FI.getIncomingArgSize(); 647} 648 649void MipsSETargetLowering:: 650getOpndList(SmallVectorImpl<SDValue> &Ops, 651 std::deque< std::pair<unsigned, SDValue> > &RegsToPass, 652 bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage, 653 CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const { 654 // T9 should contain the address of the callee function if 655 // -reloction-model=pic or it is an indirect call. 656 if (IsPICCall || !GlobalOrExternal) { 657 unsigned T9Reg = IsN64 ? Mips::T9_64 : Mips::T9; 658 RegsToPass.push_front(std::make_pair(T9Reg, Callee)); 659 } else 660 Ops.push_back(Callee); 661 662 MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal, 663 InternalLinkage, CLI, Callee, Chain); 664} 665 666SDValue MipsSETargetLowering::lowerLOAD(SDValue Op, SelectionDAG &DAG) const { 667 LoadSDNode &Nd = *cast<LoadSDNode>(Op); 668 669 if (Nd.getMemoryVT() != MVT::f64 || !NoDPLoadStore) 670 return MipsTargetLowering::lowerLOAD(Op, DAG); 671 672 // Replace a double precision load with two i32 loads and a buildpair64. 673 SDLoc DL(Op); 674 SDValue Ptr = Nd.getBasePtr(), Chain = Nd.getChain(); 675 EVT PtrVT = Ptr.getValueType(); 676 677 // i32 load from lower address. 678 SDValue Lo = DAG.getLoad(MVT::i32, DL, Chain, Ptr, 679 MachinePointerInfo(), Nd.isVolatile(), 680 Nd.isNonTemporal(), Nd.isInvariant(), 681 Nd.getAlignment()); 682 683 // i32 load from higher address. 684 Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, PtrVT)); 685 SDValue Hi = DAG.getLoad(MVT::i32, DL, Lo.getValue(1), Ptr, 686 MachinePointerInfo(), Nd.isVolatile(), 687 Nd.isNonTemporal(), Nd.isInvariant(), 688 std::min(Nd.getAlignment(), 4U)); 689 690 if (!Subtarget->isLittle()) 691 std::swap(Lo, Hi); 692 693 SDValue BP = DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, Lo, Hi); 694 SDValue Ops[2] = {BP, Hi.getValue(1)}; 695 return DAG.getMergeValues(Ops, 2, DL); 696} 697 698SDValue MipsSETargetLowering::lowerSTORE(SDValue Op, SelectionDAG &DAG) const { 699 StoreSDNode &Nd = *cast<StoreSDNode>(Op); 700 701 if (Nd.getMemoryVT() != MVT::f64 || !NoDPLoadStore) 702 return MipsTargetLowering::lowerSTORE(Op, DAG); 703 704 // Replace a double precision store with two extractelement64s and i32 stores. 705 SDLoc DL(Op); 706 SDValue Val = Nd.getValue(), Ptr = Nd.getBasePtr(), Chain = Nd.getChain(); 707 EVT PtrVT = Ptr.getValueType(); 708 SDValue Lo = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, 709 Val, DAG.getConstant(0, MVT::i32)); 710 SDValue Hi = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, 711 Val, DAG.getConstant(1, MVT::i32)); 712 713 if (!Subtarget->isLittle()) 714 std::swap(Lo, Hi); 715 716 // i32 store to lower address. 717 Chain = DAG.getStore(Chain, DL, Lo, Ptr, MachinePointerInfo(), 718 Nd.isVolatile(), Nd.isNonTemporal(), Nd.getAlignment(), 719 Nd.getTBAAInfo()); 720 721 // i32 store to higher address. 722 Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, PtrVT)); 723 return DAG.getStore(Chain, DL, Hi, Ptr, MachinePointerInfo(), 724 Nd.isVolatile(), Nd.isNonTemporal(), 725 std::min(Nd.getAlignment(), 4U), Nd.getTBAAInfo()); 726} 727 728SDValue MipsSETargetLowering::lowerMulDiv(SDValue Op, unsigned NewOpc, 729 bool HasLo, bool HasHi, 730 SelectionDAG &DAG) const { 731 EVT Ty = Op.getOperand(0).getValueType(); 732 SDLoc DL(Op); 733 SDValue Mult = DAG.getNode(NewOpc, DL, MVT::Untyped, 734 Op.getOperand(0), Op.getOperand(1)); 735 SDValue Lo, Hi; 736 737 if (HasLo) 738 Lo = DAG.getNode(MipsISD::ExtractLOHI, DL, Ty, Mult, 739 DAG.getConstant(Mips::sub_lo, MVT::i32)); 740 if (HasHi) 741 Hi = DAG.getNode(MipsISD::ExtractLOHI, DL, Ty, Mult, 742 DAG.getConstant(Mips::sub_hi, MVT::i32)); 743 744 if (!HasLo || !HasHi) 745 return HasLo ? Lo : Hi; 746 747 SDValue Vals[] = { Lo, Hi }; 748 return DAG.getMergeValues(Vals, 2, DL); 749} 750 751 752static SDValue initAccumulator(SDValue In, SDLoc DL, SelectionDAG &DAG) { 753 SDValue InLo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In, 754 DAG.getConstant(0, MVT::i32)); 755 SDValue InHi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In, 756 DAG.getConstant(1, MVT::i32)); 757 return DAG.getNode(MipsISD::InsertLOHI, DL, MVT::Untyped, InLo, InHi); 758} 759 760static SDValue extractLOHI(SDValue Op, SDLoc DL, SelectionDAG &DAG) { 761 SDValue Lo = DAG.getNode(MipsISD::ExtractLOHI, DL, MVT::i32, Op, 762 DAG.getConstant(Mips::sub_lo, MVT::i32)); 763 SDValue Hi = DAG.getNode(MipsISD::ExtractLOHI, DL, MVT::i32, Op, 764 DAG.getConstant(Mips::sub_hi, MVT::i32)); 765 return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi); 766} 767 768// This function expands mips intrinsic nodes which have 64-bit input operands 769// or output values. 770// 771// out64 = intrinsic-node in64 772// => 773// lo = copy (extract-element (in64, 0)) 774// hi = copy (extract-element (in64, 1)) 775// mips-specific-node 776// v0 = copy lo 777// v1 = copy hi 778// out64 = merge-values (v0, v1) 779// 780static SDValue lowerDSPIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) { 781 SDLoc DL(Op); 782 bool HasChainIn = Op->getOperand(0).getValueType() == MVT::Other; 783 SmallVector<SDValue, 3> Ops; 784 unsigned OpNo = 0; 785 786 // See if Op has a chain input. 787 if (HasChainIn) 788 Ops.push_back(Op->getOperand(OpNo++)); 789 790 // The next operand is the intrinsic opcode. 791 assert(Op->getOperand(OpNo).getOpcode() == ISD::TargetConstant); 792 793 // See if the next operand has type i64. 794 SDValue Opnd = Op->getOperand(++OpNo), In64; 795 796 if (Opnd.getValueType() == MVT::i64) 797 In64 = initAccumulator(Opnd, DL, DAG); 798 else 799 Ops.push_back(Opnd); 800 801 // Push the remaining operands. 802 for (++OpNo ; OpNo < Op->getNumOperands(); ++OpNo) 803 Ops.push_back(Op->getOperand(OpNo)); 804 805 // Add In64 to the end of the list. 806 if (In64.getNode()) 807 Ops.push_back(In64); 808 809 // Scan output. 810 SmallVector<EVT, 2> ResTys; 811 812 for (SDNode::value_iterator I = Op->value_begin(), E = Op->value_end(); 813 I != E; ++I) 814 ResTys.push_back((*I == MVT::i64) ? MVT::Untyped : *I); 815 816 // Create node. 817 SDValue Val = DAG.getNode(Opc, DL, ResTys, &Ops[0], Ops.size()); 818 SDValue Out = (ResTys[0] == MVT::Untyped) ? extractLOHI(Val, DL, DAG) : Val; 819 820 if (!HasChainIn) 821 return Out; 822 823 assert(Val->getValueType(1) == MVT::Other); 824 SDValue Vals[] = { Out, SDValue(Val.getNode(), 1) }; 825 return DAG.getMergeValues(Vals, 2, DL); 826} 827 828static SDValue lowerMSABinaryIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) { 829 SDLoc DL(Op); 830 SDValue LHS = Op->getOperand(1); 831 SDValue RHS = Op->getOperand(2); 832 EVT ResTy = Op->getValueType(0); 833 834 SDValue Result = DAG.getNode(Opc, DL, ResTy, LHS, RHS); 835 836 return Result; 837} 838 839static SDValue lowerMSABranchIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) { 840 SDLoc DL(Op); 841 SDValue Value = Op->getOperand(1); 842 EVT ResTy = Op->getValueType(0); 843 844 SDValue Result = DAG.getNode(Opc, DL, ResTy, Value); 845 846 return Result; 847} 848 849static SDValue lowerMSAUnaryIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) { 850 SDLoc DL(Op); 851 SDValue Value = Op->getOperand(1); 852 EVT ResTy = Op->getValueType(0); 853 854 SDValue Result = DAG.getNode(Opc, DL, ResTy, Value); 855 856 return Result; 857} 858 859SDValue MipsSETargetLowering::lowerINTRINSIC_WO_CHAIN(SDValue Op, 860 SelectionDAG &DAG) const { 861 switch (cast<ConstantSDNode>(Op->getOperand(0))->getZExtValue()) { 862 default: 863 return SDValue(); 864 case Intrinsic::mips_shilo: 865 return lowerDSPIntr(Op, DAG, MipsISD::SHILO); 866 case Intrinsic::mips_dpau_h_qbl: 867 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBL); 868 case Intrinsic::mips_dpau_h_qbr: 869 return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBR); 870 case Intrinsic::mips_dpsu_h_qbl: 871 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBL); 872 case Intrinsic::mips_dpsu_h_qbr: 873 return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBR); 874 case Intrinsic::mips_dpa_w_ph: 875 return lowerDSPIntr(Op, DAG, MipsISD::DPA_W_PH); 876 case Intrinsic::mips_dps_w_ph: 877 return lowerDSPIntr(Op, DAG, MipsISD::DPS_W_PH); 878 case Intrinsic::mips_dpax_w_ph: 879 return lowerDSPIntr(Op, DAG, MipsISD::DPAX_W_PH); 880 case Intrinsic::mips_dpsx_w_ph: 881 return lowerDSPIntr(Op, DAG, MipsISD::DPSX_W_PH); 882 case Intrinsic::mips_mulsa_w_ph: 883 return lowerDSPIntr(Op, DAG, MipsISD::MULSA_W_PH); 884 case Intrinsic::mips_mult: 885 return lowerDSPIntr(Op, DAG, MipsISD::Mult); 886 case Intrinsic::mips_multu: 887 return lowerDSPIntr(Op, DAG, MipsISD::Multu); 888 case Intrinsic::mips_madd: 889 return lowerDSPIntr(Op, DAG, MipsISD::MAdd); 890 case Intrinsic::mips_maddu: 891 return lowerDSPIntr(Op, DAG, MipsISD::MAddu); 892 case Intrinsic::mips_msub: 893 return lowerDSPIntr(Op, DAG, MipsISD::MSub); 894 case Intrinsic::mips_msubu: 895 return lowerDSPIntr(Op, DAG, MipsISD::MSubu); 896 case Intrinsic::mips_addv_b: 897 case Intrinsic::mips_addv_h: 898 case Intrinsic::mips_addv_w: 899 case Intrinsic::mips_addv_d: 900 return lowerMSABinaryIntr(Op, DAG, ISD::ADD); 901 case Intrinsic::mips_and_v: 902 return lowerMSABinaryIntr(Op, DAG, ISD::AND); 903 case Intrinsic::mips_bnz_b: 904 case Intrinsic::mips_bnz_h: 905 case Intrinsic::mips_bnz_w: 906 case Intrinsic::mips_bnz_d: 907 return lowerMSABranchIntr(Op, DAG, MipsISD::VALL_NONZERO); 908 case Intrinsic::mips_bnz_v: 909 return lowerMSABranchIntr(Op, DAG, MipsISD::VANY_NONZERO); 910 case Intrinsic::mips_bz_b: 911 case Intrinsic::mips_bz_h: 912 case Intrinsic::mips_bz_w: 913 case Intrinsic::mips_bz_d: 914 return lowerMSABranchIntr(Op, DAG, MipsISD::VALL_ZERO); 915 case Intrinsic::mips_bz_v: 916 return lowerMSABranchIntr(Op, DAG, MipsISD::VANY_ZERO); 917 case Intrinsic::mips_div_s_b: 918 case Intrinsic::mips_div_s_h: 919 case Intrinsic::mips_div_s_w: 920 case Intrinsic::mips_div_s_d: 921 return lowerMSABinaryIntr(Op, DAG, ISD::SDIV); 922 case Intrinsic::mips_div_u_b: 923 case Intrinsic::mips_div_u_h: 924 case Intrinsic::mips_div_u_w: 925 case Intrinsic::mips_div_u_d: 926 return lowerMSABinaryIntr(Op, DAG, ISD::UDIV); 927 case Intrinsic::mips_fadd_w: 928 case Intrinsic::mips_fadd_d: 929 return lowerMSABinaryIntr(Op, DAG, ISD::FADD); 930 case Intrinsic::mips_fdiv_w: 931 case Intrinsic::mips_fdiv_d: 932 return lowerMSABinaryIntr(Op, DAG, ISD::FDIV); 933 case Intrinsic::mips_fill_b: 934 case Intrinsic::mips_fill_h: 935 case Intrinsic::mips_fill_w: 936 return lowerMSAUnaryIntr(Op, DAG, MipsISD::VSPLAT); 937 case Intrinsic::mips_flog2_w: 938 case Intrinsic::mips_flog2_d: 939 return lowerMSAUnaryIntr(Op, DAG, ISD::FLOG2); 940 case Intrinsic::mips_fmul_w: 941 case Intrinsic::mips_fmul_d: 942 return lowerMSABinaryIntr(Op, DAG, ISD::FMUL); 943 case Intrinsic::mips_frint_w: 944 case Intrinsic::mips_frint_d: 945 return lowerMSAUnaryIntr(Op, DAG, ISD::FRINT); 946 case Intrinsic::mips_fsqrt_w: 947 case Intrinsic::mips_fsqrt_d: 948 return lowerMSAUnaryIntr(Op, DAG, ISD::FSQRT); 949 case Intrinsic::mips_fsub_w: 950 case Intrinsic::mips_fsub_d: 951 return lowerMSABinaryIntr(Op, DAG, ISD::FSUB); 952 case Intrinsic::mips_ldi_b: 953 case Intrinsic::mips_ldi_h: 954 case Intrinsic::mips_ldi_w: 955 case Intrinsic::mips_ldi_d: 956 return lowerMSAUnaryIntr(Op, DAG, MipsISD::VSPLAT); 957 case Intrinsic::mips_mulv_b: 958 case Intrinsic::mips_mulv_h: 959 case Intrinsic::mips_mulv_w: 960 case Intrinsic::mips_mulv_d: 961 return lowerMSABinaryIntr(Op, DAG, ISD::MUL); 962 case Intrinsic::mips_nlzc_b: 963 case Intrinsic::mips_nlzc_h: 964 case Intrinsic::mips_nlzc_w: 965 case Intrinsic::mips_nlzc_d: 966 return lowerMSAUnaryIntr(Op, DAG, ISD::CTLZ); 967 case Intrinsic::mips_or_v: 968 return lowerMSABinaryIntr(Op, DAG, ISD::OR); 969 case Intrinsic::mips_sll_b: 970 case Intrinsic::mips_sll_h: 971 case Intrinsic::mips_sll_w: 972 case Intrinsic::mips_sll_d: 973 return lowerMSABinaryIntr(Op, DAG, ISD::SHL); 974 case Intrinsic::mips_sra_b: 975 case Intrinsic::mips_sra_h: 976 case Intrinsic::mips_sra_w: 977 case Intrinsic::mips_sra_d: 978 return lowerMSABinaryIntr(Op, DAG, ISD::SRA); 979 case Intrinsic::mips_srl_b: 980 case Intrinsic::mips_srl_h: 981 case Intrinsic::mips_srl_w: 982 case Intrinsic::mips_srl_d: 983 return lowerMSABinaryIntr(Op, DAG, ISD::SRL); 984 case Intrinsic::mips_subv_b: 985 case Intrinsic::mips_subv_h: 986 case Intrinsic::mips_subv_w: 987 case Intrinsic::mips_subv_d: 988 return lowerMSABinaryIntr(Op, DAG, ISD::SUB); 989 case Intrinsic::mips_xor_v: 990 return lowerMSABinaryIntr(Op, DAG, ISD::XOR); 991 } 992} 993 994static SDValue lowerMSALoadIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr) { 995 SDLoc DL(Op); 996 SDValue ChainIn = Op->getOperand(0); 997 SDValue Address = Op->getOperand(2); 998 SDValue Offset = Op->getOperand(3); 999 EVT ResTy = Op->getValueType(0); 1000 EVT PtrTy = Address->getValueType(0); 1001 1002 Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset); 1003 1004 return DAG.getLoad(ResTy, DL, ChainIn, Address, MachinePointerInfo(), false, 1005 false, false, 16); 1006} 1007 1008SDValue MipsSETargetLowering::lowerINTRINSIC_W_CHAIN(SDValue Op, 1009 SelectionDAG &DAG) const { 1010 unsigned Intr = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue(); 1011 switch (Intr) { 1012 default: 1013 return SDValue(); 1014 case Intrinsic::mips_extp: 1015 return lowerDSPIntr(Op, DAG, MipsISD::EXTP); 1016 case Intrinsic::mips_extpdp: 1017 return lowerDSPIntr(Op, DAG, MipsISD::EXTPDP); 1018 case Intrinsic::mips_extr_w: 1019 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_W); 1020 case Intrinsic::mips_extr_r_w: 1021 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_R_W); 1022 case Intrinsic::mips_extr_rs_w: 1023 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_RS_W); 1024 case Intrinsic::mips_extr_s_h: 1025 return lowerDSPIntr(Op, DAG, MipsISD::EXTR_S_H); 1026 case Intrinsic::mips_mthlip: 1027 return lowerDSPIntr(Op, DAG, MipsISD::MTHLIP); 1028 case Intrinsic::mips_mulsaq_s_w_ph: 1029 return lowerDSPIntr(Op, DAG, MipsISD::MULSAQ_S_W_PH); 1030 case Intrinsic::mips_maq_s_w_phl: 1031 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHL); 1032 case Intrinsic::mips_maq_s_w_phr: 1033 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHR); 1034 case Intrinsic::mips_maq_sa_w_phl: 1035 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHL); 1036 case Intrinsic::mips_maq_sa_w_phr: 1037 return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHR); 1038 case Intrinsic::mips_dpaq_s_w_ph: 1039 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_S_W_PH); 1040 case Intrinsic::mips_dpsq_s_w_ph: 1041 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_S_W_PH); 1042 case Intrinsic::mips_dpaq_sa_l_w: 1043 return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_SA_L_W); 1044 case Intrinsic::mips_dpsq_sa_l_w: 1045 return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_SA_L_W); 1046 case Intrinsic::mips_dpaqx_s_w_ph: 1047 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_S_W_PH); 1048 case Intrinsic::mips_dpaqx_sa_w_ph: 1049 return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_SA_W_PH); 1050 case Intrinsic::mips_dpsqx_s_w_ph: 1051 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_S_W_PH); 1052 case Intrinsic::mips_dpsqx_sa_w_ph: 1053 return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_SA_W_PH); 1054 case Intrinsic::mips_ld_b: 1055 case Intrinsic::mips_ld_h: 1056 case Intrinsic::mips_ld_w: 1057 case Intrinsic::mips_ld_d: 1058 case Intrinsic::mips_ldx_b: 1059 case Intrinsic::mips_ldx_h: 1060 case Intrinsic::mips_ldx_w: 1061 case Intrinsic::mips_ldx_d: 1062 return lowerMSALoadIntr(Op, DAG, Intr); 1063 } 1064} 1065 1066static SDValue lowerMSAStoreIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr) { 1067 SDLoc DL(Op); 1068 SDValue ChainIn = Op->getOperand(0); 1069 SDValue Value = Op->getOperand(2); 1070 SDValue Address = Op->getOperand(3); 1071 SDValue Offset = Op->getOperand(4); 1072 EVT PtrTy = Address->getValueType(0); 1073 1074 Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset); 1075 1076 return DAG.getStore(ChainIn, DL, Value, Address, MachinePointerInfo(), false, 1077 false, 16); 1078} 1079 1080SDValue MipsSETargetLowering::lowerINTRINSIC_VOID(SDValue Op, 1081 SelectionDAG &DAG) const { 1082 unsigned Intr = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue(); 1083 switch (Intr) { 1084 default: 1085 return SDValue(); 1086 case Intrinsic::mips_st_b: 1087 case Intrinsic::mips_st_h: 1088 case Intrinsic::mips_st_w: 1089 case Intrinsic::mips_st_d: 1090 case Intrinsic::mips_stx_b: 1091 case Intrinsic::mips_stx_h: 1092 case Intrinsic::mips_stx_w: 1093 case Intrinsic::mips_stx_d: 1094 return lowerMSAStoreIntr(Op, DAG, Intr); 1095 } 1096} 1097 1098/// \brief Check if the given BuildVectorSDNode is a splat. 1099/// This method currently relies on DAG nodes being reused when equivalent, 1100/// so it's possible for this to return false even when isConstantSplat returns 1101/// true. 1102static bool isSplatVector(const BuildVectorSDNode *N) { 1103 unsigned int nOps = N->getNumOperands(); 1104 assert(nOps > 1 && "isSplat has 0 or 1 sized build vector"); 1105 1106 SDValue Operand0 = N->getOperand(0); 1107 1108 for (unsigned int i = 1; i < nOps; ++i) { 1109 if (N->getOperand(i) != Operand0) 1110 return false; 1111 } 1112 1113 return true; 1114} 1115 1116// Lowers ISD::BUILD_VECTOR into appropriate SelectionDAG nodes for the 1117// backend. 1118// 1119// Lowers according to the following rules: 1120// - Vectors of 128-bits may be legal subject to the other rules. Other sizes 1121// are not legal. 1122// - Non-constant splats are legal and are lowered to MipsISD::VSPLAT. 1123// - Constant splats with an element size of 32-bits or less are legal and are 1124// lowered to MipsISD::VSPLAT. 1125// - Constant splats with an element size of 64-bits but whose value would fit 1126// within a 10 bit immediate are legal and are lowered to MipsISD::VSPLATD. 1127// - All other ISD::BUILD_VECTORS are not legal 1128SDValue MipsSETargetLowering::lowerBUILD_VECTOR(SDValue Op, 1129 SelectionDAG &DAG) const { 1130 BuildVectorSDNode *Node = cast<BuildVectorSDNode>(Op); 1131 EVT ResTy = Op->getValueType(0); 1132 SDLoc DL(Op); 1133 APInt SplatValue, SplatUndef; 1134 unsigned SplatBitSize; 1135 bool HasAnyUndefs; 1136 1137 if (!Subtarget->hasMSA() || !ResTy.is128BitVector()) 1138 return SDValue(); 1139 1140 if (Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, 1141 HasAnyUndefs, 8, 1142 !Subtarget->isLittle())) { 1143 SDValue Result; 1144 EVT TmpVecTy; 1145 EVT ConstTy = MVT::i32; 1146 unsigned SplatOp = MipsISD::VSPLAT; 1147 1148 switch (SplatBitSize) { 1149 default: 1150 return SDValue(); 1151 case 64: 1152 TmpVecTy = MVT::v2i64; 1153 1154 // i64 is an illegal type on Mips32, but if it the constant fits into a 1155 // signed 10-bit value then we can still handle it using VSPLATD and an 1156 // i32 constant 1157 if (HasMips64) 1158 ConstTy = MVT::i64; 1159 else if (isInt<10>(SplatValue.getSExtValue())) { 1160 SplatValue = SplatValue.trunc(32); 1161 SplatOp = MipsISD::VSPLATD; 1162 } else 1163 return SDValue(); 1164 break; 1165 case 32: 1166 TmpVecTy = MVT::v4i32; 1167 break; 1168 case 16: 1169 TmpVecTy = MVT::v8i16; 1170 SplatValue = SplatValue.sext(32); 1171 break; 1172 case 8: 1173 TmpVecTy = MVT::v16i8; 1174 SplatValue = SplatValue.sext(32); 1175 break; 1176 } 1177 1178 Result = DAG.getNode(SplatOp, DL, TmpVecTy, 1179 DAG.getConstant(SplatValue, ConstTy)); 1180 if (ResTy != Result.getValueType()) 1181 Result = DAG.getNode(ISD::BITCAST, DL, ResTy, Result); 1182 1183 return Result; 1184 } 1185 else if (isSplatVector(Node)) 1186 return DAG.getNode(MipsISD::VSPLAT, DL, ResTy, Op->getOperand(0)); 1187 1188 return SDValue(); 1189} 1190 1191MachineBasicBlock * MipsSETargetLowering:: 1192emitBPOSGE32(MachineInstr *MI, MachineBasicBlock *BB) const{ 1193 // $bb: 1194 // bposge32_pseudo $vr0 1195 // => 1196 // $bb: 1197 // bposge32 $tbb 1198 // $fbb: 1199 // li $vr2, 0 1200 // b $sink 1201 // $tbb: 1202 // li $vr1, 1 1203 // $sink: 1204 // $vr0 = phi($vr2, $fbb, $vr1, $tbb) 1205 1206 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); 1207 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); 1208 const TargetRegisterClass *RC = &Mips::GPR32RegClass; 1209 DebugLoc DL = MI->getDebugLoc(); 1210 const BasicBlock *LLVM_BB = BB->getBasicBlock(); 1211 MachineFunction::iterator It = llvm::next(MachineFunction::iterator(BB)); 1212 MachineFunction *F = BB->getParent(); 1213 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB); 1214 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB); 1215 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB); 1216 F->insert(It, FBB); 1217 F->insert(It, TBB); 1218 F->insert(It, Sink); 1219 1220 // Transfer the remainder of BB and its successor edges to Sink. 1221 Sink->splice(Sink->begin(), BB, llvm::next(MachineBasicBlock::iterator(MI)), 1222 BB->end()); 1223 Sink->transferSuccessorsAndUpdatePHIs(BB); 1224 1225 // Add successors. 1226 BB->addSuccessor(FBB); 1227 BB->addSuccessor(TBB); 1228 FBB->addSuccessor(Sink); 1229 TBB->addSuccessor(Sink); 1230 1231 // Insert the real bposge32 instruction to $BB. 1232 BuildMI(BB, DL, TII->get(Mips::BPOSGE32)).addMBB(TBB); 1233 1234 // Fill $FBB. 1235 unsigned VR2 = RegInfo.createVirtualRegister(RC); 1236 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), VR2) 1237 .addReg(Mips::ZERO).addImm(0); 1238 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink); 1239 1240 // Fill $TBB. 1241 unsigned VR1 = RegInfo.createVirtualRegister(RC); 1242 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), VR1) 1243 .addReg(Mips::ZERO).addImm(1); 1244 1245 // Insert phi function to $Sink. 1246 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI), 1247 MI->getOperand(0).getReg()) 1248 .addReg(VR2).addMBB(FBB).addReg(VR1).addMBB(TBB); 1249 1250 MI->eraseFromParent(); // The pseudo instruction is gone now. 1251 return Sink; 1252} 1253 1254MachineBasicBlock * MipsSETargetLowering:: 1255emitMSACBranchPseudo(MachineInstr *MI, MachineBasicBlock *BB, 1256 unsigned BranchOp) const{ 1257 // $bb: 1258 // vany_nonzero $rd, $ws 1259 // => 1260 // $bb: 1261 // bnz.b $ws, $tbb 1262 // b $fbb 1263 // $fbb: 1264 // li $rd1, 0 1265 // b $sink 1266 // $tbb: 1267 // li $rd2, 1 1268 // $sink: 1269 // $rd = phi($rd1, $fbb, $rd2, $tbb) 1270 1271 MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); 1272 const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); 1273 const TargetRegisterClass *RC = &Mips::GPR32RegClass; 1274 DebugLoc DL = MI->getDebugLoc(); 1275 const BasicBlock *LLVM_BB = BB->getBasicBlock(); 1276 MachineFunction::iterator It = llvm::next(MachineFunction::iterator(BB)); 1277 MachineFunction *F = BB->getParent(); 1278 MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB); 1279 MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB); 1280 MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB); 1281 F->insert(It, FBB); 1282 F->insert(It, TBB); 1283 F->insert(It, Sink); 1284 1285 // Transfer the remainder of BB and its successor edges to Sink. 1286 Sink->splice(Sink->begin(), BB, llvm::next(MachineBasicBlock::iterator(MI)), 1287 BB->end()); 1288 Sink->transferSuccessorsAndUpdatePHIs(BB); 1289 1290 // Add successors. 1291 BB->addSuccessor(FBB); 1292 BB->addSuccessor(TBB); 1293 FBB->addSuccessor(Sink); 1294 TBB->addSuccessor(Sink); 1295 1296 // Insert the real bnz.b instruction to $BB. 1297 BuildMI(BB, DL, TII->get(BranchOp)) 1298 .addReg(MI->getOperand(1).getReg()) 1299 .addMBB(TBB); 1300 1301 // Fill $FBB. 1302 unsigned RD1 = RegInfo.createVirtualRegister(RC); 1303 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), RD1) 1304 .addReg(Mips::ZERO).addImm(0); 1305 BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink); 1306 1307 // Fill $TBB. 1308 unsigned RD2 = RegInfo.createVirtualRegister(RC); 1309 BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), RD2) 1310 .addReg(Mips::ZERO).addImm(1); 1311 1312 // Insert phi function to $Sink. 1313 BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI), 1314 MI->getOperand(0).getReg()) 1315 .addReg(RD1).addMBB(FBB).addReg(RD2).addMBB(TBB); 1316 1317 MI->eraseFromParent(); // The pseudo instruction is gone now. 1318 return Sink; 1319} 1320