LLVM API Documentation
00001 //===-- MipsISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Mips --------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines an instruction selector for the MIPS target. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "MipsISelDAGToDAG.h" 00015 #include "MCTargetDesc/MipsBaseInfo.h" 00016 #include "Mips.h" 00017 #include "Mips16ISelDAGToDAG.h" 00018 #include "MipsMachineFunction.h" 00019 #include "MipsRegisterInfo.h" 00020 #include "MipsSEISelDAGToDAG.h" 00021 #include "llvm/CodeGen/MachineConstantPool.h" 00022 #include "llvm/CodeGen/MachineFrameInfo.h" 00023 #include "llvm/CodeGen/MachineFunction.h" 00024 #include "llvm/CodeGen/MachineInstrBuilder.h" 00025 #include "llvm/CodeGen/MachineRegisterInfo.h" 00026 #include "llvm/CodeGen/SelectionDAGNodes.h" 00027 #include "llvm/IR/CFG.h" 00028 #include "llvm/IR/GlobalValue.h" 00029 #include "llvm/IR/Instructions.h" 00030 #include "llvm/IR/Intrinsics.h" 00031 #include "llvm/IR/Type.h" 00032 #include "llvm/Support/Debug.h" 00033 #include "llvm/Support/ErrorHandling.h" 00034 #include "llvm/Support/raw_ostream.h" 00035 #include "llvm/Target/TargetMachine.h" 00036 using namespace llvm; 00037 00038 #define DEBUG_TYPE "mips-isel" 00039 00040 //===----------------------------------------------------------------------===// 00041 // Instruction Selector Implementation 00042 //===----------------------------------------------------------------------===// 00043 00044 //===----------------------------------------------------------------------===// 00045 // MipsDAGToDAGISel - MIPS specific code to select MIPS machine 00046 // instructions for SelectionDAG operations. 00047 //===----------------------------------------------------------------------===// 00048 00049 bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) { 00050 Subtarget = &TM.getSubtarget<MipsSubtarget>(); 00051 bool Ret = SelectionDAGISel::runOnMachineFunction(MF); 00052 00053 processFunctionAfterISel(MF); 00054 00055 return Ret; 00056 } 00057 00058 /// getGlobalBaseReg - Output the instructions required to put the 00059 /// GOT address into a register. 00060 SDNode *MipsDAGToDAGISel::getGlobalBaseReg() { 00061 unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg(); 00062 return CurDAG->getRegister(GlobalBaseReg, 00063 getTargetLowering()->getPointerTy()).getNode(); 00064 } 00065 00066 /// ComplexPattern used on MipsInstrInfo 00067 /// Used on Mips Load/Store instructions 00068 bool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base, 00069 SDValue &Offset) const { 00070 llvm_unreachable("Unimplemented function."); 00071 return false; 00072 } 00073 00074 bool MipsDAGToDAGISel::selectAddrRegReg(SDValue Addr, SDValue &Base, 00075 SDValue &Offset) const { 00076 llvm_unreachable("Unimplemented function."); 00077 return false; 00078 } 00079 00080 bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base, 00081 SDValue &Offset) const { 00082 llvm_unreachable("Unimplemented function."); 00083 return false; 00084 } 00085 00086 bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base, 00087 SDValue &Offset) const { 00088 llvm_unreachable("Unimplemented function."); 00089 return false; 00090 } 00091 00092 bool MipsDAGToDAGISel::selectIntAddrMM(SDValue Addr, SDValue &Base, 00093 SDValue &Offset) const { 00094 llvm_unreachable("Unimplemented function."); 00095 return false; 00096 } 00097 00098 bool MipsDAGToDAGISel::selectIntAddrMSA(SDValue Addr, SDValue &Base, 00099 SDValue &Offset) const { 00100 llvm_unreachable("Unimplemented function."); 00101 return false; 00102 } 00103 00104 bool MipsDAGToDAGISel::selectAddr16(SDNode *Parent, SDValue N, SDValue &Base, 00105 SDValue &Offset, SDValue &Alias) { 00106 llvm_unreachable("Unimplemented function."); 00107 return false; 00108 } 00109 00110 bool MipsDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm) const { 00111 llvm_unreachable("Unimplemented function."); 00112 return false; 00113 } 00114 00115 bool MipsDAGToDAGISel::selectVSplatUimm1(SDValue N, SDValue &Imm) const { 00116 llvm_unreachable("Unimplemented function."); 00117 return false; 00118 } 00119 00120 bool MipsDAGToDAGISel::selectVSplatUimm2(SDValue N, SDValue &Imm) const { 00121 llvm_unreachable("Unimplemented function."); 00122 return false; 00123 } 00124 00125 bool MipsDAGToDAGISel::selectVSplatUimm3(SDValue N, SDValue &Imm) const { 00126 llvm_unreachable("Unimplemented function."); 00127 return false; 00128 } 00129 00130 bool MipsDAGToDAGISel::selectVSplatUimm4(SDValue N, SDValue &Imm) const { 00131 llvm_unreachable("Unimplemented function."); 00132 return false; 00133 } 00134 00135 bool MipsDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &Imm) const { 00136 llvm_unreachable("Unimplemented function."); 00137 return false; 00138 } 00139 00140 bool MipsDAGToDAGISel::selectVSplatUimm6(SDValue N, SDValue &Imm) const { 00141 llvm_unreachable("Unimplemented function."); 00142 return false; 00143 } 00144 00145 bool MipsDAGToDAGISel::selectVSplatUimm8(SDValue N, SDValue &Imm) const { 00146 llvm_unreachable("Unimplemented function."); 00147 return false; 00148 } 00149 00150 bool MipsDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &Imm) const { 00151 llvm_unreachable("Unimplemented function."); 00152 return false; 00153 } 00154 00155 bool MipsDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const { 00156 llvm_unreachable("Unimplemented function."); 00157 return false; 00158 } 00159 00160 bool MipsDAGToDAGISel::selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const { 00161 llvm_unreachable("Unimplemented function."); 00162 return false; 00163 } 00164 00165 bool MipsDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const { 00166 llvm_unreachable("Unimplemented function."); 00167 return false; 00168 } 00169 00170 bool MipsDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const { 00171 llvm_unreachable("Unimplemented function."); 00172 return false; 00173 } 00174 00175 /// Select instructions not customized! Used for 00176 /// expanded, promoted and normal instructions 00177 SDNode* MipsDAGToDAGISel::Select(SDNode *Node) { 00178 unsigned Opcode = Node->getOpcode(); 00179 00180 // Dump information about the Node being selected 00181 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n"); 00182 00183 // If we have a custom node, we already have selected! 00184 if (Node->isMachineOpcode()) { 00185 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n"); 00186 Node->setNodeId(-1); 00187 return nullptr; 00188 } 00189 00190 // See if subclasses can handle this node. 00191 std::pair<bool, SDNode*> Ret = selectNode(Node); 00192 00193 if (Ret.first) 00194 return Ret.second; 00195 00196 switch(Opcode) { 00197 default: break; 00198 00199 // Get target GOT address. 00200 case ISD::GLOBAL_OFFSET_TABLE: 00201 return getGlobalBaseReg(); 00202 00203 #ifndef NDEBUG 00204 case ISD::LOAD: 00205 case ISD::STORE: 00206 assert((Subtarget->systemSupportsUnalignedAccess() || 00207 cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <= 00208 cast<MemSDNode>(Node)->getAlignment()) && 00209 "Unexpected unaligned loads/stores."); 00210 break; 00211 #endif 00212 } 00213 00214 // Select the default instruction 00215 SDNode *ResNode = SelectCode(Node); 00216 00217 DEBUG(errs() << "=> "); 00218 if (ResNode == nullptr || ResNode == Node) 00219 DEBUG(Node->dump(CurDAG)); 00220 else 00221 DEBUG(ResNode->dump(CurDAG)); 00222 DEBUG(errs() << "\n"); 00223 return ResNode; 00224 } 00225 00226 bool MipsDAGToDAGISel:: 00227 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode, 00228 std::vector<SDValue> &OutOps) { 00229 assert(ConstraintCode == 'm' && "unexpected asm memory constraint"); 00230 OutOps.push_back(Op); 00231 return false; 00232 } 00233 00234 /// createMipsISelDag - This pass converts a legalized DAG into a 00235 /// MIPS-specific DAG, ready for instruction scheduling. 00236 FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) { 00237 if (TM.getSubtargetImpl()->inMips16Mode()) 00238 return llvm::createMips16ISelDag(TM); 00239 00240 return llvm::createMipsSEISelDag(TM); 00241 }