33 #define DEBUG_TYPE "msp430-isel"
36 struct MSP430ISelAddressMode {
55 MSP430ISelAddressMode()
56 :
BaseType(RegBase), Disp(0), GV(
nullptr),
CP(
nullptr),
57 BlockAddr(
nullptr), ES(
nullptr),
JT(-1),
Align(0) {
60 bool hasSymbolicDisplacement()
const {
61 return GV !=
nullptr ||
CP !=
nullptr || ES !=
nullptr ||
JT != -1;
64 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
66 errs() <<
"MSP430ISelAddressMode " <<
this <<
'\n';
67 if (
BaseType == RegBase &&
Base.Reg.getNode() !=
nullptr) {
68 errs() <<
"Base.Reg ";
69 Base.Reg.getNode()->dump();
70 }
else if (
BaseType == FrameIndexBase) {
71 errs() <<
" Base.FrameIndex " <<
Base.FrameIndex <<
'\n';
73 errs() <<
" Disp " << Disp <<
'\n';
101 return "MSP430 DAG->DAG Pattern Instruction Selection";
104 bool MatchAddress(
SDValue N, MSP430ISelAddressMode &AM);
105 bool MatchWrapper(
SDValue N, MSP430ISelAddressMode &AM);
106 bool MatchAddressBase(
SDValue N, MSP430ISelAddressMode &AM);
108 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
unsigned ConstraintID,
109 std::vector<SDValue> &OutOps)
override;
112 #include "MSP430GenDAGISel.inc"
129 return new MSP430DAGToDAGISel(TM, OptLevel);
136 bool MSP430DAGToDAGISel::MatchWrapper(
SDValue N, MSP430ISelAddressMode &AM) {
139 if (AM.hasSymbolicDisplacement())
145 AM.GV =
G->getGlobal();
146 AM.Disp +=
G->getOffset();
149 AM.CP =
CP->getConstVal();
150 AM.Align =
CP->getAlignment();
151 AM.Disp +=
CP->getOffset();
154 AM.ES = S->getSymbol();
157 AM.JT = J->getIndex();
160 AM.BlockAddr = cast<BlockAddressSDNode>(N0)->getBlockAddress();
168 bool MSP430DAGToDAGISel::MatchAddressBase(
SDValue N, MSP430ISelAddressMode &AM) {
170 if (AM.BaseType != MSP430ISelAddressMode::RegBase || AM.Base.Reg.getNode()) {
176 AM.BaseType = MSP430ISelAddressMode::RegBase;
181 bool MSP430DAGToDAGISel::MatchAddress(
SDValue N, MSP430ISelAddressMode &AM) {
182 DEBUG(
errs() <<
"MatchAddress: "; AM.dump());
187 uint64_t Val = cast<ConstantSDNode>(
N)->getSExtValue();
193 if (!MatchWrapper(N, AM))
198 if (AM.BaseType == MSP430ISelAddressMode::RegBase
199 && AM.Base.Reg.getNode() ==
nullptr) {
200 AM.BaseType = MSP430ISelAddressMode::FrameIndexBase;
201 AM.Base.FrameIndex = cast<FrameIndexSDNode>(
N)->getIndex();
207 MSP430ISelAddressMode Backup = AM;
223 MSP430ISelAddressMode Backup = AM;
224 uint64_t
Offset = CN->getSExtValue();
230 CurDAG->MaskedValueIsZero(N.
getOperand(0), CN->getAPIntValue())) {
239 return MatchAddressBase(N, AM);
245 bool MSP430DAGToDAGISel::SelectAddr(
SDValue N,
247 MSP430ISelAddressMode AM;
249 if (MatchAddress(N, AM))
253 if (AM.BaseType == MSP430ISelAddressMode::RegBase) {
254 if (!AM.Base.Reg.getNode())
255 AM.Base.Reg = CurDAG->getRegister(0, VT);
258 Base = (AM.BaseType == MSP430ISelAddressMode::FrameIndexBase)
259 ? CurDAG->getTargetFrameIndex(
261 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()))
265 Disp = CurDAG->getTargetGlobalAddress(AM.GV,
SDLoc(N),
269 Disp = CurDAG->getTargetConstantPool(AM.CP,
MVT::i16,
270 AM.Align, AM.Disp, 0);
272 Disp = CurDAG->getTargetExternalSymbol(AM.ES,
MVT::i16, 0);
273 else if (AM.JT != -1)
274 Disp = CurDAG->getTargetJumpTable(AM.JT,
MVT::i16, 0);
275 else if (AM.BlockAddr)
276 Disp = CurDAG->getTargetBlockAddress(AM.BlockAddr,
MVT::i32, 0,
279 Disp = CurDAG->getTargetConstant(AM.Disp,
SDLoc(N),
MVT::i16);
284 bool MSP430DAGToDAGISel::
285 SelectInlineAsmMemoryOperand(
const SDValue &
Op,
unsigned ConstraintID,
286 std::vector<SDValue> &OutOps) {
288 switch (ConstraintID) {
289 default:
return true;
291 if (!SelectAddr(Op, Op0, Op1))
296 OutOps.push_back(Op0);
297 OutOps.push_back(Op1);
311 if (cast<ConstantSDNode>(LD->
getOffset())->getZExtValue() != 1)
317 if (cast<ConstantSDNode>(LD->
getOffset())->getZExtValue() != 2)
328 bool MSP430DAGToDAGISel::tryIndexedLoad(
SDNode *N) {
338 Opcode = MSP430::MOV8rm_POST;
341 Opcode = MSP430::MOV16rm_POST;
354 unsigned Opc8,
unsigned Opc16) {
357 IsLegalToFold(N1, Op, Op, OptLevel)) {
363 unsigned Opc = (VT ==
MVT::i16 ? Opc16 : Opc8);
365 MemRefs0[0] = cast<MemSDNode>(N1)->getMemOperand();
369 cast<MachineSDNode>(ResNode)->setMemRefs(MemRefs0, MemRefs0 + 1);
403 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
406 CurDAG->SelectNodeTo(Node, MSP430::ADDframe,
MVT::i16, TFI,
407 CurDAG->getTargetConstant(0, dl,
MVT::i16));
410 ReplaceNode(Node, CurDAG->getMachineNode(
411 MSP430::ADDframe, dl,
MVT::i16, TFI,
412 CurDAG->getTargetConstant(0, dl,
MVT::i16)));
416 if (tryIndexedLoad(Node))
422 MSP430::ADD8rm_POST, MSP430::ADD16rm_POST))
425 MSP430::ADD8rm_POST, MSP430::ADD16rm_POST))
432 MSP430::SUB8rm_POST, MSP430::SUB16rm_POST))
439 MSP430::AND8rm_POST, MSP430::AND16rm_POST))
442 MSP430::AND8rm_POST, MSP430::AND16rm_POST))
449 MSP430::OR8rm_POST, MSP430::OR16rm_POST))
452 MSP430::OR8rm_POST, MSP430::OR16rm_POST))
459 MSP430::XOR8rm_POST, MSP430::XOR16rm_POST))
462 MSP430::XOR8rm_POST, MSP430::XOR16rm_POST))
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
bool hasOneUse() const
Return true if there is exactly one use of this node.
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
const SDValue & getOperand(unsigned Num) const
void setNodeId(int Id)
Set unique node id.
const SDValue & getBasePtr() const
FunctionPass * createMSP430ISelDag(MSP430TargetMachine &TM, CodeGenOpt::Level OptLevel)
createMSP430ISelDag - This pass converts a legalized DAG into a MSP430-specific DAG, ready for instruction scheduling.
The address of a basic block.
A description of a memory reference used in the backend.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
Reg
All possible values of the reg field in the ModR/M byte.
Simple integer binary arithmetic operators.
EVT getMemoryVT() const
Return the type of the in-memory value.
SDNode * getNode() const
get the SDNode which holds the desired result
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
const SDValue & getOperand(unsigned i) const
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
unsigned getOpcode() const
FunctionPass class - This class is used to implement most global optimizations.
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc, or post-dec.
const SDValue & getOffset() const
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
void dump() const
Dump this node, for debugging.
const SDValue & getChain() const
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...
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
Bitwise operators - logical and, logical or, logical xor.
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static bool isValidIndexedLoad(const LoadSDNode *LD)
Wrapper - A wrapper node for TargetConstantPool, TargetExternalSymbol, and TargetGlobalAddress.
EVT getValueType() const
Return the ValueType of the referenced return value.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
This file describes how to lower LLVM code to machine code.
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
This class is used to represent ISD::LOAD nodes.