22 #include "llvm/Config/llvm-config.h" 33 #define DEBUG_TYPE "msp430-isel" 36 struct MSP430ISelAddressMode {
51 const char *ES =
nullptr;
55 MSP430ISelAddressMode() =
default;
57 bool hasSymbolicDisplacement()
const {
58 return GV !=
nullptr || CP !=
nullptr || ES !=
nullptr || JT != -1;
61 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 63 errs() <<
"MSP430ISelAddressMode " <<
this <<
'\n';
64 if (BaseType == RegBase &&
Base.Reg.getNode() !=
nullptr) {
65 errs() <<
"Base.Reg ";
66 Base.Reg.getNode()->dump();
67 }
else if (BaseType == FrameIndexBase) {
68 errs() <<
" Base.FrameIndex " <<
Base.FrameIndex <<
'\n';
70 errs() <<
" Disp " << Disp <<
'\n';
77 errs() <<
" Align" << Align <<
'\n';
82 errs() <<
" JT" << JT <<
" Align" << Align <<
'\n';
99 return "MSP430 DAG->DAG Pattern Instruction Selection";
102 bool MatchAddress(
SDValue N, MSP430ISelAddressMode &AM);
103 bool MatchWrapper(
SDValue N, MSP430ISelAddressMode &AM);
104 bool MatchAddressBase(
SDValue N, MSP430ISelAddressMode &AM);
106 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
unsigned ConstraintID,
107 std::vector<SDValue> &OutOps)
override;
110 #include "MSP430GenDAGISel.inc" 115 bool tryIndexedLoad(
SDNode *Op);
128 return new MSP430DAGToDAGISel(TM, OptLevel);
135 bool MSP430DAGToDAGISel::MatchWrapper(
SDValue N, MSP430ISelAddressMode &AM) {
138 if (AM.hasSymbolicDisplacement())
144 AM.GV =
G->getGlobal();
145 AM.Disp +=
G->getOffset();
148 AM.CP =
CP->getConstVal();
149 AM.Align =
CP->getAlignment();
150 AM.Disp +=
CP->getOffset();
153 AM.ES = S->getSymbol();
156 AM.JT = J->getIndex();
159 AM.BlockAddr = cast<BlockAddressSDNode>(N0)->getBlockAddress();
167 bool MSP430DAGToDAGISel::MatchAddressBase(
SDValue N, MSP430ISelAddressMode &AM) {
169 if (AM.BaseType != MSP430ISelAddressMode::RegBase || AM.Base.Reg.getNode()) {
175 AM.BaseType = MSP430ISelAddressMode::RegBase;
180 bool MSP430DAGToDAGISel::MatchAddress(
SDValue N, MSP430ISelAddressMode &AM) {
186 uint64_t Val = cast<ConstantSDNode>(
N)->getSExtValue();
192 if (!MatchWrapper(N, AM))
197 if (AM.BaseType == MSP430ISelAddressMode::RegBase
198 && AM.Base.Reg.getNode() ==
nullptr) {
199 AM.BaseType = MSP430ISelAddressMode::FrameIndexBase;
200 AM.Base.FrameIndex = cast<FrameIndexSDNode>(
N)->getIndex();
206 MSP430ISelAddressMode Backup = AM;
222 MSP430ISelAddressMode Backup = AM;
223 uint64_t
Offset = CN->getSExtValue();
229 CurDAG->MaskedValueIsZero(N.
getOperand(0), CN->getAPIntValue())) {
238 return MatchAddressBase(N, AM);
244 bool MSP430DAGToDAGISel::SelectAddr(
SDValue N,
246 MSP430ISelAddressMode AM;
248 if (MatchAddress(N, AM))
251 if (AM.BaseType == MSP430ISelAddressMode::RegBase)
252 if (!AM.Base.Reg.getNode())
253 AM.Base.Reg = CurDAG->getRegister(MSP430::SR,
MVT::i16);
255 Base = (AM.BaseType == MSP430ISelAddressMode::FrameIndexBase)
256 ? CurDAG->getTargetFrameIndex(
258 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()))
262 Disp = CurDAG->getTargetGlobalAddress(AM.GV,
SDLoc(N),
266 Disp = CurDAG->getTargetConstantPool(AM.CP,
MVT::i16,
267 AM.Align, AM.Disp, 0);
269 Disp = CurDAG->getTargetExternalSymbol(AM.ES,
MVT::i16, 0);
270 else if (AM.JT != -1)
271 Disp = CurDAG->getTargetJumpTable(AM.JT,
MVT::i16, 0);
272 else if (AM.BlockAddr)
273 Disp = CurDAG->getTargetBlockAddress(AM.BlockAddr,
MVT::i32, 0,
276 Disp = CurDAG->getTargetConstant(AM.Disp,
SDLoc(N),
MVT::i16);
281 bool MSP430DAGToDAGISel::
282 SelectInlineAsmMemoryOperand(
const SDValue &
Op,
unsigned ConstraintID,
283 std::vector<SDValue> &OutOps) {
285 switch (ConstraintID) {
286 default:
return true;
288 if (!SelectAddr(Op, Op0, Op1))
293 OutOps.push_back(Op0);
294 OutOps.push_back(Op1);
308 if (cast<ConstantSDNode>(LD->
getOffset())->getZExtValue() != 1)
314 if (cast<ConstantSDNode>(LD->
getOffset())->getZExtValue() != 2)
325 bool MSP430DAGToDAGISel::tryIndexedLoad(
SDNode *N) {
335 Opcode = MSP430::MOV8rp;
338 Opcode = MSP430::MOV16rp;
351 unsigned Opc8,
unsigned Opc16) {
354 IsLegalToFold(N1, Op, Op, OptLevel)) {
360 unsigned Opc = (VT ==
MVT::i16 ? Opc16 : Opc8);
365 CurDAG->setNodeMemRefs(cast<MachineSDNode>(ResNode), {MemRef});
392 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
395 CurDAG->SelectNodeTo(Node, MSP430::ADDframe,
MVT::i16, TFI,
396 CurDAG->getTargetConstant(0, dl,
MVT::i16));
399 ReplaceNode(Node, CurDAG->getMachineNode(
400 MSP430::ADDframe, dl,
MVT::i16, TFI,
401 CurDAG->getTargetConstant(0, dl,
MVT::i16)));
405 if (tryIndexedLoad(Node))
411 MSP430::ADD8rp, MSP430::ADD16rp))
414 MSP430::ADD8rp, MSP430::ADD16rp))
421 MSP430::SUB8rp, MSP430::SUB16rp))
428 MSP430::AND8rp, MSP430::AND16rp))
431 MSP430::AND8rp, MSP430::AND16rp))
438 MSP430::BIS8rp, MSP430::BIS16rp))
441 MSP430::BIS8rp, MSP430::BIS16rp))
448 MSP430::XOR8rp, MSP430::XOR16rp))
451 MSP430::XOR8rp, MSP430::XOR16rp))
const SDValue & getOffset() const
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.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
const SDValue & getBasePtr() const
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
const SDValue & getChain() const
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc, or post-dec.
void setNodeId(int Id)
Set unique node id.
SDNode * getNode() const
get the SDNode which holds the desired result
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
FunctionPass * createMSP430ISelDag(MSP430TargetMachine &TM, CodeGenOpt::Level OptLevel)
createMSP430ISelDag - This pass converts a legalized DAG into a MSP430-specific DAG, ready for instruction scheduling.
void dump() const
Support for debugging, callable in GDB: V->dump()
The address of a basic block.
bool hasOneUse() const
Return true if there is exactly one use of this node.
A description of a memory reference used in the backend.
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
Simple integer binary arithmetic operators.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
This is an important base class in LLVM.
const SDValue & getOperand(unsigned Num) const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
FunctionPass class - This class is used to implement most global optimizations.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
This struct is a compact representation of a valid (non-zero power of two) alignment.
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
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...
EVT getMemoryVT() const
Return the type of the in-memory value.
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...
unsigned getOpcode() const
static bool isValidIndexedLoad(const LoadSDNode *LD)
Wrapper - A wrapper node for TargetConstantPool, TargetExternalSymbol, and TargetGlobalAddress.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
const SDValue & getOperand(unsigned i) const
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
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.