37 #define DEBUG_TYPE "lanai-isel"
60 return "Lanai DAG->DAG Pattern Instruction Selection";
63 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
unsigned ConstraintCode,
64 std::vector<SDValue> &OutOps)
override;
68 #include "LanaiGenDAGISel.inc"
75 void selectFrameIndex(
SDNode *N);
86 inline SDValue getI32Imm(
unsigned Imm,
const SDLoc &DL) {
87 return CurDAG->getTargetConstant(Imm, DL,
MVT::i32);
108 if (canBeRepresentedAsSls(*CN)) {
109 int32_t Imm = CN->getSExtValue();
110 Offset = CurDAG->getTargetConstant(Imm, DL, CN->getValueType(0));
122 bool LanaiDAGToDAGISel::selectAddrRiSpls(
SDValue Addr,
SDValue &Base,
131 int16_t Imm = CN->getSExtValue();
132 Offset = CurDAG->getTargetConstant(Imm, DL, CN->getValueType(0));
133 Base = CurDAG->getRegister(Lanai::R0, CN->getValueType(0));
139 if (canBeRepresentedAsSls(*CN))
143 if (isInt<10>(CN->getSExtValue())) {
144 int16_t Imm = CN->getSExtValue();
145 Offset = CurDAG->getTargetConstant(Imm, DL, CN->getValueType(0));
146 Base = CurDAG->getRegister(Lanai::R0, CN->getValueType(0));
155 Base = CurDAG->getTargetFrameIndex(
157 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
158 Offset = CurDAG->getTargetConstant(0, DL,
MVT::i32);
174 if ((RiMode &&
isInt<16>(CN->getSExtValue())) ||
175 (!RiMode && isInt<10>(CN->getSExtValue()))) {
178 dyn_cast<FrameIndexSDNode>(Addr.
getOperand(0))) {
179 Base = CurDAG->getTargetFrameIndex(
181 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
186 Offset = CurDAG->getTargetConstant(CN->getSExtValue(),
DL,
MVT::i32);
192 if (AluOperator ==
ISD::OR && RiMode &&
197 Offset = CurDAG->getTargetConstant(0, DL,
MVT::i32);
204 return selectAddrRiSpls(Addr, Base, Offset, AluOp,
true);
207 bool LanaiDAGToDAGISel::selectAddrSpls(
SDValue Addr,
SDValue &Base,
209 return selectAddrRiSpls(Addr, Base, Offset, AluOp,
false);
244 AluOp = CurDAG->getTargetConstant(AluCode,
SDLoc(Addr),
MVT::i32);
252 bool LanaiDAGToDAGISel::SelectInlineAsmMemoryOperand(
253 const SDValue &
Op,
unsigned ConstraintCode, std::vector<SDValue> &OutOps) {
255 switch (ConstraintCode) {
259 if (!selectAddrRr(Op, Op0, Op1, AluOp) &&
260 !selectAddrRi(Op, Op0, Op1, AluOp))
265 OutOps.push_back(Op0);
266 OutOps.push_back(Op1);
267 OutOps.push_back(AluOp);
295 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
297 return ReplaceNode(Node, New.
getNode());
302 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
304 return ReplaceNode(Node, New.
getNode());
309 selectFrameIndex(Node);
319 void LanaiDAGToDAGISel::selectFrameIndex(
SDNode *Node) {
324 SDValue TFI = CurDAG->getTargetFrameIndex(FI, VT);
325 unsigned Opc = Lanai::ADD_I_LO;
327 CurDAG->SelectNodeTo(Node, Opc, VT, TFI, Imm);
330 ReplaceNode(Node, CurDAG->getMachineNode(Opc, DL, VT, TFI, Imm));
336 return new LanaiDAGToDAGISel(TM);
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool hasOneUse() const
Return true if there is exactly one use of this node.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
constexpr bool isInt< 16 >(int64_t x)
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
bool isAllOnesValue() const
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Simple integer binary arithmetic operators.
SDNode * getNode() const
get the SDNode which holds the desired result
const SDValue & getOperand(unsigned i) const
unsigned getOpcode() const
FunctionPass class - This class is used to implement most global optimizations.
FunctionPass * createLanaiISelDag(LanaiTargetMachine &TM)
EVT - Extended Value Type.
void dump() const
Dump this node, for debugging.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
int64_t getSExtValue() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
static AluCode isdToLanaiAluCode(ISD::NodeType Node_type)
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...