27#define DEBUG_TYPE "lanai-isel"
28#define PASS_NAME "Lanai DAG->DAG Pattern Instruction Selection"
42 LanaiDAGToDAGISel() =
delete;
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));
126 if (isInt<16>(CN->getSExtValue())) {
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))
139 if (isInt<10>(CN->getSExtValue())) {
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()))) {
174 dyn_cast<FrameIndexSDNode>(
Addr.getOperand(0))) {
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);
256 if (isInt<16>(CN->getSExtValue()))
269 R1 =
Addr.getOperand(0);
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);
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(),
322 return ReplaceNode(
Node,
New.getNode());
327 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
329 return ReplaceNode(
Node,
New.getNode());
334 selectFrameIndex(
Node);
344void LanaiDAGToDAGISel::selectFrameIndex(
SDNode *
Node) {
346 SDValue Imm = CurDAG->getTargetConstant(0,
DL, MVT::i32);
347 int FI = cast<FrameIndexSDNode>(
Node)->getIndex();
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)
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.