2016-01-21 05:22:21 +08:00
|
|
|
//===-- AMDGPUISelDAGToDAG.cpp - A dag to dag inst selector for AMDGPU ----===//
|
2012-12-12 05:25:42 +08:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-12-02 07:04:05 +08:00
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "AMDGPUInstrInfo.h"
|
2016-02-13 07:45:29 +08:00
|
|
|
#include "AMDGPUIntrinsicInfo.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "AMDGPUISelLowering.h" // For AMDGPUISD
|
2014-06-13 09:32:00 +08:00
|
|
|
#include "AMDGPUSubtarget.h"
|
2013-02-27 01:52:23 +08:00
|
|
|
#include "SIISelLowering.h"
|
2014-07-21 23:45:01 +08:00
|
|
|
#include "SIMachineFunctionInfo.h"
|
2016-05-14 04:39:29 +08:00
|
|
|
#include "llvm/Analysis/ValueTracking.h"
|
2014-04-30 07:12:48 +08:00
|
|
|
#include "llvm/CodeGen/FunctionLoweringInfo.h"
|
2016-03-24 05:49:25 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2015-11-04 06:30:08 +08:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2013-05-24 01:10:37 +08:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
2016-02-02 21:52:43 +08:00
|
|
|
#include "llvm/IR/DiagnosticInfo.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2016-02-13 09:24:08 +08:00
|
|
|
namespace llvm {
|
|
|
|
class R600InstrInfo;
|
|
|
|
}
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Instruction Selector Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
2016-02-13 07:45:29 +08:00
|
|
|
|
|
|
|
static bool isCBranchSCC(const SDNode *N) {
|
|
|
|
assert(N->getOpcode() == ISD::BRCOND);
|
|
|
|
if (!N->hasOneUse())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SDValue Cond = N->getOperand(1);
|
|
|
|
if (Cond.getOpcode() == ISD::CopyToReg)
|
|
|
|
Cond = Cond.getOperand(2);
|
|
|
|
return Cond.getOpcode() == ISD::SETCC &&
|
|
|
|
Cond.getOperand(0).getValueType() == MVT::i32 &&
|
|
|
|
Cond.hasOneUse();
|
|
|
|
}
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
/// 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-31 07:24:40 +08:00
|
|
|
const AMDGPUSubtarget *Subtarget;
|
2015-09-22 19:14:39 +08:00
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
public:
|
|
|
|
AMDGPUDAGToDAGISel(TargetMachine &TM);
|
|
|
|
virtual ~AMDGPUDAGToDAGISel();
|
2015-01-31 07:24:40 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
2016-05-13 05:03:32 +08:00
|
|
|
void Select(SDNode *N) override;
|
2014-04-29 15:57:24 +08:00
|
|
|
const char *getPassName() const override;
|
2015-09-26 01:27:08 +08:00
|
|
|
void PreprocessISelDAG() override;
|
2014-04-29 15:57:24 +08:00
|
|
|
void PostprocessISelDAG() override;
|
2012-12-12 05:25:42 +08:00
|
|
|
|
|
|
|
private:
|
2014-04-04 04:19:27 +08:00
|
|
|
bool isInlineImmediate(SDNode *N) const;
|
2013-06-05 07:17:15 +08:00
|
|
|
bool FoldOperand(SDValue &Src, SDValue &Sel, SDValue &Neg, SDValue &Abs,
|
2013-07-23 09:48:24 +08:00
|
|
|
const R600InstrInfo *TII);
|
2013-01-23 10:09:06 +08:00
|
|
|
bool FoldOperands(unsigned, const R600InstrInfo *, std::vector<SDValue> &);
|
2013-06-05 07:17:15 +08:00
|
|
|
bool FoldDotOperands(unsigned, const R600InstrInfo *, std::vector<SDValue> &);
|
2012-12-12 05:25:42 +08: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 15:22:52 +08:00
|
|
|
static bool checkPrivateAddress(const MachineMemOperand *Op);
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2016-04-08 03:23:11 +08:00
|
|
|
static bool isGlobalStore(const MemSDNode *N);
|
|
|
|
static bool isFlatStore(const MemSDNode *N);
|
2012-12-12 05:25:42 +08:00
|
|
|
static bool isPrivateStore(const StoreSDNode *N);
|
|
|
|
static bool isLocalStore(const StoreSDNode *N);
|
|
|
|
static bool isRegionStore(const StoreSDNode *N);
|
|
|
|
|
2013-06-19 07:37:58 +08:00
|
|
|
bool isCPLoad(const LoadSDNode *N) const;
|
2016-04-08 03:23:11 +08:00
|
|
|
bool isConstantLoad(const MemSDNode *N, int cbID) const;
|
|
|
|
bool isGlobalLoad(const MemSDNode *N) const;
|
|
|
|
bool isFlatLoad(const MemSDNode *N) const;
|
2013-06-19 07:37:58 +08: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-12 05:25:42 +08:00
|
|
|
|
2016-02-13 07:45:29 +08:00
|
|
|
bool isUniformBr(const SDNode *N) const;
|
|
|
|
|
2015-05-12 23:00:49 +08:00
|
|
|
SDNode *glueCopyToM0(SDNode *N) const;
|
|
|
|
|
2013-08-15 07:24:24 +08:00
|
|
|
const TargetRegisterClass *getOperandRegClass(SDNode *N, unsigned OpNo) const;
|
2013-01-23 10:09:06 +08:00
|
|
|
bool SelectGlobalValueConstantOffset(SDValue Addr, SDValue& IntPtr);
|
2014-04-18 15:40:20 +08:00
|
|
|
bool SelectGlobalValueVariableOffset(SDValue Addr, SDValue &BaseReg,
|
|
|
|
SDValue& Offset);
|
2012-12-12 05:25:42 +08:00
|
|
|
bool SelectADDRVTX_READ(SDValue Addr, SDValue &Base, SDValue &Offset);
|
2013-02-07 01:32:29 +08:00
|
|
|
bool SelectADDRIndirect(SDValue Addr, SDValue &Base, SDValue &Offset);
|
2014-08-23 02:49:33 +08:00
|
|
|
bool isDSOffsetLegal(const SDValue &Base, unsigned Offset,
|
|
|
|
unsigned OffsetBits) const;
|
|
|
|
bool SelectDS1Addr1Offset(SDValue Ptr, SDValue &Base, SDValue &Offset) const;
|
2014-08-23 02:49:35 +08:00
|
|
|
bool SelectDS64Bit4ByteAligned(SDValue Ptr, SDValue &Base, SDValue &Offset0,
|
|
|
|
SDValue &Offset1) const;
|
2015-12-23 04:55:23 +08:00
|
|
|
bool SelectMUBUF(SDValue Addr, SDValue &SRsrc, SDValue &VAddr,
|
2014-08-12 06:18:17 +08:00
|
|
|
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 22:59:41 +08:00
|
|
|
SDValue &SOffset, SDValue &Offset, SDValue &GLC,
|
|
|
|
SDValue &SLC, SDValue &TFE) const;
|
2014-09-26 02:30:26 +08:00
|
|
|
bool SelectMUBUFAddr64(SDValue Addr, SDValue &SRsrc,
|
2015-02-11 08:34:32 +08:00
|
|
|
SDValue &VAddr, SDValue &SOffset, SDValue &Offset,
|
2014-09-26 02:30:26 +08:00
|
|
|
SDValue &SLC) const;
|
2014-07-21 23:45:01 +08:00
|
|
|
bool SelectMUBUFScratch(SDValue Addr, SDValue &RSrc, SDValue &VAddr,
|
|
|
|
SDValue &SOffset, SDValue &ImmOffset) const;
|
2014-08-12 06:18:17 +08:00
|
|
|
bool SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc, SDValue &SOffset,
|
|
|
|
SDValue &Offset, SDValue &GLC, SDValue &SLC,
|
2014-07-21 23:45:01 +08:00
|
|
|
SDValue &TFE) const;
|
2014-09-26 02:30:26 +08:00
|
|
|
bool SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc, SDValue &Soffset,
|
2016-06-10 07:42:48 +08:00
|
|
|
SDValue &Offset, SDValue &SLC) const;
|
2016-04-08 03:23:11 +08:00
|
|
|
bool SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc, SDValue &Soffset,
|
|
|
|
SDValue &Offset) const;
|
2016-03-19 00:24:20 +08:00
|
|
|
void SelectMUBUFConstant(SDValue Constant,
|
|
|
|
SDValue &SOffset,
|
|
|
|
SDValue &ImmOffset) const;
|
|
|
|
bool SelectMUBUFIntrinsicOffset(SDValue Offset, SDValue &SOffset,
|
|
|
|
SDValue &ImmOffset) const;
|
|
|
|
bool SelectMUBUFIntrinsicVOffset(SDValue Offset, SDValue &SOffset,
|
|
|
|
SDValue &ImmOffset, SDValue &VOffset) const;
|
2015-08-07 03:28:30 +08:00
|
|
|
bool SelectSMRDOffset(SDValue ByteOffsetNode, SDValue &Offset,
|
|
|
|
bool &Imm) const;
|
|
|
|
bool SelectSMRD(SDValue Addr, SDValue &SBase, SDValue &Offset,
|
|
|
|
bool &Imm) const;
|
|
|
|
bool SelectSMRDImm(SDValue Addr, SDValue &SBase, SDValue &Offset) const;
|
2015-08-07 03:28:38 +08:00
|
|
|
bool SelectSMRDImm32(SDValue Addr, SDValue &SBase, SDValue &Offset) const;
|
2015-08-07 03:28:30 +08:00
|
|
|
bool SelectSMRDSgpr(SDValue Addr, SDValue &SBase, SDValue &Offset) const;
|
|
|
|
bool SelectSMRDBufferImm(SDValue Addr, SDValue &Offset) const;
|
2015-08-07 03:28:38 +08:00
|
|
|
bool SelectSMRDBufferImm32(SDValue Addr, SDValue &Offset) const;
|
2015-08-07 03:28:30 +08:00
|
|
|
bool SelectSMRDBufferSgpr(SDValue Addr, SDValue &Offset) const;
|
2014-08-01 08:32:39 +08:00
|
|
|
bool SelectVOP3Mods(SDValue In, SDValue &Src, SDValue &SrcMods) const;
|
2015-07-13 23:47:57 +08:00
|
|
|
bool SelectVOP3NoMods(SDValue In, SDValue &Src, SDValue &SrcMods) const;
|
2014-08-01 08:32:39 +08:00
|
|
|
bool SelectVOP3Mods0(SDValue In, SDValue &Src, SDValue &SrcMods,
|
|
|
|
SDValue &Clamp, SDValue &Omod) const;
|
2015-07-13 23:47:57 +08:00
|
|
|
bool SelectVOP3NoMods0(SDValue In, SDValue &Src, SDValue &SrcMods,
|
|
|
|
SDValue &Clamp, SDValue &Omod) const;
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2014-11-14 03:49:04 +08:00
|
|
|
bool SelectVOP3Mods0Clamp(SDValue In, SDValue &Src, SDValue &SrcMods,
|
|
|
|
SDValue &Omod) const;
|
2015-01-07 07:00:37 +08:00
|
|
|
bool SelectVOP3Mods0Clamp0OMod(SDValue In, SDValue &Src, SDValue &SrcMods,
|
|
|
|
SDValue &Clamp,
|
|
|
|
SDValue &Omod) const;
|
2014-11-14 03:49:04 +08:00
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
void SelectADD_SUB_I64(SDNode *N);
|
|
|
|
void SelectDIV_SCALE(SDNode *N);
|
2014-06-24 02:00:34 +08:00
|
|
|
|
2015-03-24 21:40:27 +08:00
|
|
|
SDNode *getS_BFE(unsigned Opcode, SDLoc DL, SDValue Val,
|
|
|
|
uint32_t Offset, uint32_t Width);
|
2016-05-13 05:03:32 +08:00
|
|
|
void SelectS_BFEFromShifts(SDNode *N);
|
|
|
|
void SelectS_BFE(SDNode *N);
|
|
|
|
void SelectBRCOND(SDNode *N);
|
2016-06-10 07:42:48 +08:00
|
|
|
void SelectATOMIC_CMP_SWAP(SDNode *N);
|
2015-03-24 21:40:27 +08:00
|
|
|
|
2012-12-12 05:25:42 +08: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 15:40:20 +08:00
|
|
|
FunctionPass *llvm::createAMDGPUISelDag(TargetMachine &TM) {
|
2012-12-12 05:25:42 +08:00
|
|
|
return new AMDGPUDAGToDAGISel(TM);
|
|
|
|
}
|
|
|
|
|
2013-06-20 05:36:55 +08:00
|
|
|
AMDGPUDAGToDAGISel::AMDGPUDAGToDAGISel(TargetMachine &TM)
|
2015-01-31 07:24:40 +08:00
|
|
|
: SelectionDAGISel(TM) {}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
Subtarget = &static_cast<const AMDGPUSubtarget &>(MF.getSubtarget());
|
|
|
|
return SelectionDAGISel::runOnMachineFunction(MF);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AMDGPUDAGToDAGISel::~AMDGPUDAGToDAGISel() {
|
|
|
|
}
|
|
|
|
|
2014-04-04 04:19:27 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isInlineImmediate(SDNode *N) const {
|
|
|
|
const SITargetLowering *TL
|
|
|
|
= static_cast<const SITargetLowering *>(getTargetLowering());
|
|
|
|
return TL->analyzeImmediate(N) == 0;
|
|
|
|
}
|
|
|
|
|
2013-08-15 07:24:24 +08: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 15:40:20 +08:00
|
|
|
if (!N->isMachineOpcode())
|
|
|
|
return nullptr;
|
|
|
|
|
2013-08-15 07:24:24 +08:00
|
|
|
switch (N->getMachineOpcode()) {
|
|
|
|
default: {
|
2014-08-05 05:25:23 +08:00
|
|
|
const MCInstrDesc &Desc =
|
2015-01-31 07:24:40 +08:00
|
|
|
Subtarget->getInstrInfo()->get(N->getMachineOpcode());
|
2013-08-15 15:11:34 +08:00
|
|
|
unsigned OpIdx = Desc.getNumDefs() + OpNo;
|
|
|
|
if (OpIdx >= Desc.getNumOperands())
|
2014-04-18 15:40:20 +08:00
|
|
|
return nullptr;
|
2013-08-15 15:11:34 +08:00
|
|
|
int RegClass = Desc.OpInfo[OpIdx].RegClass;
|
2014-04-18 15:40:20 +08:00
|
|
|
if (RegClass == -1)
|
|
|
|
return nullptr;
|
|
|
|
|
2015-01-31 07:24:40 +08:00
|
|
|
return Subtarget->getRegisterInfo()->getRegClass(RegClass);
|
2013-08-15 07:24:24 +08:00
|
|
|
}
|
|
|
|
case AMDGPU::REG_SEQUENCE: {
|
2014-04-18 15:40:20 +08:00
|
|
|
unsigned RCID = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
|
2014-08-05 05:25:23 +08:00
|
|
|
const TargetRegisterClass *SuperRC =
|
2015-01-31 07:24:40 +08:00
|
|
|
Subtarget->getRegisterInfo()->getRegClass(RCID);
|
2014-04-18 15:40:20 +08:00
|
|
|
|
|
|
|
SDValue SubRegOp = N->getOperand(OpNo + 1);
|
|
|
|
unsigned SubRegIdx = cast<ConstantSDNode>(SubRegOp)->getZExtValue();
|
2015-01-31 07:24:40 +08:00
|
|
|
return Subtarget->getRegisterInfo()->getSubClassWithSubReg(SuperRC,
|
|
|
|
SubRegIdx);
|
2013-08-15 07:24:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectADDRParam(
|
2014-04-18 15:40:20 +08:00
|
|
|
SDValue Addr, SDValue& R1, SDValue& R2) {
|
2012-12-12 05:25:42 +08:00
|
|
|
|
|
|
|
if (Addr.getOpcode() == ISD::FrameIndex) {
|
|
|
|
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
|
|
|
|
R1 = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
|
2015-04-28 22:05:47 +08:00
|
|
|
R2 = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i32);
|
2012-12-12 05:25:42 +08:00
|
|
|
} else {
|
|
|
|
R1 = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
R2 = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i32);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
} else if (Addr.getOpcode() == ISD::ADD) {
|
|
|
|
R1 = Addr.getOperand(0);
|
|
|
|
R2 = Addr.getOperand(1);
|
|
|
|
} else {
|
|
|
|
R1 = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
R2 = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i32);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
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);
|
2015-04-28 22:05:47 +08:00
|
|
|
R2 = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i64);
|
2012-12-12 05:25:42 +08:00
|
|
|
} else {
|
|
|
|
R1 = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
R2 = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i64);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
} else if (Addr.getOpcode() == ISD::ADD) {
|
|
|
|
R1 = Addr.getOperand(0);
|
|
|
|
R2 = Addr.getOperand(1);
|
|
|
|
} else {
|
|
|
|
R1 = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
R2 = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i64);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-12 23:00:49 +08:00
|
|
|
SDNode *AMDGPUDAGToDAGISel::glueCopyToM0(SDNode *N) const {
|
|
|
|
if (Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS ||
|
|
|
|
!checkType(cast<MemSDNode>(N)->getMemOperand()->getValue(),
|
|
|
|
AMDGPUAS::LOCAL_ADDRESS))
|
|
|
|
return N;
|
|
|
|
|
|
|
|
const SITargetLowering& Lowering =
|
|
|
|
*static_cast<const SITargetLowering*>(getTargetLowering());
|
|
|
|
|
|
|
|
// Write max value to m0 before each load operation
|
|
|
|
|
|
|
|
SDValue M0 = Lowering.copyToM0(*CurDAG, CurDAG->getEntryNode(), SDLoc(N),
|
|
|
|
CurDAG->getTargetConstant(-1, SDLoc(N), MVT::i32));
|
|
|
|
|
|
|
|
SDValue Glue = M0.getValue(1);
|
|
|
|
|
|
|
|
SmallVector <SDValue, 8> Ops;
|
|
|
|
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
|
|
|
|
Ops.push_back(N->getOperand(i));
|
|
|
|
}
|
|
|
|
Ops.push_back(Glue);
|
|
|
|
CurDAG->MorphNodeTo(N, N->getOpcode(), N->getVTList(), Ops);
|
|
|
|
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
2015-11-11 08:01:36 +08:00
|
|
|
static unsigned selectSGPRVectorRegClassID(unsigned NumVectorElts) {
|
2015-11-03 07:30:48 +08:00
|
|
|
switch (NumVectorElts) {
|
|
|
|
case 1:
|
|
|
|
return AMDGPU::SReg_32RegClassID;
|
|
|
|
case 2:
|
|
|
|
return AMDGPU::SReg_64RegClassID;
|
|
|
|
case 4:
|
|
|
|
return AMDGPU::SReg_128RegClassID;
|
|
|
|
case 8:
|
|
|
|
return AMDGPU::SReg_256RegClassID;
|
|
|
|
case 16:
|
|
|
|
return AMDGPU::SReg_512RegClassID;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("invalid vector size");
|
|
|
|
}
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
void AMDGPUDAGToDAGISel::Select(SDNode *N) {
|
2012-12-12 05:25:42 +08:00
|
|
|
unsigned int Opc = N->getOpcode();
|
|
|
|
if (N->isMachineOpcode()) {
|
2013-09-22 16:21:56 +08:00
|
|
|
N->setNodeId(-1);
|
2016-05-13 05:03:32 +08:00
|
|
|
return; // Already selected.
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
2014-04-18 13:19:26 +08:00
|
|
|
|
2016-04-12 22:05:04 +08:00
|
|
|
if (isa<AtomicSDNode>(N) ||
|
|
|
|
(Opc == AMDGPUISD::ATOMIC_INC || Opc == AMDGPUISD::ATOMIC_DEC))
|
2015-05-12 23:00:49 +08:00
|
|
|
N = glueCopyToM0(N);
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
switch (Opc) {
|
|
|
|
default: break;
|
2014-02-26 05:36:18 +08: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-24 02:00:38 +08:00
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::SUB: {
|
2014-02-26 05:36:18 +08:00
|
|
|
if (N->getValueType(0) != MVT::i64 ||
|
2015-01-31 07:24:40 +08:00
|
|
|
Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
|
2014-02-26 05:36:18 +08:00
|
|
|
break;
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
SelectADD_SUB_I64(N);
|
|
|
|
return;
|
2014-02-26 05:36:18 +08:00
|
|
|
}
|
2014-06-12 01:40:32 +08:00
|
|
|
case ISD::SCALAR_TO_VECTOR:
|
2014-06-18 00:53:14 +08:00
|
|
|
case AMDGPUISD::BUILD_VERTICAL_VECTOR:
|
2013-03-05 23:04:49 +08:00
|
|
|
case ISD::BUILD_VECTOR: {
|
2013-08-15 07:24:32 +08:00
|
|
|
unsigned RegClassID;
|
2015-01-31 07:24:40 +08:00
|
|
|
const AMDGPURegisterInfo *TRI = Subtarget->getRegisterInfo();
|
2013-08-15 07:24:32 +08:00
|
|
|
EVT VT = N->getValueType(0);
|
|
|
|
unsigned NumVectorElts = VT.getVectorNumElements();
|
2014-06-12 01:40:32 +08:00
|
|
|
EVT EltVT = VT.getVectorElementType();
|
|
|
|
assert(EltVT.bitsEq(MVT::i32));
|
2015-01-31 07:24:40 +08:00
|
|
|
if (Subtarget->getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) {
|
2015-11-11 08:01:36 +08:00
|
|
|
RegClassID = selectSGPRVectorRegClassID(NumVectorElts);
|
2013-08-15 07:24:32 +08: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-18 00:53:14 +08:00
|
|
|
case 4:
|
|
|
|
if (Opc == AMDGPUISD::BUILD_VERTICAL_VECTOR)
|
|
|
|
RegClassID = AMDGPU::R600_Reg128VerticalRegClassID;
|
|
|
|
else
|
|
|
|
RegClassID = AMDGPU::R600_Reg128RegClassID;
|
|
|
|
break;
|
2013-08-15 07:24:32 +08:00
|
|
|
default: llvm_unreachable("Do not know how to lower this BUILD_VECTOR");
|
|
|
|
}
|
2013-03-05 23:04:49 +08:00
|
|
|
}
|
2013-08-01 23:23:42 +08:00
|
|
|
|
2015-04-28 22:05:47 +08:00
|
|
|
SDLoc DL(N);
|
|
|
|
SDValue RegClass = CurDAG->getTargetConstant(RegClassID, DL, MVT::i32);
|
2013-08-15 07:24:32 +08:00
|
|
|
|
|
|
|
if (NumVectorElts == 1) {
|
2016-05-13 05:03:32 +08:00
|
|
|
CurDAG->SelectNodeTo(N, AMDGPU::COPY_TO_REGCLASS, EltVT, N->getOperand(0),
|
|
|
|
RegClass);
|
|
|
|
return;
|
2013-08-01 23:23:42 +08:00
|
|
|
}
|
2013-08-15 07:24:32 +08: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-12 01:40:32 +08:00
|
|
|
SmallVector<SDValue, 16 * 2 + 1> RegSeqArgs(NumVectorElts * 2 + 1);
|
2013-08-15 07:24:32 +08:00
|
|
|
|
2015-04-28 22:05:47 +08:00
|
|
|
RegSeqArgs[0] = CurDAG->getTargetConstant(RegClassID, DL, MVT::i32);
|
2013-03-05 23:04:49 +08:00
|
|
|
bool IsRegSeq = true;
|
2014-06-12 01:40:32 +08:00
|
|
|
unsigned NOps = N->getNumOperands();
|
|
|
|
for (unsigned i = 0; i < NOps; i++) {
|
2013-08-15 07:24:32 +08:00
|
|
|
// XXX: Why is this here?
|
2015-04-10 19:24:51 +08:00
|
|
|
if (isa<RegisterSDNode>(N->getOperand(i))) {
|
2013-03-05 23:04:49 +08:00
|
|
|
IsRegSeq = false;
|
|
|
|
break;
|
|
|
|
}
|
2013-08-15 07:24:32 +08:00
|
|
|
RegSeqArgs[1 + (2 * i)] = N->getOperand(i);
|
|
|
|
RegSeqArgs[1 + (2 * i) + 1] =
|
2015-04-28 22:05:47 +08:00
|
|
|
CurDAG->getTargetConstant(TRI->getSubRegFromChannel(i), DL,
|
|
|
|
MVT::i32);
|
2013-03-05 23:04:49 +08:00
|
|
|
}
|
2014-06-12 01:40:32 +08: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,
|
2015-04-28 22:05:47 +08:00
|
|
|
DL, EltVT);
|
2014-06-12 01:40:32 +08:00
|
|
|
for (unsigned i = NOps; i < NumVectorElts; ++i) {
|
|
|
|
RegSeqArgs[1 + (2 * i)] = SDValue(ImpDef, 0);
|
|
|
|
RegSeqArgs[1 + (2 * i) + 1] =
|
2015-04-28 22:05:47 +08:00
|
|
|
CurDAG->getTargetConstant(TRI->getSubRegFromChannel(i), DL, MVT::i32);
|
2014-06-12 01:40:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 23:04:49 +08:00
|
|
|
if (!IsRegSeq)
|
|
|
|
break;
|
2016-05-13 05:03:32 +08:00
|
|
|
CurDAG->SelectNodeTo(N, AMDGPU::REG_SEQUENCE, N->getVTList(), RegSeqArgs);
|
|
|
|
return;
|
2013-03-05 23:04:49 +08:00
|
|
|
}
|
2013-04-06 07:31:51 +08:00
|
|
|
case ISD::BUILD_PAIR: {
|
|
|
|
SDValue RC, SubReg0, SubReg1;
|
2015-01-31 07:24:40 +08:00
|
|
|
if (Subtarget->getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
|
2013-04-06 07:31:51 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-04-28 22:05:47 +08:00
|
|
|
SDLoc DL(N);
|
2013-04-06 07:31:51 +08:00
|
|
|
if (N->getValueType(0) == MVT::i128) {
|
2015-04-28 22:05:47 +08:00
|
|
|
RC = CurDAG->getTargetConstant(AMDGPU::SReg_128RegClassID, DL, MVT::i32);
|
|
|
|
SubReg0 = CurDAG->getTargetConstant(AMDGPU::sub0_sub1, DL, MVT::i32);
|
|
|
|
SubReg1 = CurDAG->getTargetConstant(AMDGPU::sub2_sub3, DL, MVT::i32);
|
2013-04-06 07:31:51 +08:00
|
|
|
} else if (N->getValueType(0) == MVT::i64) {
|
2015-04-28 22:05:47 +08:00
|
|
|
RC = CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID, DL, MVT::i32);
|
|
|
|
SubReg0 = CurDAG->getTargetConstant(AMDGPU::sub0, DL, MVT::i32);
|
|
|
|
SubReg1 = CurDAG->getTargetConstant(AMDGPU::sub1, DL, MVT::i32);
|
2013-04-06 07:31:51 +08:00
|
|
|
} else {
|
|
|
|
llvm_unreachable("Unhandled value type for BUILD_PAIR");
|
|
|
|
}
|
|
|
|
const SDValue Ops[] = { RC, N->getOperand(0), SubReg0,
|
|
|
|
N->getOperand(1), SubReg1 };
|
2016-05-13 05:03:32 +08:00
|
|
|
ReplaceNode(N, CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, DL,
|
|
|
|
N->getValueType(0), Ops));
|
|
|
|
return;
|
2013-04-06 07:31:51 +08:00
|
|
|
}
|
2014-04-04 04:19:27 +08:00
|
|
|
|
|
|
|
case ISD::Constant:
|
|
|
|
case ISD::ConstantFP: {
|
2015-01-31 07:24:40 +08:00
|
|
|
if (Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS ||
|
2014-04-04 04:19:27 +08: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-08 03:31:13 +08:00
|
|
|
ConstantSDNode *C = cast<ConstantSDNode>(N);
|
2014-04-04 04:19:27 +08:00
|
|
|
Imm = C->getZExtValue();
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:05:47 +08:00
|
|
|
SDLoc DL(N);
|
|
|
|
SDNode *Lo = CurDAG->getMachineNode(AMDGPU::S_MOV_B32, DL, MVT::i32,
|
|
|
|
CurDAG->getConstant(Imm & 0xFFFFFFFF, DL,
|
|
|
|
MVT::i32));
|
|
|
|
SDNode *Hi = CurDAG->getMachineNode(AMDGPU::S_MOV_B32, DL, MVT::i32,
|
|
|
|
CurDAG->getConstant(Imm >> 32, DL, MVT::i32));
|
2014-04-04 04:19:27 +08:00
|
|
|
const SDValue Ops[] = {
|
2015-04-28 22:05:47 +08:00
|
|
|
CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID, DL, MVT::i32),
|
|
|
|
SDValue(Lo, 0), CurDAG->getTargetConstant(AMDGPU::sub0, DL, MVT::i32),
|
|
|
|
SDValue(Hi, 0), CurDAG->getTargetConstant(AMDGPU::sub1, DL, MVT::i32)
|
2014-04-04 04:19:27 +08:00
|
|
|
};
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
ReplaceNode(N, CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, DL,
|
|
|
|
N->getValueType(0), Ops));
|
|
|
|
return;
|
2014-04-04 04:19:27 +08:00
|
|
|
}
|
2015-09-26 01:27:08 +08:00
|
|
|
case ISD::LOAD:
|
2015-02-05 04:49:49 +08:00
|
|
|
case ISD::STORE: {
|
2015-05-12 23:00:49 +08:00
|
|
|
N = glueCopyToM0(N);
|
2015-02-05 04:49:49 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-04-18 13:19:26 +08:00
|
|
|
|
|
|
|
case AMDGPUISD::BFE_I32:
|
|
|
|
case AMDGPUISD::BFE_U32: {
|
2015-01-31 07:24:40 +08:00
|
|
|
if (Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
|
2014-04-18 13:19:26 +08: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;
|
|
|
|
|
|
|
|
uint32_t OffsetVal = Offset->getZExtValue();
|
|
|
|
uint32_t WidthVal = Width->getZExtValue();
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
ReplaceNode(N, getS_BFE(Signed ? AMDGPU::S_BFE_I32 : AMDGPU::S_BFE_U32,
|
|
|
|
SDLoc(N), N->getOperand(0), OffsetVal, WidthVal));
|
|
|
|
return;
|
2014-04-18 13:19:26 +08:00
|
|
|
}
|
2014-06-24 02:28:28 +08:00
|
|
|
case AMDGPUISD::DIV_SCALE: {
|
2016-05-13 05:03:32 +08:00
|
|
|
SelectDIV_SCALE(N);
|
|
|
|
return;
|
2014-06-24 02:28:28 +08:00
|
|
|
}
|
2014-10-10 03:06:00 +08:00
|
|
|
case ISD::CopyToReg: {
|
|
|
|
const SITargetLowering& Lowering =
|
|
|
|
*static_cast<const SITargetLowering*>(getTargetLowering());
|
|
|
|
Lowering.legalizeTargetIndependentNode(N, *CurDAG);
|
|
|
|
break;
|
|
|
|
}
|
2015-03-24 21:40:27 +08:00
|
|
|
case ISD::AND:
|
|
|
|
case ISD::SRL:
|
|
|
|
case ISD::SRA:
|
2016-04-23 06:59:16 +08:00
|
|
|
case ISD::SIGN_EXTEND_INREG:
|
2015-03-24 21:40:27 +08:00
|
|
|
if (N->getValueType(0) != MVT::i32 ||
|
|
|
|
Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
|
|
|
|
break;
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
SelectS_BFE(N);
|
|
|
|
return;
|
2016-02-13 07:45:29 +08:00
|
|
|
case ISD::BRCOND:
|
2016-05-13 05:03:32 +08:00
|
|
|
SelectBRCOND(N);
|
|
|
|
return;
|
2016-06-10 07:42:48 +08:00
|
|
|
|
|
|
|
case AMDGPUISD::ATOMIC_CMP_SWAP:
|
|
|
|
SelectATOMIC_CMP_SWAP(N);
|
|
|
|
return;
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
2014-10-10 03:06:00 +08:00
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
SelectCode(N);
|
2013-01-23 10:09:06 +08:00
|
|
|
}
|
|
|
|
|
2014-04-18 15:40:20 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::checkType(const Value *Ptr, unsigned AS) {
|
|
|
|
assert(AS != 0 && "Use checkPrivateAddress instead.");
|
|
|
|
if (!Ptr)
|
2012-12-12 05:25:42 +08:00
|
|
|
return false;
|
2014-04-18 15:40:20 +08:00
|
|
|
|
|
|
|
return Ptr->getType()->getPointerAddressSpace() == AS;
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 15:22:52 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::checkPrivateAddress(const MachineMemOperand *Op) {
|
2014-04-18 15:40:20 +08: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 15:22:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 03:23:11 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isGlobalStore(const MemSDNode *N) {
|
|
|
|
if (!N->writeMem())
|
|
|
|
return false;
|
2014-04-15 15:22:52 +08:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::GLOBAL_ADDRESS);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::isPrivateStore(const StoreSDNode *N) {
|
2014-04-18 15:40:20 +08: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-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::isLocalStore(const StoreSDNode *N) {
|
2014-04-15 15:22:52 +08:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::LOCAL_ADDRESS);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 03:23:11 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isFlatStore(const MemSDNode *N) {
|
|
|
|
if (!N->writeMem())
|
|
|
|
return false;
|
2014-09-15 23:41:53 +08:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::FLAT_ADDRESS);
|
|
|
|
}
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isRegionStore(const StoreSDNode *N) {
|
2014-04-15 15:22:52 +08:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::REGION_ADDRESS);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 03:23:11 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isConstantLoad(const MemSDNode *N, int CbId) const {
|
|
|
|
if (!N->readMem())
|
|
|
|
return false;
|
2014-04-18 15:40:20 +08: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-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 03:23:11 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isGlobalLoad(const MemSDNode *N) const {
|
|
|
|
if (!N->readMem())
|
|
|
|
return false;
|
2016-05-14 04:39:29 +08:00
|
|
|
if (N->getAddressSpace() == AMDGPUAS::CONSTANT_ADDRESS) {
|
|
|
|
if (Subtarget->getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS)
|
|
|
|
return !isa<GlobalValue>(
|
|
|
|
GetUnderlyingObject(N->getMemOperand()->getValue(),
|
|
|
|
CurDAG->getDataLayout()));
|
|
|
|
|
|
|
|
//TODO: Why do we need this?
|
|
|
|
if (N->getMemoryVT().bitsLT(MVT::i32))
|
2013-07-24 07:54:56 +08:00
|
|
|
return true;
|
2016-05-14 04:39:29 +08:00
|
|
|
}
|
2015-01-31 07:24:40 +08:00
|
|
|
|
2014-04-15 15:22:52 +08:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::GLOBAL_ADDRESS);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2013-06-19 07:37:58 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isParamLoad(const LoadSDNode *N) const {
|
2014-04-15 15:22:52 +08:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::PARAM_I_ADDRESS);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2013-06-19 07:37:58 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isLocalLoad(const LoadSDNode *N) const {
|
2014-04-15 15:22:52 +08:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::LOCAL_ADDRESS);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 03:23:11 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isFlatLoad(const MemSDNode *N) const {
|
|
|
|
if (!N->readMem())
|
|
|
|
return false;
|
2014-09-15 23:41:53 +08:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::FLAT_ADDRESS);
|
|
|
|
}
|
|
|
|
|
2013-06-19 07:37:58 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isRegionLoad(const LoadSDNode *N) const {
|
2014-04-15 15:22:52 +08:00
|
|
|
return checkType(N->getMemOperand()->getValue(), AMDGPUAS::REGION_ADDRESS);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2013-06-19 07:37:58 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isCPLoad(const LoadSDNode *N) const {
|
2012-12-12 05:25:42 +08:00
|
|
|
MachineMemOperand *MMO = N->getMemOperand();
|
2014-04-15 15:22:52 +08:00
|
|
|
if (checkPrivateAddress(N->getMemOperand())) {
|
2012-12-12 05:25:42 +08:00
|
|
|
if (MMO) {
|
2014-04-15 15:22:52 +08:00
|
|
|
const PseudoSourceValue *PSV = MMO->getPseudoValue();
|
2015-08-12 07:09:45 +08:00
|
|
|
if (PSV && PSV->isConstantPool()) {
|
2012-12-12 05:25:42 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-19 07:37:58 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isPrivateLoad(const LoadSDNode *N) const {
|
2014-04-15 15:22:52 +08:00
|
|
|
if (checkPrivateAddress(N->getMemOperand())) {
|
2012-12-12 05:25:42 +08: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 15:40:20 +08:00
|
|
|
|
|
|
|
const Value *MemVal = N->getMemOperand()->getValue();
|
2016-03-03 07:00:21 +08:00
|
|
|
return !checkType(MemVal, AMDGPUAS::LOCAL_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::GLOBAL_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::FLAT_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::REGION_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::CONSTANT_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::PARAM_D_ADDRESS) &&
|
|
|
|
!checkType(MemVal, AMDGPUAS::PARAM_I_ADDRESS);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 07:45:29 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::isUniformBr(const SDNode *N) const {
|
|
|
|
const BasicBlock *BB = FuncInfo->MBB->getBasicBlock();
|
2016-04-15 01:42:35 +08:00
|
|
|
const Instruction *Term = BB->getTerminator();
|
|
|
|
return Term->getMetadata("amdgpu.uniform") ||
|
|
|
|
Term->getMetadata("structurizecfg.uniform");
|
2016-02-13 07:45:29 +08:00
|
|
|
}
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
const char *AMDGPUDAGToDAGISel::getPassName() const {
|
|
|
|
return "AMDGPU DAG->DAG Pattern Instruction Selection";
|
|
|
|
}
|
|
|
|
|
2013-07-23 09:48:42 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Complex Patterns
|
|
|
|
//===----------------------------------------------------------------------===//
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2013-01-23 10:09:06 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectGlobalValueConstantOffset(SDValue Addr,
|
2014-04-18 15:40:20 +08:00
|
|
|
SDValue& IntPtr) {
|
2013-01-23 10:09:06 +08:00
|
|
|
if (ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Addr)) {
|
2015-04-28 22:05:47 +08:00
|
|
|
IntPtr = CurDAG->getIntPtrConstant(Cst->getZExtValue() / 4, SDLoc(Addr),
|
|
|
|
true);
|
2013-01-23 10:09:06 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectGlobalValueVariableOffset(SDValue Addr,
|
|
|
|
SDValue& BaseReg, SDValue &Offset) {
|
2014-04-18 15:40:20 +08:00
|
|
|
if (!isa<ConstantSDNode>(Addr)) {
|
2013-01-23 10:09:06 +08:00
|
|
|
BaseReg = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getIntPtrConstant(0, SDLoc(Addr), true);
|
2013-01-23 10:09:06 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectADDRVTX_READ(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) {
|
2014-04-18 15:40:20 +08:00
|
|
|
ConstantSDNode *IMMOffset;
|
2012-12-12 05:25:42 +08:00
|
|
|
|
|
|
|
if (Addr.getOpcode() == ISD::ADD
|
|
|
|
&& (IMMOffset = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))
|
|
|
|
&& isInt<16>(IMMOffset->getZExtValue())) {
|
|
|
|
|
|
|
|
Base = Addr.getOperand(0);
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(IMMOffset->getZExtValue(), SDLoc(Addr),
|
|
|
|
MVT::i32);
|
2012-12-12 05:25:42 +08:00
|
|
|
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 10:42:55 +08:00
|
|
|
SDLoc(CurDAG->getEntryNode()),
|
2012-12-12 05:25:42 +08:00
|
|
|
AMDGPU::ZERO, MVT::i32);
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(IMMOffset->getZExtValue(), SDLoc(Addr),
|
|
|
|
MVT::i32);
|
2012-12-12 05:25:42 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default case, no offset
|
|
|
|
Base = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i32);
|
2012-12-12 05:25:42 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-07 01:32:29 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectADDRIndirect(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset) {
|
|
|
|
ConstantSDNode *C;
|
2015-04-28 22:05:47 +08:00
|
|
|
SDLoc DL(Addr);
|
2013-02-07 01:32:29 +08:00
|
|
|
|
|
|
|
if ((C = dyn_cast<ConstantSDNode>(Addr))) {
|
|
|
|
Base = CurDAG->getRegister(AMDGPU::INDIRECT_BASE_ADDR, MVT::i32);
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(C->getZExtValue(), DL, MVT::i32);
|
2013-02-07 01:32:29 +08:00
|
|
|
} else if ((Addr.getOpcode() == ISD::ADD || Addr.getOpcode() == ISD::OR) &&
|
|
|
|
(C = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))) {
|
|
|
|
Base = Addr.getOperand(0);
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(C->getZExtValue(), DL, MVT::i32);
|
2013-02-07 01:32:29 +08:00
|
|
|
} else {
|
|
|
|
Base = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
2013-02-07 01:32:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-27 01:52:16 +08:00
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
void AMDGPUDAGToDAGISel::SelectADD_SUB_I64(SDNode *N) {
|
2014-06-24 02:00:34 +08:00
|
|
|
SDLoc DL(N);
|
|
|
|
SDValue LHS = N->getOperand(0);
|
|
|
|
SDValue RHS = N->getOperand(1);
|
|
|
|
|
2014-06-24 02:00:38 +08:00
|
|
|
bool IsAdd = (N->getOpcode() == ISD::ADD);
|
|
|
|
|
2015-04-28 22:05:47 +08:00
|
|
|
SDValue Sub0 = CurDAG->getTargetConstant(AMDGPU::sub0, DL, MVT::i32);
|
|
|
|
SDValue Sub1 = CurDAG->getTargetConstant(AMDGPU::sub1, DL, MVT::i32);
|
2014-06-24 02:00:34 +08:00
|
|
|
|
|
|
|
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-24 02:00:38 +08:00
|
|
|
|
2014-09-05 22:07:59 +08:00
|
|
|
unsigned Opc = IsAdd ? AMDGPU::S_ADD_U32 : AMDGPU::S_SUB_U32;
|
2014-06-24 02:00:38 +08: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-24 02:00:34 +08:00
|
|
|
|
|
|
|
SDValue Args[5] = {
|
2015-04-28 22:05:47 +08:00
|
|
|
CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID, DL, MVT::i32),
|
2014-06-24 02:00:34 +08:00
|
|
|
SDValue(AddLo,0),
|
|
|
|
Sub0,
|
|
|
|
SDValue(AddHi,0),
|
|
|
|
Sub1,
|
|
|
|
};
|
2016-05-13 05:03:32 +08:00
|
|
|
CurDAG->SelectNodeTo(N, AMDGPU::REG_SEQUENCE, MVT::i64, Args);
|
2014-06-24 02:00:34 +08:00
|
|
|
}
|
|
|
|
|
2015-02-14 12:24:28 +08:00
|
|
|
// We need to handle this here because tablegen doesn't support matching
|
|
|
|
// instructions with multiple outputs.
|
2016-05-13 05:03:32 +08:00
|
|
|
void AMDGPUDAGToDAGISel::SelectDIV_SCALE(SDNode *N) {
|
2014-06-24 02:28:28 +08:00
|
|
|
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-09-22 19:14:12 +08:00
|
|
|
// src0_modifiers, src0, src1_modifiers, src1, src2_modifiers, src2, clamp,
|
|
|
|
// omod
|
2015-02-14 12:24:28 +08:00
|
|
|
SDValue Ops[8];
|
2014-06-24 02:28:28 +08:00
|
|
|
|
2015-02-14 12:24:28 +08: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]);
|
2016-05-13 05:03:32 +08:00
|
|
|
CurDAG->SelectNodeTo(N, Opc, VT, MVT::i1, Ops);
|
2014-06-24 02:28:28 +08:00
|
|
|
}
|
|
|
|
|
2014-08-23 02:49:33 +08: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-07-07 00:01:58 +08:00
|
|
|
if (Subtarget->getGeneration() >= AMDGPUSubtarget::SEA_ISLANDS ||
|
|
|
|
Subtarget->unsafeDSOffsetFoldingEnabled())
|
2014-08-23 02:49:33 +08: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 {
|
2016-04-29 22:34:26 +08:00
|
|
|
SDLoc DL(Addr);
|
2014-08-23 02:49:33 +08:00
|
|
|
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;
|
2016-04-29 22:34:26 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(C1->getZExtValue(), DL, MVT::i16);
|
2014-08-23 02:49:33 +08:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-09 03:34:22 +08:00
|
|
|
} else if (Addr.getOpcode() == ISD::SUB) {
|
|
|
|
// sub C, x -> add (sub 0, x), C
|
|
|
|
if (const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Addr.getOperand(0))) {
|
|
|
|
int64_t ByteOffset = C->getSExtValue();
|
|
|
|
if (isUInt<16>(ByteOffset)) {
|
|
|
|
SDValue Zero = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
|
|
|
|
|
|
|
// XXX - This is kind of hacky. Create a dummy sub node so we can check
|
|
|
|
// the known bits in isDSOffsetLegal. We need to emit the selected node
|
|
|
|
// here, so this is thrown away.
|
|
|
|
SDValue Sub = CurDAG->getNode(ISD::SUB, DL, MVT::i32,
|
|
|
|
Zero, Addr.getOperand(1));
|
|
|
|
|
|
|
|
if (isDSOffsetLegal(Sub, ByteOffset, 16)) {
|
|
|
|
MachineSDNode *MachineSub
|
|
|
|
= CurDAG->getMachineNode(AMDGPU::V_SUB_I32_e32, DL, MVT::i32,
|
|
|
|
Zero, Addr.getOperand(1));
|
|
|
|
|
|
|
|
Base = SDValue(MachineSub, 0);
|
|
|
|
Offset = Addr.getOperand(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (const ConstantSDNode *CAddr = dyn_cast<ConstantSDNode>(Addr)) {
|
|
|
|
// 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.
|
2014-08-23 02:49:33 +08:00
|
|
|
|
2015-09-09 03:34:22 +08:00
|
|
|
SDLoc DL(Addr);
|
2015-04-28 22:05:47 +08:00
|
|
|
|
2014-10-15 01:21:19 +08:00
|
|
|
if (isUInt<16>(CAddr->getZExtValue())) {
|
2015-04-28 22:05:47 +08:00
|
|
|
SDValue Zero = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
2014-10-16 05:08:59 +08:00
|
|
|
MachineSDNode *MovZero = CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
|
2015-04-28 22:05:47 +08:00
|
|
|
DL, MVT::i32, Zero);
|
2014-10-16 05:08:59 +08:00
|
|
|
Base = SDValue(MovZero, 0);
|
2014-10-15 01:21:19 +08:00
|
|
|
Offset = Addr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-23 02:49:33 +08:00
|
|
|
// default case
|
|
|
|
Base = Addr;
|
2015-09-09 03:34:22 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i16);
|
2014-08-23 02:49:33 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 03:34:22 +08:00
|
|
|
// TODO: If offset is too big, put low 16-bit into offset.
|
2014-08-23 02:49:35 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectDS64Bit4ByteAligned(SDValue Addr, SDValue &Base,
|
|
|
|
SDValue &Offset0,
|
|
|
|
SDValue &Offset1) const {
|
2015-04-28 22:05:47 +08:00
|
|
|
SDLoc DL(Addr);
|
|
|
|
|
2014-08-23 02:49:35 +08:00
|
|
|
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;
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset0 = CurDAG->getTargetConstant(DWordOffset0, DL, MVT::i8);
|
|
|
|
Offset1 = CurDAG->getTargetConstant(DWordOffset1, DL, MVT::i8);
|
2014-08-23 02:49:35 +08:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-09 03:34:22 +08:00
|
|
|
} else if (Addr.getOpcode() == ISD::SUB) {
|
|
|
|
// sub C, x -> add (sub 0, x), C
|
|
|
|
if (const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Addr.getOperand(0))) {
|
|
|
|
unsigned DWordOffset0 = C->getZExtValue() / 4;
|
|
|
|
unsigned DWordOffset1 = DWordOffset0 + 1;
|
|
|
|
|
|
|
|
if (isUInt<8>(DWordOffset0)) {
|
|
|
|
SDLoc DL(Addr);
|
|
|
|
SDValue Zero = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
|
|
|
|
|
|
|
// XXX - This is kind of hacky. Create a dummy sub node so we can check
|
|
|
|
// the known bits in isDSOffsetLegal. We need to emit the selected node
|
|
|
|
// here, so this is thrown away.
|
|
|
|
SDValue Sub = CurDAG->getNode(ISD::SUB, DL, MVT::i32,
|
|
|
|
Zero, Addr.getOperand(1));
|
|
|
|
|
|
|
|
if (isDSOffsetLegal(Sub, DWordOffset1, 8)) {
|
|
|
|
MachineSDNode *MachineSub
|
|
|
|
= CurDAG->getMachineNode(AMDGPU::V_SUB_I32_e32, DL, MVT::i32,
|
|
|
|
Zero, Addr.getOperand(1));
|
|
|
|
|
|
|
|
Base = SDValue(MachineSub, 0);
|
|
|
|
Offset0 = CurDAG->getTargetConstant(DWordOffset0, DL, MVT::i8);
|
|
|
|
Offset1 = CurDAG->getTargetConstant(DWordOffset1, DL, MVT::i8);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (const ConstantSDNode *CAddr = dyn_cast<ConstantSDNode>(Addr)) {
|
2014-10-16 02:06:43 +08:00
|
|
|
unsigned DWordOffset0 = CAddr->getZExtValue() / 4;
|
|
|
|
unsigned DWordOffset1 = DWordOffset0 + 1;
|
|
|
|
assert(4 * DWordOffset0 == CAddr->getZExtValue());
|
|
|
|
|
|
|
|
if (isUInt<8>(DWordOffset0) && isUInt<8>(DWordOffset1)) {
|
2015-04-28 22:05:47 +08:00
|
|
|
SDValue Zero = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
2014-10-16 02:06:43 +08:00
|
|
|
MachineSDNode *MovZero
|
|
|
|
= CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
|
2015-04-28 22:05:47 +08:00
|
|
|
DL, MVT::i32, Zero);
|
2014-10-16 02:06:43 +08:00
|
|
|
Base = SDValue(MovZero, 0);
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset0 = CurDAG->getTargetConstant(DWordOffset0, DL, MVT::i8);
|
|
|
|
Offset1 = CurDAG->getTargetConstant(DWordOffset1, DL, MVT::i8);
|
2014-10-16 02:06:43 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-23 02:49:35 +08:00
|
|
|
// default case
|
|
|
|
Base = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset0 = CurDAG->getTargetConstant(0, DL, MVT::i8);
|
|
|
|
Offset1 = CurDAG->getTargetConstant(1, DL, MVT::i8);
|
2014-08-23 02:49:35 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-21 23:45:01 +08:00
|
|
|
static bool isLegalMUBUFImmOffset(const ConstantSDNode *Imm) {
|
|
|
|
return isUInt<12>(Imm->getZExtValue());
|
|
|
|
}
|
|
|
|
|
2015-12-23 04:55:23 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUF(SDValue Addr, SDValue &Ptr,
|
2014-08-12 06:18:17 +08:00
|
|
|
SDValue &VAddr, SDValue &SOffset,
|
|
|
|
SDValue &Offset, SDValue &Offen,
|
|
|
|
SDValue &Idxen, SDValue &Addr64,
|
|
|
|
SDValue &GLC, SDValue &SLC,
|
|
|
|
SDValue &TFE) const {
|
2015-12-23 04:55:23 +08:00
|
|
|
// Subtarget prefers to use flat instruction
|
|
|
|
if (Subtarget->useFlatForGlobal())
|
|
|
|
return false;
|
|
|
|
|
2014-06-25 07:33:07 +08:00
|
|
|
SDLoc DL(Addr);
|
|
|
|
|
2016-04-08 03:23:11 +08:00
|
|
|
if (!GLC.getNode())
|
|
|
|
GLC = CurDAG->getTargetConstant(0, DL, MVT::i1);
|
|
|
|
if (!SLC.getNode())
|
|
|
|
SLC = CurDAG->getTargetConstant(0, DL, MVT::i1);
|
2015-04-28 22:05:47 +08:00
|
|
|
TFE = CurDAG->getTargetConstant(0, DL, MVT::i1);
|
2014-08-12 06:18:17 +08:00
|
|
|
|
2015-04-28 22:05:47 +08:00
|
|
|
Idxen = CurDAG->getTargetConstant(0, DL, MVT::i1);
|
|
|
|
Offen = CurDAG->getTargetConstant(0, DL, MVT::i1);
|
|
|
|
Addr64 = CurDAG->getTargetConstant(0, DL, MVT::i1);
|
|
|
|
SOffset = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
2014-08-12 06:18:17 +08:00
|
|
|
|
2014-06-25 07:33:07 +08:00
|
|
|
if (CurDAG->isBaseWithConstantOffset(Addr)) {
|
|
|
|
SDValue N0 = Addr.getOperand(0);
|
|
|
|
SDValue N1 = Addr.getOperand(1);
|
|
|
|
ConstantSDNode *C1 = cast<ConstantSDNode>(N1);
|
|
|
|
|
2015-02-11 08:34:35 +08:00
|
|
|
if (N0.getOpcode() == ISD::ADD) {
|
|
|
|
// (add (add N2, N3), C1) -> addr64
|
|
|
|
SDValue N2 = N0.getOperand(0);
|
|
|
|
SDValue N3 = N0.getOperand(1);
|
2015-04-28 22:05:47 +08:00
|
|
|
Addr64 = CurDAG->getTargetConstant(1, DL, MVT::i1);
|
2015-02-11 08:34:35 +08:00
|
|
|
Ptr = N2;
|
|
|
|
VAddr = N3;
|
|
|
|
} else {
|
2014-06-25 07:33:07 +08:00
|
|
|
|
2014-08-12 06:18:17 +08:00
|
|
|
// (add N0, C1) -> offset
|
2015-04-28 22:05:47 +08:00
|
|
|
VAddr = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
2014-08-12 06:18:17 +08:00
|
|
|
Ptr = N0;
|
2015-02-11 08:34:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isLegalMUBUFImmOffset(C1)) {
|
2016-06-10 07:42:48 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(C1->getZExtValue(), DL, MVT::i16);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isUInt<32>(C1->getZExtValue())) {
|
2015-02-11 08:34:35 +08:00
|
|
|
// Illegal offset, store it in soffset.
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(0, DL, MVT::i16);
|
2015-02-11 08:34:35 +08:00
|
|
|
SOffset = SDValue(CurDAG->getMachineNode(AMDGPU::S_MOV_B32, DL, MVT::i32,
|
2015-04-28 22:05:47 +08:00
|
|
|
CurDAG->getTargetConstant(C1->getZExtValue(), DL, MVT::i32)),
|
|
|
|
0);
|
2015-12-23 04:55:23 +08:00
|
|
|
return true;
|
2014-06-25 07:33:07 +08:00
|
|
|
}
|
|
|
|
}
|
2015-02-11 08:34:35 +08:00
|
|
|
|
2014-06-25 07:33:07 +08:00
|
|
|
if (Addr.getOpcode() == ISD::ADD) {
|
2014-08-12 06:18:17 +08:00
|
|
|
// (add N0, N1) -> addr64
|
2014-06-25 07:33:07 +08:00
|
|
|
SDValue N0 = Addr.getOperand(0);
|
|
|
|
SDValue N1 = Addr.getOperand(1);
|
2015-04-28 22:05:47 +08:00
|
|
|
Addr64 = CurDAG->getTargetConstant(1, DL, MVT::i1);
|
2014-08-12 06:18:17 +08:00
|
|
|
Ptr = N0;
|
|
|
|
VAddr = N1;
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(0, DL, MVT::i16);
|
2015-12-23 04:55:23 +08:00
|
|
|
return true;
|
2014-06-25 07:33:07 +08:00
|
|
|
}
|
|
|
|
|
2014-08-12 06:18:17 +08:00
|
|
|
// default case -> offset
|
2015-04-28 22:05:47 +08:00
|
|
|
VAddr = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
2014-08-12 06:18:17 +08:00
|
|
|
Ptr = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(0, DL, MVT::i16);
|
2015-12-23 04:55:23 +08:00
|
|
|
|
|
|
|
return true;
|
2014-06-25 07:33:07 +08:00
|
|
|
}
|
|
|
|
|
2014-08-12 06:18:17 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFAddr64(SDValue Addr, SDValue &SRsrc,
|
2015-02-11 08:34:32 +08:00
|
|
|
SDValue &VAddr, SDValue &SOffset,
|
2015-02-27 22:59:41 +08:00
|
|
|
SDValue &Offset, SDValue &GLC,
|
|
|
|
SDValue &SLC, SDValue &TFE) const {
|
|
|
|
SDValue Ptr, Offen, Idxen, Addr64;
|
2014-07-21 23:45:01 +08:00
|
|
|
|
2015-07-20 22:28:41 +08:00
|
|
|
// addr64 bit was removed for volcanic islands.
|
|
|
|
if (Subtarget->getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS)
|
|
|
|
return false;
|
|
|
|
|
2015-12-23 04:55:23 +08:00
|
|
|
if (!SelectMUBUF(Addr, Ptr, VAddr, SOffset, Offset, Offen, Idxen, Addr64,
|
|
|
|
GLC, SLC, TFE))
|
|
|
|
return false;
|
2014-08-12 06:18:17 +08:00
|
|
|
|
|
|
|
ConstantSDNode *C = cast<ConstantSDNode>(Addr64);
|
|
|
|
if (C->getSExtValue()) {
|
|
|
|
SDLoc DL(Addr);
|
2014-11-06 03:01:17 +08:00
|
|
|
|
|
|
|
const SITargetLowering& Lowering =
|
|
|
|
*static_cast<const SITargetLowering*>(getTargetLowering());
|
|
|
|
|
|
|
|
SRsrc = SDValue(Lowering.wrapAddr64Rsrc(*CurDAG, DL, Ptr), 0);
|
2014-08-12 06:18:17 +08:00
|
|
|
return true;
|
|
|
|
}
|
2014-11-06 03:01:17 +08:00
|
|
|
|
2014-08-12 06:18:17 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-26 02:30:26 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFAddr64(SDValue Addr, SDValue &SRsrc,
|
2015-02-11 08:34:32 +08:00
|
|
|
SDValue &VAddr, SDValue &SOffset,
|
2015-09-22 19:15:07 +08:00
|
|
|
SDValue &Offset,
|
|
|
|
SDValue &SLC) const {
|
2015-04-28 22:05:47 +08:00
|
|
|
SLC = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i1);
|
2015-02-27 22:59:41 +08:00
|
|
|
SDValue GLC, TFE;
|
2014-09-26 02:30:26 +08:00
|
|
|
|
2015-02-27 22:59:41 +08:00
|
|
|
return SelectMUBUFAddr64(Addr, SRsrc, VAddr, SOffset, Offset, GLC, SLC, TFE);
|
2014-09-26 02:30:26 +08:00
|
|
|
}
|
|
|
|
|
2014-07-21 23:45:01 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFScratch(SDValue Addr, SDValue &Rsrc,
|
|
|
|
SDValue &VAddr, SDValue &SOffset,
|
|
|
|
SDValue &ImmOffset) const {
|
|
|
|
|
|
|
|
SDLoc DL(Addr);
|
|
|
|
MachineFunction &MF = CurDAG->getMachineFunction();
|
2015-12-01 05:15:53 +08:00
|
|
|
const SIMachineFunctionInfo *Info = MF.getInfo<SIMachineFunctionInfo>();
|
2015-01-21 01:49:47 +08:00
|
|
|
|
2015-12-01 05:15:53 +08:00
|
|
|
Rsrc = CurDAG->getRegister(Info->getScratchRSrcReg(), MVT::v4i32);
|
2015-12-01 05:16:03 +08:00
|
|
|
SOffset = CurDAG->getRegister(Info->getScratchWaveOffsetReg(), MVT::i32);
|
2014-07-21 23:45:01 +08:00
|
|
|
|
|
|
|
// (add n0, c1)
|
|
|
|
if (CurDAG->isBaseWithConstantOffset(Addr)) {
|
2015-07-17 03:40:09 +08:00
|
|
|
SDValue N0 = Addr.getOperand(0);
|
2014-07-21 23:45:01 +08:00
|
|
|
SDValue N1 = Addr.getOperand(1);
|
2016-02-24 12:55:29 +08:00
|
|
|
|
2015-07-17 03:40:09 +08:00
|
|
|
// Offsets in vaddr must be positive.
|
2016-02-24 12:55:29 +08:00
|
|
|
ConstantSDNode *C1 = cast<ConstantSDNode>(N1);
|
2016-03-22 02:02:18 +08:00
|
|
|
if (isLegalMUBUFImmOffset(C1)) {
|
2016-02-24 12:55:29 +08:00
|
|
|
VAddr = N0;
|
|
|
|
ImmOffset = CurDAG->getTargetConstant(C1->getZExtValue(), DL, MVT::i16);
|
|
|
|
return true;
|
2014-07-21 23:45:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// (node)
|
|
|
|
VAddr = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
ImmOffset = CurDAG->getTargetConstant(0, DL, MVT::i16);
|
2014-07-21 23:45:01 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-12 06:18:17 +08: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-03 01:05:41 +08:00
|
|
|
const SIInstrInfo *TII =
|
2015-01-31 07:24:40 +08:00
|
|
|
static_cast<const SIInstrInfo *>(Subtarget->getInstrInfo());
|
2014-07-21 23:45:01 +08:00
|
|
|
|
2015-12-23 04:55:23 +08:00
|
|
|
if (!SelectMUBUF(Addr, Ptr, VAddr, SOffset, Offset, Offen, Idxen, Addr64,
|
|
|
|
GLC, SLC, TFE))
|
|
|
|
return false;
|
2014-07-21 23:45:01 +08:00
|
|
|
|
2014-08-12 06:18:17 +08:00
|
|
|
if (!cast<ConstantSDNode>(Offen)->getSExtValue() &&
|
|
|
|
!cast<ConstantSDNode>(Idxen)->getSExtValue() &&
|
|
|
|
!cast<ConstantSDNode>(Addr64)->getSExtValue()) {
|
2014-12-03 01:05:41 +08:00
|
|
|
uint64_t Rsrc = TII->getDefaultRsrcDataFormat() |
|
2014-08-12 06:18:17 +08:00
|
|
|
APInt::getAllOnesValue(32).getZExtValue(); // Size
|
|
|
|
SDLoc DL(Addr);
|
2014-11-06 03:01:19 +08:00
|
|
|
|
|
|
|
const SITargetLowering& Lowering =
|
|
|
|
*static_cast<const SITargetLowering*>(getTargetLowering());
|
|
|
|
|
|
|
|
SRsrc = SDValue(Lowering.buildRSRC(*CurDAG, DL, Ptr, 0, Rsrc), 0);
|
2014-08-12 06:18:17 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2014-07-21 23:45:01 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 03:23:11 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc,
|
|
|
|
SDValue &Soffset, SDValue &Offset
|
|
|
|
) const {
|
|
|
|
SDValue GLC, SLC, TFE;
|
|
|
|
|
|
|
|
return SelectMUBUFOffset(Addr, SRsrc, Soffset, Offset, GLC, SLC, TFE);
|
|
|
|
}
|
2014-09-26 02:30:26 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc,
|
|
|
|
SDValue &Soffset, SDValue &Offset,
|
2016-06-10 07:42:48 +08:00
|
|
|
SDValue &SLC) const {
|
|
|
|
SDValue GLC, TFE;
|
2014-09-26 02:30:26 +08:00
|
|
|
|
|
|
|
return SelectMUBUFOffset(Addr, SRsrc, Soffset, Offset, GLC, SLC, TFE);
|
|
|
|
}
|
|
|
|
|
2016-03-19 00:24:20 +08:00
|
|
|
void AMDGPUDAGToDAGISel::SelectMUBUFConstant(SDValue Constant,
|
|
|
|
SDValue &SOffset,
|
|
|
|
SDValue &ImmOffset) const {
|
|
|
|
SDLoc DL(Constant);
|
|
|
|
uint32_t Imm = cast<ConstantSDNode>(Constant)->getZExtValue();
|
|
|
|
uint32_t Overflow = 0;
|
|
|
|
|
|
|
|
if (Imm >= 4096) {
|
|
|
|
if (Imm <= 4095 + 64) {
|
|
|
|
// Use an SOffset inline constant for 1..64
|
|
|
|
Overflow = Imm - 4095;
|
|
|
|
Imm = 4095;
|
|
|
|
} else {
|
|
|
|
// Try to keep the same value in SOffset for adjacent loads, so that
|
|
|
|
// the corresponding register contents can be re-used.
|
|
|
|
//
|
|
|
|
// Load values with all low-bits set into SOffset, so that a larger
|
|
|
|
// range of values can be covered using s_movk_i32
|
|
|
|
uint32_t High = (Imm + 1) & ~4095;
|
|
|
|
uint32_t Low = (Imm + 1) & 4095;
|
|
|
|
Imm = Low;
|
|
|
|
Overflow = High - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImmOffset = CurDAG->getTargetConstant(Imm, DL, MVT::i16);
|
|
|
|
|
|
|
|
if (Overflow <= 64)
|
|
|
|
SOffset = CurDAG->getTargetConstant(Overflow, DL, MVT::i32);
|
|
|
|
else
|
|
|
|
SOffset = SDValue(CurDAG->getMachineNode(AMDGPU::S_MOV_B32, DL, MVT::i32,
|
|
|
|
CurDAG->getTargetConstant(Overflow, DL, MVT::i32)),
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFIntrinsicOffset(SDValue Offset,
|
|
|
|
SDValue &SOffset,
|
|
|
|
SDValue &ImmOffset) const {
|
|
|
|
SDLoc DL(Offset);
|
|
|
|
|
|
|
|
if (!isa<ConstantSDNode>(Offset))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SelectMUBUFConstant(Offset, SOffset, ImmOffset);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectMUBUFIntrinsicVOffset(SDValue Offset,
|
|
|
|
SDValue &SOffset,
|
|
|
|
SDValue &ImmOffset,
|
|
|
|
SDValue &VOffset) const {
|
|
|
|
SDLoc DL(Offset);
|
|
|
|
|
|
|
|
// Don't generate an unnecessary voffset for constant offsets.
|
|
|
|
if (isa<ConstantSDNode>(Offset))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (CurDAG->isBaseWithConstantOffset(Offset)) {
|
|
|
|
SDValue N0 = Offset.getOperand(0);
|
|
|
|
SDValue N1 = Offset.getOperand(1);
|
|
|
|
SelectMUBUFConstant(N1, SOffset, ImmOffset);
|
|
|
|
VOffset = N0;
|
|
|
|
} else {
|
|
|
|
SOffset = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
|
|
|
ImmOffset = CurDAG->getTargetConstant(0, DL, MVT::i16);
|
|
|
|
VOffset = Offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-07 03:28:30 +08:00
|
|
|
///
|
|
|
|
/// \param EncodedOffset This is the immediate value that will be encoded
|
|
|
|
/// directly into the instruction. On SI/CI the \p EncodedOffset
|
|
|
|
/// will be in units of dwords and on VI+ it will be units of bytes.
|
|
|
|
static bool isLegalSMRDImmOffset(const AMDGPUSubtarget *ST,
|
|
|
|
int64_t EncodedOffset) {
|
|
|
|
return ST->getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS ?
|
|
|
|
isUInt<8>(EncodedOffset) : isUInt<20>(EncodedOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectSMRDOffset(SDValue ByteOffsetNode,
|
|
|
|
SDValue &Offset, bool &Imm) const {
|
|
|
|
|
|
|
|
// FIXME: Handle non-constant offsets.
|
|
|
|
ConstantSDNode *C = dyn_cast<ConstantSDNode>(ByteOffsetNode);
|
|
|
|
if (!C)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SDLoc SL(ByteOffsetNode);
|
|
|
|
AMDGPUSubtarget::Generation Gen = Subtarget->getGeneration();
|
|
|
|
int64_t ByteOffset = C->getSExtValue();
|
|
|
|
int64_t EncodedOffset = Gen < AMDGPUSubtarget::VOLCANIC_ISLANDS ?
|
|
|
|
ByteOffset >> 2 : ByteOffset;
|
|
|
|
|
|
|
|
if (isLegalSMRDImmOffset(Subtarget, EncodedOffset)) {
|
|
|
|
Offset = CurDAG->getTargetConstant(EncodedOffset, SL, MVT::i32);
|
|
|
|
Imm = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-07 03:28:38 +08:00
|
|
|
if (!isUInt<32>(EncodedOffset) || !isUInt<32>(ByteOffset))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (Gen == AMDGPUSubtarget::SEA_ISLANDS && isUInt<32>(EncodedOffset)) {
|
|
|
|
// 32-bit Immediates are supported on Sea Islands.
|
|
|
|
Offset = CurDAG->getTargetConstant(EncodedOffset, SL, MVT::i32);
|
|
|
|
} else {
|
2015-08-07 03:28:30 +08:00
|
|
|
SDValue C32Bit = CurDAG->getTargetConstant(ByteOffset, SL, MVT::i32);
|
|
|
|
Offset = SDValue(CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SL, MVT::i32,
|
|
|
|
C32Bit), 0);
|
|
|
|
}
|
2015-08-07 03:28:38 +08:00
|
|
|
Imm = false;
|
|
|
|
return true;
|
2015-08-07 03:28:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectSMRD(SDValue Addr, SDValue &SBase,
|
|
|
|
SDValue &Offset, bool &Imm) const {
|
|
|
|
|
|
|
|
SDLoc SL(Addr);
|
|
|
|
if (CurDAG->isBaseWithConstantOffset(Addr)) {
|
|
|
|
SDValue N0 = Addr.getOperand(0);
|
|
|
|
SDValue N1 = Addr.getOperand(1);
|
|
|
|
|
|
|
|
if (SelectSMRDOffset(N1, Offset, Imm)) {
|
|
|
|
SBase = N0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SBase = Addr;
|
|
|
|
Offset = CurDAG->getTargetConstant(0, SL, MVT::i32);
|
|
|
|
Imm = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectSMRDImm(SDValue Addr, SDValue &SBase,
|
|
|
|
SDValue &Offset) const {
|
|
|
|
bool Imm;
|
|
|
|
return SelectSMRD(Addr, SBase, Offset, Imm) && Imm;
|
|
|
|
}
|
|
|
|
|
2015-08-07 03:28:38 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectSMRDImm32(SDValue Addr, SDValue &SBase,
|
|
|
|
SDValue &Offset) const {
|
|
|
|
|
|
|
|
if (Subtarget->getGeneration() != AMDGPUSubtarget::SEA_ISLANDS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool Imm;
|
|
|
|
if (!SelectSMRD(Addr, SBase, Offset, Imm))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !Imm && isa<ConstantSDNode>(Offset);
|
|
|
|
}
|
|
|
|
|
2015-08-07 03:28:30 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectSMRDSgpr(SDValue Addr, SDValue &SBase,
|
|
|
|
SDValue &Offset) const {
|
|
|
|
bool Imm;
|
2015-08-07 03:28:38 +08:00
|
|
|
return SelectSMRD(Addr, SBase, Offset, Imm) && !Imm &&
|
|
|
|
!isa<ConstantSDNode>(Offset);
|
2015-08-07 03:28:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUDAGToDAGISel::SelectSMRDBufferImm(SDValue Addr,
|
|
|
|
SDValue &Offset) const {
|
|
|
|
bool Imm;
|
|
|
|
return SelectSMRDOffset(Addr, Offset, Imm) && Imm;
|
|
|
|
}
|
|
|
|
|
2015-08-07 03:28:38 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectSMRDBufferImm32(SDValue Addr,
|
|
|
|
SDValue &Offset) const {
|
|
|
|
if (Subtarget->getGeneration() != AMDGPUSubtarget::SEA_ISLANDS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool Imm;
|
|
|
|
if (!SelectSMRDOffset(Addr, Offset, Imm))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !Imm && isa<ConstantSDNode>(Offset);
|
|
|
|
}
|
|
|
|
|
2015-08-07 03:28:30 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectSMRDBufferSgpr(SDValue Addr,
|
|
|
|
SDValue &Offset) const {
|
|
|
|
bool Imm;
|
2015-08-07 03:28:38 +08:00
|
|
|
return SelectSMRDOffset(Addr, Offset, Imm) && !Imm &&
|
|
|
|
!isa<ConstantSDNode>(Offset);
|
2015-08-07 03:28:30 +08:00
|
|
|
}
|
|
|
|
|
2015-03-24 21:40:27 +08:00
|
|
|
SDNode *AMDGPUDAGToDAGISel::getS_BFE(unsigned Opcode, SDLoc DL, SDValue Val,
|
|
|
|
uint32_t Offset, uint32_t Width) {
|
|
|
|
// 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 PackedVal = Offset | (Width << 16);
|
2015-04-28 22:05:47 +08:00
|
|
|
SDValue PackedConst = CurDAG->getTargetConstant(PackedVal, DL, MVT::i32);
|
2015-03-24 21:40:27 +08:00
|
|
|
|
|
|
|
return CurDAG->getMachineNode(Opcode, DL, MVT::i32, Val, PackedConst);
|
|
|
|
}
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
void AMDGPUDAGToDAGISel::SelectS_BFEFromShifts(SDNode *N) {
|
2015-03-24 21:40:27 +08:00
|
|
|
// "(a << b) srl c)" ---> "BFE_U32 a, (c-b), (32-c)
|
|
|
|
// "(a << b) sra c)" ---> "BFE_I32 a, (c-b), (32-c)
|
|
|
|
// Predicate: 0 < b <= c < 32
|
|
|
|
|
|
|
|
const SDValue &Shl = N->getOperand(0);
|
|
|
|
ConstantSDNode *B = dyn_cast<ConstantSDNode>(Shl->getOperand(1));
|
|
|
|
ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1));
|
|
|
|
|
|
|
|
if (B && C) {
|
|
|
|
uint32_t BVal = B->getZExtValue();
|
|
|
|
uint32_t CVal = C->getZExtValue();
|
|
|
|
|
|
|
|
if (0 < BVal && BVal <= CVal && CVal < 32) {
|
|
|
|
bool Signed = N->getOpcode() == ISD::SRA;
|
|
|
|
unsigned Opcode = Signed ? AMDGPU::S_BFE_I32 : AMDGPU::S_BFE_U32;
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
ReplaceNode(N, getS_BFE(Opcode, SDLoc(N), Shl.getOperand(0), CVal - BVal,
|
|
|
|
32 - CVal));
|
|
|
|
return;
|
2015-03-24 21:40:27 +08:00
|
|
|
}
|
|
|
|
}
|
2016-05-13 05:03:32 +08:00
|
|
|
SelectCode(N);
|
2015-03-24 21:40:27 +08:00
|
|
|
}
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
void AMDGPUDAGToDAGISel::SelectS_BFE(SDNode *N) {
|
2015-03-24 21:40:27 +08:00
|
|
|
switch (N->getOpcode()) {
|
|
|
|
case ISD::AND:
|
|
|
|
if (N->getOperand(0).getOpcode() == ISD::SRL) {
|
|
|
|
// "(a srl b) & mask" ---> "BFE_U32 a, b, popcount(mask)"
|
|
|
|
// Predicate: isMask(mask)
|
|
|
|
const SDValue &Srl = N->getOperand(0);
|
|
|
|
ConstantSDNode *Shift = dyn_cast<ConstantSDNode>(Srl.getOperand(1));
|
|
|
|
ConstantSDNode *Mask = dyn_cast<ConstantSDNode>(N->getOperand(1));
|
|
|
|
|
|
|
|
if (Shift && Mask) {
|
|
|
|
uint32_t ShiftVal = Shift->getZExtValue();
|
|
|
|
uint32_t MaskVal = Mask->getZExtValue();
|
|
|
|
|
|
|
|
if (isMask_32(MaskVal)) {
|
|
|
|
uint32_t WidthVal = countPopulation(MaskVal);
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
ReplaceNode(N, getS_BFE(AMDGPU::S_BFE_U32, SDLoc(N),
|
|
|
|
Srl.getOperand(0), ShiftVal, WidthVal));
|
|
|
|
return;
|
2015-03-24 21:40:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISD::SRL:
|
|
|
|
if (N->getOperand(0).getOpcode() == ISD::AND) {
|
|
|
|
// "(a & mask) srl b)" ---> "BFE_U32 a, b, popcount(mask >> b)"
|
|
|
|
// Predicate: isMask(mask >> b)
|
|
|
|
const SDValue &And = N->getOperand(0);
|
|
|
|
ConstantSDNode *Shift = dyn_cast<ConstantSDNode>(N->getOperand(1));
|
|
|
|
ConstantSDNode *Mask = dyn_cast<ConstantSDNode>(And->getOperand(1));
|
|
|
|
|
|
|
|
if (Shift && Mask) {
|
|
|
|
uint32_t ShiftVal = Shift->getZExtValue();
|
|
|
|
uint32_t MaskVal = Mask->getZExtValue() >> ShiftVal;
|
|
|
|
|
|
|
|
if (isMask_32(MaskVal)) {
|
|
|
|
uint32_t WidthVal = countPopulation(MaskVal);
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
ReplaceNode(N, getS_BFE(AMDGPU::S_BFE_U32, SDLoc(N),
|
|
|
|
And.getOperand(0), ShiftVal, WidthVal));
|
|
|
|
return;
|
2015-03-24 21:40:27 +08:00
|
|
|
}
|
|
|
|
}
|
2016-05-13 05:03:32 +08:00
|
|
|
} else if (N->getOperand(0).getOpcode() == ISD::SHL) {
|
|
|
|
SelectS_BFEFromShifts(N);
|
|
|
|
return;
|
|
|
|
}
|
2015-03-24 21:40:27 +08:00
|
|
|
break;
|
|
|
|
case ISD::SRA:
|
2016-05-13 05:03:32 +08:00
|
|
|
if (N->getOperand(0).getOpcode() == ISD::SHL) {
|
|
|
|
SelectS_BFEFromShifts(N);
|
|
|
|
return;
|
|
|
|
}
|
2015-03-24 21:40:27 +08:00
|
|
|
break;
|
2016-04-23 06:59:16 +08:00
|
|
|
|
|
|
|
case ISD::SIGN_EXTEND_INREG: {
|
|
|
|
// sext_inreg (srl x, 16), i8 -> bfe_i32 x, 16, 8
|
|
|
|
SDValue Src = N->getOperand(0);
|
|
|
|
if (Src.getOpcode() != ISD::SRL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
const ConstantSDNode *Amt = dyn_cast<ConstantSDNode>(Src.getOperand(1));
|
|
|
|
if (!Amt)
|
|
|
|
break;
|
|
|
|
|
|
|
|
unsigned Width = cast<VTSDNode>(N->getOperand(1))->getVT().getSizeInBits();
|
2016-05-13 05:03:32 +08:00
|
|
|
ReplaceNode(N, getS_BFE(AMDGPU::S_BFE_I32, SDLoc(N), Src.getOperand(0),
|
|
|
|
Amt->getZExtValue(), Width));
|
|
|
|
return;
|
2016-04-23 06:59:16 +08:00
|
|
|
}
|
2015-03-24 21:40:27 +08:00
|
|
|
}
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
SelectCode(N);
|
2015-03-24 21:40:27 +08:00
|
|
|
}
|
|
|
|
|
2016-05-13 05:03:32 +08:00
|
|
|
void AMDGPUDAGToDAGISel::SelectBRCOND(SDNode *N) {
|
2016-02-13 07:45:29 +08:00
|
|
|
SDValue Cond = N->getOperand(1);
|
|
|
|
|
|
|
|
if (isCBranchSCC(N)) {
|
|
|
|
// This brcond will use S_CBRANCH_SCC*, so let tablegen handle it.
|
2016-05-13 05:03:32 +08:00
|
|
|
SelectCode(N);
|
|
|
|
return;
|
2016-02-13 07:45:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// The result of VOPC instructions is or'd against ~EXEC before it is
|
|
|
|
// written to vcc or another SGPR. This means that the value '1' is always
|
|
|
|
// written to the corresponding bit for results that are masked. In order
|
|
|
|
// to correctly check against vccz, we need to and VCC with the EXEC
|
|
|
|
// register in order to clear the value from the masked bits.
|
|
|
|
|
|
|
|
SDLoc SL(N);
|
|
|
|
|
|
|
|
SDNode *MaskedCond =
|
|
|
|
CurDAG->getMachineNode(AMDGPU::S_AND_B64, SL, MVT::i1,
|
|
|
|
CurDAG->getRegister(AMDGPU::EXEC, MVT::i1),
|
|
|
|
Cond);
|
|
|
|
SDValue VCC = CurDAG->getCopyToReg(N->getOperand(0), SL, AMDGPU::VCC,
|
|
|
|
SDValue(MaskedCond, 0),
|
|
|
|
SDValue()); // Passing SDValue() adds a
|
|
|
|
// glue output.
|
2016-05-13 05:03:32 +08:00
|
|
|
CurDAG->SelectNodeTo(N, AMDGPU::S_CBRANCH_VCCNZ, MVT::Other,
|
|
|
|
N->getOperand(2), // Basic Block
|
|
|
|
VCC.getValue(0), // Chain
|
|
|
|
VCC.getValue(1)); // Glue
|
|
|
|
return;
|
2016-02-13 07:45:29 +08:00
|
|
|
}
|
|
|
|
|
2016-06-10 07:42:48 +08:00
|
|
|
// This is here because there isn't a way to use the generated sub0_sub1 as the
|
|
|
|
// subreg index to EXTRACT_SUBREG in tablegen.
|
|
|
|
void AMDGPUDAGToDAGISel::SelectATOMIC_CMP_SWAP(SDNode *N) {
|
|
|
|
MemSDNode *Mem = cast<MemSDNode>(N);
|
|
|
|
unsigned AS = Mem->getAddressSpace();
|
|
|
|
|
|
|
|
MVT VT = N->getSimpleValueType(0);
|
|
|
|
bool Is32 = (VT == MVT::i32);
|
|
|
|
SDLoc SL(N);
|
|
|
|
|
|
|
|
MachineSDNode *CmpSwap = nullptr;
|
|
|
|
if (Subtarget->hasAddr64()) {
|
|
|
|
SDValue SRsrc, VAddr, SOffset, Offset, GLC, SLC;
|
|
|
|
|
|
|
|
if (SelectMUBUFAddr64(Mem->getBasePtr(), SRsrc, VAddr, SOffset, Offset, SLC)) {
|
|
|
|
unsigned Opcode = Is32 ? AMDGPU::BUFFER_ATOMIC_CMPSWAP_RTN_ADDR64 :
|
|
|
|
AMDGPU::BUFFER_ATOMIC_CMPSWAP_X2_RTN_ADDR64;
|
|
|
|
SDValue CmpVal = Mem->getOperand(2);
|
|
|
|
|
|
|
|
// XXX - Do we care about glue operands?
|
|
|
|
|
|
|
|
SDValue Ops[] = {
|
|
|
|
CmpVal, VAddr, SRsrc, SOffset, Offset, SLC, Mem->getChain()
|
|
|
|
};
|
|
|
|
|
|
|
|
CmpSwap = CurDAG->getMachineNode(Opcode, SL, Mem->getVTList(), Ops);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CmpSwap) {
|
|
|
|
SDValue SRsrc, SOffset, Offset, SLC;
|
|
|
|
if (SelectMUBUFOffset(Mem->getBasePtr(), SRsrc, SOffset, Offset, SLC)) {
|
|
|
|
unsigned Opcode = Is32 ? AMDGPU::BUFFER_ATOMIC_CMPSWAP_RTN_OFFSET :
|
|
|
|
AMDGPU::BUFFER_ATOMIC_CMPSWAP_X2_RTN_OFFSET;
|
|
|
|
|
|
|
|
SDValue CmpVal = Mem->getOperand(2);
|
|
|
|
SDValue Ops[] = {
|
|
|
|
CmpVal, SRsrc, SOffset, Offset, SLC, Mem->getChain()
|
|
|
|
};
|
|
|
|
|
|
|
|
CmpSwap = CurDAG->getMachineNode(Opcode, SL, Mem->getVTList(), Ops);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CmpSwap) {
|
|
|
|
SelectCode(N);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineSDNode::mmo_iterator MMOs = MF->allocateMemRefsArray(1);
|
|
|
|
*MMOs = Mem->getMemOperand();
|
|
|
|
CmpSwap->setMemRefs(MMOs, MMOs + 1);
|
|
|
|
|
|
|
|
unsigned SubReg = Is32 ? AMDGPU::sub0 : AMDGPU::sub0_sub1;
|
|
|
|
SDValue Extract
|
|
|
|
= CurDAG->getTargetExtractSubreg(SubReg, SL, VT, SDValue(CmpSwap, 0));
|
|
|
|
|
|
|
|
ReplaceUses(SDValue(N, 0), Extract);
|
|
|
|
ReplaceUses(SDValue(N, 1), SDValue(CmpSwap, 1));
|
|
|
|
CurDAG->RemoveDeadNode(N);
|
|
|
|
}
|
|
|
|
|
2014-08-01 08:32:39 +08: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);
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:05:47 +08:00
|
|
|
SrcMods = CurDAG->getTargetConstant(Mods, SDLoc(In), MVT::i32);
|
2014-08-01 08:32:39 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-13 23:47:57 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectVOP3NoMods(SDValue In, SDValue &Src,
|
|
|
|
SDValue &SrcMods) const {
|
|
|
|
bool Res = SelectVOP3Mods(In, Src, SrcMods);
|
|
|
|
return Res && cast<ConstantSDNode>(SrcMods)->isNullValue();
|
|
|
|
}
|
|
|
|
|
2014-08-01 08:32:39 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectVOP3Mods0(SDValue In, SDValue &Src,
|
|
|
|
SDValue &SrcMods, SDValue &Clamp,
|
|
|
|
SDValue &Omod) const {
|
2015-04-28 22:05:47 +08:00
|
|
|
SDLoc DL(In);
|
2014-08-01 08:32:39 +08:00
|
|
|
// FIXME: Handle Clamp and Omod
|
2015-04-28 22:05:47 +08:00
|
|
|
Clamp = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
|
|
|
Omod = CurDAG->getTargetConstant(0, DL, MVT::i32);
|
2014-08-01 08:32:39 +08:00
|
|
|
|
|
|
|
return SelectVOP3Mods(In, Src, SrcMods);
|
|
|
|
}
|
|
|
|
|
2015-07-13 23:47:57 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectVOP3NoMods0(SDValue In, SDValue &Src,
|
|
|
|
SDValue &SrcMods, SDValue &Clamp,
|
|
|
|
SDValue &Omod) const {
|
|
|
|
bool Res = SelectVOP3Mods0(In, Src, SrcMods, Clamp, Omod);
|
|
|
|
|
|
|
|
return Res && cast<ConstantSDNode>(SrcMods)->isNullValue() &&
|
|
|
|
cast<ConstantSDNode>(Clamp)->isNullValue() &&
|
|
|
|
cast<ConstantSDNode>(Omod)->isNullValue();
|
|
|
|
}
|
|
|
|
|
2014-11-14 03:49:04 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectVOP3Mods0Clamp(SDValue In, SDValue &Src,
|
|
|
|
SDValue &SrcMods,
|
|
|
|
SDValue &Omod) const {
|
|
|
|
// FIXME: Handle Omod
|
2015-04-28 22:05:47 +08:00
|
|
|
Omod = CurDAG->getTargetConstant(0, SDLoc(In), MVT::i32);
|
2014-11-14 03:49:04 +08:00
|
|
|
|
|
|
|
return SelectVOP3Mods(In, Src, SrcMods);
|
|
|
|
}
|
|
|
|
|
2015-01-07 07:00:37 +08:00
|
|
|
bool AMDGPUDAGToDAGISel::SelectVOP3Mods0Clamp0OMod(SDValue In, SDValue &Src,
|
|
|
|
SDValue &SrcMods,
|
|
|
|
SDValue &Clamp,
|
|
|
|
SDValue &Omod) const {
|
2015-04-28 22:05:47 +08:00
|
|
|
Clamp = Omod = CurDAG->getTargetConstant(0, SDLoc(In), MVT::i32);
|
2015-01-07 07:00:37 +08:00
|
|
|
return SelectVOP3Mods(In, Src, SrcMods);
|
|
|
|
}
|
|
|
|
|
2015-09-26 01:27:08 +08:00
|
|
|
void AMDGPUDAGToDAGISel::PreprocessISelDAG() {
|
2016-03-24 05:49:25 +08:00
|
|
|
MachineFrameInfo *MFI = CurDAG->getMachineFunction().getFrameInfo();
|
|
|
|
|
|
|
|
// Handle the perverse case where a frame index is being stored. We don't
|
|
|
|
// want to see multiple frame index operands on the same instruction since
|
|
|
|
// it complicates things and violates some assumptions about frame index
|
|
|
|
// lowering.
|
|
|
|
for (int I = MFI->getObjectIndexBegin(), E = MFI->getObjectIndexEnd();
|
|
|
|
I != E; ++I) {
|
|
|
|
SDValue FI = CurDAG->getTargetFrameIndex(I, MVT::i32);
|
|
|
|
|
|
|
|
// It's possible that we have a frame index defined in the function that
|
|
|
|
// isn't used in this block.
|
|
|
|
if (FI.use_empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Skip over the AssertZext inserted during lowering.
|
|
|
|
SDValue EffectiveFI = FI;
|
|
|
|
auto It = FI->use_begin();
|
|
|
|
if (It->getOpcode() == ISD::AssertZext && FI->hasOneUse()) {
|
|
|
|
EffectiveFI = SDValue(*It, 0);
|
|
|
|
It = EffectiveFI->use_begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto It = EffectiveFI->use_begin(); !It.atEnd(); ) {
|
|
|
|
SDUse &Use = It.getUse();
|
|
|
|
SDNode *User = Use.getUser();
|
|
|
|
unsigned OpIdx = It.getOperandNo();
|
|
|
|
++It;
|
|
|
|
|
|
|
|
if (MemSDNode *M = dyn_cast<MemSDNode>(User)) {
|
|
|
|
unsigned PtrIdx = M->getOpcode() == ISD::STORE ? 2 : 1;
|
|
|
|
if (OpIdx == PtrIdx)
|
|
|
|
continue;
|
|
|
|
|
2016-03-24 18:53:28 +08:00
|
|
|
unsigned OpN = M->getNumOperands();
|
2016-03-24 05:49:25 +08:00
|
|
|
SDValue NewOps[8];
|
|
|
|
|
|
|
|
assert(OpN < array_lengthof(NewOps));
|
|
|
|
for (unsigned Op = 0; Op != OpN; ++Op) {
|
|
|
|
if (Op != OpIdx) {
|
|
|
|
NewOps[Op] = M->getOperand(Op);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineSDNode *Mov = CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
|
|
|
|
SDLoc(M), MVT::i32, FI);
|
|
|
|
NewOps[Op] = SDValue(Mov, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CurDAG->UpdateNodeOperands(M, makeArrayRef(NewOps, OpN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-26 01:27:08 +08:00
|
|
|
}
|
|
|
|
|
2013-02-27 01:52:16 +08:00
|
|
|
void AMDGPUDAGToDAGISel::PostprocessISelDAG() {
|
2013-06-20 05:36:55 +08:00
|
|
|
const AMDGPUTargetLowering& Lowering =
|
2014-04-18 15:40:20 +08:00
|
|
|
*static_cast<const AMDGPUTargetLowering*>(getTargetLowering());
|
2013-09-13 07:44:44 +08:00
|
|
|
bool IsModified = false;
|
|
|
|
do {
|
|
|
|
IsModified = false;
|
|
|
|
// Go over all selected nodes and try to fold them a bit more
|
2015-07-15 06:10:54 +08:00
|
|
|
for (SDNode &Node : CurDAG->allnodes()) {
|
|
|
|
MachineSDNode *MachineNode = dyn_cast<MachineSDNode>(&Node);
|
2013-09-13 07:44:44 +08:00
|
|
|
if (!MachineNode)
|
|
|
|
continue;
|
2013-02-27 01:52:16 +08:00
|
|
|
|
2013-09-13 07:44:44 +08:00
|
|
|
SDNode *ResNode = Lowering.PostISelFolding(MachineNode, *CurDAG);
|
2015-07-15 06:10:54 +08:00
|
|
|
if (ResNode != &Node) {
|
|
|
|
ReplaceUses(&Node, ResNode);
|
2013-09-13 07:44:44 +08:00
|
|
|
IsModified = true;
|
|
|
|
}
|
2013-06-04 01:39:46 +08:00
|
|
|
}
|
2013-09-13 07:44:44 +08:00
|
|
|
CurDAG->RemoveDeadNodes();
|
|
|
|
} while (IsModified);
|
2013-02-27 01:52:16 +08:00
|
|
|
}
|