MipsISelDAGToDAG.cpp revision acfa5a203c01d99aac1bdc1e045c08153bcdbbf6
1cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//===-- MipsISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Mips --------===// 2cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// 3cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// The LLVM Compiler Infrastructure 4cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// 5cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// This file is distributed under the University of Illinois Open Source 6cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// License. See LICENSE.TXT for details. 7cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// 8cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//===----------------------------------------------------------------------===// 9cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// 10ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com// This file defines an instruction selector for the MIPS target. 11ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com// 12ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com//===----------------------------------------------------------------------===// 132af2ad9cc0b2c7d911aed2e8d2ac77c0b7d3b5dfedisonn@google.com 142af2ad9cc0b2c7d911aed2e8d2ac77c0b7d3b5dfedisonn@google.com#define DEBUG_TYPE "mips-isel" 152af2ad9cc0b2c7d911aed2e8d2ac77c0b7d3b5dfedisonn@google.com#include "MipsISelDAGToDAG.h" 162af2ad9cc0b2c7d911aed2e8d2ac77c0b7d3b5dfedisonn@google.com#include "Mips16ISelDAGToDAG.h" 172af2ad9cc0b2c7d911aed2e8d2ac77c0b7d3b5dfedisonn@google.com#include "MipsSEISelDAGToDAG.h" 182af2ad9cc0b2c7d911aed2e8d2ac77c0b7d3b5dfedisonn@google.com#include "Mips.h" 19ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com#include "MCTargetDesc/MipsBaseInfo.h" 20ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com#include "MipsMachineFunction.h" 21ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com#include "MipsRegisterInfo.h" 22ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com#include "llvm/CodeGen/MachineConstantPool.h" 23ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com#include "llvm/CodeGen/MachineFrameInfo.h" 241f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com#include "llvm/CodeGen/MachineFunction.h" 25ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com#include "llvm/CodeGen/MachineInstrBuilder.h" 26ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com#include "llvm/CodeGen/MachineRegisterInfo.h" 27ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com#include "llvm/CodeGen/SelectionDAGNodes.h" 28ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com#include "llvm/IR/GlobalValue.h" 298f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com#include "llvm/IR/Instructions.h" 308f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com#include "llvm/IR/Intrinsics.h" 318f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com#include "llvm/IR/Type.h" 32ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com#include "llvm/Support/CFG.h" 338f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com#include "llvm/Support/Debug.h" 348f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com#include "llvm/Support/ErrorHandling.h" 358f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com#include "llvm/Support/raw_ostream.h" 368f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com#include "llvm/Target/TargetMachine.h" 378f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.comusing namespace llvm; 38ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com 398f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com//===----------------------------------------------------------------------===// 40ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com// Instruction Selector Implementation 41ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com//===----------------------------------------------------------------------===// 422c8177767a4b3b6c27c6ac071c8619b557472521edisonn@google.com 438f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com//===----------------------------------------------------------------------===// 44ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com// MipsDAGToDAGISel - MIPS specific code to select MIPS machine 458f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com// instructions for SelectionDAG operations. 46ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com//===----------------------------------------------------------------------===// 478f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com 48ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.combool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) { 498f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com bool Ret = SelectionDAGISel::runOnMachineFunction(MF); 50ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com 51ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com processFunctionAfterISel(MF); 52ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com 53ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com return Ret; 548f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com} 558f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com 568f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com/// getGlobalBaseReg - Output the instructions required to put the 578f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com/// GOT address into a register. 588f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.comSDNode *MipsDAGToDAGISel::getGlobalBaseReg() { 598f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg(); 608f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com return CurDAG->getRegister(GlobalBaseReg, 618f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com getTargetLowering()->getPointerTy()).getNode(); 625c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org} 638f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com 645c70cdca5efe541b70d010e91607bf8626ea49cacommit-bot@chromium.org/// ComplexPattern used on MipsInstrInfo 658f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com/// Used on Mips Load/Store instructions 668f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.combool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base, 67370a89980b2d38a6d01903b484bf404d6c48b496skia.committer@gmail.com SDValue &Offset) const { 68370a89980b2d38a6d01903b484bf404d6c48b496skia.committer@gmail.com llvm_unreachable("Unimplemented function."); 698f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com return false; 708f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com} 718f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com 728f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.combool MipsDAGToDAGISel::selectAddrRegReg(SDValue Addr, SDValue &Base, 738f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com SDValue &Offset) const { 748f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com llvm_unreachable("Unimplemented function."); 758f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com return false; 768f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com} 778f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com 788f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.combool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base, 79ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com SDValue &Offset) const { 80ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com llvm_unreachable("Unimplemented function."); 81ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com return false; 821f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com} 83ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com 84e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.orgbool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base, 85e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org SDValue &Offset) const { 86e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org llvm_unreachable("Unimplemented function."); 87e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org return false; 88e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org} 89e54a23fcfa42b2fc9d320650de72bcb2d9566b2dcommit-bot@chromium.org 90e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.combool MipsDAGToDAGISel::selectIntAddrMM(SDValue Addr, SDValue &Base, 91e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com SDValue &Offset) const { 92e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com llvm_unreachable("Unimplemented function."); 93e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com return false; 94e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com} 95e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com 96e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.combool MipsDAGToDAGISel::selectAddr16(SDNode *Parent, SDValue N, SDValue &Base, 97e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com SDValue &Offset, SDValue &Alias) { 98e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com llvm_unreachable("Unimplemented function."); 99e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com return false; 100e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com} 1018f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com 1028f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.combool MipsDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm) const { 1038f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com llvm_unreachable("Unimplemented function."); 1048f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com return false; 1058f90a892c5130d4d26b5588e1ff151d01a40688arobertphillips@google.com} 1069b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillips 1079b14f26d0f3a974f3dd626c8354e1db1cfcd322frobertphillipsbool MipsDAGToDAGISel::selectVSplatUimm3(SDValue N, SDValue &Imm) const { 108ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com llvm_unreachable("Unimplemented function."); 109ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com return false; 110ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com} 111ac03d91ee03599eab946a8ad25e33f9fc5f3166eedisonn@google.com 112cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.combool MipsDAGToDAGISel::selectVSplatUimm4(SDValue N, SDValue &Imm) const { 113 llvm_unreachable("Unimplemented function."); 114 return false; 115} 116 117bool MipsDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &Imm) const { 118 llvm_unreachable("Unimplemented function."); 119 return false; 120} 121 122bool MipsDAGToDAGISel::selectVSplatUimm6(SDValue N, SDValue &Imm) const { 123 llvm_unreachable("Unimplemented function."); 124 return false; 125} 126 127bool MipsDAGToDAGISel::selectVSplatUimm8(SDValue N, SDValue &Imm) const { 128 llvm_unreachable("Unimplemented function."); 129 return false; 130} 131 132bool MipsDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &Imm) const { 133 llvm_unreachable("Unimplemented function."); 134 return false; 135} 136 137bool MipsDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const { 138 llvm_unreachable("Unimplemented function."); 139 return false; 140} 141 142/// Select instructions not customized! Used for 143/// expanded, promoted and normal instructions 144SDNode* MipsDAGToDAGISel::Select(SDNode *Node) { 145 unsigned Opcode = Node->getOpcode(); 146 147 // Dump information about the Node being selected 148 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n"); 149 150 // If we have a custom node, we already have selected! 151 if (Node->isMachineOpcode()) { 152 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n"); 153 Node->setNodeId(-1); 154 return NULL; 155 } 156 157 // See if subclasses can handle this node. 158 std::pair<bool, SDNode*> Ret = selectNode(Node); 159 160 if (Ret.first) 161 return Ret.second; 162 163 switch(Opcode) { 164 default: break; 165 166 // Get target GOT address. 167 case ISD::GLOBAL_OFFSET_TABLE: 168 return getGlobalBaseReg(); 169 170#ifndef NDEBUG 171 case ISD::LOAD: 172 case ISD::STORE: 173 assert(cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <= 174 cast<MemSDNode>(Node)->getAlignment() && 175 "Unexpected unaligned loads/stores."); 176 break; 177#endif 178 } 179 180 // Select the default instruction 181 SDNode *ResNode = SelectCode(Node); 182 183 DEBUG(errs() << "=> "); 184 if (ResNode == NULL || ResNode == Node) 185 DEBUG(Node->dump(CurDAG)); 186 else 187 DEBUG(ResNode->dump(CurDAG)); 188 DEBUG(errs() << "\n"); 189 return ResNode; 190} 191 192bool MipsDAGToDAGISel:: 193SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode, 194 std::vector<SDValue> &OutOps) { 195 assert(ConstraintCode == 'm' && "unexpected asm memory constraint"); 196 OutOps.push_back(Op); 197 return false; 198} 199 200/// createMipsISelDag - This pass converts a legalized DAG into a 201/// MIPS-specific DAG, ready for instruction scheduling. 202FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) { 203 if (TM.getSubtargetImpl()->inMips16Mode()) 204 return llvm::createMips16ISelDag(TM); 205 206 return llvm::createMipsSEISelDag(TM); 207} 208