2006-02-05 13:50:24 +08:00
|
|
|
//===-- SparcISelDAGToDAG.cpp - A dag to dag inst selector for Sparc ------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-02-05 13:50:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines an instruction selector for the SPARC target.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SparcTargetMachine.h"
|
[Sparc] Implement i64 load/store support for 32-bit sparc.
The LDD/STD instructions can load/store a 64bit quantity from/to
memory to/from a consecutive even/odd pair of (32-bit) registers. They
are part of SparcV8, and also present in SparcV9. (Although deprecated
there, as you can store 64bits in one register).
As recommended on llvmdev in the thread "How to enable use of 64bit
load/store for 32bit architecture" from Apr 2015, I've modeled the
64-bit load/store operations as working on a v2i32 type, rather than
making i64 a legal type, but with few legal operations. The latter
does not (currently) work, as there is much code in llvm which assumes
that if i64 is legal, operations like "add" will actually work on it.
The same assumption does not hold for v2i32 -- for vector types, it is
workable to support only load/store, and expand everything else.
This patch:
- Adds a new register class, IntPair, for even/odd pairs of registers.
- Modifies the list of reserved registers, the stack spilling code,
and register copying code to support the IntPair register class.
- Adds support in AsmParser. (note that in asm text, you write the
name of the first register of the pair only. So the parser has to
morph the single register into the equivalent paired register).
- Adds the new instructions themselves (LDD/STD/LDDA/STDA).
- Hooks up the instructions and registers as a vector type v2i32. Adds
custom legalizer to transform i64 load/stores into v2i32 load/stores
and bitcasts, so that the new instructions can actually be
generated, and marks all operations other than load/store on v2i32
as needing to be expanded.
- Copies the unfortunate SelectInlineAsm hack from ARMISelDAGToDAG.
This hack undoes the transformation of i64 operands into two
arbitrarily-allocated separate i32 registers in
SelectionDAGBuilder. and instead passes them in a single
IntPair. (Arbitrarily allocated registers are not useful, asm code
expects to be receiving a pair, which can be passed to ldd/std.)
Also adds a bunch of test cases covering all the bugs I've added along
the way.
Differential Revision: http://reviews.llvm.org/D8713
llvm-svn: 244484
2015-08-11 03:11:39 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2006-02-05 13:50:24 +08:00
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Intrinsics.h"
|
2006-02-05 13:50:24 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-09 04:53:28 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2006-02-05 13:50:24 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Instruction Selector Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SparcDAGToDAGISel - SPARC specific code to select SPARC machine
|
|
|
|
/// instructions for SelectionDAG operations.
|
|
|
|
///
|
|
|
|
namespace {
|
|
|
|
class SparcDAGToDAGISel : public SelectionDAGISel {
|
|
|
|
/// Subtarget - Keep a pointer to the Sparc Subtarget around so that we can
|
|
|
|
/// make the right decision when generating code for different targets.
|
2015-01-31 07:46:43 +08:00
|
|
|
const SparcSubtarget *Subtarget;
|
2006-02-05 13:50:24 +08:00
|
|
|
public:
|
2015-01-31 07:46:43 +08:00
|
|
|
explicit SparcDAGToDAGISel(SparcTargetMachine &tm) : SelectionDAGISel(tm) {}
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override {
|
|
|
|
Subtarget = &MF.getSubtarget<SparcSubtarget>();
|
|
|
|
return SelectionDAGISel::runOnMachineFunction(MF);
|
2006-02-05 13:50:24 +08:00
|
|
|
}
|
|
|
|
|
2016-05-14 05:46:22 +08:00
|
|
|
void Select(SDNode *N) override;
|
2006-02-05 13:50:24 +08:00
|
|
|
|
|
|
|
// Complex Pattern Selectors.
|
2010-09-22 04:31:19 +08:00
|
|
|
bool SelectADDRrr(SDValue N, SDValue &R1, SDValue &R2);
|
|
|
|
bool SelectADDRri(SDValue N, SDValue &Base, SDValue &Offset);
|
2008-10-10 18:14:15 +08:00
|
|
|
|
2008-10-10 18:14:47 +08:00
|
|
|
/// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
|
|
|
|
/// inline asm expressions.
|
2014-04-29 15:57:13 +08:00
|
|
|
bool SelectInlineAsmMemoryOperand(const SDValue &Op,
|
2015-03-13 20:45:09 +08:00
|
|
|
unsigned ConstraintID,
|
2014-04-29 15:57:13 +08:00
|
|
|
std::vector<SDValue> &OutOps) override;
|
2008-10-10 18:14:47 +08:00
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override {
|
2006-02-05 13:50:24 +08:00
|
|
|
return "SPARC DAG->DAG Pattern Instruction Selection";
|
2008-10-10 18:14:15 +08:00
|
|
|
}
|
|
|
|
|
2006-02-05 13:50:24 +08:00
|
|
|
// Include the pieces autogenerated from the target description.
|
|
|
|
#include "SparcGenDAGISel.inc"
|
2009-09-16 01:46:24 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
SDNode* getGlobalBaseReg();
|
2016-05-14 05:46:22 +08:00
|
|
|
bool tryInlineAsm(SDNode *N);
|
2006-02-05 13:50:24 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2009-09-16 01:46:24 +08:00
|
|
|
SDNode* SparcDAGToDAGISel::getGlobalBaseReg() {
|
2015-01-31 07:46:43 +08:00
|
|
|
unsigned GlobalBaseReg = Subtarget->getInstrInfo()->getGlobalBaseReg(MF);
|
2015-07-09 10:09:04 +08:00
|
|
|
return CurDAG->getRegister(GlobalBaseReg,
|
|
|
|
TLI->getPointerTy(CurDAG->getDataLayout()))
|
|
|
|
.getNode();
|
2009-09-16 01:46:24 +08:00
|
|
|
}
|
|
|
|
|
2010-09-22 04:31:19 +08:00
|
|
|
bool SparcDAGToDAGISel::SelectADDRri(SDValue Addr,
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue &Base, SDValue &Offset) {
|
2006-02-05 13:50:24 +08:00
|
|
|
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
|
2015-07-09 10:09:04 +08:00
|
|
|
Base = CurDAG->getTargetFrameIndex(
|
|
|
|
FIN->getIndex(), TLI->getPointerTy(CurDAG->getDataLayout()));
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i32);
|
2006-02-05 13:50:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
2008-09-17 05:48:12 +08:00
|
|
|
if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
|
2013-09-22 14:48:52 +08:00
|
|
|
Addr.getOpcode() == ISD::TargetGlobalAddress ||
|
|
|
|
Addr.getOpcode() == ISD::TargetGlobalTLSAddress)
|
2006-02-10 15:35:42 +08:00
|
|
|
return false; // direct calls.
|
2008-10-10 18:14:15 +08:00
|
|
|
|
2006-02-05 13:50:24 +08:00
|
|
|
if (Addr.getOpcode() == ISD::ADD) {
|
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) {
|
2010-08-18 02:17:12 +08:00
|
|
|
if (isInt<13>(CN->getSExtValue())) {
|
2008-10-10 18:14:15 +08:00
|
|
|
if (FrameIndexSDNode *FIN =
|
2006-02-05 13:50:24 +08:00
|
|
|
dyn_cast<FrameIndexSDNode>(Addr.getOperand(0))) {
|
|
|
|
// Constant offset from frame ref.
|
2015-07-09 10:09:04 +08:00
|
|
|
Base = CurDAG->getTargetFrameIndex(
|
|
|
|
FIN->getIndex(), TLI->getPointerTy(CurDAG->getDataLayout()));
|
2006-02-05 13:50:24 +08:00
|
|
|
} else {
|
2006-02-05 16:35:50 +08:00
|
|
|
Base = Addr.getOperand(0);
|
2006-02-05 13:50:24 +08:00
|
|
|
}
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(CN->getZExtValue(), SDLoc(Addr),
|
|
|
|
MVT::i32);
|
2006-02-05 13:50:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Addr.getOperand(0).getOpcode() == SPISD::Lo) {
|
2006-02-05 16:35:50 +08:00
|
|
|
Base = Addr.getOperand(1);
|
2006-02-05 13:50:24 +08:00
|
|
|
Offset = Addr.getOperand(0).getOperand(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Addr.getOperand(1).getOpcode() == SPISD::Lo) {
|
2006-02-05 16:35:50 +08:00
|
|
|
Base = Addr.getOperand(0);
|
2006-02-05 13:50:24 +08:00
|
|
|
Offset = Addr.getOperand(1).getOperand(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2006-02-05 16:35:50 +08:00
|
|
|
Base = Addr;
|
2015-04-28 22:05:47 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i32);
|
2006-02-05 13:50:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-22 04:31:19 +08:00
|
|
|
bool SparcDAGToDAGISel::SelectADDRrr(SDValue Addr, SDValue &R1, SDValue &R2) {
|
2006-02-10 15:35:42 +08:00
|
|
|
if (Addr.getOpcode() == ISD::FrameIndex) return false;
|
2008-09-17 05:48:12 +08:00
|
|
|
if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
|
2013-09-22 14:48:52 +08:00
|
|
|
Addr.getOpcode() == ISD::TargetGlobalAddress ||
|
|
|
|
Addr.getOpcode() == ISD::TargetGlobalTLSAddress)
|
2006-02-10 15:35:42 +08:00
|
|
|
return false; // direct calls.
|
2008-10-10 18:14:15 +08:00
|
|
|
|
2006-02-05 13:50:24 +08:00
|
|
|
if (Addr.getOpcode() == ISD::ADD) {
|
2010-08-18 02:17:12 +08:00
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))
|
|
|
|
if (isInt<13>(CN->getSExtValue()))
|
|
|
|
return false; // Let the reg+imm pattern catch this!
|
2006-02-05 13:50:24 +08:00
|
|
|
if (Addr.getOperand(0).getOpcode() == SPISD::Lo ||
|
|
|
|
Addr.getOperand(1).getOpcode() == SPISD::Lo)
|
|
|
|
return false; // Let the reg+imm pattern catch this!
|
2006-02-05 16:35:50 +08:00
|
|
|
R1 = Addr.getOperand(0);
|
|
|
|
R2 = Addr.getOperand(1);
|
2006-02-05 13:50:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-02-05 16:35:50 +08:00
|
|
|
R1 = Addr;
|
2015-07-09 10:09:04 +08:00
|
|
|
R2 = CurDAG->getRegister(SP::G0, TLI->getPointerTy(CurDAG->getDataLayout()));
|
2006-02-05 13:50:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
[Sparc] Implement i64 load/store support for 32-bit sparc.
The LDD/STD instructions can load/store a 64bit quantity from/to
memory to/from a consecutive even/odd pair of (32-bit) registers. They
are part of SparcV8, and also present in SparcV9. (Although deprecated
there, as you can store 64bits in one register).
As recommended on llvmdev in the thread "How to enable use of 64bit
load/store for 32bit architecture" from Apr 2015, I've modeled the
64-bit load/store operations as working on a v2i32 type, rather than
making i64 a legal type, but with few legal operations. The latter
does not (currently) work, as there is much code in llvm which assumes
that if i64 is legal, operations like "add" will actually work on it.
The same assumption does not hold for v2i32 -- for vector types, it is
workable to support only load/store, and expand everything else.
This patch:
- Adds a new register class, IntPair, for even/odd pairs of registers.
- Modifies the list of reserved registers, the stack spilling code,
and register copying code to support the IntPair register class.
- Adds support in AsmParser. (note that in asm text, you write the
name of the first register of the pair only. So the parser has to
morph the single register into the equivalent paired register).
- Adds the new instructions themselves (LDD/STD/LDDA/STDA).
- Hooks up the instructions and registers as a vector type v2i32. Adds
custom legalizer to transform i64 load/stores into v2i32 load/stores
and bitcasts, so that the new instructions can actually be
generated, and marks all operations other than load/store on v2i32
as needing to be expanded.
- Copies the unfortunate SelectInlineAsm hack from ARMISelDAGToDAG.
This hack undoes the transformation of i64 operands into two
arbitrarily-allocated separate i32 registers in
SelectionDAGBuilder. and instead passes them in a single
IntPair. (Arbitrarily allocated registers are not useful, asm code
expects to be receiving a pair, which can be passed to ldd/std.)
Also adds a bunch of test cases covering all the bugs I've added along
the way.
Differential Revision: http://reviews.llvm.org/D8713
llvm-svn: 244484
2015-08-11 03:11:39 +08:00
|
|
|
|
|
|
|
// Re-assemble i64 arguments split up in SelectionDAGBuilder's
|
|
|
|
// visitInlineAsm / GetRegistersForValue functions.
|
|
|
|
//
|
|
|
|
// Note: This function was copied from, and is essentially identical
|
|
|
|
// to ARMISelDAGToDAG::SelectInlineAsm. It is very unfortunate that
|
|
|
|
// such hacking-up is necessary; a rethink of how inline asm operands
|
|
|
|
// are handled may be in order to make doing this more sane.
|
|
|
|
//
|
|
|
|
// TODO: fix inline asm support so I can simply tell it that 'i64'
|
|
|
|
// inputs to asm need to be allocated to the IntPair register type,
|
|
|
|
// and have that work. Then, delete this function.
|
2016-05-14 05:46:22 +08:00
|
|
|
bool SparcDAGToDAGISel::tryInlineAsm(SDNode *N){
|
[Sparc] Implement i64 load/store support for 32-bit sparc.
The LDD/STD instructions can load/store a 64bit quantity from/to
memory to/from a consecutive even/odd pair of (32-bit) registers. They
are part of SparcV8, and also present in SparcV9. (Although deprecated
there, as you can store 64bits in one register).
As recommended on llvmdev in the thread "How to enable use of 64bit
load/store for 32bit architecture" from Apr 2015, I've modeled the
64-bit load/store operations as working on a v2i32 type, rather than
making i64 a legal type, but with few legal operations. The latter
does not (currently) work, as there is much code in llvm which assumes
that if i64 is legal, operations like "add" will actually work on it.
The same assumption does not hold for v2i32 -- for vector types, it is
workable to support only load/store, and expand everything else.
This patch:
- Adds a new register class, IntPair, for even/odd pairs of registers.
- Modifies the list of reserved registers, the stack spilling code,
and register copying code to support the IntPair register class.
- Adds support in AsmParser. (note that in asm text, you write the
name of the first register of the pair only. So the parser has to
morph the single register into the equivalent paired register).
- Adds the new instructions themselves (LDD/STD/LDDA/STDA).
- Hooks up the instructions and registers as a vector type v2i32. Adds
custom legalizer to transform i64 load/stores into v2i32 load/stores
and bitcasts, so that the new instructions can actually be
generated, and marks all operations other than load/store on v2i32
as needing to be expanded.
- Copies the unfortunate SelectInlineAsm hack from ARMISelDAGToDAG.
This hack undoes the transformation of i64 operands into two
arbitrarily-allocated separate i32 registers in
SelectionDAGBuilder. and instead passes them in a single
IntPair. (Arbitrarily allocated registers are not useful, asm code
expects to be receiving a pair, which can be passed to ldd/std.)
Also adds a bunch of test cases covering all the bugs I've added along
the way.
Differential Revision: http://reviews.llvm.org/D8713
llvm-svn: 244484
2015-08-11 03:11:39 +08:00
|
|
|
std::vector<SDValue> AsmNodeOperands;
|
|
|
|
unsigned Flag, Kind;
|
|
|
|
bool Changed = false;
|
|
|
|
unsigned NumOps = N->getNumOperands();
|
|
|
|
|
|
|
|
// Normally, i64 data is bounded to two arbitrary GPRs for "%r"
|
|
|
|
// constraint. However, some instructions (e.g. ldd/std) require
|
|
|
|
// (even/even+1) GPRs.
|
|
|
|
|
|
|
|
// So, here, we check for this case, and mutate the inlineasm to use
|
|
|
|
// a single IntPair register instead, which guarantees such even/odd
|
|
|
|
// placement.
|
|
|
|
|
|
|
|
SDLoc dl(N);
|
|
|
|
SDValue Glue = N->getGluedNode() ? N->getOperand(NumOps-1)
|
|
|
|
: SDValue(nullptr,0);
|
|
|
|
|
|
|
|
SmallVector<bool, 8> OpChanged;
|
|
|
|
// Glue node will be appended late.
|
|
|
|
for(unsigned i = 0, e = N->getGluedNode() ? NumOps - 1 : NumOps; i < e; ++i) {
|
|
|
|
SDValue op = N->getOperand(i);
|
|
|
|
AsmNodeOperands.push_back(op);
|
|
|
|
|
|
|
|
if (i < InlineAsm::Op_FirstOperand)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(i))) {
|
|
|
|
Flag = C->getZExtValue();
|
|
|
|
Kind = InlineAsm::getKind(Flag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Immediate operands to inline asm in the SelectionDAG are modeled with
|
|
|
|
// two operands. The first is a constant of value InlineAsm::Kind_Imm, and
|
|
|
|
// the second is a constant with the value of the immediate. If we get here
|
|
|
|
// and we have a Kind_Imm, skip the next operand, and continue.
|
|
|
|
if (Kind == InlineAsm::Kind_Imm) {
|
|
|
|
SDValue op = N->getOperand(++i);
|
|
|
|
AsmNodeOperands.push_back(op);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned NumRegs = InlineAsm::getNumOperandRegisters(Flag);
|
|
|
|
if (NumRegs)
|
|
|
|
OpChanged.push_back(false);
|
|
|
|
|
|
|
|
unsigned DefIdx = 0;
|
|
|
|
bool IsTiedToChangedOp = false;
|
|
|
|
// If it's a use that is tied with a previous def, it has no
|
|
|
|
// reg class constraint.
|
|
|
|
if (Changed && InlineAsm::isUseOperandTiedToDef(Flag, DefIdx))
|
|
|
|
IsTiedToChangedOp = OpChanged[DefIdx];
|
|
|
|
|
|
|
|
if (Kind != InlineAsm::Kind_RegUse && Kind != InlineAsm::Kind_RegDef
|
|
|
|
&& Kind != InlineAsm::Kind_RegDefEarlyClobber)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
unsigned RC;
|
|
|
|
bool HasRC = InlineAsm::hasRegClassConstraint(Flag, RC);
|
|
|
|
if ((!IsTiedToChangedOp && (!HasRC || RC != SP::IntRegsRegClassID))
|
|
|
|
|| NumRegs != 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
assert((i+2 < NumOps) && "Invalid number of operands in inline asm");
|
|
|
|
SDValue V0 = N->getOperand(i+1);
|
|
|
|
SDValue V1 = N->getOperand(i+2);
|
|
|
|
unsigned Reg0 = cast<RegisterSDNode>(V0)->getReg();
|
|
|
|
unsigned Reg1 = cast<RegisterSDNode>(V1)->getReg();
|
|
|
|
SDValue PairedReg;
|
|
|
|
MachineRegisterInfo &MRI = MF->getRegInfo();
|
|
|
|
|
|
|
|
if (Kind == InlineAsm::Kind_RegDef ||
|
|
|
|
Kind == InlineAsm::Kind_RegDefEarlyClobber) {
|
|
|
|
// Replace the two GPRs with 1 GPRPair and copy values from GPRPair to
|
|
|
|
// the original GPRs.
|
|
|
|
|
|
|
|
unsigned GPVR = MRI.createVirtualRegister(&SP::IntPairRegClass);
|
|
|
|
PairedReg = CurDAG->getRegister(GPVR, MVT::v2i32);
|
|
|
|
SDValue Chain = SDValue(N,0);
|
|
|
|
|
|
|
|
SDNode *GU = N->getGluedUser();
|
|
|
|
SDValue RegCopy = CurDAG->getCopyFromReg(Chain, dl, GPVR, MVT::v2i32,
|
|
|
|
Chain.getValue(1));
|
|
|
|
|
|
|
|
// Extract values from a GPRPair reg and copy to the original GPR reg.
|
|
|
|
SDValue Sub0 = CurDAG->getTargetExtractSubreg(SP::sub_even, dl, MVT::i32,
|
|
|
|
RegCopy);
|
|
|
|
SDValue Sub1 = CurDAG->getTargetExtractSubreg(SP::sub_odd, dl, MVT::i32,
|
|
|
|
RegCopy);
|
|
|
|
SDValue T0 = CurDAG->getCopyToReg(Sub0, dl, Reg0, Sub0,
|
|
|
|
RegCopy.getValue(1));
|
|
|
|
SDValue T1 = CurDAG->getCopyToReg(Sub1, dl, Reg1, Sub1, T0.getValue(1));
|
|
|
|
|
|
|
|
// Update the original glue user.
|
|
|
|
std::vector<SDValue> Ops(GU->op_begin(), GU->op_end()-1);
|
|
|
|
Ops.push_back(T1.getValue(1));
|
|
|
|
CurDAG->UpdateNodeOperands(GU, Ops);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// For Kind == InlineAsm::Kind_RegUse, we first copy two GPRs into a
|
|
|
|
// GPRPair and then pass the GPRPair to the inline asm.
|
|
|
|
SDValue Chain = AsmNodeOperands[InlineAsm::Op_InputChain];
|
|
|
|
|
|
|
|
// As REG_SEQ doesn't take RegisterSDNode, we copy them first.
|
|
|
|
SDValue T0 = CurDAG->getCopyFromReg(Chain, dl, Reg0, MVT::i32,
|
|
|
|
Chain.getValue(1));
|
|
|
|
SDValue T1 = CurDAG->getCopyFromReg(Chain, dl, Reg1, MVT::i32,
|
|
|
|
T0.getValue(1));
|
|
|
|
SDValue Pair = SDValue(
|
|
|
|
CurDAG->getMachineNode(
|
|
|
|
TargetOpcode::REG_SEQUENCE, dl, MVT::v2i32,
|
|
|
|
{
|
|
|
|
CurDAG->getTargetConstant(SP::IntPairRegClassID, dl,
|
|
|
|
MVT::i32),
|
|
|
|
T0,
|
|
|
|
CurDAG->getTargetConstant(SP::sub_even, dl, MVT::i32),
|
|
|
|
T1,
|
|
|
|
CurDAG->getTargetConstant(SP::sub_odd, dl, MVT::i32),
|
|
|
|
}),
|
|
|
|
0);
|
|
|
|
|
|
|
|
// Copy REG_SEQ into a GPRPair-typed VR and replace the original two
|
|
|
|
// i32 VRs of inline asm with it.
|
|
|
|
unsigned GPVR = MRI.createVirtualRegister(&SP::IntPairRegClass);
|
|
|
|
PairedReg = CurDAG->getRegister(GPVR, MVT::v2i32);
|
|
|
|
Chain = CurDAG->getCopyToReg(T1, dl, GPVR, Pair, T1.getValue(1));
|
|
|
|
|
|
|
|
AsmNodeOperands[InlineAsm::Op_InputChain] = Chain;
|
|
|
|
Glue = Chain.getValue(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Changed = true;
|
|
|
|
|
|
|
|
if(PairedReg.getNode()) {
|
|
|
|
OpChanged[OpChanged.size() -1 ] = true;
|
|
|
|
Flag = InlineAsm::getFlagWord(Kind, 1 /* RegNum*/);
|
|
|
|
if (IsTiedToChangedOp)
|
|
|
|
Flag = InlineAsm::getFlagWordForMatchingOp(Flag, DefIdx);
|
|
|
|
else
|
|
|
|
Flag = InlineAsm::getFlagWordForRegClass(Flag, SP::IntPairRegClassID);
|
|
|
|
// Replace the current flag.
|
|
|
|
AsmNodeOperands[AsmNodeOperands.size() -1] = CurDAG->getTargetConstant(
|
|
|
|
Flag, dl, MVT::i32);
|
|
|
|
// Add the new register node and skip the original two GPRs.
|
|
|
|
AsmNodeOperands.push_back(PairedReg);
|
|
|
|
// Skip the next two GPRs.
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Glue.getNode())
|
|
|
|
AsmNodeOperands.push_back(Glue);
|
|
|
|
if (!Changed)
|
2016-05-14 05:46:22 +08:00
|
|
|
return false;
|
[Sparc] Implement i64 load/store support for 32-bit sparc.
The LDD/STD instructions can load/store a 64bit quantity from/to
memory to/from a consecutive even/odd pair of (32-bit) registers. They
are part of SparcV8, and also present in SparcV9. (Although deprecated
there, as you can store 64bits in one register).
As recommended on llvmdev in the thread "How to enable use of 64bit
load/store for 32bit architecture" from Apr 2015, I've modeled the
64-bit load/store operations as working on a v2i32 type, rather than
making i64 a legal type, but with few legal operations. The latter
does not (currently) work, as there is much code in llvm which assumes
that if i64 is legal, operations like "add" will actually work on it.
The same assumption does not hold for v2i32 -- for vector types, it is
workable to support only load/store, and expand everything else.
This patch:
- Adds a new register class, IntPair, for even/odd pairs of registers.
- Modifies the list of reserved registers, the stack spilling code,
and register copying code to support the IntPair register class.
- Adds support in AsmParser. (note that in asm text, you write the
name of the first register of the pair only. So the parser has to
morph the single register into the equivalent paired register).
- Adds the new instructions themselves (LDD/STD/LDDA/STDA).
- Hooks up the instructions and registers as a vector type v2i32. Adds
custom legalizer to transform i64 load/stores into v2i32 load/stores
and bitcasts, so that the new instructions can actually be
generated, and marks all operations other than load/store on v2i32
as needing to be expanded.
- Copies the unfortunate SelectInlineAsm hack from ARMISelDAGToDAG.
This hack undoes the transformation of i64 operands into two
arbitrarily-allocated separate i32 registers in
SelectionDAGBuilder. and instead passes them in a single
IntPair. (Arbitrarily allocated registers are not useful, asm code
expects to be receiving a pair, which can be passed to ldd/std.)
Also adds a bunch of test cases covering all the bugs I've added along
the way.
Differential Revision: http://reviews.llvm.org/D8713
llvm-svn: 244484
2015-08-11 03:11:39 +08:00
|
|
|
|
|
|
|
SDValue New = CurDAG->getNode(ISD::INLINEASM, SDLoc(N),
|
|
|
|
CurDAG->getVTList(MVT::Other, MVT::Glue), AsmNodeOperands);
|
|
|
|
New->setNodeId(-1);
|
2016-05-14 05:46:22 +08:00
|
|
|
ReplaceNode(N, New.getNode());
|
|
|
|
return true;
|
[Sparc] Implement i64 load/store support for 32-bit sparc.
The LDD/STD instructions can load/store a 64bit quantity from/to
memory to/from a consecutive even/odd pair of (32-bit) registers. They
are part of SparcV8, and also present in SparcV9. (Although deprecated
there, as you can store 64bits in one register).
As recommended on llvmdev in the thread "How to enable use of 64bit
load/store for 32bit architecture" from Apr 2015, I've modeled the
64-bit load/store operations as working on a v2i32 type, rather than
making i64 a legal type, but with few legal operations. The latter
does not (currently) work, as there is much code in llvm which assumes
that if i64 is legal, operations like "add" will actually work on it.
The same assumption does not hold for v2i32 -- for vector types, it is
workable to support only load/store, and expand everything else.
This patch:
- Adds a new register class, IntPair, for even/odd pairs of registers.
- Modifies the list of reserved registers, the stack spilling code,
and register copying code to support the IntPair register class.
- Adds support in AsmParser. (note that in asm text, you write the
name of the first register of the pair only. So the parser has to
morph the single register into the equivalent paired register).
- Adds the new instructions themselves (LDD/STD/LDDA/STDA).
- Hooks up the instructions and registers as a vector type v2i32. Adds
custom legalizer to transform i64 load/stores into v2i32 load/stores
and bitcasts, so that the new instructions can actually be
generated, and marks all operations other than load/store on v2i32
as needing to be expanded.
- Copies the unfortunate SelectInlineAsm hack from ARMISelDAGToDAG.
This hack undoes the transformation of i64 operands into two
arbitrarily-allocated separate i32 registers in
SelectionDAGBuilder. and instead passes them in a single
IntPair. (Arbitrarily allocated registers are not useful, asm code
expects to be receiving a pair, which can be passed to ldd/std.)
Also adds a bunch of test cases covering all the bugs I've added along
the way.
Differential Revision: http://reviews.llvm.org/D8713
llvm-svn: 244484
2015-08-11 03:11:39 +08:00
|
|
|
}
|
|
|
|
|
2016-05-14 05:46:22 +08:00
|
|
|
void SparcDAGToDAGISel::Select(SDNode *N) {
|
2013-05-25 10:42:55 +08:00
|
|
|
SDLoc dl(N);
|
2013-09-22 16:21:56 +08:00
|
|
|
if (N->isMachineOpcode()) {
|
|
|
|
N->setNodeId(-1);
|
2016-05-14 05:46:22 +08:00
|
|
|
return; // Already selected.
|
2013-09-22 16:21:56 +08:00
|
|
|
}
|
2006-02-09 08:37:58 +08:00
|
|
|
|
2006-02-05 13:50:24 +08:00
|
|
|
switch (N->getOpcode()) {
|
|
|
|
default: break;
|
2016-05-14 05:46:22 +08:00
|
|
|
case ISD::INLINEASM: {
|
|
|
|
if (tryInlineAsm(N))
|
|
|
|
return;
|
[Sparc] Implement i64 load/store support for 32-bit sparc.
The LDD/STD instructions can load/store a 64bit quantity from/to
memory to/from a consecutive even/odd pair of (32-bit) registers. They
are part of SparcV8, and also present in SparcV9. (Although deprecated
there, as you can store 64bits in one register).
As recommended on llvmdev in the thread "How to enable use of 64bit
load/store for 32bit architecture" from Apr 2015, I've modeled the
64-bit load/store operations as working on a v2i32 type, rather than
making i64 a legal type, but with few legal operations. The latter
does not (currently) work, as there is much code in llvm which assumes
that if i64 is legal, operations like "add" will actually work on it.
The same assumption does not hold for v2i32 -- for vector types, it is
workable to support only load/store, and expand everything else.
This patch:
- Adds a new register class, IntPair, for even/odd pairs of registers.
- Modifies the list of reserved registers, the stack spilling code,
and register copying code to support the IntPair register class.
- Adds support in AsmParser. (note that in asm text, you write the
name of the first register of the pair only. So the parser has to
morph the single register into the equivalent paired register).
- Adds the new instructions themselves (LDD/STD/LDDA/STDA).
- Hooks up the instructions and registers as a vector type v2i32. Adds
custom legalizer to transform i64 load/stores into v2i32 load/stores
and bitcasts, so that the new instructions can actually be
generated, and marks all operations other than load/store on v2i32
as needing to be expanded.
- Copies the unfortunate SelectInlineAsm hack from ARMISelDAGToDAG.
This hack undoes the transformation of i64 operands into two
arbitrarily-allocated separate i32 registers in
SelectionDAGBuilder. and instead passes them in a single
IntPair. (Arbitrarily allocated registers are not useful, asm code
expects to be receiving a pair, which can be passed to ldd/std.)
Also adds a bunch of test cases covering all the bugs I've added along
the way.
Differential Revision: http://reviews.llvm.org/D8713
llvm-svn: 244484
2015-08-11 03:11:39 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-09-16 01:46:24 +08:00
|
|
|
case SPISD::GLOBAL_BASE_REG:
|
2016-05-14 05:46:22 +08:00
|
|
|
ReplaceNode(N, getGlobalBaseReg());
|
|
|
|
return;
|
2009-09-16 01:46:24 +08:00
|
|
|
|
2006-02-05 13:50:24 +08:00
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::UDIV: {
|
2013-04-16 10:57:02 +08:00
|
|
|
// sdivx / udivx handle 64-bit divides.
|
|
|
|
if (N->getValueType(0) == MVT::i64)
|
|
|
|
break;
|
2006-02-05 13:50:24 +08:00
|
|
|
// FIXME: should use a custom expander to expose the SRA to the dag.
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue DivLHS = N->getOperand(0);
|
|
|
|
SDValue DivRHS = N->getOperand(1);
|
2008-10-10 18:14:15 +08:00
|
|
|
|
2006-02-05 13:50:24 +08:00
|
|
|
// Set the Y register to the high-part.
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue TopPart;
|
2006-02-05 13:50:24 +08:00
|
|
|
if (N->getOpcode() == ISD::SDIV) {
|
2009-09-26 02:54:59 +08:00
|
|
|
TopPart = SDValue(CurDAG->getMachineNode(SP::SRAri, dl, MVT::i32, DivLHS,
|
2015-04-28 22:05:47 +08:00
|
|
|
CurDAG->getTargetConstant(31, dl, MVT::i32)),
|
|
|
|
0);
|
2006-02-05 13:50:24 +08:00
|
|
|
} else {
|
2009-08-12 04:47:22 +08:00
|
|
|
TopPart = CurDAG->getRegister(SP::G0, MVT::i32);
|
2006-02-05 13:50:24 +08:00
|
|
|
}
|
2015-07-09 00:25:12 +08:00
|
|
|
TopPart = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, SP::Y, TopPart,
|
|
|
|
SDValue())
|
|
|
|
.getValue(1);
|
2006-02-05 13:50:24 +08:00
|
|
|
|
|
|
|
// FIXME: Handle div by immediate.
|
|
|
|
unsigned Opcode = N->getOpcode() == ISD::SDIV ? SP::SDIVrr : SP::UDIVrr;
|
2016-10-10 16:53:06 +08:00
|
|
|
// SDIV is a hardware erratum on some LEON2 processors. Replace it with SDIVcc here.
|
|
|
|
if (((SparcTargetMachine&)TM).getSubtargetImpl()->performSDIVReplace()
|
|
|
|
&&
|
|
|
|
Opcode == SP::SDIVrr) {
|
|
|
|
Opcode = SP::SDIVCCrr;
|
|
|
|
}
|
2016-05-14 05:46:22 +08:00
|
|
|
CurDAG->SelectNodeTo(N, Opcode, MVT::i32, DivLHS, DivRHS, TopPart);
|
|
|
|
return;
|
2008-10-10 18:14:15 +08:00
|
|
|
}
|
2006-02-05 13:50:24 +08:00
|
|
|
}
|
2008-10-10 18:14:15 +08:00
|
|
|
|
2016-05-14 05:46:22 +08:00
|
|
|
SelectCode(N);
|
2006-02-05 13:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 18:14:47 +08:00
|
|
|
/// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
|
|
|
|
/// inline asm expressions.
|
|
|
|
bool
|
|
|
|
SparcDAGToDAGISel::SelectInlineAsmMemoryOperand(const SDValue &Op,
|
2015-03-13 20:45:09 +08:00
|
|
|
unsigned ConstraintID,
|
2008-10-10 18:14:47 +08:00
|
|
|
std::vector<SDValue> &OutOps) {
|
|
|
|
SDValue Op0, Op1;
|
2015-03-13 20:45:09 +08:00
|
|
|
switch (ConstraintID) {
|
2008-10-10 18:14:47 +08:00
|
|
|
default: return true;
|
2015-03-19 19:27:23 +08:00
|
|
|
case InlineAsm::Constraint_i:
|
2016-05-20 17:03:01 +08:00
|
|
|
case InlineAsm::Constraint_o:
|
2015-03-13 20:45:09 +08:00
|
|
|
case InlineAsm::Constraint_m: // memory
|
2010-09-22 04:31:19 +08:00
|
|
|
if (!SelectADDRrr(Op, Op0, Op1))
|
|
|
|
SelectADDRri(Op, Op0, Op1);
|
2008-10-10 18:14:47 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutOps.push_back(Op0);
|
|
|
|
OutOps.push_back(Op1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-10 18:14:15 +08:00
|
|
|
/// createSparcISelDag - This pass converts a legalized DAG into a
|
2006-02-05 13:50:24 +08:00
|
|
|
/// SPARC-specific DAG, ready for instruction scheduling.
|
|
|
|
///
|
2008-10-04 00:55:19 +08:00
|
|
|
FunctionPass *llvm::createSparcISelDag(SparcTargetMachine &TM) {
|
2006-02-05 13:50:24 +08:00
|
|
|
return new SparcDAGToDAGISel(TM);
|
|
|
|
}
|