27#define DEBUG_TYPE "lanai-isel"
28#define PASS_NAME "Lanai DAG->DAG Pattern Instruction Selection"
42 LanaiDAGToDAGISel() =
delete;
47 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
49 std::vector<SDValue> &OutOps)
override;
53#include "LanaiGenDAGISel.inc"
60 void selectFrameIndex(
SDNode *
N);
72 return CurDAG->getTargetConstant(Imm,
DL, MVT::i32);
94char LanaiDAGToDAGISelLegacy::ID = 0;
104 if (canBeRepresentedAsSls(*CN)) {
105 int32_t
Imm = CN->getSExtValue();
106 Offset = CurDAG->getTargetConstant(Imm,
DL, CN->getValueType(0));
110 if (Addr.getOpcode() ==
ISD::OR &&
111 Addr.getOperand(1).getOpcode() == LanaiISD::SMALL) {
112 Offset = Addr.getOperand(1).getOperand(0);
127 int16_t
Imm = CN->getSExtValue();
128 Offset = CurDAG->getTargetConstant(Imm,
DL, CN->getValueType(0));
129 Base = CurDAG->getRegister(Lanai::R0, CN->getValueType(0));
130 AluOp = CurDAG->getTargetConstant(
LPAC::ADD,
DL, MVT::i32);
135 if (canBeRepresentedAsSls(*CN))
140 int16_t
Imm = CN->getSExtValue();
141 Offset = CurDAG->getTargetConstant(Imm,
DL, CN->getValueType(0));
142 Base = CurDAG->getRegister(Lanai::R0, CN->getValueType(0));
143 AluOp = CurDAG->getTargetConstant(
LPAC::ADD,
DL, MVT::i32);
151 Base = CurDAG->getTargetFrameIndex(
153 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
154 Offset = CurDAG->getTargetConstant(0,
DL, MVT::i32);
155 AluOp = CurDAG->getTargetConstant(
LPAC::ADD,
DL, MVT::i32);
167 AluOp = CurDAG->getTargetConstant(
LPAC::ADD,
DL, MVT::i32);
170 if ((RiMode &&
isInt<16>(CN->getSExtValue())) ||
171 (!RiMode &&
isInt<10>(CN->getSExtValue()))) {
173 if (FrameIndexSDNode *FIN =
175 Base = CurDAG->getTargetFrameIndex(
177 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
182 Offset = CurDAG->getTargetConstant(CN->getSExtValue(),
DL, MVT::i32);
188 if (AluOperator ==
ISD::OR && RiMode &&
193 Offset = CurDAG->getTargetConstant(0,
DL, MVT::i32);
194 AluOp = CurDAG->getTargetConstant(
LPAC::ADD,
DL, MVT::i32);
200 return selectAddrRiSpls(Addr,
Base,
Offset, AluOp,
true);
205 return selectAddrRiSpls(Addr,
Base,
Offset, AluOp,
false);
271 AluOp = CurDAG->getTargetConstant(AluCode, SDLoc(Addr), MVT::i32);
279bool LanaiDAGToDAGISel::SelectInlineAsmMemoryOperand(
281 std::vector<SDValue> &OutOps) {
283 switch (ConstraintCode) {
286 case InlineAsm::ConstraintCode::m:
287 if (!selectAddrRr(
Op, Op0, Op1, AluOp) &&
288 !selectAddrRi(
Op, Op0, Op1, AluOp))
293 OutOps.push_back(Op0);
294 OutOps.push_back(Op1);
295 OutOps.push_back(AluOp);
301void LanaiDAGToDAGISel::Select(SDNode *Node) {
302 unsigned Opcode =
Node->getOpcode();
305 if (
Node->isMachineOpcode()) {
312 EVT VT =
Node->getValueType(0);
315 if (VT == MVT::i32) {
319 if (ConstNode->
isZero()) {
320 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
321 SDLoc(Node), Lanai::R0, MVT::i32);
322 return ReplaceNode(Node,
New.getNode());
327 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
328 SDLoc(Node), Lanai::R1, MVT::i32);
329 return ReplaceNode(Node,
New.getNode());
334 selectFrameIndex(Node);
344void LanaiDAGToDAGISel::selectFrameIndex(SDNode *Node) {
346 SDValue Imm = CurDAG->getTargetConstant(0,
DL, MVT::i32);
348 EVT VT =
Node->getValueType(0);
349 SDValue TFI = CurDAG->getTargetFrameIndex(FI, VT);
350 unsigned Opc = Lanai::ADD_I_LO;
351 if (
Node->hasOneUse()) {
352 CurDAG->SelectNodeTo(Node,
Opc, VT, TFI, Imm);
355 ReplaceNode(Node, CurDAG->getMachineNode(
Opc,
DL, VT, TFI, Imm));
361 return new LanaiDAGToDAGISelLegacy(TM);
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
int64_t getSExtValue() const
FunctionPass class - This class is used to implement most global optimizations.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
const SDValue & getOperand(unsigned i) const
unsigned getOpcode() const
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
Primary interface to the complete machine description for the target machine.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
@ ADD
Simple integer binary arithmetic operators.
@ TargetGlobalAddress
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
@ SHL
Shift and rotation operations.
@ AND
Bitwise operators - logical and, logical or, logical xor.
@ ADDE
Carry-using nodes for multiple precision addition and subtraction.
static AluCode isdToLanaiAluCode(ISD::NodeType Node_type)
NodeAddr< NodeBase * > Node
This is an optimization pass for GlobalISel generic memory operations.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
FunctionPass * createLanaiISelDag(LanaiTargetMachine &TM)
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.