LLVM: lib/Target/XCore/XCoreISelDAGToDAG.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
23#include "llvm/IR/IntrinsicsXCore.h"
26using namespace llvm;
27
28#define DEBUG_TYPE "xcore-isel"
29#define PASS_NAME "XCore DAG->DAG Pattern Instruction Selection"
30
31
32
33
34namespace {
36
37 public:
38 XCoreDAGToDAGISel() = delete;
39
42
45
46
47
48 inline SDValue getI32Imm(unsigned Imm, const SDLoc &dl) {
49 return CurDAG->getTargetConstant(Imm, dl, MVT::i32);
50 }
51
52 inline bool immMskBitp(SDNode *inN) const {
56 return false;
57 }
59 return (msksize >= 1 && msksize <= 8) ||
60 msksize == 16 || msksize == 24 || msksize == 32;
61 }
62
63
65
66 bool SelectInlineAsmMemoryOperand(const SDValue &Op,
68 std::vector &OutOps) override;
69
70
71 #include "XCoreGenDAGISel.inc"
72 };
73
75 public:
76 static char ID;
80 ID, std::make_unique(TM, OptLevel)) {}
81 };
82}
83
84char XCoreDAGToDAGISelLegacy::ID = 0;
85
87
88
89
90
93 return new XCoreDAGToDAGISelLegacy(TM, OptLevel);
94}
95
100 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
101 Offset = CurDAG->getTargetConstant(0, SDLoc(Addr), MVT::i32);
102 return true;
103 }
105 ConstantSDNode *CN = nullptr;
109
110 Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
112 MVT::i32);
113 return true;
114 }
115 }
116 return false;
117}
118
119bool XCoreDAGToDAGISel::SelectInlineAsmMemoryOperand(
121 std::vector &OutOps) {
123 switch (ConstraintID) {
124 default: return true;
125 case InlineAsm::ConstraintCode::m:
126 switch (Op.getOpcode()) {
127 default: return true;
128 case XCoreISD::CPRelativeWrapper:
129 Reg = CurDAG->getRegister(XCore::CP, MVT::i32);
130 break;
131 case XCoreISD::DPRelativeWrapper:
132 Reg = CurDAG->getRegister(XCore::DP, MVT::i32);
133 break;
134 }
135 }
136 OutOps.push_back(Reg);
137 OutOps.push_back(Op.getOperand(0));
138 return false;
139}
140
141void XCoreDAGToDAGISel::Select(SDNode *N) {
142 SDLoc dl(N);
143 switch (N->getOpcode()) {
144 default: break;
146 uint64_t Val = N->getAsZExtVal();
147 if (immMskBitp(N)) {
148
149
151 ReplaceNode(
152 N, CurDAG->getMachineNode(XCore::MKMSK_rus, dl, MVT::i32, MskSize));
153 return;
154 }
156 SDValue CPIdx = CurDAG->getTargetConstantPool(
157 ConstantInt::get(Type::getInt32Ty(*CurDAG->getContext()), Val),
158 getTargetLowering()->getPointerTy(CurDAG->getDataLayout()));
159 SDNode *node = CurDAG->getMachineNode(XCore::LDWCP_lru6, dl, MVT::i32,
160 MVT::Other, CPIdx,
161 CurDAG->getEntryNode());
162 MachineMemOperand *MemOp =
166 ReplaceNode(N, node);
167 return;
168 }
169 break;
170 }
171 case ISD::BRIND:
172 if (tryBRIND(N))
173 return;
174 break;
175
176 }
177 SelectCode(N);
178}
179
180
181
182
183
186{
187 if (Chain == Old)
188 return New;
192 bool found = false;
193 for (unsigned i = 0, e = Chain->getNumOperands(); i != e; ++i) {
195 Ops.push_back(New);
196 found = true;
197 } else {
199 }
200 }
201 if (!found)
204}
205
206bool XCoreDAGToDAGISel::tryBRIND(SDNode *N) {
207 SDLoc dl(N);
208
209 SDValue Chain = N->getOperand(0);
212 return false;
214 if (IntNo != Intrinsic::xcore_checkevent)
215 return false;
218 if (!CheckEventChainOut.use_empty()) {
219
220
221
222
225 CheckEventChainIn);
227 return false;
228 Chain = NewChain;
229 }
230
231
232
233
234 SDValue constOne = getI32Imm(1, dl);
236 SDValue(CurDAG->getMachineNode(XCore::SETSR_branch_u6, dl, MVT::Glue,
237 constOne, Chain), 0);
238 Glue =
239 SDValue(CurDAG->getMachineNode(XCore::CLRSR_branch_u6, dl, MVT::Glue,
240 constOne, Glue), 0);
241 if (nextAddr->getOpcode() == XCoreISD::PCRelativeWrapper &&
243 CurDAG->SelectNodeTo(N, XCore::BRFU_lu6, MVT::Other,
245 return true;
246 }
247 CurDAG->SelectNodeTo(N, XCore::BAU_1r, MVT::Other, nextAddr, Glue);
248 return true;
249}
AMDGPU Register Bank Select
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file describes how to lower LLVM code to machine code.
static SDValue replaceInChain(SelectionDAG *CurDAG, SDValue Chain, SDValue Old, SDValue New)
Given a chain return a new chain where any appearance of Old is replaced by New.
Definition XCoreISelDAGToDAG.cpp:185
int64_t getSExtValue() const
FunctionPass class - This class is used to implement most global optimizations.
@ MOLoad
The memory access reads data.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
unsigned getNumOperands() const
Return the number of values used by this operation.
const SDValue & getOperand(unsigned Num) const
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
const SDValue & getOperand(unsigned i) const
unsigned getOpcode() const
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ ADD
Simple integer binary arithmetic operators.
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
@ INTRINSIC_W_CHAIN
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
constexpr bool isMask_32(uint32_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
CodeGenOptLevel
Code generation optimization level.
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
FunctionPass * createXCoreISelDag(XCoreTargetMachine &TM, CodeGenOptLevel OptLevel)
createXCoreISelDag - This pass converts a legalized DAG into a XCore-specific DAG,...
Definition XCoreISelDAGToDAG.cpp:91
static LLVM_ABI MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.