2012-12-11 21:25:42 +00:00
|
|
|
//===-- AMDILISelDAGToDAG.cpp - A dag to dag inst selector for AMDIL ------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//==-----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
/// \brief Defines an instruction selector for the AMDGPU target.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "AMDGPUInstrInfo.h"
|
|
|
|
#include "AMDGPUISelLowering.h" // For AMDGPUISD
|
|
|
|
#include "AMDGPURegisterInfo.h"
|
2014-06-13 01:32:00 +00:00
|
|
|
#include "AMDGPUSubtarget.h"
|
2012-12-11 21:25:42 +00:00
|
|
|
#include "R600InstrInfo.h"
|
2014-07-21 15:45:01 +00:00
|
|
|
#include "SIDefines.h"
|
2013-02-26 17:52:23 +00:00
|
|
|
#include "SIISelLowering.h"
|
2014-07-21 15:45:01 +00:00
|
|
|
#include "SIMachineFunctionInfo.h"
|
2014-04-29 23:12:48 +00:00
|
|
|
#include "llvm/CodeGen/FunctionLoweringInfo.h"
|
2012-12-11 21:25:42 +00:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2014-07-21 15:45:01 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2013-05-23 17:10:37 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2012-12-11 21:25:42 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
2014-04-29 23:12:48 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
2012-12-11 21:25:42 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Instruction Selector Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
/// AMDGPU specific code to select AMDGPU machine instructions for
|
|
|
|
/// SelectionDAG operations.
|
|
|
|
class AMDGPUDAGToDAGISel : public SelectionDAGISel {
|
|
|
|
// Subtarget - Keep a pointer to the AMDGPU Subtarget around so that we can
|
|
|
|
// make the right decision when generating code for different targets.
|
2015-01-30 23:24:40 +00:00
|
|
|
const AMDGPUSubtarget *Subtarget;
|
2012-12-11 21:25:42 +00:00
|
|
|
public:
|
|
|
|
AMDGPUDAGToDAGISel(TargetMachine &TM);
|
|
|
|
virtual ~AMDGPUDAGToDAGISel();
|
2015-01-30 23:24:40 +00:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2014-04-29 07:57:24 +00:00
|
|
|
SDNode *Select(SDNode *N) override;
|
|
|
|
const char *getPassName() const override;
|
|
|
|
void PostprocessISelDAG() override;
|
2012-12-11 21:25:42 +00:00
|
|
|
|
|
|
|
private:
|
2014-04-03 20:19:27 +00:00
|
|
|
bool isInlineImmediate(SDNode *N) const;
|
2012-12-11 21:25:42 +00:00
|
|
|
inline SDValue getSmallIPtrImm(unsigned Imm);
|
2013-06-04 23:17:15 +00:00
|
|
|
bool FoldOperand(SDValue &Src, SDValue &Sel, SDValue &Neg, SDValue &Abs,
|
2013-07-23 01:48:24 +00:00
|
|
|
const R600InstrInfo *TII);
|
2013-01-23 02:09:06 +00:00
|
|
|
bool FoldOperands(unsigned, const R600InstrInfo *, std::vector<SDValue> &);
|
2013-06-04 23:17:15 +00:00
|
|
|
bool FoldDotOperands(unsigned, const R600InstrInfo *, std::vector<SDValue> &);
|
2012-12-11 21:25:42 +00:00
|
|
|
|
|
|
|
// Complex pattern selectors
|
|
|
|
bool SelectADDRParam(SDValue Addr, SDValue& R1, SDValue& R2);
|
|
|
|
bool SelectADDR(SDValue N, SDValue &R1, SDValue &R2);
|
|
|
|
bool SelectADDR64(SDValue N, SDValue &R1, SDValue &R2);
|
|
|
|
|
|
|
|
static bool checkType(const Value *ptr, unsigned int addrspace);
|
2014-04-15 07:22:52 +00:00
|
|
|
static bool checkPrivateAddress(const MachineMemOperand *Op);
|
2012-12-11 21:25:42 +00:00
|
|
|
|
|
|
|
static bool isGlobalStore(const StoreSDNode *N);
|
2014-09-15 15:41:53 +00:00
|
|
|
static bool isFlatStore(const StoreSDNode *N);
|
2012-12-11 21:25:42 +00:00
|
|
|
static bool isPrivateStore(const StoreSDNode *N);
|
|
|
|
static bool isLocalStore(const StoreSDNode *N);
|
|
|
|
static bool isRegionStore(const StoreSDNode *N);
|
|
|
|
|
2013-06-18 23:37:58 +00:00
|
|
|
bool isCPLoad(const LoadSDNode *N) const;
|
|
|
|
bool isConstantLoad(const LoadSDNode *N, int cbID) const;
|
|
|
|
bool isGlobalLoad(const LoadSDNode *N) const;
|
2014-09-15 15:41:53 +00:00
|
|
|
bool isFlatLoad(const LoadSDNode *N) const;
|
2013-06-18 23:37:58 +00:00
|
|
|
bool isParamLoad(const LoadSDNode *N) const;
|
|
|
|
bool isPrivateLoad(const LoadSDNode *N) const;
|
|
|
|
bool isLocalLoad(const LoadSDNode *N) const;
|
|
|
|
bool isRegionLoad(const LoadSDNode *N) const;
|
2012-12-11 21:25:42 +00:00
|
|
|
|
2013-08-14 23:24:24 +00:00
|
|
|
const TargetRegisterClass *getOperandRegClass(SDNode *N, unsigned OpNo) const;
|
2013-01-23 02:09:06 +00:00
|
|
|
bool SelectGlobalValueConstantOffset(SDValue Addr, SDValue& IntPtr);
|
2014-04-18 07:40:20 +00:00
|
|
|
bool SelectGlobalValueVariableOffset(SDValue Addr, SDValue &BaseReg,
|
|
|
|
SDValue& Offset);
|
2012-12-11 21:25:42 +00:00
|
|
|
bool SelectADDRVTX_READ(SDValue Addr, SDValue &Base, SDValue &Offset);
|
2013-02-06 17:32:29 +00:00
|
|
|
bool SelectADDRIndirect(SDValue Addr, SDValue &Base, SDValue &Offset);
|
2014-08-22 18:49:33 +00:00
|
|
|
bool isDSOffsetLegal(const SDValue &Base, unsigned Offset,
|
|
|
|
unsigned OffsetBits) const;
|
|
|
|
bool SelectDS1Addr1Offset(SDValue Ptr, SDValue &Base, SDValue &Offset) const;
|
2014-08-22 18:49:35 +00:00
|
|
|
bool SelectDS64Bit4ByteAligned(SDValue Ptr, SDValue &Base, SDValue &Offset0,
|
|
|
|
SDValue &Offset1) const;
|
2014-08-11 22:18:17 +00:00
|
|
|
void SelectMUBUF(SDValue Addr, SDValue &SRsrc, SDValue &VAddr,
|
|
|
|
SDValue &SOffset, SDValue &Offset, SDValue &Offen,
|
|
|
|
SDValue &Idxen, SDValue &Addr64, SDValue &GLC, SDValue &SLC,
|
|
|
|
SDValue &TFE) const;
|
|
|
|
bool SelectMUBUFAddr64(SDValue Addr, SDValue &SRsrc, SDValue &VAddr,
|
2015-02-27 14:59:41 +00:00
|
|
|
SDValue &SOffset, SDValue &Offset, SDValue &GLC,
|
|
|
|
SDValue &SLC, SDValue &TFE) const;
|
2014-09-25 18:30:26 +00:00
|
|
|
bool SelectMUBUFAddr64(SDValue Addr, SDValue &SRsrc,
|
2015-02-11 00:34:32 +00:00
|
|
|
SDValue &VAddr, SDValue &SOffset, SDValue &Offset,
|
2014-09-25 18:30:26 +00:00
|
|
|
SDValue &SLC) const;
|
2014-07-21 15:45:01 +00:00
|
|
|
bool SelectMUBUFScratch(SDValue Addr, SDValue &RSrc, SDValue &VAddr,
|
|
|
|
SDValue &SOffset, SDValue &ImmOffset) const;
|
2014-08-11 22:18:17 +00:00
|
|
|
bool SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc, SDValue &SOffset,
|
|
|
|
SDValue &Offset, SDValue &GLC, SDValue &SLC,
|
2014-07-21 15:45:01 +00:00
|
|
|
SDValue &TFE) const;
|
2014-09-25 18:30:26 +00:00
|
|
|
bool SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc, SDValue &Soffset,
|
|
|
|
SDValue &Offset, SDValue &GLC) const;
|
2014-09-15 15:41:53 +00:00
|
|
|
SDNode *SelectAddrSpaceCast(SDNode *N);
|
2014-08-01 00:32:39 +00:00
|
|
|
bool SelectVOP3Mods(SDValue In, SDValue &Src, SDValue &SrcMods) const;
|
|
|
|
bool SelectVOP3Mods0(SDValue In, SDValue &Src, SDValue &SrcMods,
|
|
|
|
SDValue &Clamp, SDValue &Omod) const;
|
2012-12-11 21:25:42 +00:00
|
|
|
|
2014-11-13 19:49:04 +00:00
|
|
|
bool SelectVOP3Mods0Clamp(SDValue In, SDValue &Src, SDValue &SrcMods,
|
|
|
|
SDValue &Omod) const;
|
2015-01-06 23:00:37 +00:00
|
|
|
bool SelectVOP3Mods0Clamp0OMod(SDValue In, SDValue &Src, SDValue &SrcMods,
|
|
|
|
SDValue &Clamp,
|
|
|
|
SDValue &Omod) const;
|
2014-11-13 19:49:04 +00:00
|
|
|
|
2014-06-23 18:00:38 +00:00
|
|
|
SDNode *SelectADD_SUB_I64(SDNode *N);
|
2014-06-23 18:28:28 +00:00
|
|
|
SDNode *SelectDIV_SCALE(SDNode *N);
|
2014-06-23 18:00:34 +00:00
|
|
|
|
2012-12-11 21:25:42 +00:00
|
|
|
// Include the pieces autogenerated from the target description.
|
|
|
|
#include "AMDGPUGenDAGISel.inc"
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
/// \brief This pass converts a legalized DAG into a AMDGPU-specific
|
|
|
|
// DAG, ready for instruction scheduling.
|
2014-04-18 07:40:20 +00:00
|
|
|
FunctionPass *llvm::createAMDGPUISelDag(TargetMachine &TM) {
|
2012-12-11 21:25:42 +00:00
|
|
|
return new AMDGPUDAGToDAGISel(TM);
|
|
|
|
}
|
|
|
|
|
2013-06-19 21:36:55 +00:00
|
|
|
AMDGPUDAGToDAGISel::AMDGPUDAGToDAGISel(TargetMachine &TM)
|
2015-01-30 23:24:40 +00:00
|
|
|
: SelectionDAGISel(TM) {}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
Subtarget = &static_cast<const AMDGPUSubtarget &>(MF.getSubtarget());
|
|
|
|
return SelectionDAGISel::runOnMachineFunction(MF);
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AMDGPUDAGToDAGISel::~AMDGPUDAGToDAGISel() {
|
|
|
|
}
|
|
|
|
|
2014-04-03 20:19:27 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isInlineImmediate(SDNode *N) const {
|
|
|
|
const SITargetLowering *TL
|
|
|
|
= static_cast<const SITargetLowering *>(getTargetLowering());
|
|
|
|
return TL->analyzeImmediate(N) == 0;
|
|
|
|
}
|
|
|
|
|
2013-08-14 23:24:24 +00:00
|
|
|
/// \brief Determine the register class for \p OpNo
|
|
|
|
/// \returns The register class of the virtual register that will be used for
|
|
|
|
/// the given operand number \OpNo or NULL if the register class cannot be
|
|
|
|
/// determined.
|
|
|
|
const TargetRegisterClass *AMDGPUDAGToDAGISel::getOperandRegClass(SDNode *N,
|
|
|
|
unsigned OpNo) const {
|
2014-04-18 07:40:20 +00:00
|
|
|
if (!N->isMachineOpcode())
|
|
|
|
return nullptr;
|
|
|
|
|
2013-08-14 23:24:24 +00:00
|
|
|
switch (N->getMachineOpcode()) {
|
|
|
|
default: {
|
2014-08-04 21:25:23 +00:00
|
|
|
const MCInstrDesc &Desc =
|
2015-01-30 23:24:40 +00:00
|
|
|
Subtarget->getInstrInfo()->get(N->getMachineOpcode());
|
2013-08-15 07:11:34 +00:00
|
|
|
unsigned OpIdx = Desc.getNumDefs() + OpNo;
|
|
|
|
if (OpIdx >= Desc.getNumOperands())
|
2014-04-18 07:40:20 +00:00
|
|
|
return nullptr;
|
2013-08-15 07:11:34 +00:00
|
|
|
int RegClass = Desc.OpInfo[OpIdx].RegClass;
|
2014-04-18 07:40:20 +00:00
|
|
|
if (RegClass == -1)
|
|
|
|
return nullptr;
|
|
|
|
|
2015-01-30 23:24:40 +00:00
|
|
|
return Subtarget->getRegisterInfo()->getRegClass(RegClass);
|
2013-08-14 23:24:24 +00:00
|
|
|
}
|
|
|
|
case AMDGPU::REG_SEQUENCE: {
|
2014-04-18 07:40:20 +00:00
|
|
|
unsigned RCID = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
|
2014-08-04 21:25:23 +00:00
|
|
|
const TargetRegisterClass *SuperRC =
|
2015-01-30 23:24:40 +00:00
|
|
|
Subtarget->getRegisterInfo()->getRegClass(RCID);
|
2014-04-18 07:40:20 +00:00
|
|
|
|
|
|
|
SDValue SubRegOp = N->getOperand(OpNo + 1);
|
|
|
|
unsigned SubRegIdx = cast<ConstantSDNode>(SubRegOp)->getZExtValue();
|
2015-01-30 23:24:40 +00:00
|
|
|
return Subtarget->getRegisterInfo()->getSubClassWithSubReg(SuperRC,
|
|
|
|
SubRegIdx);
|
2013-08-14 23:24:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-11 21:25:42 +00:00
|
|
|
SDValue AMDGPUDAGToDAGISel::getSmallIPtrImm(unsigned int Imm) {
|
|
|
|
return CurDAG->getTargetConstant(Imm, MVT::i32);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectADDRParam(
|
2014-04-18 07:40:20 +00:00
|
|
|
SDValue Addr, SDValue& R1, SDValue& R2) {
|
2012-12-11 21:25:42 +00:00
|
|
|
|
|
|
|
if (Addr.getOpcode() == ISD::FrameIndex) {
|
|
|
|
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
|
|
|
|
R1 = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
|
|
|
|
R2 = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
} else {
|
|
|
|
R1 = Addr;
|
|
|
|
R2 = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
}
|
|
|
|
} else if (Addr.getOpcode() == ISD::ADD) {
|
|
|
|
R1 = Addr.getOperand(0);
|
|
|
|
R2 = Addr.getOperand(1);
|
|
|
|
} else {
|
|
|
|
R1 = Addr;
|
|
|
|
R2 = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectADDR(SDValue Addr, SDValue& R1, SDValue& R2) {
|
|
|
|
if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
|
|
|
|
Addr.getOpcode() == ISD::TargetGlobalAddress) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return SelectADDRParam(Addr, R1, R2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectADDR64(SDValue Addr, SDValue& R1, SDValue& R2) {
|
|
|
|
if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
|
|
|
|
Addr.getOpcode() == ISD::TargetGlobalAddress) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Addr.getOpcode() == ISD::FrameIndex) {
|
|
|
|
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
|
|
|
|
R1 = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i64);
|
|
|
|
R2 = CurDAG->getTargetConstant(0, MVT::i64);
|
|
|
|
} else {
|
|
|
|
R1 = Addr;
|
|
|
|
R2 = CurDAG->getTargetConstant(0, MVT::i64);
|
|
|
|
}
|
|
|
|
} else if (Addr.getOpcode() == ISD::ADD) {
|
|
|
|
R1 = Addr.getOperand(0);
|
|
|
|
R2 = Addr.getOperand(1);
|
|
|
|
} else {
|
|
|
|
R1 = Addr;
|
|
|
|
R2 = CurDAG->getTargetConstant(0, MVT::i64);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDNode *AMDGPUDAGToDAGISel::Select(SDNode *N) {
|
|
|
|
unsigned int Opc = N->getOpcode();
|
|
|
|
if (N->isMachineOpcode()) {
|
2013-09-22 08:21:56 +00:00
|
|
|
N->setNodeId(-1);
|
2014-04-18 07:40:20 +00:00
|
|
|
return nullptr; // Already selected.
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
2014-04-18 05:19:26 +00:00
|
|
|
|
2012-12-11 21:25:42 +00:00
|
|
|
switch (Opc) {
|
|
|
|
default: break;
|
2014-02-25 21:36:18 +00:00
|
|
|
// We are selecting i64 ADD here instead of custom lower it during
|
|
|
|
// DAG legalization, so we can fold some i64 ADDs used for address
|
|
|
|
// calculation into the LOAD and STORE instructions.
|
2014-06-23 18:00:38 +00:00
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::SUB: {
|
2014-02-25 21:36:18 +00:00
|
|
|
if (N->getValueType(0) != MVT::i64 ||
|
2015-01-30 23:24:40 +00:00
|
|
|
Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
|
2014-02-25 21:36:18 +00:00
|
|
|
break;
|
|
|
|
|
2014-06-23 18:00:38 +00:00
|
|
|
return SelectADD_SUB_I64(N);
|
2014-02-25 21:36:18 +00:00
|
|
|
}
|
2014-06-11 17:40:32 +00:00
|
|
|
case ISD::SCALAR_TO_VECTOR:
|
2014-06-17 16:53:14 +00:00
|
|
|
case AMDGPUISD::BUILD_VERTICAL_VECTOR:
|
2013-03-05 15:04:49 +00:00
|
|
|
case ISD::BUILD_VECTOR: {
|
2013-08-14 23:24:32 +00:00
|
|
|
unsigned RegClassID;
|
2015-01-30 23:24:40 +00:00
|
|
|
const AMDGPURegisterInfo *TRI = Subtarget->getRegisterInfo();
|
2013-08-14 23:24:32 +00:00
|
|
|
EVT VT = N->getValueType(0);
|
|
|
|
unsigned NumVectorElts = VT.getVectorNumElements();
|
2014-06-11 17:40:32 +00:00
|
|
|
EVT EltVT = VT.getVectorElementType();
|
|
|
|
assert(EltVT.bitsEq(MVT::i32));
|
2015-01-30 23:24:40 +00:00
|
|
|
if (Subtarget->getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) {
|
2013-08-14 23:24:32 +00:00
|
|
|
bool UseVReg = true;
|
|
|
|
for (SDNode::use_iterator U = N->use_begin(), E = SDNode::use_end();
|
|
|
|
U != E; ++U) {
|
|
|
|
if (!U->isMachineOpcode()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const TargetRegisterClass *RC = getOperandRegClass(*U, U.getOperandNo());
|
|
|
|
if (!RC) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-30 23:24:40 +00:00
|
|
|
if (static_cast<const SIRegisterInfo *>(TRI)->isSGPRClass(RC)) {
|
2013-08-14 23:24:32 +00:00
|
|
|
UseVReg = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch(NumVectorElts) {
|
2015-01-07 20:59:25 +00:00
|
|
|
case 1: RegClassID = UseVReg ? AMDGPU::VGPR_32RegClassID :
|
2013-08-14 23:24:32 +00:00
|
|
|
AMDGPU::SReg_32RegClassID;
|
|
|
|
break;
|
|
|
|
case 2: RegClassID = UseVReg ? AMDGPU::VReg_64RegClassID :
|
|
|
|
AMDGPU::SReg_64RegClassID;
|
|
|
|
break;
|
|
|
|
case 4: RegClassID = UseVReg ? AMDGPU::VReg_128RegClassID :
|
|
|
|
AMDGPU::SReg_128RegClassID;
|
|
|
|
break;
|
|
|
|
case 8: RegClassID = UseVReg ? AMDGPU::VReg_256RegClassID :
|
|
|
|
AMDGPU::SReg_256RegClassID;
|
|
|
|
break;
|
|
|
|
case 16: RegClassID = UseVReg ? AMDGPU::VReg_512RegClassID :
|
|
|
|
AMDGPU::SReg_512RegClassID;
|
|
|
|
break;
|
2013-08-31 21:20:04 +00:00
|
|
|
default: llvm_unreachable("Do not know how to lower this BUILD_VECTOR");
|
2013-08-14 23:24:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// BUILD_VECTOR was lowered into an IMPLICIT_DEF + 4 INSERT_SUBREG
|
|
|
|
// that adds a 128 bits reg copy when going through TwoAddressInstructions
|
|
|
|
// pass. We want to avoid 128 bits copies as much as possible because they
|
|
|
|
// can't be bundled by our scheduler.
|
|
|
|
switch(NumVectorElts) {
|
|
|
|
case 2: RegClassID = AMDGPU::R600_Reg64RegClassID; break;
|
2014-06-17 16:53:14 +00:00
|
|
|
case 4:
|
|
|
|
if (Opc == AMDGPUISD::BUILD_VERTICAL_VECTOR)
|
|
|
|
RegClassID = AMDGPU::R600_Reg128VerticalRegClassID;
|
|
|
|
else
|
|
|
|
RegClassID = AMDGPU::R600_Reg128RegClassID;
|
|
|
|
break;
|
2013-08-14 23:24:32 +00:00
|
|
|
default: llvm_unreachable("Do not know how to lower this BUILD_VECTOR");
|
|
|
|
}
|
2013-03-05 15:04:49 +00:00
|
|
|
}
|
2013-08-01 15:23:42 +00:00
|
|
|
|
2013-08-14 23:24:32 +00:00
|
|
|
SDValue RegClass = CurDAG->getTargetConstant(RegClassID, MVT::i32);
|
|
|
|
|
|
|
|
if (NumVectorElts == 1) {
|
2014-06-11 17:40:32 +00:00
|
|
|
return CurDAG->SelectNodeTo(N, AMDGPU::COPY_TO_REGCLASS, EltVT,
|
2013-08-14 23:24:32 +00:00
|
|
|
N->getOperand(0), RegClass);
|
2013-08-01 15:23:42 +00:00
|
|
|
}
|
2013-08-14 23:24:32 +00:00
|
|
|
|
|
|
|
assert(NumVectorElts <= 16 && "Vectors with more than 16 elements not "
|
|
|
|
"supported yet");
|
|
|
|
// 16 = Max Num Vector Elements
|
|
|
|
// 2 = 2 REG_SEQUENCE operands per element (value, subreg index)
|
|
|
|
// 1 = Vector Register Class
|
2014-06-11 17:40:32 +00:00
|
|
|
SmallVector<SDValue, 16 * 2 + 1> RegSeqArgs(NumVectorElts * 2 + 1);
|
2013-08-14 23:24:32 +00:00
|
|
|
|
|
|
|
RegSeqArgs[0] = CurDAG->getTargetConstant(RegClassID, MVT::i32);
|
2013-03-05 15:04:49 +00:00
|
|
|
bool IsRegSeq = true;
|
2014-06-11 17:40:32 +00:00
|
|
|
unsigned NOps = N->getNumOperands();
|
|
|
|
for (unsigned i = 0; i < NOps; i++) {
|
2013-08-14 23:24:32 +00:00
|
|
|
// XXX: Why is this here?
|
2013-03-05 15:04:49 +00:00
|
|
|
if (dyn_cast<RegisterSDNode>(N->getOperand(i))) {
|
|
|
|
IsRegSeq = false;
|
|
|
|
break;
|
|
|
|
}
|
2013-08-14 23:24:32 +00:00
|
|
|
RegSeqArgs[1 + (2 * i)] = N->getOperand(i);
|
|
|
|
RegSeqArgs[1 + (2 * i) + 1] =
|
|
|
|
CurDAG->getTargetConstant(TRI->getSubRegFromChannel(i), MVT::i32);
|
2013-03-05 15:04:49 +00:00
|
|
|
}
|
2014-06-11 17:40:32 +00:00
|
|
|
|
|
|
|
if (NOps != NumVectorElts) {
|
|
|
|
// Fill in the missing undef elements if this was a scalar_to_vector.
|
|
|
|
assert(Opc == ISD::SCALAR_TO_VECTOR && NOps < NumVectorElts);
|
|
|
|
|
|
|
|
MachineSDNode *ImpDef = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
|
|
|
|
SDLoc(N), EltVT);
|
|
|
|
for (unsigned i = NOps; i < NumVectorElts; ++i) {
|
|
|
|
RegSeqArgs[1 + (2 * i)] = SDValue(ImpDef, 0);
|
|
|
|
RegSeqArgs[1 + (2 * i) + 1] =
|
|
|
|
CurDAG->getTargetConstant(TRI->getSubRegFromChannel(i), MVT::i32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 15:04:49 +00:00
|
|
|
if (!IsRegSeq)
|
|
|
|
break;
|
|
|
|
return CurDAG->SelectNodeTo(N, AMDGPU::REG_SEQUENCE, N->getVTList(),
|
2014-04-27 19:21:11 +00:00
|
|
|
RegSeqArgs);
|
2013-03-05 15:04:49 +00:00
|
|
|
}
|
2013-04-05 23:31:51 +00:00
|
|
|
case ISD::BUILD_PAIR: {
|
|
|
|
SDValue RC, SubReg0, SubReg1;
|
2015-01-30 23:24:40 +00:00
|
|
|
if (Subtarget->getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
|
2013-04-05 23:31:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (N->getValueType(0) == MVT::i128) {
|
|
|
|
RC = CurDAG->getTargetConstant(AMDGPU::SReg_128RegClassID, MVT::i32);
|
|
|
|
SubReg0 = CurDAG->getTargetConstant(AMDGPU::sub0_sub1, MVT::i32);
|
|
|
|
SubReg1 = CurDAG->getTargetConstant(AMDGPU::sub2_sub3, MVT::i32);
|
|
|
|
} else if (N->getValueType(0) == MVT::i64) {
|
2014-04-18 00:36:21 +00:00
|
|
|
RC = CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID, MVT::i32);
|
2013-04-05 23:31:51 +00:00
|
|
|
SubReg0 = CurDAG->getTargetConstant(AMDGPU::sub0, MVT::i32);
|
|
|
|
SubReg1 = CurDAG->getTargetConstant(AMDGPU::sub1, MVT::i32);
|
|
|
|
} else {
|
|
|
|
llvm_unreachable("Unhandled value type for BUILD_PAIR");
|
|
|
|
}
|
|
|
|
const SDValue Ops[] = { RC, N->getOperand(0), SubReg0,
|
|
|
|
N->getOperand(1), SubReg1 };
|
|
|
|
return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE,
|
2013-05-25 02:42:55 +00:00
|
|
|
SDLoc(N), N->getValueType(0), Ops);
|
2013-04-05 23:31:51 +00:00
|
|
|
}
|
2014-04-03 20:19:27 +00:00
|
|
|
|
|
|
|
case ISD::Constant:
|
|
|
|
case ISD::ConstantFP: {
|
2015-01-30 23:24:40 +00:00
|
|
|
if (Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS ||
|
2014-04-03 20:19:27 +00:00
|
|
|
N->getValueType(0).getSizeInBits() != 64 || isInlineImmediate(N))
|
|
|
|
break;
|
|
|
|
|
|
|
|
uint64_t Imm;
|
|
|
|
if (ConstantFPSDNode *FP = dyn_cast<ConstantFPSDNode>(N))
|
|
|
|
Imm = FP->getValueAPF().bitcastToAPInt().getZExtValue();
|
|
|
|
else {
|
2014-04-07 19:31:13 +00:00
|
|
|
ConstantSDNode *C = cast<ConstantSDNode>(N);
|
2014-04-03 20:19:27 +00:00
|
|
|
Imm = C->getZExtValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
SDNode *Lo = CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SDLoc(N), MVT::i32,
|
|
|
|
CurDAG->getConstant(Imm & 0xFFFFFFFF, MVT::i32));
|
|
|
|
SDNode *Hi = CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SDLoc(N), MVT::i32,
|
|
|
|
CurDAG->getConstant(Imm >> 32, MVT::i32));
|
|
|
|
const SDValue Ops[] = {
|
|
|
|
CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID, MVT::i32),
|
|
|
|
SDValue(Lo, 0), CurDAG->getTargetConstant(AMDGPU::sub0, MVT::i32),
|
|
|
|
SDValue(Hi, 0), CurDAG->getTargetConstant(AMDGPU::sub1, MVT::i32)
|
|
|
|
};
|
|
|
|
|
|
|
|
return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, SDLoc(N),
|
|
|
|
N->getValueType(0), Ops);
|
|
|
|
}
|
|
|
|
|
2015-01-23 22:05:45 +00:00
|
|
|
case ISD::LOAD: {
|
|
|
|
// To simplify the TableGen patters, we replace all i64 loads with
|
|
|
|
// v2i32 loads. Alternatively, we could promote i64 loads to v2i32
|
|
|
|
// during DAG legalization, however, so places (ExpandUnalignedLoad)
|
|
|
|
// in the DAG legalizer assume that if i64 is legal, so doing this
|
|
|
|
// promotion early can cause problems.
|
|
|
|
EVT VT = N->getValueType(0);
|
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(N);
|
|
|
|
if (VT != MVT::i64 || LD->getExtensionType() != ISD::NON_EXTLOAD)
|
|
|
|
break;
|
|
|
|
|
|
|
|
SDValue NewLoad = CurDAG->getLoad(MVT::v2i32, SDLoc(N), LD->getChain(),
|
|
|
|
LD->getBasePtr(), LD->getMemOperand());
|
|
|
|
SDValue BitCast = CurDAG->getNode(ISD::BITCAST, SDLoc(N),
|
|
|
|
MVT::i64, NewLoad);
|
|
|
|
CurDAG->ReplaceAllUsesOfValueWith(SDValue(N, 1), NewLoad.getValue(1));
|
|
|
|
CurDAG->ReplaceAllUsesOfValueWith(SDValue(N, 0), BitCast);
|
|
|
|
SelectCode(NewLoad.getNode());
|
|
|
|
N = BitCast.getNode();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-02-04 20:49:49 +00:00
|
|
|
case ISD::STORE: {
|
|
|
|
// Handle i64 stores here for the same reason mentioned above for loads.
|
|
|
|
StoreSDNode *ST = cast<StoreSDNode>(N);
|
|
|
|
SDValue Value = ST->getValue();
|
|
|
|
if (Value.getValueType() != MVT::i64 || ST->isTruncatingStore())
|
|
|
|
break;
|
|
|
|
|
|
|
|
SDValue NewValue = CurDAG->getNode(ISD::BITCAST, SDLoc(N),
|
|
|
|
MVT::v2i32, Value);
|
|
|
|
SDValue NewStore = CurDAG->getStore(ST->getChain(), SDLoc(N), NewValue,
|
|
|
|
ST->getBasePtr(), ST->getMemOperand());
|
|
|
|
|
|
|
|
CurDAG->ReplaceAllUsesOfValueWith(SDValue(N, 0), NewStore);
|
|
|
|
|
|
|
|
if (NewValue.getOpcode() == ISD::BITCAST) {
|
|
|
|
Select(NewStore.getNode());
|
|
|
|
return SelectCode(NewValue.getNode());
|
|
|
|
}
|
|
|
|
|
|
|
|
// getNode() may fold the bitcast if its input was another bitcast. If that
|
|
|
|
// happens we should only select the new store.
|
|
|
|
N = NewStore.getNode();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-13 23:36:50 +00:00
|
|
|
case AMDGPUISD::REGISTER_LOAD: {
|
2015-01-30 23:24:40 +00:00
|
|
|
if (Subtarget->getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS)
|
2013-11-13 23:36:50 +00:00
|
|
|
break;
|
|
|
|
SDValue Addr, Offset;
|
|
|
|
|
|
|
|
SelectADDRIndirect(N->getOperand(1), Addr, Offset);
|
|
|
|
const SDValue Ops[] = {
|
|
|
|
Addr,
|
|
|
|
Offset,
|
|
|
|
CurDAG->getTargetConstant(0, MVT::i32),
|
|
|
|
N->getOperand(0),
|
|
|
|
};
|
|
|
|
return CurDAG->getMachineNode(AMDGPU::SI_RegisterLoad, SDLoc(N),
|
|
|
|
CurDAG->getVTList(MVT::i32, MVT::i64, MVT::Other),
|
|
|
|
Ops);
|
|
|
|
}
|
|
|
|
case AMDGPUISD::REGISTER_STORE: {
|
2015-01-30 23:24:40 +00:00
|
|
|
if (Subtarget->getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS)
|
2013-11-13 23:36:50 +00:00
|
|
|
break;
|
|
|
|
SDValue Addr, Offset;
|
|
|
|
SelectADDRIndirect(N->getOperand(2), Addr, Offset);
|
|
|
|
const SDValue Ops[] = {
|
|
|
|
N->getOperand(1),
|
|
|
|
Addr,
|
|
|
|
Offset,
|
|
|
|
CurDAG->getTargetConstant(0, MVT::i32),
|
|
|
|
N->getOperand(0),
|
|
|
|
};
|
|
|
|
return CurDAG->getMachineNode(AMDGPU::SI_RegisterStorePseudo, SDLoc(N),
|
|
|
|
CurDAG->getVTList(MVT::Other),
|
|
|
|
Ops);
|
|
|
|
}
|
2014-04-18 05:19:26 +00:00
|
|
|
|
|
|
|
case AMDGPUISD::BFE_I32:
|
|
|
|
case AMDGPUISD::BFE_U32: {
|
2015-01-30 23:24:40 +00:00
|
|
|
if (Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
|
2014-04-18 05:19:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// There is a scalar version available, but unlike the vector version which
|
|
|
|
// has a separate operand for the offset and width, the scalar version packs
|
|
|
|
// the width and offset into a single operand. Try to move to the scalar
|
|
|
|
// version if the offsets are constant, so that we can try to keep extended
|
|
|
|
// loads of kernel arguments in SGPRs.
|
|
|
|
|
|
|
|
// TODO: Technically we could try to pattern match scalar bitshifts of
|
|
|
|
// dynamic values, but it's probably not useful.
|
|
|
|
ConstantSDNode *Offset = dyn_cast<ConstantSDNode>(N->getOperand(1));
|
|
|
|
if (!Offset)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ConstantSDNode *Width = dyn_cast<ConstantSDNode>(N->getOperand(2));
|
|
|
|
if (!Width)
|
|
|
|
break;
|
|
|
|
|
|
|
|
bool Signed = Opc == AMDGPUISD::BFE_I32;
|
|
|
|
|
|
|
|
// Transformation function, pack the offset and width of a BFE into
|
|
|
|
// the format expected by the S_BFE_I32 / S_BFE_U32. In the second
|
|
|
|
// source, bits [5:0] contain the offset and bits [22:16] the width.
|
|
|
|
|
|
|
|
uint32_t OffsetVal = Offset->getZExtValue();
|
|
|
|
uint32_t WidthVal = Width->getZExtValue();
|
|
|
|
|
|
|
|
uint32_t PackedVal = OffsetVal | WidthVal << 16;
|
|
|
|
|
|
|
|
SDValue PackedOffsetWidth = CurDAG->getTargetConstant(PackedVal, MVT::i32);
|
|
|
|
return CurDAG->getMachineNode(Signed ? AMDGPU::S_BFE_I32 : AMDGPU::S_BFE_U32,
|
|
|
|
SDLoc(N),
|
|
|
|
MVT::i32,
|
|
|
|
N->getOperand(0),
|
|
|
|
PackedOffsetWidth);
|
|
|
|
|
|
|
|
}
|
2014-06-23 18:28:28 +00:00
|
|
|
case AMDGPUISD::DIV_SCALE: {
|
|
|
|
return SelectDIV_SCALE(N);
|
|
|
|
}
|
2014-10-09 19:06:00 +00:00
|
|
|
case ISD::CopyToReg: {
|
|
|
|
const SITargetLowering& Lowering =
|
|
|
|
*static_cast<const SITargetLowering*>(getTargetLowering());
|
|
|
|
Lowering.legalizeTargetIndependentNode(N, *CurDAG);
|
|
|
|
break;
|
|
|
|
}
|
2014-09-15 15:41:53 +00:00
|
|
|
case ISD::ADDRSPACECAST:
|
|
|
|
return SelectAddrSpaceCast(N);
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
2014-10-09 19:06:00 +00:00
|
|
|
|
2013-09-12 23:45:00 +00:00
|
|
|
return SelectCode(N);
|
2013-01-23 02:09:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 21:25:42 +00:00
|
|
|
|
2014-04-18 07:40:20 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::checkType(const Value *Ptr, unsigned AS) {
|
|
|
|
assert(AS != 0 && "Use checkPrivateAddress instead.");
|
|
|
|
if (!Ptr)
|
2012-12-11 21:25:42 +00:00
|
|
|
return false;
|
2014-04-18 07:40:20 +00:00
|
|
|
|
|
|
|
return Ptr->getType()->getPointerAddressSpace() == AS;
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 07:22:52 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::checkPrivateAddress(const MachineMemOperand *Op) {
|
2014-04-18 07:40:20 +00:00
|
|
|
if (Op->getPseudoValue())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (PointerType *PT = dyn_cast<PointerType>(Op->getValue()->getType()))
|
|
|
|
return PT->getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS;
|
|
|
|
|
|
|
|
return false;
|
2014-04-15 07:22:52 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 21:25:42 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isGlobalStore(const StoreSDNode *N) {
|
2014-04-15 07:22:52 +00:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::GLOBAL_ADDRESS);
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::isPrivateStore(const StoreSDNode *N) {
|
2014-04-18 07:40:20 +00:00
|
|
|
const Value *MemVal = N->getMemOperand()->getValue();
|
|
|
|
return (!checkType(MemVal, AMDGPUAS::LOCAL_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::GLOBAL_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::REGION_ADDRESS));
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::isLocalStore(const StoreSDNode *N) {
|
2014-04-15 07:22:52 +00:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::LOCAL_ADDRESS);
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-15 15:41:53 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isFlatStore(const StoreSDNode *N) {
|
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::FLAT_ADDRESS);
|
|
|
|
}
|
|
|
|
|
2012-12-11 21:25:42 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isRegionStore(const StoreSDNode *N) {
|
2014-04-15 07:22:52 +00:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::REGION_ADDRESS);
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2013-07-23 01:48:18 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isConstantLoad(const LoadSDNode *N, int CbId) const {
|
2014-04-18 07:40:20 +00:00
|
|
|
const Value *MemVal = N->getMemOperand()->getValue();
|
|
|
|
if (CbId == -1)
|
|
|
|
return checkType(MemVal, AMDGPUAS::CONSTANT_ADDRESS);
|
|
|
|
|
|
|
|
return checkType(MemVal, AMDGPUAS::CONSTANT_BUFFER_0 + CbId);
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 23:37:58 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isGlobalLoad(const LoadSDNode *N) const {
|
2015-01-30 23:24:40 +00:00
|
|
|
if (N->getAddressSpace() == AMDGPUAS::CONSTANT_ADDRESS)
|
|
|
|
if (Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS ||
|
|
|
|
N->getMemoryVT().bitsLT(MVT::i32))
|
2013-07-23 23:54:56 +00:00
|
|
|
return true;
|
2015-01-30 23:24:40 +00:00
|
|
|
|
2014-04-15 07:22:52 +00:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::GLOBAL_ADDRESS);
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 23:37:58 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isParamLoad(const LoadSDNode *N) const {
|
2014-04-15 07:22:52 +00:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::PARAM_I_ADDRESS);
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 23:37:58 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isLocalLoad(const LoadSDNode *N) const {
|
2014-04-15 07:22:52 +00:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::LOCAL_ADDRESS);
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-15 15:41:53 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isFlatLoad(const LoadSDNode *N) const {
|
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::FLAT_ADDRESS);
|
|
|
|
}
|
|
|
|
|
2013-06-18 23:37:58 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isRegionLoad(const LoadSDNode *N) const {
|
2014-04-15 07:22:52 +00:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::REGION_ADDRESS);
|
2012-12-11 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 23:37:58 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isCPLoad(const LoadSDNode *N) const {
|
2012-12-11 21:25:42 +00:00
|
|
|
MachineMemOperand *MMO = N->getMemOperand();
|
2014-04-15 07:22:52 +00:00
|
|
|
if (checkPrivateAddress(N->getMemOperand())) {
|
2012-12-11 21:25:42 +00:00
|
|
|
if (MMO) {
|
2014-04-15 07:22:52 +00:00
|
|
|
const PseudoSourceValue *PSV = MMO->getPseudoValue();
|
2012-12-11 21:25:42 +00:00
|
|
|
if (PSV && PSV == PseudoSourceValue::getConstantPool()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-18 23:37:58 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isPrivateLoad(const LoadSDNode *N) const {
|
2014-04-15 07:22:52 +00:00
|
|
|
if (checkPrivateAddress(N->getMemOperand())) {
|
2012-12-11 21:25:42 +00:00
|
|
|
// Check to make sure we are not a constant pool load or a constant load
|
|
|
|
// that is marked as a private load
|
|
|
|
if (isCPLoad(N) || isConstantLoad(N, -1)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-04-18 07:40:20 +00:00
|
|
|
|
|
|
|
const Value *MemVal = N->getMemOperand()->getValue();
|
|
|
|
if (!checkType(MemVal, AMDGPUAS::LOCAL_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::GLOBAL_ADDRESS) &&
|
2014-09-15 15:41:53 +00:00
|
|
|
!checkType(MemVal, AMDGPUAS::FLAT_ADDRESS) &&
|
2014-04-18 07:40:20 +00:00
|
|
|
!checkType(MemVal, AMDGPUAS::REGION_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::CONSTANT_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::PARAM_D_ADDRESS) &&
|
2014-09-15 15:41:53 +00:00
|
|
|
!checkType(MemVal, AMDGPUAS::PARAM_I_ADDRESS)) {
|
2012-12-11 21:25:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *AMDGPUDAGToDAGISel::getPassName() const {
|
|
|
|
return "AMDGPU DAG->DAG Pattern Instruction Selection";
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUGTMP
|
|
|
|
#undef INT64_C
|
|
|
|
#endif
|
|
|
|
#undef DEBUGTMP
|
|
|
|
|
2013-07-23 01:48:42 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Complex Patterns
|
|
|
|
//===----------------------------------------------------------------------===//
|
2012-12-11 21:25:42 +00:00
|
|
|
|
2013-01-23 02:09:06 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectGlobalValueConstantOffset(SDValue Addr,
|
2014-04-18 07:40:20 +00:00
|
|
|
SDValue& IntPtr) {
|
2013-01-23 02:09:06 +00:00
|
|
|
if (ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Addr)) {
|
|
|
|
IntPtr = CurDAG->getIntPtrConstant(Cst->getZExtValue() / 4, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectGlobalValueVariableOffset(SDValue Addr,
|
|
|
|
SDValue& BaseReg, SDValue &Offset) {
|
2014-04-18 07:40:20 +00:00
|
|
|
if (!isa<ConstantSDNode>(Addr)) {
|
2013-01-23 02:09:06 +00:00
|
|
|
BaseReg = Addr;
|
|
|
|
Offset = CurDAG->getIntPtrConstant(0, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-11 21:25:42 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectADDRVTX_READ(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) {
|
2014-04-18 07:40:20 +00:00
|
|
|
ConstantSDNode *IMMOffset;
|
2012-12-11 21:25:42 +00:00
|
|
|
|
|
|
|
if (Addr.getOpcode() == ISD::ADD
|
|
|
|
&& (IMMOffset = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))
|
|
|
|
&& isInt<16>(IMMOffset->getZExtValue())) {
|
|
|
|
|
|
|
|
Base = Addr.getOperand(0);
|
|
|
|
Offset = CurDAG->getTargetConstant(IMMOffset->getZExtValue(), MVT::i32);
|
|
|
|
return true;
|
|
|
|
// If the pointer address is constant, we can move it to the offset field.
|
|
|
|
} else if ((IMMOffset = dyn_cast<ConstantSDNode>(Addr))
|
|
|
|
&& isInt<16>(IMMOffset->getZExtValue())) {
|
|
|
|
Base = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
|
2013-05-25 02:42:55 +00:00
|
|
|
SDLoc(CurDAG->getEntryNode()),
|
2012-12-11 21:25:42 +00:00
|
|
|
AMDGPU::ZERO, MVT::i32);
|
|
|
|
Offset = CurDAG->getTargetConstant(IMMOffset->getZExtValue(), MVT::i32);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default case, no offset
|
|
|
|
Base = Addr;
|
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-06 17:32:29 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectADDRIndirect(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) {
|
|
|
|
ConstantSDNode *C;
|
|
|
|
|
|
|
|
if ((C = dyn_cast<ConstantSDNode>(Addr))) {
|
|
|
|
Base = CurDAG->getRegister(AMDGPU::INDIRECT_BASE_ADDR, MVT::i32);
|
|
|
|
Offset = CurDAG->getTargetConstant(C->getZExtValue(), MVT::i32);
|
|
|
|
} else if ((Addr.getOpcode() == ISD::ADD || Addr.getOpcode() == ISD::OR) &&
|
|
|
|
(C = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))) {
|
|
|
|
Base = Addr.getOperand(0);
|
|
|
|
Offset = CurDAG->getTargetConstant(C->getZExtValue(), MVT::i32);
|
|
|
|
} else {
|
|
|
|
Base = Addr;
|
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-26 17:52:16 +00:00
|
|
|
|
2014-06-23 18:00:38 +00:00
|
|
|
SDNode *AMDGPUDAGToDAGISel::SelectADD_SUB_I64(SDNode *N) {
|
2014-06-23 18:00:34 +00:00
|
|
|
SDLoc DL(N);
|
|
|
|
SDValue LHS = N->getOperand(0);
|
|
|
|
SDValue RHS = N->getOperand(1);
|
|
|
|
|
2014-06-23 18:00:38 +00:00
|
|
|
bool IsAdd = (N->getOpcode() == ISD::ADD);
|
|
|
|
|
2014-06-23 18:00:34 +00:00
|
|
|
SDValue Sub0 = CurDAG->getTargetConstant(AMDGPU::sub0, MVT::i32);
|
|
|
|
SDValue Sub1 = CurDAG->getTargetConstant(AMDGPU::sub1, MVT::i32);
|
|
|
|
|
|
|
|
SDNode *Lo0 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
|
|
|
|
DL, MVT::i32, LHS, Sub0);
|
|
|
|
SDNode *Hi0 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
|
|
|
|
DL, MVT::i32, LHS, Sub1);
|
|
|
|
|
|
|
|
SDNode *Lo1 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
|
|
|
|
DL, MVT::i32, RHS, Sub0);
|
|
|
|
SDNode *Hi1 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
|
|
|
|
DL, MVT::i32, RHS, Sub1);
|
|
|
|
|
|
|
|
SDVTList VTList = CurDAG->getVTList(MVT::i32, MVT::Glue);
|
|
|
|
SDValue AddLoArgs[] = { SDValue(Lo0, 0), SDValue(Lo1, 0) };
|
|
|
|
|
2014-06-23 18:00:38 +00:00
|
|
|
|
2014-09-05 14:07:59 +00:00
|
|
|
unsigned Opc = IsAdd ? AMDGPU::S_ADD_U32 : AMDGPU::S_SUB_U32;
|
2014-06-23 18:00:38 +00:00
|
|
|
unsigned CarryOpc = IsAdd ? AMDGPU::S_ADDC_U32 : AMDGPU::S_SUBB_U32;
|
|
|
|
|
|
|
|
SDNode *AddLo = CurDAG->getMachineNode( Opc, DL, VTList, AddLoArgs);
|
|
|
|
SDValue Carry(AddLo, 1);
|
|
|
|
SDNode *AddHi
|
|
|
|
= CurDAG->getMachineNode(CarryOpc, DL, MVT::i32,
|
|
|
|
SDValue(Hi0, 0), SDValue(Hi1, 0), Carry);
|
2014-06-23 18:00:34 +00:00
|
|
|
|
|
|
|
SDValue Args[5] = {
|
|
|
|
CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID, MVT::i32),
|
|
|
|
SDValue(AddLo,0),
|
|
|
|
Sub0,
|
|
|
|
SDValue(AddHi,0),
|
|
|
|
Sub1,
|
|
|
|
};
|
|
|
|
return CurDAG->SelectNodeTo(N, AMDGPU::REG_SEQUENCE, MVT::i64, Args);
|
|
|
|
}
|
|
|
|
|
2015-02-14 04:24:28 +00:00
|
|
|
// We need to handle this here because tablegen doesn't support matching
|
|
|
|
// instructions with multiple outputs.
|
2014-06-23 18:28:28 +00:00
|
|
|
SDNode *AMDGPUDAGToDAGISel::SelectDIV_SCALE(SDNode *N) {
|
|
|
|
SDLoc SL(N);
|
|
|
|
EVT VT = N->getValueType(0);
|
|
|
|
|
|
|
|
assert(VT == MVT::f32 || VT == MVT::f64);
|
|
|
|
|
|
|
|
unsigned Opc
|
|
|
|
= (VT == MVT::f64) ? AMDGPU::V_DIV_SCALE_F64 : AMDGPU::V_DIV_SCALE_F32;
|
|
|
|
|
2015-02-14 04:24:28 +00:00
|
|
|
// src0_modifiers, src0, src1_modifiers, src1, src2_modifiers, src2, clamp, omod
|
|
|
|
SDValue Ops[8];
|
2014-06-23 18:28:28 +00:00
|
|
|
|
2015-02-14 04:24:28 +00:00
|
|
|
SelectVOP3Mods0(N->getOperand(0), Ops[1], Ops[0], Ops[6], Ops[7]);
|
|
|
|
SelectVOP3Mods(N->getOperand(1), Ops[3], Ops[2]);
|
|
|
|
SelectVOP3Mods(N->getOperand(2), Ops[5], Ops[4]);
|
2014-06-23 18:28:28 +00:00
|
|
|
return CurDAG->SelectNodeTo(N, Opc, VT, MVT::i1, Ops);
|
|
|
|
}
|
|
|
|
|
2014-08-22 18:49:33 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::isDSOffsetLegal(const SDValue &Base, unsigned Offset,
|
|
|
|
unsigned OffsetBits) const {
|
|
|
|
if ((OffsetBits == 16 && !isUInt<16>(Offset)) ||
|
|
|
|
(OffsetBits == 8 && !isUInt<8>(Offset)))
|
|
|
|
return false;
|
|
|
|
|
2015-01-30 23:24:40 +00:00
|
|
|
if (Subtarget->getGeneration() >= AMDGPUSubtarget::SEA_ISLANDS)
|
2014-08-22 18:49:33 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// On Southern Islands instruction with a negative base value and an offset
|
|
|
|
// don't seem to work.
|
|
|
|
return CurDAG->SignBitIsZero(Base);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectDS1Addr1Offset(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) const {
|
|
|
|
if (CurDAG->isBaseWithConstantOffset(Addr)) {
|
|
|
|
SDValue N0 = Addr.getOperand(0);
|
|
|
|
SDValue N1 = Addr.getOperand(1);
|
|
|
|
ConstantSDNode *C1 = cast<ConstantSDNode>(N1);
|
|
|
|
if (isDSOffsetLegal(N0, C1->getSExtValue(), 16)) {
|
|
|
|
// (add n0, c0)
|
|
|
|
Base = N0;
|
|
|
|
Offset = N1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 17:21:19 +00:00
|
|
|
// If we have a constant address, prefer to put the constant into the
|
|
|
|
// offset. This can save moves to load the constant address since multiple
|
|
|
|
// operations can share the zero base address register, and enables merging
|
|
|
|
// into read2 / write2 instructions.
|
|
|
|
if (const ConstantSDNode *CAddr = dyn_cast<ConstantSDNode>(Addr)) {
|
|
|
|
if (isUInt<16>(CAddr->getZExtValue())) {
|
2014-10-15 21:08:59 +00:00
|
|
|
SDValue Zero = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
MachineSDNode *MovZero = CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
|
|
|
|
SDLoc(Addr), MVT::i32, Zero);
|
|
|
|
Base = SDValue(MovZero, 0);
|
2014-10-14 17:21:19 +00:00
|
|
|
Offset = Addr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-22 18:49:33 +00:00
|
|
|
// default case
|
|
|
|
Base = Addr;
|
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i16);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-22 18:49:35 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectDS64Bit4ByteAligned(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset0,
|
|
|
|
SDValue &Offset1) const {
|
|
|
|
if (CurDAG->isBaseWithConstantOffset(Addr)) {
|
|
|
|
SDValue N0 = Addr.getOperand(0);
|
|
|
|
SDValue N1 = Addr.getOperand(1);
|
|
|
|
ConstantSDNode *C1 = cast<ConstantSDNode>(N1);
|
|
|
|
unsigned DWordOffset0 = C1->getZExtValue() / 4;
|
|
|
|
unsigned DWordOffset1 = DWordOffset0 + 1;
|
|
|
|
// (add n0, c0)
|
|
|
|
if (isDSOffsetLegal(N0, DWordOffset1, 8)) {
|
|
|
|
Base = N0;
|
|
|
|
Offset0 = CurDAG->getTargetConstant(DWordOffset0, MVT::i8);
|
|
|
|
Offset1 = CurDAG->getTargetConstant(DWordOffset1, MVT::i8);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-15 18:06:43 +00:00
|
|
|
if (const ConstantSDNode *CAddr = dyn_cast<ConstantSDNode>(Addr)) {
|
|
|
|
unsigned DWordOffset0 = CAddr->getZExtValue() / 4;
|
|
|
|
unsigned DWordOffset1 = DWordOffset0 + 1;
|
|
|
|
assert(4 * DWordOffset0 == CAddr->getZExtValue());
|
|
|
|
|
|
|
|
if (isUInt<8>(DWordOffset0) && isUInt<8>(DWordOffset1)) {
|
|
|
|
SDValue Zero = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
MachineSDNode *MovZero
|
|
|
|
= CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
|
|
|
|
SDLoc(Addr), MVT::i32, Zero);
|
|
|
|
Base = SDValue(MovZero, 0);
|
|
|
|
Offset0 = CurDAG->getTargetConstant(DWordOffset0, MVT::i8);
|
|
|
|
Offset1 = CurDAG->getTargetConstant(DWordOffset1, MVT::i8);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-22 18:49:35 +00:00
|
|
|
// default case
|
|
|
|
Base = Addr;
|
|
|
|
Offset0 = CurDAG->getTargetConstant(0, MVT::i8);
|
|
|
|
Offset1 = CurDAG->getTargetConstant(1, MVT::i8);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-21 15:45:01 +00:00
|
|
|
static bool isLegalMUBUFImmOffset(const ConstantSDNode *Imm) {
|
|
|
|
return isUInt<12>(Imm->getZExtValue());
|
|
|
|
}
|
|
|
|
|
2014-08-11 22:18:17 +00:00
|
|
|
void AMDGPUDAGToDAGISel::SelectMUBUF(SDValue Addr, SDValue &Ptr,
|
|
|
|
SDValue &VAddr, SDValue &SOffset,
|
|
|
|
SDValue &Offset, SDValue &Offen,
|
|
|
|
SDValue &Idxen, SDValue &Addr64,
|
|
|
|
SDValue &GLC, SDValue &SLC,
|
|
|
|
SDValue &TFE) const {
|
2014-06-24 23:33:07 +00:00
|
|
|
SDLoc DL(Addr);
|
|
|
|
|
2014-08-11 22:18:17 +00:00
|
|
|
GLC = CurDAG->getTargetConstant(0, MVT::i1);
|
|
|
|
SLC = CurDAG->getTargetConstant(0, MVT::i1);
|
|
|
|
TFE = CurDAG->getTargetConstant(0, MVT::i1);
|
|
|
|
|
|
|
|
Idxen = CurDAG->getTargetConstant(0, MVT::i1);
|
|
|
|
Offen = CurDAG->getTargetConstant(0, MVT::i1);
|
|
|
|
Addr64 = CurDAG->getTargetConstant(0, MVT::i1);
|
|
|
|
SOffset = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
|
2014-06-24 23:33:07 +00:00
|
|
|
if (CurDAG->isBaseWithConstantOffset(Addr)) {
|
|
|
|
SDValue N0 = Addr.getOperand(0);
|
|
|
|
SDValue N1 = Addr.getOperand(1);
|
|
|
|
ConstantSDNode *C1 = cast<ConstantSDNode>(N1);
|
|
|
|
|
2015-02-11 00:34:35 +00:00
|
|
|
if (N0.getOpcode() == ISD::ADD) {
|
|
|
|
// (add (add N2, N3), C1) -> addr64
|
|
|
|
SDValue N2 = N0.getOperand(0);
|
|
|
|
SDValue N3 = N0.getOperand(1);
|
|
|
|
Addr64 = CurDAG->getTargetConstant(1, MVT::i1);
|
|
|
|
Ptr = N2;
|
|
|
|
VAddr = N3;
|
|
|
|
} else {
|
2014-06-24 23:33:07 +00:00
|
|
|
|
2014-08-11 22:18:17 +00:00
|
|
|
// (add N0, C1) -> offset
|
|
|
|
VAddr = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
Ptr = N0;
|
2015-02-11 00:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isLegalMUBUFImmOffset(C1)) {
|
|
|
|
Offset = CurDAG->getTargetConstant(C1->getZExtValue(), MVT::i16);
|
|
|
|
return;
|
|
|
|
} else if (isUInt<32>(C1->getZExtValue())) {
|
|
|
|
// Illegal offset, store it in soffset.
|
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i16);
|
|
|
|
SOffset = SDValue(CurDAG->getMachineNode(AMDGPU::S_MOV_B32, DL, MVT::i32,
|
|
|
|
CurDAG->getTargetConstant(C1->getZExtValue(), MVT::i32)), 0);
|
2014-08-11 22:18:17 +00:00
|
|
|
return;
|
2014-06-24 23:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-11 00:34:35 +00:00
|
|
|
|
2014-06-24 23:33:07 +00:00
|
|
|
if (Addr.getOpcode() == ISD::ADD) {
|
2014-08-11 22:18:17 +00:00
|
|
|
// (add N0, N1) -> addr64
|
2014-06-24 23:33:07 +00:00
|
|
|
SDValue N0 = Addr.getOperand(0);
|
|
|
|
SDValue N1 = Addr.getOperand(1);
|
2014-08-11 22:18:17 +00:00
|
|
|
Addr64 = CurDAG->getTargetConstant(1, MVT::i1);
|
|
|
|
Ptr = N0;
|
|
|
|
VAddr = N1;
|
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i16);
|
|
|
|
return;
|
2014-06-24 23:33:07 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 22:18:17 +00:00
|
|
|
// default case -> offset
|
|
|
|
VAddr = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
Ptr = Addr;
|
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i16);
|
|
|
|
|
2014-06-24 23:33:07 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 22:18:17 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFAddr64(SDValue Addr, SDValue &SRsrc,
|
2015-02-11 00:34:32 +00:00
|
|
|
SDValue &VAddr, SDValue &SOffset,
|
2015-02-27 14:59:41 +00:00
|
|
|
SDValue &Offset, SDValue &GLC,
|
|
|
|
SDValue &SLC, SDValue &TFE) const {
|
|
|
|
SDValue Ptr, Offen, Idxen, Addr64;
|
2014-07-21 15:45:01 +00:00
|
|
|
|
2014-08-11 22:18:17 +00:00
|
|
|
SelectMUBUF(Addr, Ptr, VAddr, SOffset, Offset, Offen, Idxen, Addr64,
|
|
|
|
GLC, SLC, TFE);
|
|
|
|
|
|
|
|
ConstantSDNode *C = cast<ConstantSDNode>(Addr64);
|
|
|
|
if (C->getSExtValue()) {
|
|
|
|
SDLoc DL(Addr);
|
2014-11-05 19:01:17 +00:00
|
|
|
|
|
|
|
const SITargetLowering& Lowering =
|
|
|
|
*static_cast<const SITargetLowering*>(getTargetLowering());
|
|
|
|
|
|
|
|
SRsrc = SDValue(Lowering.wrapAddr64Rsrc(*CurDAG, DL, Ptr), 0);
|
2014-08-11 22:18:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-11-05 19:01:17 +00:00
|
|
|
|
2014-08-11 22:18:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-25 18:30:26 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFAddr64(SDValue Addr, SDValue &SRsrc,
|
2015-02-11 00:34:32 +00:00
|
|
|
SDValue &VAddr, SDValue &SOffset,
|
|
|
|
SDValue &Offset,
|
|
|
|
SDValue &SLC) const {
|
2014-09-25 18:30:26 +00:00
|
|
|
SLC = CurDAG->getTargetConstant(0, MVT::i1);
|
2015-02-27 14:59:41 +00:00
|
|
|
SDValue GLC, TFE;
|
2014-09-25 18:30:26 +00:00
|
|
|
|
2015-02-27 14:59:41 +00:00
|
|
|
return SelectMUBUFAddr64(Addr, SRsrc, VAddr, SOffset, Offset, GLC, SLC, TFE);
|
2014-09-25 18:30:26 +00:00
|
|
|
}
|
|
|
|
|
2014-07-21 15:45:01 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFScratch(SDValue Addr, SDValue &Rsrc,
|
|
|
|
SDValue &VAddr, SDValue &SOffset,
|
|
|
|
SDValue &ImmOffset) const {
|
|
|
|
|
|
|
|
SDLoc DL(Addr);
|
|
|
|
MachineFunction &MF = CurDAG->getMachineFunction();
|
2014-08-05 02:39:49 +00:00
|
|
|
const SIRegisterInfo *TRI =
|
2015-01-30 23:24:40 +00:00
|
|
|
static_cast<const SIRegisterInfo *>(Subtarget->getRegisterInfo());
|
2014-07-21 15:45:01 +00:00
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
2014-08-21 20:40:58 +00:00
|
|
|
const SITargetLowering& Lowering =
|
|
|
|
*static_cast<const SITargetLowering*>(getTargetLowering());
|
2014-07-21 15:45:01 +00:00
|
|
|
|
|
|
|
unsigned ScratchOffsetReg =
|
|
|
|
TRI->getPreloadedValue(MF, SIRegisterInfo::SCRATCH_WAVE_OFFSET);
|
2014-08-21 20:40:58 +00:00
|
|
|
Lowering.CreateLiveInRegister(*CurDAG, &AMDGPU::SReg_32RegClass,
|
|
|
|
ScratchOffsetReg, MVT::i32);
|
2015-01-20 17:49:47 +00:00
|
|
|
SDValue Sym0 = CurDAG->getExternalSymbol("SCRATCH_RSRC_DWORD0", MVT::i32);
|
|
|
|
SDValue ScratchRsrcDword0 =
|
|
|
|
SDValue(CurDAG->getMachineNode(AMDGPU::S_MOV_B32, DL, MVT::i32, Sym0), 0);
|
2014-07-21 15:45:01 +00:00
|
|
|
|
2015-01-20 17:49:47 +00:00
|
|
|
SDValue Sym1 = CurDAG->getExternalSymbol("SCRATCH_RSRC_DWORD1", MVT::i32);
|
|
|
|
SDValue ScratchRsrcDword1 =
|
|
|
|
SDValue(CurDAG->getMachineNode(AMDGPU::S_MOV_B32, DL, MVT::i32, Sym1), 0);
|
|
|
|
|
|
|
|
const SDValue RsrcOps[] = {
|
|
|
|
CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID, MVT::i32),
|
|
|
|
ScratchRsrcDword0,
|
|
|
|
CurDAG->getTargetConstant(AMDGPU::sub0, MVT::i32),
|
|
|
|
ScratchRsrcDword1,
|
|
|
|
CurDAG->getTargetConstant(AMDGPU::sub1, MVT::i32),
|
|
|
|
};
|
|
|
|
SDValue ScratchPtr = SDValue(CurDAG->getMachineNode(AMDGPU::REG_SEQUENCE, DL,
|
|
|
|
MVT::v2i32, RsrcOps), 0);
|
2014-11-05 19:01:19 +00:00
|
|
|
Rsrc = SDValue(Lowering.buildScratchRSRC(*CurDAG, DL, ScratchPtr), 0);
|
2014-07-21 15:45:01 +00:00
|
|
|
SOffset = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), DL,
|
|
|
|
MRI.getLiveInVirtReg(ScratchOffsetReg), MVT::i32);
|
|
|
|
|
|
|
|
// (add n0, c1)
|
|
|
|
if (CurDAG->isBaseWithConstantOffset(Addr)) {
|
|
|
|
SDValue N1 = Addr.getOperand(1);
|
|
|
|
ConstantSDNode *C1 = cast<ConstantSDNode>(N1);
|
|
|
|
|
|
|
|
if (isLegalMUBUFImmOffset(C1)) {
|
|
|
|
VAddr = Addr.getOperand(0);
|
|
|
|
ImmOffset = CurDAG->getTargetConstant(C1->getZExtValue(), MVT::i16);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// (node)
|
|
|
|
VAddr = Addr;
|
|
|
|
ImmOffset = CurDAG->getTargetConstant(0, MVT::i16);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-11 22:18:17 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc,
|
|
|
|
SDValue &SOffset, SDValue &Offset,
|
|
|
|
SDValue &GLC, SDValue &SLC,
|
|
|
|
SDValue &TFE) const {
|
|
|
|
SDValue Ptr, VAddr, Offen, Idxen, Addr64;
|
2014-12-02 17:05:41 +00:00
|
|
|
const SIInstrInfo *TII =
|
2015-01-30 23:24:40 +00:00
|
|
|
static_cast<const SIInstrInfo *>(Subtarget->getInstrInfo());
|
2014-07-21 15:45:01 +00:00
|
|
|
|
2014-08-11 22:18:17 +00:00
|
|
|
SelectMUBUF(Addr, Ptr, VAddr, SOffset, Offset, Offen, Idxen, Addr64,
|
|
|
|
GLC, SLC, TFE);
|
2014-07-21 15:45:01 +00:00
|
|
|
|
2014-08-11 22:18:17 +00:00
|
|
|
if (!cast<ConstantSDNode>(Offen)->getSExtValue() &&
|
|
|
|
!cast<ConstantSDNode>(Idxen)->getSExtValue() &&
|
|
|
|
!cast<ConstantSDNode>(Addr64)->getSExtValue()) {
|
2014-12-02 17:05:41 +00:00
|
|
|
uint64_t Rsrc = TII->getDefaultRsrcDataFormat() |
|
2014-08-11 22:18:17 +00:00
|
|
|
APInt::getAllOnesValue(32).getZExtValue(); // Size
|
|
|
|
SDLoc DL(Addr);
|
2014-11-05 19:01:19 +00:00
|
|
|
|
|
|
|
const SITargetLowering& Lowering =
|
|
|
|
*static_cast<const SITargetLowering*>(getTargetLowering());
|
|
|
|
|
|
|
|
SRsrc = SDValue(Lowering.buildRSRC(*CurDAG, DL, Ptr, 0, Rsrc), 0);
|
2014-08-11 22:18:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2014-07-21 15:45:01 +00:00
|
|
|
}
|
|
|
|
|
2014-09-25 18:30:26 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc,
|
|
|
|
SDValue &Soffset, SDValue &Offset,
|
|
|
|
SDValue &GLC) const {
|
|
|
|
SDValue SLC, TFE;
|
|
|
|
|
|
|
|
return SelectMUBUFOffset(Addr, SRsrc, Soffset, Offset, GLC, SLC, TFE);
|
|
|
|
}
|
|
|
|
|
2014-09-15 15:41:53 +00:00
|
|
|
// FIXME: This is incorrect and only enough to be able to compile.
|
|
|
|
SDNode *AMDGPUDAGToDAGISel::SelectAddrSpaceCast(SDNode *N) {
|
|
|
|
AddrSpaceCastSDNode *ASC = cast<AddrSpaceCastSDNode>(N);
|
|
|
|
SDLoc DL(N);
|
|
|
|
|
2015-01-30 23:24:40 +00:00
|
|
|
assert(Subtarget->hasFlatAddressSpace() &&
|
2014-09-15 15:41:53 +00:00
|
|
|
"addrspacecast only supported with flat address space!");
|
|
|
|
|
|
|
|
assert((ASC->getSrcAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS &&
|
|
|
|
ASC->getDestAddressSpace() != AMDGPUAS::CONSTANT_ADDRESS) &&
|
|
|
|
"Cannot cast address space to / from constant address!");
|
|
|
|
|
|
|
|
assert((ASC->getSrcAddressSpace() == AMDGPUAS::FLAT_ADDRESS ||
|
|
|
|
ASC->getDestAddressSpace() == AMDGPUAS::FLAT_ADDRESS) &&
|
|
|
|
"Can only cast to / from flat address space!");
|
|
|
|
|
|
|
|
// The flat instructions read the address as the index of the VGPR holding the
|
|
|
|
// address, so casting should just be reinterpreting the base VGPR, so just
|
|
|
|
// insert trunc / bitcast / zext.
|
|
|
|
|
|
|
|
SDValue Src = ASC->getOperand(0);
|
|
|
|
EVT DestVT = ASC->getValueType(0);
|
|
|
|
EVT SrcVT = Src.getValueType();
|
|
|
|
|
|
|
|
unsigned SrcSize = SrcVT.getSizeInBits();
|
|
|
|
unsigned DestSize = DestVT.getSizeInBits();
|
|
|
|
|
|
|
|
if (SrcSize > DestSize) {
|
|
|
|
assert(SrcSize == 64 && DestSize == 32);
|
|
|
|
return CurDAG->getMachineNode(
|
|
|
|
TargetOpcode::EXTRACT_SUBREG,
|
|
|
|
DL,
|
|
|
|
DestVT,
|
|
|
|
Src,
|
|
|
|
CurDAG->getTargetConstant(AMDGPU::sub0, MVT::i32));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (DestSize > SrcSize) {
|
|
|
|
assert(SrcSize == 32 && DestSize == 64);
|
|
|
|
|
2015-01-12 19:33:18 +00:00
|
|
|
// FIXME: This is probably wrong, we should never be defining
|
|
|
|
// a register class with both VGPRs and SGPRs
|
|
|
|
SDValue RC = CurDAG->getTargetConstant(AMDGPU::VS_64RegClassID, MVT::i32);
|
2014-09-15 15:41:53 +00:00
|
|
|
|
|
|
|
const SDValue Ops[] = {
|
|
|
|
RC,
|
|
|
|
Src,
|
|
|
|
CurDAG->getTargetConstant(AMDGPU::sub0, MVT::i32),
|
|
|
|
SDValue(CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SDLoc(N), MVT::i32,
|
|
|
|
CurDAG->getConstant(0, MVT::i32)), 0),
|
|
|
|
CurDAG->getTargetConstant(AMDGPU::sub1, MVT::i32)
|
|
|
|
};
|
|
|
|
|
|
|
|
return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE,
|
|
|
|
SDLoc(N), N->getValueType(0), Ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(SrcSize == 64 && DestSize == 64);
|
|
|
|
return CurDAG->getNode(ISD::BITCAST, DL, DestVT, Src).getNode();
|
|
|
|
}
|
|
|
|
|
2014-08-01 00:32:39 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectVOP3Mods(SDValue In, SDValue &Src,
|
|
|
|
SDValue &SrcMods) const {
|
|
|
|
|
|
|
|
unsigned Mods = 0;
|
|
|
|
|
|
|
|
Src = In;
|
|
|
|
|
|
|
|
if (Src.getOpcode() == ISD::FNEG) {
|
|
|
|
Mods |= SISrcMods::NEG;
|
|
|
|
Src = Src.getOperand(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Src.getOpcode() == ISD::FABS) {
|
|
|
|
Mods |= SISrcMods::ABS;
|
|
|
|
Src = Src.getOperand(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SrcMods = CurDAG->getTargetConstant(Mods, MVT::i32);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectVOP3Mods0(SDValue In, SDValue &Src,
|
|
|
|
SDValue &SrcMods, SDValue &Clamp,
|
|
|
|
SDValue &Omod) const {
|
|
|
|
// FIXME: Handle Clamp and Omod
|
|
|
|
Clamp = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
Omod = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
|
|
|
|
return SelectVOP3Mods(In, Src, SrcMods);
|
|
|
|
}
|
|
|
|
|
2014-11-13 19:49:04 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectVOP3Mods0Clamp(SDValue In, SDValue &Src,
|
|
|
|
SDValue &SrcMods,
|
|
|
|
SDValue &Omod) const {
|
|
|
|
// FIXME: Handle Omod
|
|
|
|
Omod = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
|
|
|
|
return SelectVOP3Mods(In, Src, SrcMods);
|
|
|
|
}
|
|
|
|
|
2015-01-06 23:00:37 +00:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectVOP3Mods0Clamp0OMod(SDValue In, SDValue &Src,
|
|
|
|
SDValue &SrcMods,
|
|
|
|
SDValue &Clamp,
|
|
|
|
SDValue &Omod) const {
|
|
|
|
Clamp = Omod = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
return SelectVOP3Mods(In, Src, SrcMods);
|
|
|
|
}
|
|
|
|
|
2013-02-26 17:52:16 +00:00
|
|
|
void AMDGPUDAGToDAGISel::PostprocessISelDAG() {
|
2013-06-19 21:36:55 +00:00
|
|
|
const AMDGPUTargetLowering& Lowering =
|
2014-04-18 07:40:20 +00:00
|
|
|
*static_cast<const AMDGPUTargetLowering*>(getTargetLowering());
|
2013-09-12 23:44:44 +00:00
|
|
|
bool IsModified = false;
|
|
|
|
do {
|
|
|
|
IsModified = false;
|
|
|
|
// Go over all selected nodes and try to fold them a bit more
|
|
|
|
for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
|
|
|
|
E = CurDAG->allnodes_end(); I != E; ++I) {
|
2013-02-26 17:52:16 +00:00
|
|
|
|
2013-09-12 23:44:44 +00:00
|
|
|
SDNode *Node = I;
|
2013-06-03 17:39:46 +00:00
|
|
|
|
2013-09-12 23:44:44 +00:00
|
|
|
MachineSDNode *MachineNode = dyn_cast<MachineSDNode>(I);
|
|
|
|
if (!MachineNode)
|
|
|
|
continue;
|
2013-02-26 17:52:16 +00:00
|
|
|
|
2013-09-12 23:44:44 +00:00
|
|
|
SDNode *ResNode = Lowering.PostISelFolding(MachineNode, *CurDAG);
|
|
|
|
if (ResNode != Node) {
|
|
|
|
ReplaceUses(Node, ResNode);
|
|
|
|
IsModified = true;
|
|
|
|
}
|
2013-06-03 17:39:46 +00:00
|
|
|
}
|
2013-09-12 23:44:44 +00:00
|
|
|
CurDAG->RemoveDeadNodes();
|
|
|
|
} while (IsModified);
|
2013-02-26 17:52:16 +00:00
|
|
|
}
|