36#define DEBUG_TYPE "lanai-isel"
37#define PASS_NAME "Lanai DAG->DAG Pattern Instruction Selection"
51 LanaiDAGToDAGISel() =
delete;
58 std::vector<SDValue> &OutOps)
override;
62#include "LanaiGenDAGISel.inc"
69 void selectFrameIndex(
SDNode *
N);
81 return CurDAG->getTargetConstant(Imm,
DL, MVT::i32);
103char LanaiDAGToDAGISelLegacy::ID = 0;
113 if (canBeRepresentedAsSls(*CN)) {
114 int32_t
Imm = CN->getSExtValue();
115 Offset = CurDAG->getTargetConstant(Imm,
DL, CN->getValueType(0));
135 if (isInt<16>(CN->getSExtValue())) {
136 int16_t
Imm = CN->getSExtValue();
137 Offset = CurDAG->getTargetConstant(Imm,
DL, CN->getValueType(0));
138 Base = CurDAG->getRegister(Lanai::R0, CN->getValueType(0));
139 AluOp = CurDAG->getTargetConstant(
LPAC::ADD,
DL, MVT::i32);
144 if (canBeRepresentedAsSls(*CN))
148 if (isInt<10>(CN->getSExtValue())) {
149 int16_t
Imm = CN->getSExtValue();
150 Offset = CurDAG->getTargetConstant(Imm,
DL, CN->getValueType(0));
151 Base = CurDAG->getRegister(Lanai::R0, CN->getValueType(0));
152 AluOp = CurDAG->getTargetConstant(
LPAC::ADD,
DL, MVT::i32);
160 Base = CurDAG->getTargetFrameIndex(
162 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
163 Offset = CurDAG->getTargetConstant(0,
DL, MVT::i32);
164 AluOp = CurDAG->getTargetConstant(
LPAC::ADD,
DL, MVT::i32);
176 AluOp = CurDAG->getTargetConstant(
LPAC::ADD,
DL, MVT::i32);
179 if ((RiMode && isInt<16>(CN->getSExtValue())) ||
180 (!RiMode && isInt<10>(CN->getSExtValue()))) {
183 dyn_cast<FrameIndexSDNode>(
Addr.getOperand(0))) {
184 Base = CurDAG->getTargetFrameIndex(
186 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
191 Offset = CurDAG->getTargetConstant(CN->getSExtValue(),
DL, MVT::i32);
197 if (AluOperator ==
ISD::OR && RiMode &&
202 Offset = CurDAG->getTargetConstant(0,
DL, MVT::i32);
203 AluOp = CurDAG->getTargetConstant(
LPAC::ADD,
DL, MVT::i32);
265 if (isInt<16>(CN->getSExtValue()))
278 R1 =
Addr.getOperand(0);
280 AluOp = CurDAG->getTargetConstant(AluCode,
SDLoc(
Addr), MVT::i32);
288bool LanaiDAGToDAGISel::SelectInlineAsmMemoryOperand(
290 std::vector<SDValue> &OutOps) {
292 switch (ConstraintCode) {
295 case InlineAsm::ConstraintCode::m:
296 if (!selectAddrRr(
Op, Op0, Op1, AluOp) &&
297 !selectAddrRi(
Op, Op0, Op1, AluOp))
302 OutOps.push_back(Op0);
303 OutOps.push_back(Op1);
304 OutOps.push_back(AluOp);
311 unsigned Opcode =
Node->getOpcode();
314 if (
Node->isMachineOpcode()) {
321 EVT VT =
Node->getValueType(0);
324 if (VT == MVT::i32) {
328 if (ConstNode->
isZero()) {
329 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
331 return ReplaceNode(
Node,
New.getNode());
336 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
338 return ReplaceNode(
Node,
New.getNode());
343 selectFrameIndex(
Node);
353void LanaiDAGToDAGISel::selectFrameIndex(
SDNode *
Node) {
355 SDValue Imm = CurDAG->getTargetConstant(0,
DL, MVT::i32);
356 int FI = cast<FrameIndexSDNode>(
Node)->getIndex();
357 EVT VT =
Node->getValueType(0);
358 SDValue TFI = CurDAG->getTargetFrameIndex(FI, VT);
359 unsigned Opc = Lanai::ADD_I_LO;
360 if (
Node->hasOneUse()) {
361 CurDAG->SelectNodeTo(
Node, Opc, VT, TFI, Imm);
364 ReplaceNode(
Node, CurDAG->getMachineNode(Opc,
DL, VT, TFI, Imm));
370 return new LanaiDAGToDAGISelLegacy(TM);
amdgpu AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
DEMANGLE_DUMP_METHOD void dump() const
int64_t getSExtValue() const
This class represents an Operation in the Expression.
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.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, InlineAsm::ConstraintCode ConstraintID, std::vector< SDValue > &OutOps)
SelectInlineAsmMemoryOperand - Select the specified address as a target addressing mode,...
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)
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createLanaiISelDag(LanaiTargetMachine &TM)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.