2012-02-17 16:55:11 +08:00
|
|
|
//===-- MipsISelDAGToDAG.cpp - A Dag to Dag Inst Selector for Mips --------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
|
|
|
// This file defines an instruction selector for the MIPS target.
|
|
|
|
//
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2013-03-15 02:27:31 +08:00
|
|
|
#include "MipsISelDAGToDAG.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "MCTargetDesc/MipsBaseInfo.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "Mips.h"
|
|
|
|
#include "Mips16ISelDAGToDAG.h"
|
2007-11-05 11:02:32 +08:00
|
|
|
#include "MipsMachineFunction.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "MipsRegisterInfo.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "MipsSEISelDAGToDAG.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2007-12-31 12:13:23 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-02-28 10:55:02 +08:00
|
|
|
#include "llvm/CodeGen/SelectionDAGNodes.h"
|
2014-03-04 19:45:46 +08:00
|
|
|
#include "llvm/IR/CFG.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/GlobalValue.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/Intrinsics.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-09 04:53:28 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "mips-isel"
|
|
|
|
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
// Instruction Selector Implementation
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
|
|
|
|
// instructions for SelectionDAG operations.
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2012-03-08 09:51:59 +08:00
|
|
|
|
2012-02-25 06:34:47 +08:00
|
|
|
bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
bool Ret = SelectionDAGISel::runOnMachineFunction(MF);
|
2012-02-28 15:46:26 +08:00
|
|
|
|
2013-03-15 02:33:23 +08:00
|
|
|
processFunctionAfterISel(MF);
|
2012-02-25 06:34:47 +08:00
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2007-11-13 03:49:57 +08:00
|
|
|
/// getGlobalBaseReg - Output the instructions required to put the
|
|
|
|
/// GOT address into a register.
|
2009-06-04 04:30:14 +08:00
|
|
|
SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
|
2012-02-25 06:34:47 +08:00
|
|
|
unsigned GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg();
|
2013-06-20 05:36:55 +08:00
|
|
|
return CurDAG->getRegister(GlobalBaseReg,
|
|
|
|
getTargetLowering()->getPointerTy()).getNode();
|
2007-11-13 03:49:57 +08:00
|
|
|
}
|
|
|
|
|
2007-06-06 15:42:06 +08:00
|
|
|
/// ComplexPattern used on MipsInstrInfo
|
|
|
|
/// Used on Mips Load/Store instructions
|
2013-02-16 08:14:37 +08:00
|
|
|
bool MipsDAGToDAGISel::selectAddrRegImm(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) const {
|
2013-03-15 02:27:31 +08:00
|
|
|
llvm_unreachable("Unimplemented function.");
|
2013-02-16 05:20:45 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-28 20:04:29 +08:00
|
|
|
bool MipsDAGToDAGISel::selectAddrRegReg(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-16 08:14:37 +08:00
|
|
|
bool MipsDAGToDAGISel::selectAddrDefault(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) const {
|
2013-03-15 02:27:31 +08:00
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
|
|
|
|
2013-02-16 08:14:37 +08:00
|
|
|
bool MipsDAGToDAGISel::selectIntAddr(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) const {
|
2013-03-15 02:27:31 +08:00
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
2012-10-28 14:02:37 +08:00
|
|
|
}
|
|
|
|
|
2013-08-14 04:19:16 +08:00
|
|
|
bool MipsDAGToDAGISel::selectIntAddrMM(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-03 22:31:21 +08:00
|
|
|
bool MipsDAGToDAGISel::selectIntAddrMSA(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-15 02:33:23 +08:00
|
|
|
bool MipsDAGToDAGISel::selectAddr16(SDNode *Parent, SDValue N, SDValue &Base,
|
2013-03-15 02:27:31 +08:00
|
|
|
SDValue &Offset, SDValue &Alias) {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
2011-12-21 07:10:57 +08:00
|
|
|
}
|
|
|
|
|
2013-09-24 21:33:07 +08:00
|
|
|
bool MipsDAGToDAGISel::selectVSplat(SDNode *N, APInt &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-27 19:48:57 +08:00
|
|
|
bool MipsDAGToDAGISel::selectVSplatUimm1(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsDAGToDAGISel::selectVSplatUimm2(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-24 21:33:07 +08:00
|
|
|
bool MipsDAGToDAGISel::selectVSplatUimm3(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsDAGToDAGISel::selectVSplatUimm4(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsDAGToDAGISel::selectVSplatUimm6(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsDAGToDAGISel::selectVSplatUimm8(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsDAGToDAGISel::selectVSplatSimm5(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsDAGToDAGISel::selectVSplatUimmPow2(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-12 18:45:18 +08:00
|
|
|
bool MipsDAGToDAGISel::selectVSplatUimmInvPow2(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-30 22:45:14 +08:00
|
|
|
bool MipsDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const {
|
|
|
|
llvm_unreachable("Unimplemented function.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-06 15:42:06 +08:00
|
|
|
/// Select instructions not customized! Used for
|
|
|
|
/// expanded, promoted and normal instructions
|
2010-01-05 09:24:18 +08:00
|
|
|
SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
|
2007-06-06 15:42:06 +08:00
|
|
|
unsigned Opcode = Node->getOpcode();
|
|
|
|
|
|
|
|
// Dump information about the Node being selected
|
2010-03-02 14:34:30 +08:00
|
|
|
DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
|
2007-06-06 15:42:06 +08:00
|
|
|
|
|
|
|
// If we have a custom node, we already have selected!
|
2008-07-18 03:10:17 +08:00
|
|
|
if (Node->isMachineOpcode()) {
|
2010-03-02 14:34:30 +08:00
|
|
|
DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
|
2013-09-22 16:21:56 +08:00
|
|
|
Node->setNodeId(-1);
|
2014-04-25 13:30:21 +08:00
|
|
|
return nullptr;
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
|
|
|
|
2013-03-15 02:27:31 +08:00
|
|
|
// See if subclasses can handle this node.
|
2013-03-15 02:33:23 +08:00
|
|
|
std::pair<bool, SDNode*> Ret = selectNode(Node);
|
2013-03-15 02:27:31 +08:00
|
|
|
|
|
|
|
if (Ret.first)
|
|
|
|
return Ret.second;
|
2011-12-21 07:10:57 +08:00
|
|
|
|
2007-06-06 15:42:06 +08:00
|
|
|
switch(Opcode) {
|
2011-12-21 06:58:01 +08:00
|
|
|
default: break;
|
|
|
|
|
|
|
|
// Get target GOT address.
|
|
|
|
case ISD::GLOBAL_OFFSET_TABLE:
|
|
|
|
return getGlobalBaseReg();
|
2011-12-21 06:25:50 +08:00
|
|
|
|
2012-09-15 09:52:08 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
case ISD::LOAD:
|
|
|
|
case ISD::STORE:
|
2014-05-23 21:18:02 +08:00
|
|
|
assert((Subtarget.systemSupportsUnalignedAccess() ||
|
|
|
|
cast<MemSDNode>(Node)->getMemoryVT().getSizeInBits() / 8 <=
|
|
|
|
cast<MemSDNode>(Node)->getAlignment()) &&
|
2012-09-15 09:52:08 +08:00
|
|
|
"Unexpected unaligned loads/stores.");
|
|
|
|
break;
|
|
|
|
#endif
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Select the default instruction
|
2010-01-05 09:24:18 +08:00
|
|
|
SDNode *ResNode = SelectCode(Node);
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2010-03-02 14:34:30 +08:00
|
|
|
DEBUG(errs() << "=> ");
|
2014-04-25 13:30:21 +08:00
|
|
|
if (ResNode == nullptr || ResNode == Node)
|
2010-01-05 09:24:18 +08:00
|
|
|
DEBUG(Node->dump(CurDAG));
|
2007-06-06 15:42:06 +08:00
|
|
|
else
|
|
|
|
DEBUG(ResNode->dump(CurDAG));
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << "\n");
|
2007-06-06 15:42:06 +08:00
|
|
|
return ResNode;
|
|
|
|
}
|
|
|
|
|
2011-06-21 08:40:49 +08:00
|
|
|
bool MipsDAGToDAGISel::
|
|
|
|
SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
|
|
|
|
std::vector<SDValue> &OutOps) {
|
|
|
|
assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
|
|
|
|
OutOps.push_back(Op);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-05 01:51:39 +08:00
|
|
|
/// createMipsISelDag - This pass converts a legalized DAG into a
|
2007-06-06 15:42:06 +08:00
|
|
|
/// MIPS-specific DAG, ready for instruction scheduling.
|
|
|
|
FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
|
2013-03-15 02:27:31 +08:00
|
|
|
if (TM.getSubtargetImpl()->inMips16Mode())
|
|
|
|
return llvm::createMips16ISelDag(TM);
|
|
|
|
|
|
|
|
return llvm::createMipsSEISelDag(TM);
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|