36 #define DEBUG_TYPE "lanai-isel" 59 return "Lanai DAG->DAG Pattern Instruction Selection";
62 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
unsigned ConstraintCode,
63 std::vector<SDValue> &OutOps)
override;
67 #include "LanaiGenDAGISel.inc" 74 void selectFrameIndex(
SDNode *N);
85 inline SDValue getI32Imm(
unsigned Imm,
const SDLoc &DL) {
86 return CurDAG->getTargetConstant(Imm, DL,
MVT::i32);
107 if (canBeRepresentedAsSls(*CN)) {
108 int32_t Imm = CN->getSExtValue();
109 Offset = CurDAG->getTargetConstant(Imm, DL, CN->getValueType(0));
130 int16_t Imm = CN->getSExtValue();
131 Offset = CurDAG->getTargetConstant(Imm, DL, CN->getValueType(0));
132 Base = CurDAG->getRegister(Lanai::R0, CN->getValueType(0));
138 if (canBeRepresentedAsSls(*CN))
142 if (isInt<10>(CN->getSExtValue())) {
143 int16_t Imm = CN->getSExtValue();
144 Offset = CurDAG->getTargetConstant(Imm, DL, CN->getValueType(0));
145 Base = CurDAG->getRegister(Lanai::R0, CN->getValueType(0));
154 Base = CurDAG->getTargetFrameIndex(
156 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
157 Offset = CurDAG->getTargetConstant(0, DL,
MVT::i32);
173 if ((RiMode &&
isInt<16>(CN->getSExtValue())) ||
174 (!RiMode && isInt<10>(CN->getSExtValue()))) {
177 dyn_cast<FrameIndexSDNode>(Addr.
getOperand(0))) {
178 Base = CurDAG->getTargetFrameIndex(
180 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
185 Offset = CurDAG->getTargetConstant(CN->getSExtValue(), DL,
MVT::i32);
191 if (AluOperator ==
ISD::OR && RiMode &&
196 Offset = CurDAG->getTargetConstant(0, DL,
MVT::i32);
203 return selectAddrRiSpls(Addr, Base, Offset, AluOp,
true);
206 bool LanaiDAGToDAGISel::selectAddrSpls(
SDValue Addr,
SDValue &Base,
208 return selectAddrRiSpls(Addr, Base, Offset, AluOp,
false);
243 AluOp = CurDAG->getTargetConstant(AluCode,
SDLoc(Addr),
MVT::i32);
251 bool LanaiDAGToDAGISel::SelectInlineAsmMemoryOperand(
252 const SDValue &
Op,
unsigned ConstraintCode, std::vector<SDValue> &OutOps) {
254 switch (ConstraintCode) {
258 if (!selectAddrRr(Op, Op0, Op1, AluOp) &&
259 !selectAddrRi(Op, Op0, Op1, AluOp))
264 OutOps.push_back(Op0);
265 OutOps.push_back(Op1);
266 OutOps.push_back(AluOp);
291 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
293 return ReplaceNode(Node, New.
getNode());
298 SDValue New = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
300 return ReplaceNode(Node, New.
getNode());
305 selectFrameIndex(Node);
315 void LanaiDAGToDAGISel::selectFrameIndex(
SDNode *Node) {
318 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
320 SDValue TFI = CurDAG->getTargetFrameIndex(FI, VT);
321 unsigned Opc = Lanai::ADD_I_LO;
323 CurDAG->SelectNodeTo(Node, Opc, VT, TFI, Imm);
326 ReplaceNode(Node, CurDAG->getMachineNode(Opc, DL, VT, TFI, Imm));
332 return new LanaiDAGToDAGISel(TM);
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
This class represents lattice values for constants.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
constexpr bool isInt< 16 >(int64_t x)
SDNode * getNode() const
get the SDNode which holds the desired result
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
bool isAllOnesValue() const
bool hasOneUse() const
Return true if there is exactly one use of this node.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
int64_t getSExtValue() const
Simple integer binary arithmetic operators.
FunctionPass class - This class is used to implement most global optimizations.
FunctionPass * createLanaiISelDag(LanaiTargetMachine &TM)
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
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...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
unsigned getOpcode() const
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
const SDValue & getOperand(unsigned i) const
static AluCode isdToLanaiAluCode(ISD::NodeType Node_type)
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...