LLVM 20.0.0git
HexagonISelLowering.cpp
Go to the documentation of this file.
1//===-- HexagonISelLowering.cpp - Hexagon DAG Lowering Implementation -----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the interfaces that Hexagon uses to lower LLVM code
10// into a selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#include "HexagonISelLowering.h"
15#include "Hexagon.h"
17#include "HexagonRegisterInfo.h"
18#include "HexagonSubtarget.h"
21#include "llvm/ADT/APInt.h"
22#include "llvm/ADT/ArrayRef.h"
33#include "llvm/IR/BasicBlock.h"
34#include "llvm/IR/CallingConv.h"
35#include "llvm/IR/DataLayout.h"
39#include "llvm/IR/Function.h"
40#include "llvm/IR/GlobalValue.h"
41#include "llvm/IR/IRBuilder.h"
42#include "llvm/IR/InlineAsm.h"
45#include "llvm/IR/Intrinsics.h"
46#include "llvm/IR/IntrinsicsHexagon.h"
47#include "llvm/IR/Module.h"
48#include "llvm/IR/Type.h"
49#include "llvm/IR/Value.h"
53#include "llvm/Support/Debug.h"
58#include <algorithm>
59#include <cassert>
60#include <cstdint>
61#include <limits>
62#include <utility>
63
64using namespace llvm;
65
66#define DEBUG_TYPE "hexagon-lowering"
67
68static cl::opt<bool> EmitJumpTables("hexagon-emit-jump-tables",
69 cl::init(true), cl::Hidden,
70 cl::desc("Control jump table emission on Hexagon target"));
71
72static cl::opt<bool>
73 EnableHexSDNodeSched("enable-hexagon-sdnode-sched", cl::Hidden,
74 cl::desc("Enable Hexagon SDNode scheduling"));
75
77 cl::desc("Enable Fast Math processing"));
78
79static cl::opt<int> MinimumJumpTables("minimum-jump-tables", cl::Hidden,
80 cl::init(5),
81 cl::desc("Set minimum jump tables"));
82
83static cl::opt<int>
84 MaxStoresPerMemcpyCL("max-store-memcpy", cl::Hidden, cl::init(6),
85 cl::desc("Max #stores to inline memcpy"));
86
87static cl::opt<int>
89 cl::desc("Max #stores to inline memcpy"));
90
91static cl::opt<int>
92 MaxStoresPerMemmoveCL("max-store-memmove", cl::Hidden, cl::init(6),
93 cl::desc("Max #stores to inline memmove"));
94
95static cl::opt<int>
97 cl::init(4),
98 cl::desc("Max #stores to inline memmove"));
99
100static cl::opt<int>
101 MaxStoresPerMemsetCL("max-store-memset", cl::Hidden, cl::init(8),
102 cl::desc("Max #stores to inline memset"));
103
104static cl::opt<int>
106 cl::desc("Max #stores to inline memset"));
107
108static cl::opt<bool> AlignLoads("hexagon-align-loads",
109 cl::Hidden, cl::init(false),
110 cl::desc("Rewrite unaligned loads as a pair of aligned loads"));
111
112static cl::opt<bool>
113 DisableArgsMinAlignment("hexagon-disable-args-min-alignment", cl::Hidden,
114 cl::init(false),
115 cl::desc("Disable minimum alignment of 1 for "
116 "arguments passed by value on stack"));
117
118namespace {
119
120 class HexagonCCState : public CCState {
121 unsigned NumNamedVarArgParams = 0;
122
123 public:
124 HexagonCCState(CallingConv::ID CC, bool IsVarArg, MachineFunction &MF,
126 unsigned NumNamedArgs)
127 : CCState(CC, IsVarArg, MF, locs, C),
128 NumNamedVarArgParams(NumNamedArgs) {}
129 unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; }
130 };
131
132} // end anonymous namespace
133
134
135// Implement calling convention for Hexagon.
136
137static bool CC_SkipOdd(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
138 CCValAssign::LocInfo &LocInfo,
139 ISD::ArgFlagsTy &ArgFlags, CCState &State) {
140 static const MCPhysReg ArgRegs[] = {
141 Hexagon::R0, Hexagon::R1, Hexagon::R2,
142 Hexagon::R3, Hexagon::R4, Hexagon::R5
143 };
144 const unsigned NumArgRegs = std::size(ArgRegs);
145 unsigned RegNum = State.getFirstUnallocated(ArgRegs);
146
147 // RegNum is an index into ArgRegs: skip a register if RegNum is odd.
148 if (RegNum != NumArgRegs && RegNum % 2 == 1)
149 State.AllocateReg(ArgRegs[RegNum]);
150
151 // Always return false here, as this function only makes sure that the first
152 // unallocated register has an even register number and does not actually
153 // allocate a register for the current argument.
154 return false;
155}
156
157#include "HexagonGenCallingConv.inc"
158
159
162 const {
163 return SDValue();
164}
165
166/// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified
167/// by "Src" to address "Dst" of size "Size". Alignment information is
168/// specified by the specific parameter attribute. The copy will be passed as
169/// a byval function parameter. Sometimes what we are copying is the end of a
170/// larger object, the part that does not fit in registers.
172 SDValue Chain, ISD::ArgFlagsTy Flags,
173 SelectionDAG &DAG, const SDLoc &dl) {
174 SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), dl, MVT::i32);
175 return DAG.getMemcpy(
176 Chain, dl, Dst, Src, SizeNode, Flags.getNonZeroByValAlign(),
177 /*isVolatile=*/false, /*AlwaysInline=*/false,
178 /*CI=*/nullptr, std::nullopt, MachinePointerInfo(), MachinePointerInfo());
179}
180
181bool
183 CallingConv::ID CallConv, MachineFunction &MF, bool IsVarArg,
185 LLVMContext &Context) const {
187 CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
188
190 return CCInfo.CheckReturn(Outs, RetCC_Hexagon_HVX);
191 return CCInfo.CheckReturn(Outs, RetCC_Hexagon);
192}
193
194// LowerReturn - Lower ISD::RET. If a struct is larger than 8 bytes and is
195// passed by value, the function prototype is modified to return void and
196// the value is stored in memory pointed by a pointer passed by caller.
199 bool IsVarArg,
201 const SmallVectorImpl<SDValue> &OutVals,
202 const SDLoc &dl, SelectionDAG &DAG) const {
203 // CCValAssign - represent the assignment of the return value to locations.
205
206 // CCState - Info about the registers and stack slot.
207 CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
208 *DAG.getContext());
209
210 // Analyze return values of ISD::RET
211 if (Subtarget.useHVXOps())
212 CCInfo.AnalyzeReturn(Outs, RetCC_Hexagon_HVX);
213 else
214 CCInfo.AnalyzeReturn(Outs, RetCC_Hexagon);
215
216 SDValue Glue;
217 SmallVector<SDValue, 4> RetOps(1, Chain);
218
219 // Copy the result values into the output registers.
220 for (unsigned i = 0; i != RVLocs.size(); ++i) {
221 CCValAssign &VA = RVLocs[i];
222 SDValue Val = OutVals[i];
223
224 switch (VA.getLocInfo()) {
225 default:
226 // Loc info must be one of Full, BCvt, SExt, ZExt, or AExt.
227 llvm_unreachable("Unknown loc info!");
229 break;
231 Val = DAG.getBitcast(VA.getLocVT(), Val);
232 break;
234 Val = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Val);
235 break;
237 Val = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Val);
238 break;
240 Val = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Val);
241 break;
242 }
243
244 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Val, Glue);
245
246 // Guarantee that all emitted copies are stuck together with flags.
247 Glue = Chain.getValue(1);
248 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
249 }
250
251 RetOps[0] = Chain; // Update chain.
252
253 // Add the glue if we have it.
254 if (Glue.getNode())
255 RetOps.push_back(Glue);
256
257 return DAG.getNode(HexagonISD::RET_GLUE, dl, MVT::Other, RetOps);
258}
259
261 // If either no tail call or told not to tail call at all, don't.
262 return CI->isTailCall();
263}
264
266 const char* RegName, LLT VT, const MachineFunction &) const {
267 // Just support r19, the linux kernel uses it.
269 .Case("r0", Hexagon::R0)
270 .Case("r1", Hexagon::R1)
271 .Case("r2", Hexagon::R2)
272 .Case("r3", Hexagon::R3)
273 .Case("r4", Hexagon::R4)
274 .Case("r5", Hexagon::R5)
275 .Case("r6", Hexagon::R6)
276 .Case("r7", Hexagon::R7)
277 .Case("r8", Hexagon::R8)
278 .Case("r9", Hexagon::R9)
279 .Case("r10", Hexagon::R10)
280 .Case("r11", Hexagon::R11)
281 .Case("r12", Hexagon::R12)
282 .Case("r13", Hexagon::R13)
283 .Case("r14", Hexagon::R14)
284 .Case("r15", Hexagon::R15)
285 .Case("r16", Hexagon::R16)
286 .Case("r17", Hexagon::R17)
287 .Case("r18", Hexagon::R18)
288 .Case("r19", Hexagon::R19)
289 .Case("r20", Hexagon::R20)
290 .Case("r21", Hexagon::R21)
291 .Case("r22", Hexagon::R22)
292 .Case("r23", Hexagon::R23)
293 .Case("r24", Hexagon::R24)
294 .Case("r25", Hexagon::R25)
295 .Case("r26", Hexagon::R26)
296 .Case("r27", Hexagon::R27)
297 .Case("r28", Hexagon::R28)
298 .Case("r29", Hexagon::R29)
299 .Case("r30", Hexagon::R30)
300 .Case("r31", Hexagon::R31)
301 .Case("r1:0", Hexagon::D0)
302 .Case("r3:2", Hexagon::D1)
303 .Case("r5:4", Hexagon::D2)
304 .Case("r7:6", Hexagon::D3)
305 .Case("r9:8", Hexagon::D4)
306 .Case("r11:10", Hexagon::D5)
307 .Case("r13:12", Hexagon::D6)
308 .Case("r15:14", Hexagon::D7)
309 .Case("r17:16", Hexagon::D8)
310 .Case("r19:18", Hexagon::D9)
311 .Case("r21:20", Hexagon::D10)
312 .Case("r23:22", Hexagon::D11)
313 .Case("r25:24", Hexagon::D12)
314 .Case("r27:26", Hexagon::D13)
315 .Case("r29:28", Hexagon::D14)
316 .Case("r31:30", Hexagon::D15)
317 .Case("sp", Hexagon::R29)
318 .Case("fp", Hexagon::R30)
319 .Case("lr", Hexagon::R31)
320 .Case("p0", Hexagon::P0)
321 .Case("p1", Hexagon::P1)
322 .Case("p2", Hexagon::P2)
323 .Case("p3", Hexagon::P3)
324 .Case("sa0", Hexagon::SA0)
325 .Case("lc0", Hexagon::LC0)
326 .Case("sa1", Hexagon::SA1)
327 .Case("lc1", Hexagon::LC1)
328 .Case("m0", Hexagon::M0)
329 .Case("m1", Hexagon::M1)
330 .Case("usr", Hexagon::USR)
331 .Case("ugp", Hexagon::UGP)
332 .Case("cs0", Hexagon::CS0)
333 .Case("cs1", Hexagon::CS1)
334 .Default(Register());
335 if (Reg)
336 return Reg;
337
338 report_fatal_error("Invalid register name global variable");
339}
340
341/// LowerCallResult - Lower the result values of an ISD::CALL into the
342/// appropriate copies out of appropriate physical registers. This assumes that
343/// Chain/Glue are the input chain/glue to use, and that TheCall is the call
344/// being lowered. Returns a SDNode with the same number of values as the
345/// ISD::CALL.
347 SDValue Chain, SDValue Glue, CallingConv::ID CallConv, bool IsVarArg,
348 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
350 const SmallVectorImpl<SDValue> &OutVals, SDValue Callee) const {
351 // Assign locations to each value returned by this call.
353
354 CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs,
355 *DAG.getContext());
356
357 if (Subtarget.useHVXOps())
358 CCInfo.AnalyzeCallResult(Ins, RetCC_Hexagon_HVX);
359 else
360 CCInfo.AnalyzeCallResult(Ins, RetCC_Hexagon);
361
362 // Copy all of the result registers out of their specified physreg.
363 for (unsigned i = 0; i != RVLocs.size(); ++i) {
364 SDValue RetVal;
365 if (RVLocs[i].getValVT() == MVT::i1) {
366 // Return values of type MVT::i1 require special handling. The reason
367 // is that MVT::i1 is associated with the PredRegs register class, but
368 // values of that type are still returned in R0. Generate an explicit
369 // copy into a predicate register from R0, and treat the value of the
370 // predicate register as the call result.
371 auto &MRI = DAG.getMachineFunction().getRegInfo();
372 SDValue FR0 = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(),
373 MVT::i32, Glue);
374 // FR0 = (Value, Chain, Glue)
375 Register PredR = MRI.createVirtualRegister(&Hexagon::PredRegsRegClass);
376 SDValue TPR = DAG.getCopyToReg(FR0.getValue(1), dl, PredR,
377 FR0.getValue(0), FR0.getValue(2));
378 // TPR = (Chain, Glue)
379 // Don't glue this CopyFromReg, because it copies from a virtual
380 // register. If it is glued to the call, InstrEmitter will add it
381 // as an implicit def to the call (EmitMachineNode).
382 RetVal = DAG.getCopyFromReg(TPR.getValue(0), dl, PredR, MVT::i1);
383 Glue = TPR.getValue(1);
384 Chain = TPR.getValue(0);
385 } else {
386 RetVal = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(),
387 RVLocs[i].getValVT(), Glue);
388 Glue = RetVal.getValue(2);
389 Chain = RetVal.getValue(1);
390 }
391 InVals.push_back(RetVal.getValue(0));
392 }
393
394 return Chain;
395}
396
397/// LowerCall - Functions arguments are copied from virtual regs to
398/// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted.
401 SmallVectorImpl<SDValue> &InVals) const {
402 SelectionDAG &DAG = CLI.DAG;
403 SDLoc &dl = CLI.DL;
405 SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
407 SDValue Chain = CLI.Chain;
408 SDValue Callee = CLI.Callee;
409 CallingConv::ID CallConv = CLI.CallConv;
410 bool IsVarArg = CLI.IsVarArg;
411 bool DoesNotReturn = CLI.DoesNotReturn;
412
413 bool IsStructRet = Outs.empty() ? false : Outs[0].Flags.isSRet();
415 MachineFrameInfo &MFI = MF.getFrameInfo();
416 auto PtrVT = getPointerTy(MF.getDataLayout());
417
418 unsigned NumParams = CLI.CB ? CLI.CB->getFunctionType()->getNumParams() : 0;
419 if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee))
420 Callee = DAG.getTargetGlobalAddress(GAN->getGlobal(), dl, MVT::i32);
421
422 // Linux ABI treats var-arg calls the same way as regular ones.
423 bool TreatAsVarArg = !Subtarget.isEnvironmentMusl() && IsVarArg;
424
425 // Analyze operands of the call, assigning locations to each operand.
427 HexagonCCState CCInfo(CallConv, TreatAsVarArg, MF, ArgLocs, *DAG.getContext(),
428 NumParams);
429
430 if (Subtarget.useHVXOps())
431 CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_HVX);
433 CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_Legacy);
434 else
435 CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon);
436
437 if (CLI.IsTailCall) {
438 bool StructAttrFlag = MF.getFunction().hasStructRetAttr();
439 CLI.IsTailCall = IsEligibleForTailCallOptimization(Callee, CallConv,
440 IsVarArg, IsStructRet, StructAttrFlag, Outs,
441 OutVals, Ins, DAG);
442 for (const CCValAssign &VA : ArgLocs) {
443 if (VA.isMemLoc()) {
444 CLI.IsTailCall = false;
445 break;
446 }
447 }
448 LLVM_DEBUG(dbgs() << (CLI.IsTailCall ? "Eligible for Tail Call\n"
449 : "Argument must be passed on stack. "
450 "Not eligible for Tail Call\n"));
451 }
452 // Get a count of how many bytes are to be pushed on the stack.
453 unsigned NumBytes = CCInfo.getStackSize();
455 SmallVector<SDValue, 8> MemOpChains;
456
457 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
458 SDValue StackPtr =
459 DAG.getCopyFromReg(Chain, dl, HRI.getStackRegister(), PtrVT);
460
461 bool NeedsArgAlign = false;
462 Align LargestAlignSeen;
463 // Walk the register/memloc assignments, inserting copies/loads.
464 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
465 CCValAssign &VA = ArgLocs[i];
466 SDValue Arg = OutVals[i];
467 ISD::ArgFlagsTy Flags = Outs[i].Flags;
468 // Record if we need > 8 byte alignment on an argument.
469 bool ArgAlign = Subtarget.isHVXVectorType(VA.getValVT());
470 NeedsArgAlign |= ArgAlign;
471
472 // Promote the value if needed.
473 switch (VA.getLocInfo()) {
474 default:
475 // Loc info must be one of Full, BCvt, SExt, ZExt, or AExt.
476 llvm_unreachable("Unknown loc info!");
478 break;
480 Arg = DAG.getBitcast(VA.getLocVT(), Arg);
481 break;
483 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
484 break;
486 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
487 break;
489 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
490 break;
491 }
492
493 if (VA.isMemLoc()) {
494 unsigned LocMemOffset = VA.getLocMemOffset();
495 SDValue MemAddr = DAG.getConstant(LocMemOffset, dl,
496 StackPtr.getValueType());
497 MemAddr = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, MemAddr);
498 if (ArgAlign)
499 LargestAlignSeen = std::max(
500 LargestAlignSeen, Align(VA.getLocVT().getStoreSizeInBits() / 8));
501 if (Flags.isByVal()) {
502 // The argument is a struct passed by value. According to LLVM, "Arg"
503 // is a pointer.
504 MemOpChains.push_back(CreateCopyOfByValArgument(Arg, MemAddr, Chain,
505 Flags, DAG, dl));
506 } else {
508 DAG.getMachineFunction(), LocMemOffset);
509 SDValue S = DAG.getStore(Chain, dl, Arg, MemAddr, LocPI);
510 MemOpChains.push_back(S);
511 }
512 continue;
513 }
514
515 // Arguments that can be passed on register must be kept at RegsToPass
516 // vector.
517 if (VA.isRegLoc())
518 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
519 }
520
521 if (NeedsArgAlign && Subtarget.hasV60Ops()) {
522 LLVM_DEBUG(dbgs() << "Function needs byte stack align due to call args\n");
523 Align VecAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
524 LargestAlignSeen = std::max(LargestAlignSeen, VecAlign);
525 MFI.ensureMaxAlignment(LargestAlignSeen);
526 }
527 // Transform all store nodes into one single node because all store
528 // nodes are independent of each other.
529 if (!MemOpChains.empty())
530 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains);
531
532 SDValue Glue;
533 if (!CLI.IsTailCall) {
534 Chain = DAG.getCALLSEQ_START(Chain, NumBytes, 0, dl);
535 Glue = Chain.getValue(1);
536 }
537
538 // Build a sequence of copy-to-reg nodes chained together with token
539 // chain and flag operands which copy the outgoing args into registers.
540 // The Glue is necessary since all emitted instructions must be
541 // stuck together.
542 if (!CLI.IsTailCall) {
543 for (const auto &R : RegsToPass) {
544 Chain = DAG.getCopyToReg(Chain, dl, R.first, R.second, Glue);
545 Glue = Chain.getValue(1);
546 }
547 } else {
548 // For tail calls lower the arguments to the 'real' stack slot.
549 //
550 // Force all the incoming stack arguments to be loaded from the stack
551 // before any new outgoing arguments are stored to the stack, because the
552 // outgoing stack slots may alias the incoming argument stack slots, and
553 // the alias isn't otherwise explicit. This is slightly more conservative
554 // than necessary, because it means that each store effectively depends
555 // on every argument instead of just those arguments it would clobber.
556 //
557 // Do not flag preceding copytoreg stuff together with the following stuff.
558 Glue = SDValue();
559 for (const auto &R : RegsToPass) {
560 Chain = DAG.getCopyToReg(Chain, dl, R.first, R.second, Glue);
561 Glue = Chain.getValue(1);
562 }
563 Glue = SDValue();
564 }
565
566 bool LongCalls = MF.getSubtarget<HexagonSubtarget>().useLongCalls();
567 unsigned Flags = LongCalls ? HexagonII::HMOTF_ConstExtended : 0;
568
569 // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
570 // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
571 // node so that legalize doesn't hack it.
572 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
573 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, PtrVT, 0, Flags);
574 } else if (ExternalSymbolSDNode *S =
575 dyn_cast<ExternalSymbolSDNode>(Callee)) {
576 Callee = DAG.getTargetExternalSymbol(S->getSymbol(), PtrVT, Flags);
577 }
578
579 // Returns a chain & a flag for retval copy to use.
581 Ops.push_back(Chain);
582 Ops.push_back(Callee);
583
584 // Add argument registers to the end of the list so that they are
585 // known live into the call.
586 for (const auto &R : RegsToPass)
587 Ops.push_back(DAG.getRegister(R.first, R.second.getValueType()));
588
589 const uint32_t *Mask = HRI.getCallPreservedMask(MF, CallConv);
590 assert(Mask && "Missing call preserved mask for calling convention");
591 Ops.push_back(DAG.getRegisterMask(Mask));
592
593 if (Glue.getNode())
594 Ops.push_back(Glue);
595
596 if (CLI.IsTailCall) {
597 MFI.setHasTailCall();
598 return DAG.getNode(HexagonISD::TC_RETURN, dl, MVT::Other, Ops);
599 }
600
601 // Set this here because we need to know this for "hasFP" in frame lowering.
602 // The target-independent code calls getFrameRegister before setting it, and
603 // getFrameRegister uses hasFP to determine whether the function has FP.
604 MFI.setHasCalls(true);
605
606 unsigned OpCode = DoesNotReturn ? HexagonISD::CALLnr : HexagonISD::CALL;
607 Chain = DAG.getNode(OpCode, dl, {MVT::Other, MVT::Glue}, Ops);
608 Glue = Chain.getValue(1);
609
610 // Create the CALLSEQ_END node.
611 Chain = DAG.getCALLSEQ_END(Chain, NumBytes, 0, Glue, dl);
612 Glue = Chain.getValue(1);
613
614 // Handle result values, copying them out of physregs into vregs that we
615 // return.
616 return LowerCallResult(Chain, Glue, CallConv, IsVarArg, Ins, dl, DAG,
617 InVals, OutVals, Callee);
618}
619
620/// Returns true by value, base pointer and offset pointer and addressing
621/// mode by reference if this node can be combined with a load / store to
622/// form a post-indexed load / store.
625 SelectionDAG &DAG) const {
626 LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(N);
627 if (!LSN)
628 return false;
629 EVT VT = LSN->getMemoryVT();
630 if (!VT.isSimple())
631 return false;
632 bool IsLegalType = VT == MVT::i8 || VT == MVT::i16 || VT == MVT::i32 ||
633 VT == MVT::i64 || VT == MVT::f32 || VT == MVT::f64 ||
634 VT == MVT::v2i16 || VT == MVT::v2i32 || VT == MVT::v4i8 ||
635 VT == MVT::v4i16 || VT == MVT::v8i8 ||
636 Subtarget.isHVXVectorType(VT.getSimpleVT());
637 if (!IsLegalType)
638 return false;
639
640 if (Op->getOpcode() != ISD::ADD)
641 return false;
642 Base = Op->getOperand(0);
643 Offset = Op->getOperand(1);
644 if (!isa<ConstantSDNode>(Offset.getNode()))
645 return false;
646 AM = ISD::POST_INC;
647
648 int32_t V = cast<ConstantSDNode>(Offset.getNode())->getSExtValue();
649 return Subtarget.getInstrInfo()->isValidAutoIncImm(VT, V);
650}
651
654 return SDValue();
655 else
656 return Op;
657}
658
662 auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>();
663 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
664 unsigned LR = HRI.getRARegister();
665
666 if ((Op.getOpcode() != ISD::INLINEASM &&
667 Op.getOpcode() != ISD::INLINEASM_BR) || HMFI.hasClobberLR())
668 return Op;
669
670 unsigned NumOps = Op.getNumOperands();
671 if (Op.getOperand(NumOps-1).getValueType() == MVT::Glue)
672 --NumOps; // Ignore the flag operand.
673
674 for (unsigned i = InlineAsm::Op_FirstOperand; i != NumOps;) {
675 const InlineAsm::Flag Flags(Op.getConstantOperandVal(i));
676 unsigned NumVals = Flags.getNumOperandRegisters();
677 ++i; // Skip the ID value.
678
679 switch (Flags.getKind()) {
680 default:
681 llvm_unreachable("Bad flags!");
685 i += NumVals;
686 break;
690 for (; NumVals; --NumVals, ++i) {
691 Register Reg = cast<RegisterSDNode>(Op.getOperand(i))->getReg();
692 if (Reg != LR)
693 continue;
694 HMFI.setHasClobberLR(true);
695 return Op;
696 }
697 break;
698 }
699 }
700 }
701
702 return Op;
703}
704
705// Need to transform ISD::PREFETCH into something that doesn't inherit
706// all of the properties of ISD::PREFETCH, specifically SDNPMayLoad and
707// SDNPMayStore.
709 SelectionDAG &DAG) const {
710 SDValue Chain = Op.getOperand(0);
711 SDValue Addr = Op.getOperand(1);
712 // Lower it to DCFETCH($reg, #0). A "pat" will try to merge the offset in,
713 // if the "reg" is fed by an "add".
714 SDLoc DL(Op);
715 SDValue Zero = DAG.getConstant(0, DL, MVT::i32);
716 return DAG.getNode(HexagonISD::DCFETCH, DL, MVT::Other, Chain, Addr, Zero);
717}
718
719// Custom-handle ISD::READCYCLECOUNTER because the target-independent SDNode
720// is marked as having side-effects, while the register read on Hexagon does
721// not have any. TableGen refuses to accept the direct pattern from that node
722// to the A4_tfrcpp.
724 SelectionDAG &DAG) const {
725 SDValue Chain = Op.getOperand(0);
726 SDLoc dl(Op);
727 SDVTList VTs = DAG.getVTList(MVT::i64, MVT::Other);
728 return DAG.getNode(HexagonISD::READCYCLE, dl, VTs, Chain);
729}
730
731// Custom-handle ISD::READSTEADYCOUNTER because the target-independent SDNode
732// is marked as having side-effects, while the register read on Hexagon does
733// not have any. TableGen refuses to accept the direct pattern from that node
734// to the A4_tfrcpp.
736 SelectionDAG &DAG) const {
737 SDValue Chain = Op.getOperand(0);
738 SDLoc dl(Op);
739 SDVTList VTs = DAG.getVTList(MVT::i64, MVT::Other);
740 return DAG.getNode(HexagonISD::READTIMER, dl, VTs, Chain);
741}
742
744 SelectionDAG &DAG) const {
745 SDValue Chain = Op.getOperand(0);
746 unsigned IntNo = Op.getConstantOperandVal(1);
747 // Lower the hexagon_prefetch builtin to DCFETCH, as above.
748 if (IntNo == Intrinsic::hexagon_prefetch) {
749 SDValue Addr = Op.getOperand(2);
750 SDLoc DL(Op);
751 SDValue Zero = DAG.getConstant(0, DL, MVT::i32);
752 return DAG.getNode(HexagonISD::DCFETCH, DL, MVT::Other, Chain, Addr, Zero);
753 }
754 return SDValue();
755}
756
759 SelectionDAG &DAG) const {
760 SDValue Chain = Op.getOperand(0);
761 SDValue Size = Op.getOperand(1);
762 SDValue Align = Op.getOperand(2);
763 SDLoc dl(Op);
764
765 ConstantSDNode *AlignConst = dyn_cast<ConstantSDNode>(Align);
766 assert(AlignConst && "Non-constant Align in LowerDYNAMIC_STACKALLOC");
767
768 unsigned A = AlignConst->getSExtValue();
769 auto &HFI = *Subtarget.getFrameLowering();
770 // "Zero" means natural stack alignment.
771 if (A == 0)
772 A = HFI.getStackAlign().value();
773
774 LLVM_DEBUG({
775 dbgs () << __func__ << " Align: " << A << " Size: ";
776 Size.getNode()->dump(&DAG);
777 dbgs() << "\n";
778 });
779
780 SDValue AC = DAG.getConstant(A, dl, MVT::i32);
781 SDVTList VTs = DAG.getVTList(MVT::i32, MVT::Other);
782 SDValue AA = DAG.getNode(HexagonISD::ALLOCA, dl, VTs, Chain, Size, AC);
783
785 return AA;
786}
787
789 SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
790 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
791 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
793 MachineFrameInfo &MFI = MF.getFrameInfo();
795
796 // Linux ABI treats var-arg calls the same way as regular ones.
797 bool TreatAsVarArg = !Subtarget.isEnvironmentMusl() && IsVarArg;
798
799 // Assign locations to all of the incoming arguments.
801 HexagonCCState CCInfo(CallConv, TreatAsVarArg, MF, ArgLocs,
802 *DAG.getContext(),
804
805 if (Subtarget.useHVXOps())
806 CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_HVX);
808 CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_Legacy);
809 else
810 CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon);
811
812 // For LLVM, in the case when returning a struct by value (>8byte),
813 // the first argument is a pointer that points to the location on caller's
814 // stack where the return value will be stored. For Hexagon, the location on
815 // caller's stack is passed only when the struct size is smaller than (and
816 // equal to) 8 bytes. If not, no address will be passed into callee and
817 // callee return the result direclty through R0/R1.
818 auto NextSingleReg = [] (const TargetRegisterClass &RC, unsigned Reg) {
819 switch (RC.getID()) {
820 case Hexagon::IntRegsRegClassID:
821 return Reg - Hexagon::R0 + 1;
822 case Hexagon::DoubleRegsRegClassID:
823 return (Reg - Hexagon::D0 + 1) * 2;
824 case Hexagon::HvxVRRegClassID:
825 return Reg - Hexagon::V0 + 1;
826 case Hexagon::HvxWRRegClassID:
827 return (Reg - Hexagon::W0 + 1) * 2;
828 }
829 llvm_unreachable("Unexpected register class");
830 };
831
832 auto &HFL = const_cast<HexagonFrameLowering&>(*Subtarget.getFrameLowering());
833 auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>();
834 HFL.FirstVarArgSavedReg = 0;
836
837 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
838 CCValAssign &VA = ArgLocs[i];
839 ISD::ArgFlagsTy Flags = Ins[i].Flags;
840 bool ByVal = Flags.isByVal();
841
842 // Arguments passed in registers:
843 // 1. 32- and 64-bit values and HVX vectors are passed directly,
844 // 2. Large structs are passed via an address, and the address is
845 // passed in a register.
846 if (VA.isRegLoc() && ByVal && Flags.getByValSize() <= 8)
847 llvm_unreachable("ByValSize must be bigger than 8 bytes");
848
849 bool InReg = VA.isRegLoc() &&
850 (!ByVal || (ByVal && Flags.getByValSize() > 8));
851
852 if (InReg) {
853 MVT RegVT = VA.getLocVT();
854 if (VA.getLocInfo() == CCValAssign::BCvt)
855 RegVT = VA.getValVT();
856
857 const TargetRegisterClass *RC = getRegClassFor(RegVT);
858 Register VReg = MRI.createVirtualRegister(RC);
859 SDValue Copy = DAG.getCopyFromReg(Chain, dl, VReg, RegVT);
860
861 // Treat values of type MVT::i1 specially: they are passed in
862 // registers of type i32, but they need to remain as values of
863 // type i1 for consistency of the argument lowering.
864 if (VA.getValVT() == MVT::i1) {
865 assert(RegVT.getSizeInBits() <= 32);
866 SDValue T = DAG.getNode(ISD::AND, dl, RegVT,
867 Copy, DAG.getConstant(1, dl, RegVT));
868 Copy = DAG.getSetCC(dl, MVT::i1, T, DAG.getConstant(0, dl, RegVT),
869 ISD::SETNE);
870 } else {
871#ifndef NDEBUG
872 unsigned RegSize = RegVT.getSizeInBits();
873 assert(RegSize == 32 || RegSize == 64 ||
874 Subtarget.isHVXVectorType(RegVT));
875#endif
876 }
877 InVals.push_back(Copy);
878 MRI.addLiveIn(VA.getLocReg(), VReg);
879 HFL.FirstVarArgSavedReg = NextSingleReg(*RC, VA.getLocReg());
880 } else {
881 assert(VA.isMemLoc() && "Argument should be passed in memory");
882
883 // If it's a byval parameter, then we need to compute the
884 // "real" size, not the size of the pointer.
885 unsigned ObjSize = Flags.isByVal()
886 ? Flags.getByValSize()
887 : VA.getLocVT().getStoreSizeInBits() / 8;
888
889 // Create the frame index object for this incoming parameter.
891 int FI = MFI.CreateFixedObject(ObjSize, Offset, true);
892 SDValue FIN = DAG.getFrameIndex(FI, MVT::i32);
893
894 if (Flags.isByVal()) {
895 // If it's a pass-by-value aggregate, then do not dereference the stack
896 // location. Instead, we should generate a reference to the stack
897 // location.
898 InVals.push_back(FIN);
899 } else {
900 SDValue L = DAG.getLoad(VA.getValVT(), dl, Chain, FIN,
902 InVals.push_back(L);
903 }
904 }
905 }
906
907 if (IsVarArg && Subtarget.isEnvironmentMusl()) {
908 for (int i = HFL.FirstVarArgSavedReg; i < 6; i++)
909 MRI.addLiveIn(Hexagon::R0+i);
910 }
911
912 if (IsVarArg && Subtarget.isEnvironmentMusl()) {
913 HMFI.setFirstNamedArgFrameIndex(HMFI.getFirstNamedArgFrameIndex() - 1);
914 HMFI.setLastNamedArgFrameIndex(-int(MFI.getNumFixedObjects()));
915
916 // Create Frame index for the start of register saved area.
917 int NumVarArgRegs = 6 - HFL.FirstVarArgSavedReg;
918 bool RequiresPadding = (NumVarArgRegs & 1);
919 int RegSaveAreaSizePlusPadding = RequiresPadding
920 ? (NumVarArgRegs + 1) * 4
921 : NumVarArgRegs * 4;
922
923 if (RegSaveAreaSizePlusPadding > 0) {
924 // The offset to saved register area should be 8 byte aligned.
925 int RegAreaStart = HEXAGON_LRFP_SIZE + CCInfo.getStackSize();
926 if (!(RegAreaStart % 8))
927 RegAreaStart = (RegAreaStart + 7) & -8;
928
929 int RegSaveAreaFrameIndex =
930 MFI.CreateFixedObject(RegSaveAreaSizePlusPadding, RegAreaStart, true);
931 HMFI.setRegSavedAreaStartFrameIndex(RegSaveAreaFrameIndex);
932
933 // This will point to the next argument passed via stack.
934 int Offset = RegAreaStart + RegSaveAreaSizePlusPadding;
935 int FI = MFI.CreateFixedObject(Hexagon_PointerSize, Offset, true);
936 HMFI.setVarArgsFrameIndex(FI);
937 } else {
938 // This will point to the next argument passed via stack, when
939 // there is no saved register area.
940 int Offset = HEXAGON_LRFP_SIZE + CCInfo.getStackSize();
941 int FI = MFI.CreateFixedObject(Hexagon_PointerSize, Offset, true);
942 HMFI.setRegSavedAreaStartFrameIndex(FI);
943 HMFI.setVarArgsFrameIndex(FI);
944 }
945 }
946
947
948 if (IsVarArg && !Subtarget.isEnvironmentMusl()) {
949 // This will point to the next argument passed via stack.
950 int Offset = HEXAGON_LRFP_SIZE + CCInfo.getStackSize();
951 int FI = MFI.CreateFixedObject(Hexagon_PointerSize, Offset, true);
952 HMFI.setVarArgsFrameIndex(FI);
953 }
954
955 return Chain;
956}
957
960 // VASTART stores the address of the VarArgsFrameIndex slot into the
961 // memory location argument.
964 SDValue Addr = DAG.getFrameIndex(QFI->getVarArgsFrameIndex(), MVT::i32);
965 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
966
967 if (!Subtarget.isEnvironmentMusl()) {
968 return DAG.getStore(Op.getOperand(0), SDLoc(Op), Addr, Op.getOperand(1),
970 }
971 auto &FuncInfo = *MF.getInfo<HexagonMachineFunctionInfo>();
972 auto &HFL = *Subtarget.getFrameLowering();
973 SDLoc DL(Op);
975
976 // Get frame index of va_list.
977 SDValue FIN = Op.getOperand(1);
978
979 // If first Vararg register is odd, add 4 bytes to start of
980 // saved register area to point to the first register location.
981 // This is because the saved register area has to be 8 byte aligned.
982 // Incase of an odd start register, there will be 4 bytes of padding in
983 // the beginning of saved register area. If all registers area used up,
984 // the following condition will handle it correctly.
985 SDValue SavedRegAreaStartFrameIndex =
986 DAG.getFrameIndex(FuncInfo.getRegSavedAreaStartFrameIndex(), MVT::i32);
987
988 auto PtrVT = getPointerTy(DAG.getDataLayout());
989
990 if (HFL.FirstVarArgSavedReg & 1)
991 SavedRegAreaStartFrameIndex =
992 DAG.getNode(ISD::ADD, DL, PtrVT,
993 DAG.getFrameIndex(FuncInfo.getRegSavedAreaStartFrameIndex(),
994 MVT::i32),
995 DAG.getIntPtrConstant(4, DL));
996
997 // Store the saved register area start pointer.
998 SDValue Store =
999 DAG.getStore(Op.getOperand(0), DL,
1000 SavedRegAreaStartFrameIndex,
1001 FIN, MachinePointerInfo(SV));
1002 MemOps.push_back(Store);
1003
1004 // Store saved register area end pointer.
1005 FIN = DAG.getNode(ISD::ADD, DL, PtrVT,
1006 FIN, DAG.getIntPtrConstant(4, DL));
1007 Store = DAG.getStore(Op.getOperand(0), DL,
1008 DAG.getFrameIndex(FuncInfo.getVarArgsFrameIndex(),
1009 PtrVT),
1010 FIN, MachinePointerInfo(SV, 4));
1011 MemOps.push_back(Store);
1012
1013 // Store overflow area pointer.
1014 FIN = DAG.getNode(ISD::ADD, DL, PtrVT,
1015 FIN, DAG.getIntPtrConstant(4, DL));
1016 Store = DAG.getStore(Op.getOperand(0), DL,
1017 DAG.getFrameIndex(FuncInfo.getVarArgsFrameIndex(),
1018 PtrVT),
1019 FIN, MachinePointerInfo(SV, 8));
1020 MemOps.push_back(Store);
1021
1022 return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOps);
1023}
1024
1025SDValue
1027 // Assert that the linux ABI is enabled for the current compilation.
1028 assert(Subtarget.isEnvironmentMusl() && "Linux ABI should be enabled");
1029 SDValue Chain = Op.getOperand(0);
1030 SDValue DestPtr = Op.getOperand(1);
1031 SDValue SrcPtr = Op.getOperand(2);
1032 const Value *DestSV = cast<SrcValueSDNode>(Op.getOperand(3))->getValue();
1033 const Value *SrcSV = cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
1034 SDLoc DL(Op);
1035 // Size of the va_list is 12 bytes as it has 3 pointers. Therefore,
1036 // we need to memcopy 12 bytes from va_list to another similar list.
1037 return DAG.getMemcpy(
1038 Chain, DL, DestPtr, SrcPtr, DAG.getIntPtrConstant(12, DL), Align(4),
1039 /*isVolatile*/ false, false, /*CI=*/nullptr, std::nullopt,
1040 MachinePointerInfo(DestSV), MachinePointerInfo(SrcSV));
1041}
1042
1044 const SDLoc &dl(Op);
1045 SDValue LHS = Op.getOperand(0);
1046 SDValue RHS = Op.getOperand(1);
1047 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
1048 MVT ResTy = ty(Op);
1049 MVT OpTy = ty(LHS);
1050
1051 if (OpTy == MVT::v2i16 || OpTy == MVT::v4i8) {
1052 MVT ElemTy = OpTy.getVectorElementType();
1053 assert(ElemTy.isScalarInteger());
1055 OpTy.getVectorNumElements());
1056 return DAG.getSetCC(dl, ResTy,
1057 DAG.getSExtOrTrunc(LHS, SDLoc(LHS), WideTy),
1058 DAG.getSExtOrTrunc(RHS, SDLoc(RHS), WideTy), CC);
1059 }
1060
1061 // Treat all other vector types as legal.
1062 if (ResTy.isVector())
1063 return Op;
1064
1065 // Comparisons of short integers should use sign-extend, not zero-extend,
1066 // since we can represent small negative values in the compare instructions.
1067 // The LLVM default is to use zero-extend arbitrarily in these cases.
1068 auto isSExtFree = [this](SDValue N) {
1069 switch (N.getOpcode()) {
1070 case ISD::TRUNCATE: {
1071 // A sign-extend of a truncate of a sign-extend is free.
1072 SDValue Op = N.getOperand(0);
1073 if (Op.getOpcode() != ISD::AssertSext)
1074 return false;
1075 EVT OrigTy = cast<VTSDNode>(Op.getOperand(1))->getVT();
1076 unsigned ThisBW = ty(N).getSizeInBits();
1077 unsigned OrigBW = OrigTy.getSizeInBits();
1078 // The type that was sign-extended to get the AssertSext must be
1079 // narrower than the type of N (so that N has still the same value
1080 // as the original).
1081 return ThisBW >= OrigBW;
1082 }
1083 case ISD::LOAD:
1084 // We have sign-extended loads.
1085 return true;
1086 }
1087 return false;
1088 };
1089
1090 if (OpTy == MVT::i8 || OpTy == MVT::i16) {
1091 ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS);
1092 bool IsNegative = C && C->getAPIntValue().isNegative();
1093 if (IsNegative || isSExtFree(LHS) || isSExtFree(RHS))
1094 return DAG.getSetCC(dl, ResTy,
1095 DAG.getSExtOrTrunc(LHS, SDLoc(LHS), MVT::i32),
1096 DAG.getSExtOrTrunc(RHS, SDLoc(RHS), MVT::i32), CC);
1097 }
1098
1099 return SDValue();
1100}
1101
1102SDValue
1104 SDValue PredOp = Op.getOperand(0);
1105 SDValue Op1 = Op.getOperand(1), Op2 = Op.getOperand(2);
1106 MVT OpTy = ty(Op1);
1107 const SDLoc &dl(Op);
1108
1109 if (OpTy == MVT::v2i16 || OpTy == MVT::v4i8) {
1110 MVT ElemTy = OpTy.getVectorElementType();
1111 assert(ElemTy.isScalarInteger());
1113 OpTy.getVectorNumElements());
1114 // Generate (trunc (select (_, sext, sext))).
1115 return DAG.getSExtOrTrunc(
1116 DAG.getSelect(dl, WideTy, PredOp,
1117 DAG.getSExtOrTrunc(Op1, dl, WideTy),
1118 DAG.getSExtOrTrunc(Op2, dl, WideTy)),
1119 dl, OpTy);
1120 }
1121
1122 return SDValue();
1123}
1124
1125SDValue
1127 EVT ValTy = Op.getValueType();
1128 ConstantPoolSDNode *CPN = cast<ConstantPoolSDNode>(Op);
1129 Constant *CVal = nullptr;
1130 bool isVTi1Type = false;
1131 if (auto *CV = dyn_cast<ConstantVector>(CPN->getConstVal())) {
1132 if (cast<VectorType>(CV->getType())->getElementType()->isIntegerTy(1)) {
1133 IRBuilder<> IRB(CV->getContext());
1135 unsigned VecLen = CV->getNumOperands();
1136 assert(isPowerOf2_32(VecLen) &&
1137 "conversion only supported for pow2 VectorSize");
1138 for (unsigned i = 0; i < VecLen; ++i)
1139 NewConst.push_back(IRB.getInt8(CV->getOperand(i)->isZeroValue()));
1140
1141 CVal = ConstantVector::get(NewConst);
1142 isVTi1Type = true;
1143 }
1144 }
1145 Align Alignment = CPN->getAlign();
1146 bool IsPositionIndependent = isPositionIndependent();
1147 unsigned char TF = IsPositionIndependent ? HexagonII::MO_PCREL : 0;
1148
1149 unsigned Offset = 0;
1150 SDValue T;
1151 if (CPN->isMachineConstantPoolEntry())
1152 T = DAG.getTargetConstantPool(CPN->getMachineCPVal(), ValTy, Alignment,
1153 Offset, TF);
1154 else if (isVTi1Type)
1155 T = DAG.getTargetConstantPool(CVal, ValTy, Alignment, Offset, TF);
1156 else
1157 T = DAG.getTargetConstantPool(CPN->getConstVal(), ValTy, Alignment, Offset,
1158 TF);
1159
1160 assert(cast<ConstantPoolSDNode>(T)->getTargetFlags() == TF &&
1161 "Inconsistent target flag encountered");
1162
1163 if (IsPositionIndependent)
1164 return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), ValTy, T);
1165 return DAG.getNode(HexagonISD::CP, SDLoc(Op), ValTy, T);
1166}
1167
1168SDValue
1170 EVT VT = Op.getValueType();
1171 int Idx = cast<JumpTableSDNode>(Op)->getIndex();
1172 if (isPositionIndependent()) {
1174 return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), VT, T);
1175 }
1176
1177 SDValue T = DAG.getTargetJumpTable(Idx, VT);
1178 return DAG.getNode(HexagonISD::JT, SDLoc(Op), VT, T);
1179}
1180
1181SDValue
1183 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1185 MachineFrameInfo &MFI = MF.getFrameInfo();
1186 MFI.setReturnAddressIsTaken(true);
1187
1189 return SDValue();
1190
1191 EVT VT = Op.getValueType();
1192 SDLoc dl(Op);
1193 unsigned Depth = Op.getConstantOperandVal(0);
1194 if (Depth) {
1195 SDValue FrameAddr = LowerFRAMEADDR(Op, DAG);
1196 SDValue Offset = DAG.getConstant(4, dl, MVT::i32);
1197 return DAG.getLoad(VT, dl, DAG.getEntryNode(),
1198 DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset),
1200 }
1201
1202 // Return LR, which contains the return address. Mark it an implicit live-in.
1203 Register Reg = MF.addLiveIn(HRI.getRARegister(), getRegClassFor(MVT::i32));
1204 return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT);
1205}
1206
1207SDValue
1209 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1211 MFI.setFrameAddressIsTaken(true);
1212
1213 EVT VT = Op.getValueType();
1214 SDLoc dl(Op);
1215 unsigned Depth = Op.getConstantOperandVal(0);
1216 SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl,
1217 HRI.getFrameRegister(), VT);
1218 while (Depth--)
1219 FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr,
1221 return FrameAddr;
1222}
1223
1224SDValue
1226 SDLoc dl(Op);
1227 return DAG.getNode(HexagonISD::BARRIER, dl, MVT::Other, Op.getOperand(0));
1228}
1229
1230SDValue
1232 SDLoc dl(Op);
1233 auto *GAN = cast<GlobalAddressSDNode>(Op);
1234 auto PtrVT = getPointerTy(DAG.getDataLayout());
1235 auto *GV = GAN->getGlobal();
1236 int64_t Offset = GAN->getOffset();
1237
1238 auto &HLOF = *HTM.getObjFileLowering();
1240
1241 if (RM == Reloc::Static) {
1242 SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset);
1243 const GlobalObject *GO = GV->getAliaseeObject();
1244 if (GO && Subtarget.useSmallData() && HLOF.isGlobalInSmallSection(GO, HTM))
1245 return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, GA);
1246 return DAG.getNode(HexagonISD::CONST32, dl, PtrVT, GA);
1247 }
1248
1249 bool UsePCRel = getTargetMachine().shouldAssumeDSOLocal(GV);
1250 if (UsePCRel) {
1251 SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset,
1253 return DAG.getNode(HexagonISD::AT_PCREL, dl, PtrVT, GA);
1254 }
1255
1256 // Use GOT index.
1257 SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT);
1258 SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, HexagonII::MO_GOT);
1259 SDValue Off = DAG.getConstant(Offset, dl, MVT::i32);
1260 return DAG.getNode(HexagonISD::AT_GOT, dl, PtrVT, GOT, GA, Off);
1261}
1262
1263// Specifies that for loads and stores VT can be promoted to PromotedLdStVT.
1264SDValue
1266 const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress();
1267 SDLoc dl(Op);
1268 EVT PtrVT = getPointerTy(DAG.getDataLayout());
1269
1271 if (RM == Reloc::Static) {
1272 SDValue A = DAG.getTargetBlockAddress(BA, PtrVT);
1273 return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, A);
1274 }
1275
1277 return DAG.getNode(HexagonISD::AT_PCREL, dl, PtrVT, A);
1278}
1279
1280SDValue
1282 const {
1283 EVT PtrVT = getPointerTy(DAG.getDataLayout());
1286 return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), PtrVT, GOTSym);
1287}
1288
1289SDValue
1291 GlobalAddressSDNode *GA, SDValue Glue, EVT PtrVT, unsigned ReturnReg,
1292 unsigned char OperandFlags) const {
1294 MachineFrameInfo &MFI = MF.getFrameInfo();
1295 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
1296 SDLoc dl(GA);
1297 SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl,
1298 GA->getValueType(0),
1299 GA->getOffset(),
1300 OperandFlags);
1301 // Create Operands for the call.The Operands should have the following:
1302 // 1. Chain SDValue
1303 // 2. Callee which in this case is the Global address value.
1304 // 3. Registers live into the call.In this case its R0, as we
1305 // have just one argument to be passed.
1306 // 4. Glue.
1307 // Note: The order is important.
1308
1309 const auto &HRI = *Subtarget.getRegisterInfo();
1310 const uint32_t *Mask = HRI.getCallPreservedMask(MF, CallingConv::C);
1311 assert(Mask && "Missing call preserved mask for calling convention");
1312 SDValue Ops[] = { Chain, TGA, DAG.getRegister(Hexagon::R0, PtrVT),
1313 DAG.getRegisterMask(Mask), Glue };
1314 Chain = DAG.getNode(HexagonISD::CALL, dl, NodeTys, Ops);
1315
1316 // Inform MFI that function has calls.
1317 MFI.setAdjustsStack(true);
1318
1319 Glue = Chain.getValue(1);
1320 return DAG.getCopyFromReg(Chain, dl, ReturnReg, PtrVT, Glue);
1321}
1322
1323//
1324// Lower using the intial executable model for TLS addresses
1325//
1326SDValue
1328 SelectionDAG &DAG) const {
1329 SDLoc dl(GA);
1330 int64_t Offset = GA->getOffset();
1331 auto PtrVT = getPointerTy(DAG.getDataLayout());
1332
1333 // Get the thread pointer.
1334 SDValue TP = DAG.getCopyFromReg(DAG.getEntryNode(), dl, Hexagon::UGP, PtrVT);
1335
1336 bool IsPositionIndependent = isPositionIndependent();
1337 unsigned char TF =
1338 IsPositionIndependent ? HexagonII::MO_IEGOT : HexagonII::MO_IE;
1339
1340 // First generate the TLS symbol address
1341 SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT,
1342 Offset, TF);
1343
1344 SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA);
1345
1346 if (IsPositionIndependent) {
1347 // Generate the GOT pointer in case of position independent code
1349
1350 // Add the TLS Symbol address to GOT pointer.This gives
1351 // GOT relative relocation for the symbol.
1352 Sym = DAG.getNode(ISD::ADD, dl, PtrVT, GOT, Sym);
1353 }
1354
1355 // Load the offset value for TLS symbol.This offset is relative to
1356 // thread pointer.
1357 SDValue LoadOffset =
1358 DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Sym, MachinePointerInfo());
1359
1360 // Address of the thread local variable is the add of thread
1361 // pointer and the offset of the variable.
1362 return DAG.getNode(ISD::ADD, dl, PtrVT, TP, LoadOffset);
1363}
1364
1365//
1366// Lower using the local executable model for TLS addresses
1367//
1368SDValue
1370 SelectionDAG &DAG) const {
1371 SDLoc dl(GA);
1372 int64_t Offset = GA->getOffset();
1373 auto PtrVT = getPointerTy(DAG.getDataLayout());
1374
1375 // Get the thread pointer.
1376 SDValue TP = DAG.getCopyFromReg(DAG.getEntryNode(), dl, Hexagon::UGP, PtrVT);
1377 // Generate the TLS symbol address
1378 SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, Offset,
1380 SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA);
1381
1382 // Address of the thread local variable is the add of thread
1383 // pointer and the offset of the variable.
1384 return DAG.getNode(ISD::ADD, dl, PtrVT, TP, Sym);
1385}
1386
1387//
1388// Lower using the general dynamic model for TLS addresses
1389//
1390SDValue
1392 SelectionDAG &DAG) const {
1393 SDLoc dl(GA);
1394 int64_t Offset = GA->getOffset();
1395 auto PtrVT = getPointerTy(DAG.getDataLayout());
1396
1397 // First generate the TLS symbol address
1398 SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, Offset,
1400
1401 // Then, generate the GOT pointer
1402 SDValue GOT = LowerGLOBAL_OFFSET_TABLE(TGA, DAG);
1403
1404 // Add the TLS symbol and the GOT pointer
1405 SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA);
1406 SDValue Chain = DAG.getNode(ISD::ADD, dl, PtrVT, GOT, Sym);
1407
1408 // Copy over the argument to R0
1409 SDValue InGlue;
1410 Chain = DAG.getCopyToReg(DAG.getEntryNode(), dl, Hexagon::R0, Chain, InGlue);
1411 InGlue = Chain.getValue(1);
1412
1413 unsigned Flags = DAG.getSubtarget<HexagonSubtarget>().useLongCalls()
1416
1417 return GetDynamicTLSAddr(DAG, Chain, GA, InGlue, PtrVT,
1418 Hexagon::R0, Flags);
1419}
1420
1421//
1422// Lower TLS addresses.
1423//
1424// For now for dynamic models, we only support the general dynamic model.
1425//
1426SDValue
1428 SelectionDAG &DAG) const {
1429 GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op);
1430
1431 switch (HTM.getTLSModel(GA->getGlobal())) {
1434 return LowerToTLSGeneralDynamicModel(GA, DAG);
1436 return LowerToTLSInitialExecModel(GA, DAG);
1438 return LowerToTLSLocalExecModel(GA, DAG);
1439 }
1440 llvm_unreachable("Bogus TLS model");
1441}
1442
1443//===----------------------------------------------------------------------===//
1444// TargetLowering Implementation
1445//===----------------------------------------------------------------------===//
1446
1448 const HexagonSubtarget &ST)
1449 : TargetLowering(TM), HTM(static_cast<const HexagonTargetMachine&>(TM)),
1450 Subtarget(ST) {
1451 auto &HRI = *Subtarget.getRegisterInfo();
1452
1456 setStackPointerRegisterToSaveRestore(HRI.getStackRegister());
1459
1462
1465 else
1467
1468 // Limits for inline expansion of memcpy/memmove
1475
1476 //
1477 // Set up register classes.
1478 //
1479
1480 addRegisterClass(MVT::i1, &Hexagon::PredRegsRegClass);
1481 addRegisterClass(MVT::v2i1, &Hexagon::PredRegsRegClass); // bbbbaaaa
1482 addRegisterClass(MVT::v4i1, &Hexagon::PredRegsRegClass); // ddccbbaa
1483 addRegisterClass(MVT::v8i1, &Hexagon::PredRegsRegClass); // hgfedcba
1484 addRegisterClass(MVT::i32, &Hexagon::IntRegsRegClass);
1485 addRegisterClass(MVT::v2i16, &Hexagon::IntRegsRegClass);
1486 addRegisterClass(MVT::v4i8, &Hexagon::IntRegsRegClass);
1487 addRegisterClass(MVT::i64, &Hexagon::DoubleRegsRegClass);
1488 addRegisterClass(MVT::v8i8, &Hexagon::DoubleRegsRegClass);
1489 addRegisterClass(MVT::v4i16, &Hexagon::DoubleRegsRegClass);
1490 addRegisterClass(MVT::v2i32, &Hexagon::DoubleRegsRegClass);
1491
1492 addRegisterClass(MVT::f32, &Hexagon::IntRegsRegClass);
1493 addRegisterClass(MVT::f64, &Hexagon::DoubleRegsRegClass);
1494
1495 //
1496 // Handling of scalar operations.
1497 //
1498 // All operations default to "legal", except:
1499 // - indexed loads and stores (pre-/post-incremented),
1500 // - ANY_EXTEND_VECTOR_INREG, ATOMIC_CMP_SWAP_WITH_SUCCESS, CONCAT_VECTORS,
1501 // ConstantFP, FCEIL, FCOPYSIGN, FEXP, FEXP2, FFLOOR, FGETSIGN,
1502 // FLOG, FLOG2, FLOG10, FMAXNUM, FMINNUM, FNEARBYINT, FRINT, FROUND, TRAP,
1503 // FTRUNC, PREFETCH, SIGN_EXTEND_VECTOR_INREG, ZERO_EXTEND_VECTOR_INREG,
1504 // which default to "expand" for at least one type.
1505
1506 // Misc operations.
1509 setOperationAction(ISD::TRAP, MVT::Other, Legal);
1525
1526 // Custom legalize GlobalAddress nodes into CONST32.
1530
1531 // Hexagon needs to optimize cases with negative constants.
1535 setOperationAction(ISD::SETCC, MVT::v2i16, Custom);
1536
1537 // VASTART needs to be custom lowered to use the VarArgsFrameIndex.
1539 setOperationAction(ISD::VAEND, MVT::Other, Expand);
1540 setOperationAction(ISD::VAARG, MVT::Other, Expand);
1541 if (Subtarget.isEnvironmentMusl())
1543 else
1545
1549
1550 if (EmitJumpTables)
1552 else
1553 setMinimumJumpTableEntries(std::numeric_limits<unsigned>::max());
1554 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
1555
1556 for (unsigned LegalIntOp :
1558 setOperationAction(LegalIntOp, MVT::i32, Legal);
1559 setOperationAction(LegalIntOp, MVT::i64, Legal);
1560 }
1561
1562 // Hexagon has A4_addp_c and A4_subp_c that take and generate a carry bit,
1563 // but they only operate on i64.
1564 for (MVT VT : MVT::integer_valuetypes()) {
1571 }
1574
1579
1580 // Popcount can count # of 1s in i64 but returns i32.
1585
1590
1595
1596 for (unsigned IntExpOp :
1601 for (MVT VT : MVT::integer_valuetypes())
1602 setOperationAction(IntExpOp, VT, Expand);
1603 }
1604
1605 for (unsigned FPExpOp :
1608 for (MVT VT : MVT::fp_valuetypes())
1609 setOperationAction(FPExpOp, VT, Expand);
1610 }
1611
1612 // No extending loads from i32.
1613 for (MVT VT : MVT::integer_valuetypes()) {
1614 setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i32, Expand);
1615 setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i32, Expand);
1616 setLoadExtAction(ISD::EXTLOAD, VT, MVT::i32, Expand);
1617 }
1618 // Turn FP truncstore into trunc + store.
1619 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
1620 // Turn FP extload into load/fpextend.
1621 for (MVT VT : MVT::fp_valuetypes())
1622 setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand);
1623
1624 // Expand BR_CC and SELECT_CC for all integer and fp types.
1625 for (MVT VT : MVT::integer_valuetypes()) {
1628 }
1629 for (MVT VT : MVT::fp_valuetypes()) {
1632 }
1633 setOperationAction(ISD::BR_CC, MVT::Other, Expand);
1634
1635 //
1636 // Handling of vector operations.
1637 //
1638
1639 // Set the action for vector operations to "expand", then override it with
1640 // either "custom" or "legal" for specific cases.
1641 static const unsigned VectExpOps[] = {
1642 // Integer arithmetic:
1646 // Logical/bit:
1649 // Floating point arithmetic/math functions:
1656 // Misc:
1658 // Vector:
1664 };
1665
1667 for (unsigned VectExpOp : VectExpOps)
1668 setOperationAction(VectExpOp, VT, Expand);
1669
1670 // Expand all extending loads and truncating stores:
1671 for (MVT TargetVT : MVT::fixedlen_vector_valuetypes()) {
1672 if (TargetVT == VT)
1673 continue;
1674 setLoadExtAction(ISD::EXTLOAD, TargetVT, VT, Expand);
1675 setLoadExtAction(ISD::ZEXTLOAD, TargetVT, VT, Expand);
1676 setLoadExtAction(ISD::SEXTLOAD, TargetVT, VT, Expand);
1677 setTruncStoreAction(VT, TargetVT, Expand);
1678 }
1679
1680 // Normalize all inputs to SELECT to be vectors of i32.
1681 if (VT.getVectorElementType() != MVT::i32) {
1682 MVT VT32 = MVT::getVectorVT(MVT::i32, VT.getSizeInBits()/32);
1684 AddPromotedToType(ISD::SELECT, VT, VT32);
1685 }
1689 }
1690
1691 // Extending loads from (native) vectors of i8 into (native) vectors of i16
1692 // are legal.
1693 setLoadExtAction(ISD::EXTLOAD, MVT::v2i16, MVT::v2i8, Legal);
1694 setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i16, MVT::v2i8, Legal);
1695 setLoadExtAction(ISD::SEXTLOAD, MVT::v2i16, MVT::v2i8, Legal);
1696 setLoadExtAction(ISD::EXTLOAD, MVT::v4i16, MVT::v4i8, Legal);
1697 setLoadExtAction(ISD::ZEXTLOAD, MVT::v4i16, MVT::v4i8, Legal);
1698 setLoadExtAction(ISD::SEXTLOAD, MVT::v4i16, MVT::v4i8, Legal);
1699
1703
1704 // Types natively supported:
1705 for (MVT NativeVT : {MVT::v8i1, MVT::v4i1, MVT::v2i1, MVT::v4i8,
1706 MVT::v8i8, MVT::v2i16, MVT::v4i16, MVT::v2i32}) {
1713
1714 setOperationAction(ISD::ADD, NativeVT, Legal);
1715 setOperationAction(ISD::SUB, NativeVT, Legal);
1716 setOperationAction(ISD::MUL, NativeVT, Legal);
1717 setOperationAction(ISD::AND, NativeVT, Legal);
1718 setOperationAction(ISD::OR, NativeVT, Legal);
1719 setOperationAction(ISD::XOR, NativeVT, Legal);
1720
1721 if (NativeVT.getVectorElementType() != MVT::i1) {
1725 }
1726 }
1727
1728 for (MVT VT : {MVT::v8i8, MVT::v4i16, MVT::v2i32}) {
1733 }
1734
1735 // Custom lower unaligned loads.
1736 // Also, for both loads and stores, verify the alignment of the address
1737 // in case it is a compile-time constant. This is a usability feature to
1738 // provide a meaningful error message to users.
1739 for (MVT VT : {MVT::i16, MVT::i32, MVT::v4i8, MVT::i64, MVT::v8i8,
1740 MVT::v2i16, MVT::v4i16, MVT::v2i32}) {
1743 }
1744
1745 // Custom-lower load/stores of boolean vectors.
1746 for (MVT VT : {MVT::v2i1, MVT::v4i1, MVT::v8i1}) {
1749 }
1750
1751 // Normalize integer compares to EQ/GT/UGT
1752 for (MVT VT : {MVT::v2i16, MVT::v4i8, MVT::v8i8, MVT::v2i32, MVT::v4i16,
1753 MVT::v2i32}) {
1761 }
1762
1763 // Normalize boolean compares to [U]LE/[U]LT
1764 for (MVT VT : {MVT::i1, MVT::v2i1, MVT::v4i1, MVT::v8i1}) {
1769 }
1770
1771 // Custom-lower bitcasts from i8 to v8i1.
1773 setOperationAction(ISD::SETCC, MVT::v2i16, Custom);
1779
1780 // V5+.
1786
1789
1802
1803 // Special handling for half-precision floating point conversions.
1804 // Lower half float conversions into library calls.
1809
1810 setLoadExtAction(ISD::EXTLOAD, MVT::f32, MVT::f16, Expand);
1811 setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f16, Expand);
1812 setTruncStoreAction(MVT::f32, MVT::f16, Expand);
1813 setTruncStoreAction(MVT::f64, MVT::f16, Expand);
1814
1815 // Handling of indexed loads/stores: default is "expand".
1816 //
1817 for (MVT VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i64, MVT::f32, MVT::f64,
1818 MVT::v2i16, MVT::v2i32, MVT::v4i8, MVT::v4i16, MVT::v8i8}) {
1821 }
1822
1823 // Subtarget-specific operation actions.
1824 //
1825 if (Subtarget.hasV60Ops()) {
1830 }
1831 if (Subtarget.hasV66Ops()) {
1834 }
1835 if (Subtarget.hasV67Ops()) {
1839 }
1840
1844
1845 if (Subtarget.useHVXOps())
1846 initializeHVXLowering();
1847
1849
1850 //
1851 // Library calls for unsupported operations
1852 //
1853 bool FastMath = EnableFastMath;
1854
1855 setLibcallName(RTLIB::SDIV_I32, "__hexagon_divsi3");
1856 setLibcallName(RTLIB::SDIV_I64, "__hexagon_divdi3");
1857 setLibcallName(RTLIB::UDIV_I32, "__hexagon_udivsi3");
1858 setLibcallName(RTLIB::UDIV_I64, "__hexagon_udivdi3");
1859 setLibcallName(RTLIB::SREM_I32, "__hexagon_modsi3");
1860 setLibcallName(RTLIB::SREM_I64, "__hexagon_moddi3");
1861 setLibcallName(RTLIB::UREM_I32, "__hexagon_umodsi3");
1862 setLibcallName(RTLIB::UREM_I64, "__hexagon_umoddi3");
1863
1864 // This is the only fast library function for sqrtd.
1865 if (FastMath)
1866 setLibcallName(RTLIB::SQRT_F64, "__hexagon_fast2_sqrtdf2");
1867
1868 // Prefix is: nothing for "slow-math",
1869 // "fast2_" for V5+ fast-math double-precision
1870 // (actually, keep fast-math and fast-math2 separate for now)
1871 if (FastMath) {
1872 setLibcallName(RTLIB::ADD_F64, "__hexagon_fast_adddf3");
1873 setLibcallName(RTLIB::SUB_F64, "__hexagon_fast_subdf3");
1874 setLibcallName(RTLIB::MUL_F64, "__hexagon_fast_muldf3");
1875 setLibcallName(RTLIB::DIV_F64, "__hexagon_fast_divdf3");
1876 setLibcallName(RTLIB::DIV_F32, "__hexagon_fast_divsf3");
1877 } else {
1878 setLibcallName(RTLIB::ADD_F64, "__hexagon_adddf3");
1879 setLibcallName(RTLIB::SUB_F64, "__hexagon_subdf3");
1880 setLibcallName(RTLIB::MUL_F64, "__hexagon_muldf3");
1881 setLibcallName(RTLIB::DIV_F64, "__hexagon_divdf3");
1882 setLibcallName(RTLIB::DIV_F32, "__hexagon_divsf3");
1883 }
1884
1885 if (FastMath)
1886 setLibcallName(RTLIB::SQRT_F32, "__hexagon_fast2_sqrtf");
1887 else
1888 setLibcallName(RTLIB::SQRT_F32, "__hexagon_sqrtf");
1889
1890 // Routines to handle fp16 storage type.
1891 setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
1892 setLibcallName(RTLIB::FPROUND_F64_F16, "__truncdfhf2");
1893 setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
1894}
1895
1896const char* HexagonTargetLowering::getTargetNodeName(unsigned Opcode) const {
1897 switch ((HexagonISD::NodeType)Opcode) {
1898 case HexagonISD::ADDC: return "HexagonISD::ADDC";
1899 case HexagonISD::SUBC: return "HexagonISD::SUBC";
1900 case HexagonISD::ALLOCA: return "HexagonISD::ALLOCA";
1901 case HexagonISD::AT_GOT: return "HexagonISD::AT_GOT";
1902 case HexagonISD::AT_PCREL: return "HexagonISD::AT_PCREL";
1903 case HexagonISD::BARRIER: return "HexagonISD::BARRIER";
1904 case HexagonISD::CALL: return "HexagonISD::CALL";
1905 case HexagonISD::CALLnr: return "HexagonISD::CALLnr";
1906 case HexagonISD::CALLR: return "HexagonISD::CALLR";
1907 case HexagonISD::COMBINE: return "HexagonISD::COMBINE";
1908 case HexagonISD::CONST32_GP: return "HexagonISD::CONST32_GP";
1909 case HexagonISD::CONST32: return "HexagonISD::CONST32";
1910 case HexagonISD::CP: return "HexagonISD::CP";
1911 case HexagonISD::DCFETCH: return "HexagonISD::DCFETCH";
1912 case HexagonISD::EH_RETURN: return "HexagonISD::EH_RETURN";
1913 case HexagonISD::TSTBIT: return "HexagonISD::TSTBIT";
1914 case HexagonISD::EXTRACTU: return "HexagonISD::EXTRACTU";
1915 case HexagonISD::INSERT: return "HexagonISD::INSERT";
1916 case HexagonISD::JT: return "HexagonISD::JT";
1917 case HexagonISD::RET_GLUE: return "HexagonISD::RET_GLUE";
1918 case HexagonISD::TC_RETURN: return "HexagonISD::TC_RETURN";
1919 case HexagonISD::VASL: return "HexagonISD::VASL";
1920 case HexagonISD::VASR: return "HexagonISD::VASR";
1921 case HexagonISD::VLSR: return "HexagonISD::VLSR";
1922 case HexagonISD::MFSHL: return "HexagonISD::MFSHL";
1923 case HexagonISD::MFSHR: return "HexagonISD::MFSHR";
1924 case HexagonISD::SSAT: return "HexagonISD::SSAT";
1925 case HexagonISD::USAT: return "HexagonISD::USAT";
1926 case HexagonISD::SMUL_LOHI: return "HexagonISD::SMUL_LOHI";
1927 case HexagonISD::UMUL_LOHI: return "HexagonISD::UMUL_LOHI";
1928 case HexagonISD::USMUL_LOHI: return "HexagonISD::USMUL_LOHI";
1929 case HexagonISD::VEXTRACTW: return "HexagonISD::VEXTRACTW";
1930 case HexagonISD::VINSERTW0: return "HexagonISD::VINSERTW0";
1931 case HexagonISD::VROR: return "HexagonISD::VROR";
1932 case HexagonISD::READCYCLE: return "HexagonISD::READCYCLE";
1933 case HexagonISD::READTIMER: return "HexagonISD::READTIMER";
1934 case HexagonISD::PTRUE: return "HexagonISD::PTRUE";
1935 case HexagonISD::PFALSE: return "HexagonISD::PFALSE";
1936 case HexagonISD::D2P: return "HexagonISD::D2P";
1937 case HexagonISD::P2D: return "HexagonISD::P2D";
1938 case HexagonISD::V2Q: return "HexagonISD::V2Q";
1939 case HexagonISD::Q2V: return "HexagonISD::Q2V";
1940 case HexagonISD::QCAT: return "HexagonISD::QCAT";
1941 case HexagonISD::QTRUE: return "HexagonISD::QTRUE";
1942 case HexagonISD::QFALSE: return "HexagonISD::QFALSE";
1943 case HexagonISD::TL_EXTEND: return "HexagonISD::TL_EXTEND";
1944 case HexagonISD::TL_TRUNCATE: return "HexagonISD::TL_TRUNCATE";
1945 case HexagonISD::TYPECAST: return "HexagonISD::TYPECAST";
1946 case HexagonISD::VALIGN: return "HexagonISD::VALIGN";
1947 case HexagonISD::VALIGNADDR: return "HexagonISD::VALIGNADDR";
1948 case HexagonISD::ISEL: return "HexagonISD::ISEL";
1949 case HexagonISD::OP_END: break;
1950 }
1951 return nullptr;
1952}
1953
1954bool
1955HexagonTargetLowering::validateConstPtrAlignment(SDValue Ptr, Align NeedAlign,
1956 const SDLoc &dl, SelectionDAG &DAG) const {
1957 auto *CA = dyn_cast<ConstantSDNode>(Ptr);
1958 if (!CA)
1959 return true;
1960 unsigned Addr = CA->getZExtValue();
1961 Align HaveAlign =
1962 Addr != 0 ? Align(1ull << llvm::countr_zero(Addr)) : NeedAlign;
1963 if (HaveAlign >= NeedAlign)
1964 return true;
1965
1966 static int DK_MisalignedTrap = llvm::getNextAvailablePluginDiagnosticKind();
1967
1968 struct DiagnosticInfoMisalignedTrap : public DiagnosticInfo {
1969 DiagnosticInfoMisalignedTrap(StringRef M)
1970 : DiagnosticInfo(DK_MisalignedTrap, DS_Remark), Msg(M) {}
1971 void print(DiagnosticPrinter &DP) const override {
1972 DP << Msg;
1973 }
1974 static bool classof(const DiagnosticInfo *DI) {
1975 return DI->getKind() == DK_MisalignedTrap;
1976 }
1977 StringRef Msg;
1978 };
1979
1980 std::string ErrMsg;
1981 raw_string_ostream O(ErrMsg);
1982 O << "Misaligned constant address: " << format_hex(Addr, 10)
1983 << " has alignment " << HaveAlign.value()
1984 << ", but the memory access requires " << NeedAlign.value();
1985 if (DebugLoc DL = dl.getDebugLoc())
1986 DL.print(O << ", at ");
1987 O << ". The instruction has been replaced with a trap.";
1988
1989 DAG.getContext()->diagnose(DiagnosticInfoMisalignedTrap(O.str()));
1990 return false;
1991}
1992
1993SDValue
1994HexagonTargetLowering::replaceMemWithUndef(SDValue Op, SelectionDAG &DAG)
1995 const {
1996 const SDLoc &dl(Op);
1997 auto *LS = cast<LSBaseSDNode>(Op.getNode());
1998 assert(!LS->isIndexed() && "Not expecting indexed ops on constant address");
1999
2000 SDValue Chain = LS->getChain();
2001 SDValue Trap = DAG.getNode(ISD::TRAP, dl, MVT::Other, Chain);
2002 if (LS->getOpcode() == ISD::LOAD)
2003 return DAG.getMergeValues({DAG.getUNDEF(ty(Op)), Trap}, dl);
2004 return Trap;
2005}
2006
2007// Bit-reverse Load Intrinsic: Check if the instruction is a bit reverse load
2008// intrinsic.
2009static bool isBrevLdIntrinsic(const Value *Inst) {
2010 unsigned ID = cast<IntrinsicInst>(Inst)->getIntrinsicID();
2011 return (ID == Intrinsic::hexagon_L2_loadrd_pbr ||
2012 ID == Intrinsic::hexagon_L2_loadri_pbr ||
2013 ID == Intrinsic::hexagon_L2_loadrh_pbr ||
2014 ID == Intrinsic::hexagon_L2_loadruh_pbr ||
2015 ID == Intrinsic::hexagon_L2_loadrb_pbr ||
2016 ID == Intrinsic::hexagon_L2_loadrub_pbr);
2017}
2018
2019// Bit-reverse Load Intrinsic :Crawl up and figure out the object from previous
2020// instruction. So far we only handle bitcast, extract value and bit reverse
2021// load intrinsic instructions. Should we handle CGEP ?
2023 if (Operator::getOpcode(V) == Instruction::ExtractValue ||
2024 Operator::getOpcode(V) == Instruction::BitCast)
2025 V = cast<Operator>(V)->getOperand(0);
2026 else if (isa<IntrinsicInst>(V) && isBrevLdIntrinsic(V))
2027 V = cast<Instruction>(V)->getOperand(0);
2028 return V;
2029}
2030
2031// Bit-reverse Load Intrinsic: For a PHI Node return either an incoming edge or
2032// a back edge. If the back edge comes from the intrinsic itself, the incoming
2033// edge is returned.
2034static Value *returnEdge(const PHINode *PN, Value *IntrBaseVal) {
2035 const BasicBlock *Parent = PN->getParent();
2036 int Idx = -1;
2037 for (unsigned i = 0, e = PN->getNumIncomingValues(); i < e; ++i) {
2038 BasicBlock *Blk = PN->getIncomingBlock(i);
2039 // Determine if the back edge is originated from intrinsic.
2040 if (Blk == Parent) {
2041 Value *BackEdgeVal = PN->getIncomingValue(i);
2042 Value *BaseVal;
2043 // Loop over till we return the same Value or we hit the IntrBaseVal.
2044 do {
2045 BaseVal = BackEdgeVal;
2046 BackEdgeVal = getBrevLdObject(BackEdgeVal);
2047 } while ((BaseVal != BackEdgeVal) && (IntrBaseVal != BackEdgeVal));
2048 // If the getBrevLdObject returns IntrBaseVal, we should return the
2049 // incoming edge.
2050 if (IntrBaseVal == BackEdgeVal)
2051 continue;
2052 Idx = i;
2053 break;
2054 } else // Set the node to incoming edge.
2055 Idx = i;
2056 }
2057 assert(Idx >= 0 && "Unexpected index to incoming argument in PHI");
2058 return PN->getIncomingValue(Idx);
2059}
2060
2061// Bit-reverse Load Intrinsic: Figure out the underlying object the base
2062// pointer points to, for the bit-reverse load intrinsic. Setting this to
2063// memoperand might help alias analysis to figure out the dependencies.
2065 Value *IntrBaseVal = V;
2066 Value *BaseVal;
2067 // Loop over till we return the same Value, implies we either figure out
2068 // the object or we hit a PHI
2069 do {
2070 BaseVal = V;
2071 V = getBrevLdObject(V);
2072 } while (BaseVal != V);
2073
2074 // Identify the object from PHINode.
2075 if (const PHINode *PN = dyn_cast<PHINode>(V))
2076 return returnEdge(PN, IntrBaseVal);
2077 // For non PHI nodes, the object is the last value returned by getBrevLdObject
2078 else
2079 return V;
2080}
2081
2082/// Given an intrinsic, checks if on the target the intrinsic will need to map
2083/// to a MemIntrinsicNode (touches memory). If this is the case, it returns
2084/// true and store the intrinsic information into the IntrinsicInfo that was
2085/// passed to the function.
2087 const CallInst &I,
2088 MachineFunction &MF,
2089 unsigned Intrinsic) const {
2090 switch (Intrinsic) {
2091 case Intrinsic::hexagon_L2_loadrd_pbr:
2092 case Intrinsic::hexagon_L2_loadri_pbr:
2093 case Intrinsic::hexagon_L2_loadrh_pbr:
2094 case Intrinsic::hexagon_L2_loadruh_pbr:
2095 case Intrinsic::hexagon_L2_loadrb_pbr:
2096 case Intrinsic::hexagon_L2_loadrub_pbr: {
2098 auto &DL = I.getDataLayout();
2099 auto &Cont = I.getCalledFunction()->getParent()->getContext();
2100 // The intrinsic function call is of the form { ElTy, i8* }
2101 // @llvm.hexagon.L2.loadXX.pbr(i8*, i32). The pointer and memory access type
2102 // should be derived from ElTy.
2103 Type *ElTy = I.getCalledFunction()->getReturnType()->getStructElementType(0);
2104 Info.memVT = MVT::getVT(ElTy);
2105 llvm::Value *BasePtrVal = I.getOperand(0);
2106 Info.ptrVal = getUnderLyingObjectForBrevLdIntr(BasePtrVal);
2107 // The offset value comes through Modifier register. For now, assume the
2108 // offset is 0.
2109 Info.offset = 0;
2110 Info.align = DL.getABITypeAlign(Info.memVT.getTypeForEVT(Cont));
2112 return true;
2113 }
2114 case Intrinsic::hexagon_V6_vgathermw:
2115 case Intrinsic::hexagon_V6_vgathermw_128B:
2116 case Intrinsic::hexagon_V6_vgathermh:
2117 case Intrinsic::hexagon_V6_vgathermh_128B:
2118 case Intrinsic::hexagon_V6_vgathermhw:
2119 case Intrinsic::hexagon_V6_vgathermhw_128B:
2120 case Intrinsic::hexagon_V6_vgathermwq:
2121 case Intrinsic::hexagon_V6_vgathermwq_128B:
2122 case Intrinsic::hexagon_V6_vgathermhq:
2123 case Intrinsic::hexagon_V6_vgathermhq_128B:
2124 case Intrinsic::hexagon_V6_vgathermhwq:
2125 case Intrinsic::hexagon_V6_vgathermhwq_128B: {
2126 const Module &M = *I.getParent()->getParent()->getParent();
2128 Type *VecTy = I.getArgOperand(1)->getType();
2129 Info.memVT = MVT::getVT(VecTy);
2130 Info.ptrVal = I.getArgOperand(0);
2131 Info.offset = 0;
2132 Info.align =
2133 MaybeAlign(M.getDataLayout().getTypeAllocSizeInBits(VecTy) / 8);
2137 return true;
2138 }
2139 default:
2140 break;
2141 }
2142 return false;
2143}
2144
2146 return X.getValueType().isScalarInteger(); // 'tstbit'
2147}
2148
2150 return isTruncateFree(EVT::getEVT(Ty1), EVT::getEVT(Ty2));
2151}
2152
2154 if (!VT1.isSimple() || !VT2.isSimple())
2155 return false;
2156 return VT1.getSimpleVT() == MVT::i64 && VT2.getSimpleVT() == MVT::i32;
2157}
2158
2160 const MachineFunction &MF, EVT VT) const {
2162}
2163
2164// Should we expand the build vector with shuffles?
2166 unsigned DefinedValues) const {
2167 return false;
2168}
2169
2171 unsigned Index) const {
2173 if (!ResVT.isSimple() || !SrcVT.isSimple())
2174 return false;
2175
2176 MVT ResTy = ResVT.getSimpleVT(), SrcTy = SrcVT.getSimpleVT();
2177 if (ResTy.getVectorElementType() != MVT::i1)
2178 return true;
2179
2180 // Non-HVX bool vectors are relatively cheap.
2181 return SrcTy.getVectorNumElements() <= 8;
2182}
2183
2185 return Op.getOpcode() == ISD::CONCAT_VECTORS ||
2187}
2188
2190 EVT VT) const {
2191 return true;
2192}
2193
2196 unsigned VecLen = VT.getVectorMinNumElements();
2197 MVT ElemTy = VT.getVectorElementType();
2198
2199 if (VecLen == 1 || VT.isScalableVector())
2201
2202 if (Subtarget.useHVXOps()) {
2203 unsigned Action = getPreferredHvxVectorAction(VT);
2204 if (Action != ~0u)
2205 return static_cast<TargetLoweringBase::LegalizeTypeAction>(Action);
2206 }
2207
2208 // Always widen (remaining) vectors of i1.
2209 if (ElemTy == MVT::i1)
2211 // Widen non-power-of-2 vectors. Such types cannot be split right now,
2212 // and computeRegisterProperties will override "split" with "widen",
2213 // which can cause other issues.
2214 if (!isPowerOf2_32(VecLen))
2216
2218}
2219
2222 if (Subtarget.useHVXOps()) {
2223 unsigned Action = getCustomHvxOperationAction(Op);
2224 if (Action != ~0u)
2225 return static_cast<TargetLoweringBase::LegalizeAction>(Action);
2226 }
2228}
2229
2230std::pair<SDValue, int>
2231HexagonTargetLowering::getBaseAndOffset(SDValue Addr) const {
2232 if (Addr.getOpcode() == ISD::ADD) {
2233 SDValue Op1 = Addr.getOperand(1);
2234 if (auto *CN = dyn_cast<const ConstantSDNode>(Op1.getNode()))
2235 return { Addr.getOperand(0), CN->getSExtValue() };
2236 }
2237 return { Addr, 0 };
2238}
2239
2240// Lower a vector shuffle (V1, V2, V3). V1 and V2 are the two vectors
2241// to select data from, V3 is the permutation.
2242SDValue
2244 const {
2245 const auto *SVN = cast<ShuffleVectorSDNode>(Op);
2246 ArrayRef<int> AM = SVN->getMask();
2247 assert(AM.size() <= 8 && "Unexpected shuffle mask");
2248 unsigned VecLen = AM.size();
2249
2250 MVT VecTy = ty(Op);
2251 assert(!Subtarget.isHVXVectorType(VecTy, true) &&
2252 "HVX shuffles should be legal");
2253 assert(VecTy.getSizeInBits() <= 64 && "Unexpected vector length");
2254
2255 SDValue Op0 = Op.getOperand(0);
2256 SDValue Op1 = Op.getOperand(1);
2257 const SDLoc &dl(Op);
2258
2259 // If the inputs are not the same as the output, bail. This is not an
2260 // error situation, but complicates the handling and the default expansion
2261 // (into BUILD_VECTOR) should be adequate.
2262 if (ty(Op0) != VecTy || ty(Op1) != VecTy)
2263 return SDValue();
2264
2265 // Normalize the mask so that the first non-negative index comes from
2266 // the first operand.
2267 SmallVector<int, 8> Mask(AM);
2268 unsigned F = llvm::find_if(AM, [](int M) { return M >= 0; }) - AM.data();
2269 if (F == AM.size())
2270 return DAG.getUNDEF(VecTy);
2271 if (AM[F] >= int(VecLen)) {
2273 std::swap(Op0, Op1);
2274 }
2275
2276 // Express the shuffle mask in terms of bytes.
2277 SmallVector<int,8> ByteMask;
2278 unsigned ElemBytes = VecTy.getVectorElementType().getSizeInBits() / 8;
2279 for (int M : Mask) {
2280 if (M < 0) {
2281 for (unsigned j = 0; j != ElemBytes; ++j)
2282 ByteMask.push_back(-1);
2283 } else {
2284 for (unsigned j = 0; j != ElemBytes; ++j)
2285 ByteMask.push_back(M*ElemBytes + j);
2286 }
2287 }
2288 assert(ByteMask.size() <= 8);
2289
2290 // All non-undef (non-negative) indexes are well within [0..127], so they
2291 // fit in a single byte. Build two 64-bit words:
2292 // - MaskIdx where each byte is the corresponding index (for non-negative
2293 // indexes), and 0xFF for negative indexes, and
2294 // - MaskUnd that has 0xFF for each negative index.
2295 uint64_t MaskIdx = 0;
2296 uint64_t MaskUnd = 0;
2297 for (unsigned i = 0, e = ByteMask.size(); i != e; ++i) {
2298 unsigned S = 8*i;
2299 uint64_t M = ByteMask[i] & 0xFF;
2300 if (M == 0xFF)
2301 MaskUnd |= M << S;
2302 MaskIdx |= M << S;
2303 }
2304
2305 if (ByteMask.size() == 4) {
2306 // Identity.
2307 if (MaskIdx == (0x03020100 | MaskUnd))
2308 return Op0;
2309 // Byte swap.
2310 if (MaskIdx == (0x00010203 | MaskUnd)) {
2311 SDValue T0 = DAG.getBitcast(MVT::i32, Op0);
2312 SDValue T1 = DAG.getNode(ISD::BSWAP, dl, MVT::i32, T0);
2313 return DAG.getBitcast(VecTy, T1);
2314 }
2315
2316 // Byte packs.
2317 SDValue Concat10 =
2318 getCombine(Op1, Op0, dl, typeJoin({ty(Op1), ty(Op0)}), DAG);
2319 if (MaskIdx == (0x06040200 | MaskUnd))
2320 return getInstr(Hexagon::S2_vtrunehb, dl, VecTy, {Concat10}, DAG);
2321 if (MaskIdx == (0x07050301 | MaskUnd))
2322 return getInstr(Hexagon::S2_vtrunohb, dl, VecTy, {Concat10}, DAG);
2323
2324 SDValue Concat01 =
2325 getCombine(Op0, Op1, dl, typeJoin({ty(Op0), ty(Op1)}), DAG);
2326 if (MaskIdx == (0x02000604 | MaskUnd))
2327 return getInstr(Hexagon::S2_vtrunehb, dl, VecTy, {Concat01}, DAG);
2328 if (MaskIdx == (0x03010705 | MaskUnd))
2329 return getInstr(Hexagon::S2_vtrunohb, dl, VecTy, {Concat01}, DAG);
2330 }
2331
2332 if (ByteMask.size() == 8) {
2333 // Identity.
2334 if (MaskIdx == (0x0706050403020100ull | MaskUnd))
2335 return Op0;
2336 // Byte swap.
2337 if (MaskIdx == (0x0001020304050607ull | MaskUnd)) {
2338 SDValue T0 = DAG.getBitcast(MVT::i64, Op0);
2339 SDValue T1 = DAG.getNode(ISD::BSWAP, dl, MVT::i64, T0);
2340 return DAG.getBitcast(VecTy, T1);
2341 }
2342
2343 // Halfword picks.
2344 if (MaskIdx == (0x0d0c050409080100ull | MaskUnd))
2345 return getInstr(Hexagon::S2_shuffeh, dl, VecTy, {Op1, Op0}, DAG);
2346 if (MaskIdx == (0x0f0e07060b0a0302ull | MaskUnd))
2347 return getInstr(Hexagon::S2_shuffoh, dl, VecTy, {Op1, Op0}, DAG);
2348 if (MaskIdx == (0x0d0c090805040100ull | MaskUnd))
2349 return getInstr(Hexagon::S2_vtrunewh, dl, VecTy, {Op1, Op0}, DAG);
2350 if (MaskIdx == (0x0f0e0b0a07060302ull | MaskUnd))
2351 return getInstr(Hexagon::S2_vtrunowh, dl, VecTy, {Op1, Op0}, DAG);
2352 if (MaskIdx == (0x0706030205040100ull | MaskUnd)) {
2353 VectorPair P = opSplit(Op0, dl, DAG);
2354 return getInstr(Hexagon::S2_packhl, dl, VecTy, {P.second, P.first}, DAG);
2355 }
2356
2357 // Byte packs.
2358 if (MaskIdx == (0x0e060c040a020800ull | MaskUnd))
2359 return getInstr(Hexagon::S2_shuffeb, dl, VecTy, {Op1, Op0}, DAG);
2360 if (MaskIdx == (0x0f070d050b030901ull | MaskUnd))
2361 return getInstr(Hexagon::S2_shuffob, dl, VecTy, {Op1, Op0}, DAG);
2362 }
2363
2364 return SDValue();
2365}
2366
2367SDValue
2368HexagonTargetLowering::getSplatValue(SDValue Op, SelectionDAG &DAG) const {
2369 switch (Op.getOpcode()) {
2370 case ISD::BUILD_VECTOR:
2371 if (SDValue S = cast<BuildVectorSDNode>(Op)->getSplatValue())
2372 return S;
2373 break;
2374 case ISD::SPLAT_VECTOR:
2375 return Op.getOperand(0);
2376 }
2377 return SDValue();
2378}
2379
2380// Create a Hexagon-specific node for shifting a vector by an integer.
2381SDValue
2382HexagonTargetLowering::getVectorShiftByInt(SDValue Op, SelectionDAG &DAG)
2383 const {
2384 unsigned NewOpc;
2385 switch (Op.getOpcode()) {
2386 case ISD::SHL:
2387 NewOpc = HexagonISD::VASL;
2388 break;
2389 case ISD::SRA:
2390 NewOpc = HexagonISD::VASR;
2391 break;
2392 case ISD::SRL:
2393 NewOpc = HexagonISD::VLSR;
2394 break;
2395 default:
2396 llvm_unreachable("Unexpected shift opcode");
2397 }
2398
2399 if (SDValue Sp = getSplatValue(Op.getOperand(1), DAG))
2400 return DAG.getNode(NewOpc, SDLoc(Op), ty(Op), Op.getOperand(0), Sp);
2401 return SDValue();
2402}
2403
2404SDValue
2406 const SDLoc &dl(Op);
2407
2408 // First try to convert the shift (by vector) to a shift by a scalar.
2409 // If we first split the shift, the shift amount will become 'extract
2410 // subvector', and will no longer be recognized as scalar.
2411 SDValue Res = Op;
2412 if (SDValue S = getVectorShiftByInt(Op, DAG))
2413 Res = S;
2414
2415 unsigned Opc = Res.getOpcode();
2416 switch (Opc) {
2417 case HexagonISD::VASR:
2418 case HexagonISD::VLSR:
2419 case HexagonISD::VASL:
2420 break;
2421 default:
2422 // No instructions for shifts by non-scalars.
2423 return SDValue();
2424 }
2425
2426 MVT ResTy = ty(Res);
2427 if (ResTy.getVectorElementType() != MVT::i8)
2428 return Res;
2429
2430 // For shifts of i8, extend the inputs to i16, then truncate back to i8.
2431 assert(ResTy.getVectorElementType() == MVT::i8);
2432 SDValue Val = Res.getOperand(0), Amt = Res.getOperand(1);
2433
2434 auto ShiftPartI8 = [&dl, &DAG, this](unsigned Opc, SDValue V, SDValue A) {
2435 MVT Ty = ty(V);
2436 MVT ExtTy = MVT::getVectorVT(MVT::i16, Ty.getVectorNumElements());
2437 SDValue ExtV = Opc == HexagonISD::VASR ? DAG.getSExtOrTrunc(V, dl, ExtTy)
2438 : DAG.getZExtOrTrunc(V, dl, ExtTy);
2439 SDValue ExtS = DAG.getNode(Opc, dl, ExtTy, {ExtV, A});
2440 return DAG.getZExtOrTrunc(ExtS, dl, Ty);
2441 };
2442
2443 if (ResTy.getSizeInBits() == 32)
2444 return ShiftPartI8(Opc, Val, Amt);
2445
2446 auto [LoV, HiV] = opSplit(Val, dl, DAG);
2447 return DAG.getNode(ISD::CONCAT_VECTORS, dl, ResTy,
2448 {ShiftPartI8(Opc, LoV, Amt), ShiftPartI8(Opc, HiV, Amt)});
2449}
2450
2451SDValue
2453 if (isa<ConstantSDNode>(Op.getOperand(1).getNode()))
2454 return Op;
2455 return SDValue();
2456}
2457
2458SDValue
2460 MVT ResTy = ty(Op);
2461 SDValue InpV = Op.getOperand(0);
2462 MVT InpTy = ty(InpV);
2463 assert(ResTy.getSizeInBits() == InpTy.getSizeInBits());
2464 const SDLoc &dl(Op);
2465
2466 // Handle conversion from i8 to v8i1.
2467 if (InpTy == MVT::i8) {
2468 if (ResTy == MVT::v8i1) {
2469 SDValue Sc = DAG.getBitcast(tyScalar(InpTy), InpV);
2470 SDValue Ext = DAG.getZExtOrTrunc(Sc, dl, MVT::i32);
2471 return getInstr(Hexagon::C2_tfrrp, dl, ResTy, Ext, DAG);
2472 }
2473 return SDValue();
2474 }
2475
2476 return Op;
2477}
2478
2479bool
2480HexagonTargetLowering::getBuildVectorConstInts(ArrayRef<SDValue> Values,
2481 MVT VecTy, SelectionDAG &DAG,
2482 MutableArrayRef<ConstantInt*> Consts) const {
2483 MVT ElemTy = VecTy.getVectorElementType();
2484 unsigned ElemWidth = ElemTy.getSizeInBits();
2485 IntegerType *IntTy = IntegerType::get(*DAG.getContext(), ElemWidth);
2486 bool AllConst = true;
2487
2488 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
2489 SDValue V = Values[i];
2490 if (V.isUndef()) {
2491 Consts[i] = ConstantInt::get(IntTy, 0);
2492 continue;
2493 }
2494 // Make sure to always cast to IntTy.
2495 if (auto *CN = dyn_cast<ConstantSDNode>(V.getNode())) {
2496 const ConstantInt *CI = CN->getConstantIntValue();
2497 Consts[i] = ConstantInt::get(IntTy, CI->getValue().getSExtValue());
2498 } else if (auto *CN = dyn_cast<ConstantFPSDNode>(V.getNode())) {
2499 const ConstantFP *CF = CN->getConstantFPValue();
2501 Consts[i] = ConstantInt::get(IntTy, A.getZExtValue());
2502 } else {
2503 AllConst = false;
2504 }
2505 }
2506 return AllConst;
2507}
2508
2509SDValue
2510HexagonTargetLowering::buildVector32(ArrayRef<SDValue> Elem, const SDLoc &dl,
2511 MVT VecTy, SelectionDAG &DAG) const {
2512 MVT ElemTy = VecTy.getVectorElementType();
2513 assert(VecTy.getVectorNumElements() == Elem.size());
2514
2515 SmallVector<ConstantInt*,4> Consts(Elem.size());
2516 bool AllConst = getBuildVectorConstInts(Elem, VecTy, DAG, Consts);
2517
2518 unsigned First, Num = Elem.size();
2519 for (First = 0; First != Num; ++First) {
2520 if (!isUndef(Elem[First]))
2521 break;
2522 }
2523 if (First == Num)
2524 return DAG.getUNDEF(VecTy);
2525
2526 if (AllConst &&
2527 llvm::all_of(Consts, [](ConstantInt *CI) { return CI->isZero(); }))
2528 return getZero(dl, VecTy, DAG);
2529
2530 if (ElemTy == MVT::i16 || ElemTy == MVT::f16) {
2531 assert(Elem.size() == 2);
2532 if (AllConst) {
2533 // The 'Consts' array will have all values as integers regardless
2534 // of the vector element type.
2535 uint32_t V = (Consts[0]->getZExtValue() & 0xFFFF) |
2536 Consts[1]->getZExtValue() << 16;
2537 return DAG.getBitcast(VecTy, DAG.getConstant(V, dl, MVT::i32));
2538 }
2539 SDValue E0, E1;
2540 if (ElemTy == MVT::f16) {
2541 E0 = DAG.getZExtOrTrunc(DAG.getBitcast(MVT::i16, Elem[0]), dl, MVT::i32);
2542 E1 = DAG.getZExtOrTrunc(DAG.getBitcast(MVT::i16, Elem[1]), dl, MVT::i32);
2543 } else {
2544 E0 = Elem[0];
2545 E1 = Elem[1];
2546 }
2547 SDValue N = getInstr(Hexagon::A2_combine_ll, dl, MVT::i32, {E1, E0}, DAG);
2548 return DAG.getBitcast(VecTy, N);
2549 }
2550
2551 if (ElemTy == MVT::i8) {
2552 // First try generating a constant.
2553 if (AllConst) {
2554 uint32_t V = (Consts[0]->getZExtValue() & 0xFF) |
2555 (Consts[1]->getZExtValue() & 0xFF) << 8 |
2556 (Consts[2]->getZExtValue() & 0xFF) << 16 |
2557 Consts[3]->getZExtValue() << 24;
2558 return DAG.getBitcast(MVT::v4i8, DAG.getConstant(V, dl, MVT::i32));
2559 }
2560
2561 // Then try splat.
2562 bool IsSplat = true;
2563 for (unsigned i = First+1; i != Num; ++i) {
2564 if (Elem[i] == Elem[First] || isUndef(Elem[i]))
2565 continue;
2566 IsSplat = false;
2567 break;
2568 }
2569 if (IsSplat) {
2570 // Legalize the operand of SPLAT_VECTOR.
2571 SDValue Ext = DAG.getZExtOrTrunc(Elem[First], dl, MVT::i32);
2572 return DAG.getNode(ISD::SPLAT_VECTOR, dl, VecTy, Ext);
2573 }
2574
2575 // Generate
2576 // (zxtb(Elem[0]) | (zxtb(Elem[1]) << 8)) |
2577 // (zxtb(Elem[2]) | (zxtb(Elem[3]) << 8)) << 16
2578 assert(Elem.size() == 4);
2579 SDValue Vs[4];
2580 for (unsigned i = 0; i != 4; ++i) {
2581 Vs[i] = DAG.getZExtOrTrunc(Elem[i], dl, MVT::i32);
2582 Vs[i] = DAG.getZeroExtendInReg(Vs[i], dl, MVT::i8);
2583 }
2584 SDValue S8 = DAG.getConstant(8, dl, MVT::i32);
2585 SDValue T0 = DAG.getNode(ISD::SHL, dl, MVT::i32, {Vs[1], S8});
2586 SDValue T1 = DAG.getNode(ISD::SHL, dl, MVT::i32, {Vs[3], S8});
2587 SDValue B0 = DAG.getNode(ISD::OR, dl, MVT::i32, {Vs[0], T0});
2588 SDValue B1 = DAG.getNode(ISD::OR, dl, MVT::i32, {Vs[2], T1});
2589
2590 SDValue R = getInstr(Hexagon::A2_combine_ll, dl, MVT::i32, {B1, B0}, DAG);
2591 return DAG.getBitcast(MVT::v4i8, R);
2592 }
2593
2594#ifndef NDEBUG
2595 dbgs() << "VecTy: " << VecTy << '\n';
2596#endif
2597 llvm_unreachable("Unexpected vector element type");
2598}
2599
2600SDValue
2601HexagonTargetLowering::buildVector64(ArrayRef<SDValue> Elem, const SDLoc &dl,
2602 MVT VecTy, SelectionDAG &DAG) const {
2603 MVT ElemTy = VecTy.getVectorElementType();
2604 assert(VecTy.getVectorNumElements() == Elem.size());
2605
2606 SmallVector<ConstantInt*,8> Consts(Elem.size());
2607 bool AllConst = getBuildVectorConstInts(Elem, VecTy, DAG, Consts);
2608
2609 unsigned First, Num = Elem.size();
2610 for (First = 0; First != Num; ++First) {
2611 if (!isUndef(Elem[First]))
2612 break;
2613 }
2614 if (First == Num)
2615 return DAG.getUNDEF(VecTy);
2616
2617 if (AllConst &&
2618 llvm::all_of(Consts, [](ConstantInt *CI) { return CI->isZero(); }))
2619 return getZero(dl, VecTy, DAG);
2620
2621 // First try splat if possible.
2622 if (ElemTy == MVT::i16 || ElemTy == MVT::f16) {
2623 bool IsSplat = true;
2624 for (unsigned i = First+1; i != Num; ++i) {
2625 if (Elem[i] == Elem[First] || isUndef(Elem[i]))
2626 continue;
2627 IsSplat = false;
2628 break;
2629 }
2630 if (IsSplat) {
2631 // Legalize the operand of SPLAT_VECTOR
2632 SDValue S = ElemTy == MVT::f16 ? DAG.getBitcast(MVT::i16, Elem[First])
2633 : Elem[First];
2634 SDValue Ext = DAG.getZExtOrTrunc(S, dl, MVT::i32);
2635 return DAG.getNode(ISD::SPLAT_VECTOR, dl, VecTy, Ext);
2636 }
2637 }
2638
2639 // Then try constant.
2640 if (AllConst) {
2641 uint64_t Val = 0;
2642 unsigned W = ElemTy.getSizeInBits();
2643 uint64_t Mask = (1ull << W) - 1;
2644 for (unsigned i = 0; i != Num; ++i)
2645 Val = (Val << W) | (Consts[Num-1-i]->getZExtValue() & Mask);
2646 SDValue V0 = DAG.getConstant(Val, dl, MVT::i64);
2647 return DAG.getBitcast(VecTy, V0);
2648 }
2649
2650 // Build two 32-bit vectors and concatenate.
2651 MVT HalfTy = MVT::getVectorVT(ElemTy, Num/2);
2652 SDValue L = (ElemTy == MVT::i32)
2653 ? Elem[0]
2654 : buildVector32(Elem.take_front(Num/2), dl, HalfTy, DAG);
2655 SDValue H = (ElemTy == MVT::i32)
2656 ? Elem[1]
2657 : buildVector32(Elem.drop_front(Num/2), dl, HalfTy, DAG);
2658 return getCombine(H, L, dl, VecTy, DAG);
2659}
2660
2661SDValue
2662HexagonTargetLowering::extractVector(SDValue VecV, SDValue IdxV,
2663 const SDLoc &dl, MVT ValTy, MVT ResTy,
2664 SelectionDAG &DAG) const {
2665 MVT VecTy = ty(VecV);
2666 assert(!ValTy.isVector() ||
2667 VecTy.getVectorElementType() == ValTy.getVectorElementType());
2668 if (VecTy.getVectorElementType() == MVT::i1)
2669 return extractVectorPred(VecV, IdxV, dl, ValTy, ResTy, DAG);
2670
2671 unsigned VecWidth = VecTy.getSizeInBits();
2672 unsigned ValWidth = ValTy.getSizeInBits();
2673 unsigned ElemWidth = VecTy.getVectorElementType().getSizeInBits();
2674 assert((VecWidth % ElemWidth) == 0);
2675 assert(VecWidth == 32 || VecWidth == 64);
2676
2677 // Cast everything to scalar integer types.
2678 MVT ScalarTy = tyScalar(VecTy);
2679 VecV = DAG.getBitcast(ScalarTy, VecV);
2680
2681 SDValue WidthV = DAG.getConstant(ValWidth, dl, MVT::i32);
2682 SDValue ExtV;
2683
2684 if (auto *IdxN = dyn_cast<ConstantSDNode>(IdxV)) {
2685 unsigned Off = IdxN->getZExtValue() * ElemWidth;
2686 if (VecWidth == 64 && ValWidth == 32) {
2687 assert(Off == 0 || Off == 32);
2688 ExtV = Off == 0 ? LoHalf(VecV, DAG) : HiHalf(VecV, DAG);
2689 } else if (Off == 0 && (ValWidth % 8) == 0) {
2690 ExtV = DAG.getZeroExtendInReg(VecV, dl, tyScalar(ValTy));
2691 } else {
2692 SDValue OffV = DAG.getConstant(Off, dl, MVT::i32);
2693 // The return type of EXTRACTU must be the same as the type of the
2694 // input vector.
2695 ExtV = DAG.getNode(HexagonISD::EXTRACTU, dl, ScalarTy,
2696 {VecV, WidthV, OffV});
2697 }
2698 } else {
2699 if (ty(IdxV) != MVT::i32)
2700 IdxV = DAG.getZExtOrTrunc(IdxV, dl, MVT::i32);
2701 SDValue OffV = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV,
2702 DAG.getConstant(ElemWidth, dl, MVT::i32));
2703 ExtV = DAG.getNode(HexagonISD::EXTRACTU, dl, ScalarTy,
2704 {VecV, WidthV, OffV});
2705 }
2706
2707 // Cast ExtV to the requested result type.
2708 ExtV = DAG.getZExtOrTrunc(ExtV, dl, tyScalar(ResTy));
2709 ExtV = DAG.getBitcast(ResTy, ExtV);
2710 return ExtV;
2711}
2712
2713SDValue
2714HexagonTargetLowering::extractVectorPred(SDValue VecV, SDValue IdxV,
2715 const SDLoc &dl, MVT ValTy, MVT ResTy,
2716 SelectionDAG &DAG) const {
2717 // Special case for v{8,4,2}i1 (the only boolean vectors legal in Hexagon
2718 // without any coprocessors).
2719 MVT VecTy = ty(VecV);
2720 unsigned VecWidth = VecTy.getSizeInBits();
2721 unsigned ValWidth = ValTy.getSizeInBits();
2722 assert(VecWidth == VecTy.getVectorNumElements() &&
2723 "Vector elements should equal vector width size");
2724 assert(VecWidth == 8 || VecWidth == 4 || VecWidth == 2);
2725
2726 // Check if this is an extract of the lowest bit.
2727 if (isNullConstant(IdxV) && ValTy.getSizeInBits() == 1) {
2728 // Extracting the lowest bit is a no-op, but it changes the type,
2729 // so it must be kept as an operation to avoid errors related to
2730 // type mismatches.
2731 return DAG.getNode(HexagonISD::TYPECAST, dl, MVT::i1, VecV);
2732 }
2733
2734 // If the value extracted is a single bit, use tstbit.
2735 if (ValWidth == 1) {
2736 SDValue A0 = getInstr(Hexagon::C2_tfrpr, dl, MVT::i32, {VecV}, DAG);
2737 SDValue M0 = DAG.getConstant(8 / VecWidth, dl, MVT::i32);
2738 SDValue I0 = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, M0);
2739 return DAG.getNode(HexagonISD::TSTBIT, dl, MVT::i1, A0, I0);
2740 }
2741
2742 // Each bool vector (v2i1, v4i1, v8i1) always occupies 8 bits in
2743 // a predicate register. The elements of the vector are repeated
2744 // in the register (if necessary) so that the total number is 8.
2745 // The extracted subvector will need to be expanded in such a way.
2746 unsigned Scale = VecWidth / ValWidth;
2747
2748 // Generate (p2d VecV) >> 8*Idx to move the interesting bytes to
2749 // position 0.
2750 assert(ty(IdxV) == MVT::i32);
2751 unsigned VecRep = 8 / VecWidth;
2752 SDValue S0 = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV,
2753 DAG.getConstant(8*VecRep, dl, MVT::i32));
2754 SDValue T0 = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, VecV);
2755 SDValue T1 = DAG.getNode(ISD::SRL, dl, MVT::i64, T0, S0);
2756 while (Scale > 1) {
2757 // The longest possible subvector is at most 32 bits, so it is always
2758 // contained in the low subregister.
2759 T1 = LoHalf(T1, DAG);
2760 T1 = expandPredicate(T1, dl, DAG);
2761 Scale /= 2;
2762 }
2763
2764 return DAG.getNode(HexagonISD::D2P, dl, ResTy, T1);
2765}
2766
2767SDValue
2768HexagonTargetLowering::insertVector(SDValue VecV, SDValue ValV, SDValue IdxV,
2769 const SDLoc &dl, MVT ValTy,
2770 SelectionDAG &DAG) const {
2771 MVT VecTy = ty(VecV);
2772 if (VecTy.getVectorElementType() == MVT::i1)
2773 return insertVectorPred(VecV, ValV, IdxV, dl, ValTy, DAG);
2774
2775 unsigned VecWidth = VecTy.getSizeInBits();
2776 unsigned ValWidth = ValTy.getSizeInBits();
2777 assert(VecWidth == 32 || VecWidth == 64);
2778 assert((VecWidth % ValWidth) == 0);
2779
2780 // Cast everything to scalar integer types.
2781 MVT ScalarTy = MVT::getIntegerVT(VecWidth);
2782 // The actual type of ValV may be different than ValTy (which is related
2783 // to the vector type).
2784 unsigned VW = ty(ValV).getSizeInBits();
2785 ValV = DAG.getBitcast(MVT::getIntegerVT(VW), ValV);
2786 VecV = DAG.getBitcast(ScalarTy, VecV);
2787 if (VW != VecWidth)
2788 ValV = DAG.getAnyExtOrTrunc(ValV, dl, ScalarTy);
2789
2790 SDValue WidthV = DAG.getConstant(ValWidth, dl, MVT::i32);
2791 SDValue InsV;
2792
2793 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(IdxV)) {
2794 unsigned W = C->getZExtValue() * ValWidth;
2795 SDValue OffV = DAG.getConstant(W, dl, MVT::i32);
2796 InsV = DAG.getNode(HexagonISD::INSERT, dl, ScalarTy,
2797 {VecV, ValV, WidthV, OffV});
2798 } else {
2799 if (ty(IdxV) != MVT::i32)
2800 IdxV = DAG.getZExtOrTrunc(IdxV, dl, MVT::i32);
2801 SDValue OffV = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, WidthV);
2802 InsV = DAG.getNode(HexagonISD::INSERT, dl, ScalarTy,
2803 {VecV, ValV, WidthV, OffV});
2804 }
2805
2806 return DAG.getNode(ISD::BITCAST, dl, VecTy, InsV);
2807}
2808
2809SDValue
2810HexagonTargetLowering::insertVectorPred(SDValue VecV, SDValue ValV,
2811 SDValue IdxV, const SDLoc &dl,
2812 MVT ValTy, SelectionDAG &DAG) const {
2813 MVT VecTy = ty(VecV);
2814 unsigned VecLen = VecTy.getVectorNumElements();
2815
2816 if (ValTy == MVT::i1) {
2817 SDValue ToReg = getInstr(Hexagon::C2_tfrpr, dl, MVT::i32, {VecV}, DAG);
2818 SDValue Ext = DAG.getSExtOrTrunc(ValV, dl, MVT::i32);
2819 SDValue Width = DAG.getConstant(8 / VecLen, dl, MVT::i32);
2820 SDValue Idx = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, Width);
2821 SDValue Ins =
2822 DAG.getNode(HexagonISD::INSERT, dl, MVT::i32, {ToReg, Ext, Width, Idx});
2823 return getInstr(Hexagon::C2_tfrrp, dl, VecTy, {Ins}, DAG);
2824 }
2825
2826 assert(ValTy.getVectorElementType() == MVT::i1);
2827 SDValue ValR = ValTy.isVector()
2828 ? DAG.getNode(HexagonISD::P2D, dl, MVT::i64, ValV)
2829 : DAG.getSExtOrTrunc(ValV, dl, MVT::i64);
2830
2831 unsigned Scale = VecLen / ValTy.getVectorNumElements();
2832 assert(Scale > 1);
2833
2834 for (unsigned R = Scale; R > 1; R /= 2) {
2835 ValR = contractPredicate(ValR, dl, DAG);
2836 ValR = getCombine(DAG.getUNDEF(MVT::i32), ValR, dl, MVT::i64, DAG);
2837 }
2838
2839 SDValue Width = DAG.getConstant(64 / Scale, dl, MVT::i32);
2840 SDValue Idx = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, Width);
2841 SDValue VecR = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, VecV);
2842 SDValue Ins =
2843 DAG.getNode(HexagonISD::INSERT, dl, MVT::i64, {VecR, ValR, Width, Idx});
2844 return DAG.getNode(HexagonISD::D2P, dl, VecTy, Ins);
2845}
2846
2847SDValue
2848HexagonTargetLowering::expandPredicate(SDValue Vec32, const SDLoc &dl,
2849 SelectionDAG &DAG) const {
2850 assert(ty(Vec32).getSizeInBits() == 32);
2851 if (isUndef(Vec32))
2852 return DAG.getUNDEF(MVT::i64);
2853 SDValue P = DAG.getBitcast(MVT::v4i8, Vec32);
2854 SDValue X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i16, P);
2855 return DAG.getBitcast(MVT::i64, X);
2856}
2857
2858SDValue
2859HexagonTargetLowering::contractPredicate(SDValue Vec64, const SDLoc &dl,
2860 SelectionDAG &DAG) const {
2861 assert(ty(Vec64).getSizeInBits() == 64);
2862 if (isUndef(Vec64))
2863 return DAG.getUNDEF(MVT::i32);
2864 // Collect even bytes:
2865 SDValue A = DAG.getBitcast(MVT::v8i8, Vec64);
2866 SDValue S = DAG.getVectorShuffle(MVT::v8i8, dl, A, DAG.getUNDEF(MVT::v8i8),
2867 {0, 2, 4, 6, 1, 3, 5, 7});
2868 return extractVector(S, DAG.getConstant(0, dl, MVT::i32), dl, MVT::v4i8,
2869 MVT::i32, DAG);
2870}
2871
2872SDValue
2873HexagonTargetLowering::getZero(const SDLoc &dl, MVT Ty, SelectionDAG &DAG)
2874 const {
2875 if (Ty.isVector()) {
2876 unsigned W = Ty.getSizeInBits();
2877 if (W <= 64)
2878 return DAG.getBitcast(Ty, DAG.getConstant(0, dl, MVT::getIntegerVT(W)));
2879 return DAG.getNode(ISD::SPLAT_VECTOR, dl, Ty, getZero(dl, MVT::i32, DAG));
2880 }
2881
2882 if (Ty.isInteger())
2883 return DAG.getConstant(0, dl, Ty);
2884 if (Ty.isFloatingPoint())
2885 return DAG.getConstantFP(0.0, dl, Ty);
2886 llvm_unreachable("Invalid type for zero");
2887}
2888
2889SDValue
2890HexagonTargetLowering::appendUndef(SDValue Val, MVT ResTy, SelectionDAG &DAG)
2891 const {
2892 MVT ValTy = ty(Val);
2894
2895 unsigned ValLen = ValTy.getVectorNumElements();
2896 unsigned ResLen = ResTy.getVectorNumElements();
2897 if (ValLen == ResLen)
2898 return Val;
2899
2900 const SDLoc &dl(Val);
2901 assert(ValLen < ResLen);
2902 assert(ResLen % ValLen == 0);
2903
2904 SmallVector<SDValue, 4> Concats = {Val};
2905 for (unsigned i = 1, e = ResLen / ValLen; i < e; ++i)
2906 Concats.push_back(DAG.getUNDEF(ValTy));
2907
2908 return DAG.getNode(ISD::CONCAT_VECTORS, dl, ResTy, Concats);
2909}
2910
2911SDValue
2912HexagonTargetLowering::getCombine(SDValue Hi, SDValue Lo, const SDLoc &dl,
2913 MVT ResTy, SelectionDAG &DAG) const {
2914 MVT ElemTy = ty(Hi);
2915 assert(ElemTy == ty(Lo));
2916
2917 if (!ElemTy.isVector()) {
2918 assert(ElemTy.isScalarInteger());
2919 MVT PairTy = MVT::getIntegerVT(2 * ElemTy.getSizeInBits());
2920 SDValue Pair = DAG.getNode(ISD::BUILD_PAIR, dl, PairTy, Lo, Hi);
2921 return DAG.getBitcast(ResTy, Pair);
2922 }
2923
2924 unsigned Width = ElemTy.getSizeInBits();
2925 MVT IntTy = MVT::getIntegerVT(Width);
2926 MVT PairTy = MVT::getIntegerVT(2 * Width);
2927 SDValue Pair =
2929 {DAG.getBitcast(IntTy, Lo), DAG.getBitcast(IntTy, Hi)});
2930 return DAG.getBitcast(ResTy, Pair);
2931}
2932
2933SDValue
2935 MVT VecTy = ty(Op);
2936 unsigned BW = VecTy.getSizeInBits();
2937 const SDLoc &dl(Op);
2939 for (unsigned i = 0, e = Op.getNumOperands(); i != e; ++i)
2940 Ops.push_back(Op.getOperand(i));
2941
2942 if (BW == 32)
2943 return buildVector32(Ops, dl, VecTy, DAG);
2944 if (BW == 64)
2945 return buildVector64(Ops, dl, VecTy, DAG);
2946
2947 if (VecTy == MVT::v8i1 || VecTy == MVT::v4i1 || VecTy == MVT::v2i1) {
2948 // Check if this is a special case or all-0 or all-1.
2949 bool All0 = true, All1 = true;
2950 for (SDValue P : Ops) {
2951 auto *CN = dyn_cast<ConstantSDNode>(P.getNode());
2952 if (CN == nullptr) {
2953 All0 = All1 = false;
2954 break;
2955 }
2956 uint32_t C = CN->getZExtValue();
2957 All0 &= (C == 0);
2958 All1 &= (C == 1);
2959 }
2960 if (All0)
2961 return DAG.getNode(HexagonISD::PFALSE, dl, VecTy);
2962 if (All1)
2963 return DAG.getNode(HexagonISD::PTRUE, dl, VecTy);
2964
2965 // For each i1 element in the resulting predicate register, put 1
2966 // shifted by the index of the element into a general-purpose register,
2967 // then or them together and transfer it back into a predicate register.
2968 SDValue Rs[8];
2969 SDValue Z = getZero(dl, MVT::i32, DAG);
2970 // Always produce 8 bits, repeat inputs if necessary.
2971 unsigned Rep = 8 / VecTy.getVectorNumElements();
2972 for (unsigned i = 0; i != 8; ++i) {
2973 SDValue S = DAG.getConstant(1ull << i, dl, MVT::i32);
2974 Rs[i] = DAG.getSelect(dl, MVT::i32, Ops[i/Rep], S, Z);
2975 }
2976 for (ArrayRef<SDValue> A(Rs); A.size() != 1; A = A.drop_back(A.size()/2)) {
2977 for (unsigned i = 0, e = A.size()/2; i != e; ++i)
2978 Rs[i] = DAG.getNode(ISD::OR, dl, MVT::i32, Rs[2*i], Rs[2*i+1]);
2979 }
2980 // Move the value directly to a predicate register.
2981 return getInstr(Hexagon::C2_tfrrp, dl, VecTy, {Rs[0]}, DAG);
2982 }
2983
2984 return SDValue();
2985}
2986
2987SDValue
2989 SelectionDAG &DAG) const {
2990 MVT VecTy = ty(Op);
2991 const SDLoc &dl(Op);
2992 if (VecTy.getSizeInBits() == 64) {
2993 assert(Op.getNumOperands() == 2);
2994 return getCombine(Op.getOperand(1), Op.getOperand(0), dl, VecTy, DAG);
2995 }
2996
2997 MVT ElemTy = VecTy.getVectorElementType();
2998 if (ElemTy == MVT::i1) {
2999 assert(VecTy == MVT::v2i1 || VecTy == MVT::v4i1 || VecTy == MVT::v8i1);
3000 MVT OpTy = ty(Op.getOperand(0));
3001 // Scale is how many times the operands need to be contracted to match
3002 // the representation in the target register.
3003 unsigned Scale = VecTy.getVectorNumElements() / OpTy.getVectorNumElements();
3004 assert(Scale == Op.getNumOperands() && Scale > 1);
3005
3006 // First, convert all bool vectors to integers, then generate pairwise
3007 // inserts to form values of doubled length. Up until there are only
3008 // two values left to concatenate, all of these values will fit in a
3009 // 32-bit integer, so keep them as i32 to use 32-bit inserts.
3010 SmallVector<SDValue,4> Words[2];
3011 unsigned IdxW = 0;
3012
3013 for (SDValue P : Op.getNode()->op_values()) {
3014 SDValue W = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, P);
3015 for (unsigned R = Scale; R > 1; R /= 2) {
3016 W = contractPredicate(W, dl, DAG);
3017 W = getCombine(DAG.getUNDEF(MVT::i32), W, dl, MVT::i64, DAG);
3018 }
3019 W = LoHalf(W, DAG);
3020 Words[IdxW].push_back(W);
3021 }
3022
3023 while (Scale > 2) {
3024 SDValue WidthV = DAG.getConstant(64 / Scale, dl, MVT::i32);
3025 Words[IdxW ^ 1].clear();
3026
3027 for (unsigned i = 0, e = Words[IdxW].size(); i != e; i += 2) {
3028 SDValue W0 = Words[IdxW][i], W1 = Words[IdxW][i+1];
3029 // Insert W1 into W0 right next to the significant bits of W0.
3030 SDValue T = DAG.getNode(HexagonISD::INSERT, dl, MVT::i32,
3031 {W0, W1, WidthV, WidthV});
3032 Words[IdxW ^ 1].push_back(T);
3033 }
3034 IdxW ^= 1;
3035 Scale /= 2;
3036 }
3037
3038 // At this point there should only be two words left, and Scale should be 2.
3039 assert(Scale == 2 && Words[IdxW].size() == 2);
3040
3041 SDValue WW = getCombine(Words[IdxW][1], Words[IdxW][0], dl, MVT::i64, DAG);
3042 return DAG.getNode(HexagonISD::D2P, dl, VecTy, WW);
3043 }
3044
3045 return SDValue();
3046}
3047
3048SDValue
3050 SelectionDAG &DAG) const {
3051 SDValue Vec = Op.getOperand(0);
3052 MVT ElemTy = ty(Vec).getVectorElementType();
3053 return extractVector(Vec, Op.getOperand(1), SDLoc(Op), ElemTy, ty(Op), DAG);
3054}
3055
3056SDValue
3058 SelectionDAG &DAG) const {
3059 return extractVector(Op.getOperand(0), Op.getOperand(1), SDLoc(Op),
3060 ty(Op), ty(Op), DAG);
3061}
3062
3063SDValue
3065 SelectionDAG &DAG) const {
3066 return insertVector(Op.getOperand(0), Op.getOperand(1), Op.getOperand(2),
3067 SDLoc(Op), ty(Op).getVectorElementType(), DAG);
3068}
3069
3070SDValue
3072 SelectionDAG &DAG) const {
3073 SDValue ValV = Op.getOperand(1);
3074 return insertVector(Op.getOperand(0), ValV, Op.getOperand(2),
3075 SDLoc(Op), ty(ValV), DAG);
3076}
3077
3078bool
3080 // Assuming the caller does not have either a signext or zeroext modifier, and
3081 // only one value is accepted, any reasonable truncation is allowed.
3082 if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy())
3083 return false;
3084
3085 // FIXME: in principle up to 64-bit could be made safe, but it would be very
3086 // fragile at the moment: any support for multiple value returns would be
3087 // liable to disallow tail calls involving i64 -> iN truncation in many cases.
3088 return Ty1->getPrimitiveSizeInBits() <= 32;
3089}
3090
3091SDValue
3093 MVT Ty = ty(Op);
3094 const SDLoc &dl(Op);
3095 LoadSDNode *LN = cast<LoadSDNode>(Op.getNode());
3096 MVT MemTy = LN->getMemoryVT().getSimpleVT();
3098
3099 bool LoadPred = MemTy == MVT::v2i1 || MemTy == MVT::v4i1 || MemTy == MVT::v8i1;
3100 if (LoadPred) {
3101 SDValue NL = DAG.getLoad(
3102 LN->getAddressingMode(), ISD::ZEXTLOAD, MVT::i32, dl, LN->getChain(),
3103 LN->getBasePtr(), LN->getOffset(), LN->getPointerInfo(),
3104 /*MemoryVT*/ MVT::i8, LN->getAlign(), LN->getMemOperand()->getFlags(),
3105 LN->getAAInfo(), LN->getRanges());
3106 LN = cast<LoadSDNode>(NL.getNode());
3107 }
3108
3109 Align ClaimAlign = LN->getAlign();
3110 if (!validateConstPtrAlignment(LN->getBasePtr(), ClaimAlign, dl, DAG))
3111 return replaceMemWithUndef(Op, DAG);
3112
3113 // Call LowerUnalignedLoad for all loads, it recognizes loads that
3114 // don't need extra aligning.
3115 SDValue LU = LowerUnalignedLoad(SDValue(LN, 0), DAG);
3116 if (LoadPred) {
3117 SDValue TP = getInstr(Hexagon::C2_tfrrp, dl, MemTy, {LU}, DAG);
3118 if (ET == ISD::SEXTLOAD) {
3119 TP = DAG.getSExtOrTrunc(TP, dl, Ty);
3120 } else if (ET != ISD::NON_EXTLOAD) {
3121 TP = DAG.getZExtOrTrunc(TP, dl, Ty);
3122 }
3123 SDValue Ch = cast<LoadSDNode>(LU.getNode())->getChain();
3124 return DAG.getMergeValues({TP, Ch}, dl);
3125 }
3126 return LU;
3127}
3128
3129SDValue
3131 const SDLoc &dl(Op);
3132 StoreSDNode *SN = cast<StoreSDNode>(Op.getNode());
3133 SDValue Val = SN->getValue();
3134 MVT Ty = ty(Val);
3135
3136 if (Ty == MVT::v2i1 || Ty == MVT::v4i1 || Ty == MVT::v8i1) {
3137 // Store the exact predicate (all bits).
3138 SDValue TR = getInstr(Hexagon::C2_tfrpr, dl, MVT::i32, {Val}, DAG);
3139 SDValue NS = DAG.getTruncStore(SN->getChain(), dl, TR, SN->getBasePtr(),
3140 MVT::i8, SN->getMemOperand());
3141 if (SN->isIndexed()) {
3142 NS = DAG.getIndexedStore(NS, dl, SN->getBasePtr(), SN->getOffset(),
3143 SN->getAddressingMode());
3144 }
3145 SN = cast<StoreSDNode>(NS.getNode());
3146 }
3147
3148 Align ClaimAlign = SN->getAlign();
3149 if (!validateConstPtrAlignment(SN->getBasePtr(), ClaimAlign, dl, DAG))
3150 return replaceMemWithUndef(Op, DAG);
3151
3152 MVT StoreTy = SN->getMemoryVT().getSimpleVT();
3153 Align NeedAlign = Subtarget.getTypeAlignment(StoreTy);
3154 if (ClaimAlign < NeedAlign)
3155 return expandUnalignedStore(SN, DAG);
3156 return SDValue(SN, 0);
3157}
3158
3159SDValue
3161 const {
3162 LoadSDNode *LN = cast<LoadSDNode>(Op.getNode());
3163 MVT LoadTy = ty(Op);
3164 unsigned NeedAlign = Subtarget.getTypeAlignment(LoadTy).value();
3165 unsigned HaveAlign = LN->getAlign().value();
3166 if (HaveAlign >= NeedAlign)
3167 return Op;
3168
3169 const SDLoc &dl(Op);
3170 const DataLayout &DL = DAG.getDataLayout();
3171 LLVMContext &Ctx = *DAG.getContext();
3172
3173 // If the load aligning is disabled or the load can be broken up into two
3174 // smaller legal loads, do the default (target-independent) expansion.
3175 bool DoDefault = false;
3176 // Handle it in the default way if this is an indexed load.
3177 if (!LN->isUnindexed())
3178 DoDefault = true;
3179
3180 if (!AlignLoads) {
3182 *LN->getMemOperand()))
3183 return Op;
3184 DoDefault = true;
3185 }
3186 if (!DoDefault && (2 * HaveAlign) == NeedAlign) {
3187 // The PartTy is the equivalent of "getLoadableTypeOfSize(HaveAlign)".
3188 MVT PartTy = HaveAlign <= 8 ? MVT::getIntegerVT(8 * HaveAlign)
3189 : MVT::getVectorVT(MVT::i8, HaveAlign);
3190 DoDefault =
3191 allowsMemoryAccessForAlignment(Ctx, DL, PartTy, *LN->getMemOperand());
3192 }
3193 if (DoDefault) {
3194 std::pair<SDValue, SDValue> P = expandUnalignedLoad(LN, DAG);
3195 return DAG.getMergeValues({P.first, P.second}, dl);
3196 }
3197
3198 // The code below generates two loads, both aligned as NeedAlign, and
3199 // with the distance of NeedAlign between them. For that to cover the
3200 // bits that need to be loaded (and without overlapping), the size of
3201 // the loads should be equal to NeedAlign. This is true for all loadable
3202 // types, but add an assertion in case something changes in the future.
3203 assert(LoadTy.getSizeInBits() == 8*NeedAlign);
3204
3205 unsigned LoadLen = NeedAlign;
3206 SDValue Base = LN->getBasePtr();
3207 SDValue Chain = LN->getChain();
3208 auto BO = getBaseAndOffset(Base);
3209 unsigned BaseOpc = BO.first.getOpcode();
3210 if (BaseOpc == HexagonISD::VALIGNADDR && BO.second % LoadLen == 0)
3211 return Op;
3212
3213 if (BO.second % LoadLen != 0) {
3214 BO.first = DAG.getNode(ISD::ADD, dl, MVT::i32, BO.first,
3215 DAG.getConstant(BO.second % LoadLen, dl, MVT::i32));
3216 BO.second -= BO.second % LoadLen;
3217 }
3218 SDValue BaseNoOff = (BaseOpc != HexagonISD::VALIGNADDR)
3219 ? DAG.getNode(HexagonISD::VALIGNADDR, dl, MVT::i32, BO.first,
3220 DAG.getConstant(NeedAlign, dl, MVT::i32))
3221 : BO.first;
3222 SDValue Base0 =
3223 DAG.getMemBasePlusOffset(BaseNoOff, TypeSize::getFixed(BO.second), dl);
3224 SDValue Base1 = DAG.getMemBasePlusOffset(
3225 BaseNoOff, TypeSize::getFixed(BO.second + LoadLen), dl);
3226
3227 MachineMemOperand *WideMMO = nullptr;
3228 if (MachineMemOperand *MMO = LN->getMemOperand()) {
3230 WideMMO = MF.getMachineMemOperand(
3231 MMO->getPointerInfo(), MMO->getFlags(), 2 * LoadLen, Align(LoadLen),
3232 MMO->getAAInfo(), MMO->getRanges(), MMO->getSyncScopeID(),
3233 MMO->getSuccessOrdering(), MMO->getFailureOrdering());
3234 }
3235
3236 SDValue Load0 = DAG.getLoad(LoadTy, dl, Chain, Base0, WideMMO);
3237 SDValue Load1 = DAG.getLoad(LoadTy, dl, Chain, Base1, WideMMO);
3238
3239 SDValue Aligned = DAG.getNode(HexagonISD::VALIGN, dl, LoadTy,
3240 {Load1, Load0, BaseNoOff.getOperand(0)});
3241 SDValue NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
3242 Load0.getValue(1), Load1.getValue(1));
3243 SDValue M = DAG.getMergeValues({Aligned, NewChain}, dl);
3244 return M;
3245}
3246
3247SDValue
3249 SDValue X = Op.getOperand(0), Y = Op.getOperand(1);
3250 auto *CY = dyn_cast<ConstantSDNode>(Y);
3251 if (!CY)
3252 return SDValue();
3253
3254 const SDLoc &dl(Op);
3255 SDVTList VTs = Op.getNode()->getVTList();
3256 assert(VTs.NumVTs == 2);
3257 assert(VTs.VTs[1] == MVT::i1);
3258 unsigned Opc = Op.getOpcode();
3259
3260 if (CY) {
3261 uint64_t VY = CY->getZExtValue();
3262 assert(VY != 0 && "This should have been folded");
3263 // X +/- 1
3264 if (VY != 1)
3265 return SDValue();
3266
3267 if (Opc == ISD::UADDO) {
3268 SDValue Op = DAG.getNode(ISD::ADD, dl, VTs.VTs[0], {X, Y});
3269 SDValue Ov = DAG.getSetCC(dl, MVT::i1, Op, getZero(dl, ty(Op), DAG),
3270 ISD::SETEQ);
3271 return DAG.getMergeValues({Op, Ov}, dl);
3272 }
3273 if (Opc == ISD::USUBO) {
3274 SDValue Op = DAG.getNode(ISD::SUB, dl, VTs.VTs[0], {X, Y});
3275 SDValue Ov = DAG.getSetCC(dl, MVT::i1, Op,
3276 DAG.getConstant(-1, dl, ty(Op)), ISD::SETEQ);
3277 return DAG.getMergeValues({Op, Ov}, dl);
3278 }
3279 }
3280
3281 return SDValue();
3282}
3283
3285 SelectionDAG &DAG) const {
3286 const SDLoc &dl(Op);
3287 unsigned Opc = Op.getOpcode();
3288 SDValue X = Op.getOperand(0), Y = Op.getOperand(1), C = Op.getOperand(2);
3289
3290 if (Opc == ISD::UADDO_CARRY)
3291 return DAG.getNode(HexagonISD::ADDC, dl, Op.getNode()->getVTList(),
3292 { X, Y, C });
3293
3294 EVT CarryTy = C.getValueType();
3295 SDValue SubC = DAG.getNode(HexagonISD::SUBC, dl, Op.getNode()->getVTList(),
3296 { X, Y, DAG.getLogicalNOT(dl, C, CarryTy) });
3297 SDValue Out[] = { SubC.getValue(0),
3298 DAG.getLogicalNOT(dl, SubC.getValue(1), CarryTy) };
3299 return DAG.getMergeValues(Out, dl);
3300}
3301
3302SDValue
3304 SDValue Chain = Op.getOperand(0);
3305 SDValue Offset = Op.getOperand(1);
3306 SDValue Handler = Op.getOperand(2);
3307 SDLoc dl(Op);
3308 auto PtrVT = getPointerTy(DAG.getDataLayout());
3309
3310 // Mark function as containing a call to EH_RETURN.
3311 HexagonMachineFunctionInfo *FuncInfo =
3313 FuncInfo->setHasEHReturn();
3314
3315 unsigned OffsetReg = Hexagon::R28;
3316
3317 SDValue StoreAddr =
3318 DAG.getNode(ISD::ADD, dl, PtrVT, DAG.getRegister(Hexagon::R30, PtrVT),
3319 DAG.getIntPtrConstant(4, dl));
3320 Chain = DAG.getStore(Chain, dl, Handler, StoreAddr, MachinePointerInfo());
3321 Chain = DAG.getCopyToReg(Chain, dl, OffsetReg, Offset);
3322
3323 // Not needed we already use it as explict input to EH_RETURN.
3324 // MF.getRegInfo().addLiveOut(OffsetReg);
3325
3326 return DAG.getNode(HexagonISD::EH_RETURN, dl, MVT::Other, Chain);
3327}
3328
3329SDValue
3331 unsigned Opc = Op.getOpcode();
3332
3333 // Handle INLINEASM first.
3334 if (Opc == ISD::INLINEASM || Opc == ISD::INLINEASM_BR)
3335 return LowerINLINEASM(Op, DAG);
3336
3337 if (isHvxOperation(Op.getNode(), DAG)) {
3338 // If HVX lowering returns nothing, try the default lowering.
3339 if (SDValue V = LowerHvxOperation(Op, DAG))
3340 return V;
3341 }
3342
3343 switch (Opc) {
3344 default:
3345#ifndef NDEBUG
3346 Op.getNode()->dumpr(&DAG);
3347 if (Opc > HexagonISD::OP_BEGIN && Opc < HexagonISD::OP_END)
3348 errs() << "Error: check for a non-legal type in this operation\n";
3349#endif
3350 llvm_unreachable("Should not custom lower this!");
3351
3352 case ISD::FDIV:
3353 return LowerFDIV(Op, DAG);
3354 case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG);
3359 case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG);
3360 case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG);
3361 case ISD::BITCAST: return LowerBITCAST(Op, DAG);
3362 case ISD::LOAD: return LowerLoad(Op, DAG);
3363 case ISD::STORE: return LowerStore(Op, DAG);
3364 case ISD::UADDO:
3365 case ISD::USUBO: return LowerUAddSubO(Op, DAG);
3366 case ISD::UADDO_CARRY:
3367 case ISD::USUBO_CARRY: return LowerUAddSubOCarry(Op, DAG);
3368 case ISD::SRA:
3369 case ISD::SHL:
3370 case ISD::SRL: return LowerVECTOR_SHIFT(Op, DAG);
3371 case ISD::ROTL: return LowerROTL(Op, DAG);
3372 case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
3373 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
3374 case ISD::EH_RETURN: return LowerEH_RETURN(Op, DAG);
3375 case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG);
3376 case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG);
3378 case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG);
3379 case ISD::GlobalAddress: return LowerGLOBALADDRESS(Op, DAG);
3380 case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
3382 case ISD::VACOPY: return LowerVACOPY(Op, DAG);
3383 case ISD::VASTART: return LowerVASTART(Op, DAG);
3385 case ISD::SETCC: return LowerSETCC(Op, DAG);
3386 case ISD::VSELECT: return LowerVSELECT(Op, DAG);
3388 case ISD::INTRINSIC_VOID: return LowerINTRINSIC_VOID(Op, DAG);
3389 case ISD::PREFETCH: return LowerPREFETCH(Op, DAG);
3392 break;
3393 }
3394
3395 return SDValue();
3396}
3397
3398void
3401 SelectionDAG &DAG) const {
3402 if (isHvxOperation(N, DAG)) {
3403 LowerHvxOperationWrapper(N, Results, DAG);
3404 if (!Results.empty())
3405 return;
3406 }
3407
3408 SDValue Op(N, 0);
3409 unsigned Opc = N->getOpcode();
3410
3411 switch (Opc) {
3412 case HexagonISD::SSAT:
3413 case HexagonISD::USAT:
3414 Results.push_back(opJoin(SplitVectorOp(Op, DAG), SDLoc(Op), DAG));
3415 break;
3416 case ISD::STORE:
3417 // We are only custom-lowering stores to verify the alignment of the
3418 // address if it is a compile-time constant. Since a store can be
3419 // modified during type-legalization (the value being stored may need
3420 // legalization), return empty Results here to indicate that we don't
3421 // really make any changes in the custom lowering.
3422 return;
3423 default:
3425 break;
3426 }
3427}
3428
3429void
3432 SelectionDAG &DAG) const {
3433 if (isHvxOperation(N, DAG)) {
3434 ReplaceHvxNodeResults(N, Results, DAG);
3435 if (!Results.empty())
3436 return;
3437 }
3438
3439 const SDLoc &dl(N);
3440 switch (N->getOpcode()) {
3441 case ISD::SRL:
3442 case ISD::SRA:
3443 case ISD::SHL:
3444 return;
3445 case ISD::BITCAST:
3446 // Handle a bitcast from v8i1 to i8.
3447 if (N->getValueType(0) == MVT::i8) {
3448 if (N->getOperand(0).getValueType() == MVT::v8i1) {
3449 SDValue P = getInstr(Hexagon::C2_tfrpr, dl, MVT::i32,
3450 N->getOperand(0), DAG);
3451 SDValue T = DAG.getAnyExtOrTrunc(P, dl, MVT::i8);
3452 Results.push_back(T);
3453 }
3454 }
3455 break;
3456 }
3457}
3458
3459SDValue
3461 DAGCombinerInfo &DCI) const {
3462 if (isHvxOperation(N, DCI.DAG)) {
3463 if (SDValue V = PerformHvxDAGCombine(N, DCI))
3464 return V;
3465 return SDValue();
3466 }
3467
3468 SDValue Op(N, 0);
3469 const SDLoc &dl(Op);
3470 unsigned Opc = Op.getOpcode();
3471
3472 if (Opc == ISD::TRUNCATE) {
3473 SDValue Op0 = Op.getOperand(0);
3474 // fold (truncate (build pair x, y)) -> (truncate x) or x
3475 if (Op0.getOpcode() == ISD::BUILD_PAIR) {
3476 EVT TruncTy = Op.getValueType();
3477 SDValue Elem0 = Op0.getOperand(0);
3478 // if we match the low element of the pair, just return it.
3479 if (Elem0.getValueType() == TruncTy)
3480 return Elem0;
3481 // otherwise, if the low part is still too large, apply the truncate.
3482 if (Elem0.getValueType().bitsGT(TruncTy))
3483 return DCI.DAG.getNode(ISD::TRUNCATE, dl, TruncTy, Elem0);
3484 }
3485 }
3486
3487 if (DCI.isBeforeLegalizeOps())
3488 return SDValue();
3489
3490 if (Opc == HexagonISD::P2D) {
3491 SDValue P = Op.getOperand(0);
3492 switch (P.getOpcode()) {
3493 case HexagonISD::PTRUE:
3494 return DCI.DAG.getConstant(-1, dl, ty(Op));
3495 case HexagonISD::PFALSE:
3496 return getZero(dl, ty(Op), DCI.DAG);
3497 default:
3498 break;
3499 }
3500 } else if (Opc == ISD::VSELECT) {
3501 // This is pretty much duplicated in HexagonISelLoweringHVX...
3502 //
3503 // (vselect (xor x, ptrue), v0, v1) -> (vselect x, v1, v0)
3504 SDValue Cond = Op.getOperand(0);
3505 if (Cond->getOpcode() == ISD::XOR) {
3506 SDValue C0 = Cond.getOperand(0), C1 = Cond.getOperand(1);
3507 if (C1->getOpcode() == HexagonISD::PTRUE) {
3508 SDValue VSel = DCI.DAG.getNode(ISD::VSELECT, dl, ty(Op), C0,
3509 Op.getOperand(2), Op.getOperand(1));
3510 return VSel;
3511 }
3512 }
3513 } else if (Opc == ISD::TRUNCATE) {
3514 SDValue Op0 = Op.getOperand(0);
3515 // fold (truncate (build pair x, y)) -> (truncate x) or x
3516 if (Op0.getOpcode() == ISD::BUILD_PAIR) {
3517 MVT TruncTy = ty(Op);
3518 SDValue Elem0 = Op0.getOperand(0);
3519 // if we match the low element of the pair, just return it.
3520 if (ty(Elem0) == TruncTy)
3521 return Elem0;
3522 // otherwise, if the low part is still too large, apply the truncate.
3523 if (ty(Elem0).bitsGT(TruncTy))
3524 return DCI.DAG.getNode(ISD::TRUNCATE, dl, TruncTy, Elem0);
3525 }
3526 } else if (Opc == ISD::OR) {
3527 // fold (or (shl xx, s), (zext y)) -> (COMBINE (shl xx, s-32), y)
3528 // if s >= 32
3529 auto fold0 = [&, this](SDValue Op) {
3530 if (ty(Op) != MVT::i64)
3531 return SDValue();
3532 SDValue Shl = Op.getOperand(0);
3533 SDValue Zxt = Op.getOperand(1);
3534 if (Shl.getOpcode() != ISD::SHL)
3535 std::swap(Shl, Zxt);
3536
3537 if (Shl.getOpcode() != ISD::SHL || Zxt.getOpcode() != ISD::ZERO_EXTEND)
3538 return SDValue();
3539
3540 SDValue Z = Zxt.getOperand(0);
3541 auto *Amt = dyn_cast<ConstantSDNode>(Shl.getOperand(1));
3542 if (Amt && Amt->getZExtValue() >= 32 && ty(Z).getSizeInBits() <= 32) {
3543 unsigned A = Amt->getZExtValue();
3544 SDValue S = Shl.getOperand(0);
3545 SDValue T0 = DCI.DAG.getNode(ISD::SHL, dl, ty(S), S,
3546 DCI.DAG.getConstant(A - 32, dl, MVT::i32));
3547 SDValue T1 = DCI.DAG.getZExtOrTrunc(T0, dl, MVT::i32);
3548 SDValue T2 = DCI.DAG.getZExtOrTrunc(Z, dl, MVT::i32);
3549 return DCI.DAG.getNode(HexagonISD::COMBINE, dl, MVT::i64, {T1, T2});
3550 }
3551 return SDValue();
3552 };
3553
3554 if (SDValue R = fold0(Op))
3555 return R;
3556 }
3557
3558 return SDValue();
3559}
3560
3561/// Returns relocation base for the given PIC jumptable.
3562SDValue
3564 SelectionDAG &DAG) const {
3565 int Idx = cast<JumpTableSDNode>(Table)->getIndex();
3566 EVT VT = Table.getValueType();
3568 return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Table), VT, T);
3569}
3570
3571//===----------------------------------------------------------------------===//
3572// Inline Assembly Support
3573//===----------------------------------------------------------------------===//
3574
3577 if (Constraint.size() == 1) {
3578 switch (Constraint[0]) {
3579 case 'q':
3580 case 'v':
3581 if (Subtarget.useHVXOps())
3582 return C_RegisterClass;
3583 break;
3584 case 'a':
3585 return C_RegisterClass;
3586 default:
3587 break;
3588 }
3589 }
3590 return TargetLowering::getConstraintType(Constraint);
3591}
3592
3593std::pair<unsigned, const TargetRegisterClass*>
3595 const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const {
3596
3597 if (Constraint.size() == 1) {
3598 switch (Constraint[0]) {
3599 case 'r': // R0-R31
3600 switch (VT.SimpleTy) {
3601 default:
3602 return {0u, nullptr};
3603 case MVT::i1:
3604 case MVT::i8:
3605 case MVT::i16:
3606 case MVT::i32:
3607 case MVT::f32:
3608 return {0u, &Hexagon::IntRegsRegClass};
3609 case MVT::i64:
3610 case MVT::f64:
3611 return {0u, &Hexagon::DoubleRegsRegClass};
3612 }
3613 break;
3614 case 'a': // M0-M1
3615 if (VT != MVT::i32)
3616 return {0u, nullptr};
3617 return {0u, &Hexagon::ModRegsRegClass};
3618 case 'q': // q0-q3
3619 switch (VT.getSizeInBits()) {
3620 default:
3621 return {0u, nullptr};
3622 case 64:
3623 case 128:
3624 return {0u, &Hexagon::HvxQRRegClass};
3625 }
3626 break;
3627 case 'v': // V0-V31
3628 switch (VT.getSizeInBits()) {
3629 default:
3630 return {0u, nullptr};
3631 case 512:
3632 return {0u, &Hexagon::HvxVRRegClass};
3633 case 1024:
3634 if (Subtarget.hasV60Ops() && Subtarget.useHVX128BOps())
3635 return {0u, &Hexagon::HvxVRRegClass};
3636 return {0u, &Hexagon::HvxWRRegClass};
3637 case 2048:
3638 return {0u, &Hexagon::HvxWRRegClass};
3639 }
3640 break;
3641 default:
3642 return {0u, nullptr};
3643 }
3644 }
3645
3646 return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
3647}
3648
3649/// isFPImmLegal - Returns true if the target can instruction select the
3650/// specified FP immediate natively. If false, the legalizer will
3651/// materialize the FP immediate as a load from a constant pool.
3653 bool ForCodeSize) const {
3654 return true;
3655}
3656
3657/// isLegalAddressingMode - Return true if the addressing mode represented by
3658/// AM is legal for this target, for a load/store of the specified type.
3660 const AddrMode &AM, Type *Ty,
3661 unsigned AS, Instruction *I) const {
3662 if (Ty->isSized()) {
3663 // When LSR detects uses of the same base address to access different
3664 // types (e.g. unions), it will assume a conservative type for these
3665 // uses:
3666 // LSR Use: Kind=Address of void in addrspace(4294967295), ...
3667 // The type Ty passed here would then be "void". Skip the alignment
3668 // checks, but do not return false right away, since that confuses
3669 // LSR into crashing.
3670 Align A = DL.getABITypeAlign(Ty);
3671 // The base offset must be a multiple of the alignment.
3672 if (!isAligned(A, AM.BaseOffs))
3673 return false;
3674 // The shifted offset must fit in 11 bits.
3675 if (!isInt<11>(AM.BaseOffs >> Log2(A)))
3676 return false;
3677 }
3678
3679 // No global is ever allowed as a base.
3680 if (AM.BaseGV)
3681 return false;
3682
3683 int Scale = AM.Scale;
3684 if (Scale < 0)
3685 Scale = -Scale;
3686 switch (Scale) {
3687 case 0: // No scale reg, "r+i", "r", or just "i".
3688 break;
3689 default: // No scaled addressing mode.
3690 return false;
3691 }
3692 return true;
3693}
3694
3695/// Return true if folding a constant offset with the given GlobalAddress is
3696/// legal. It is frequently not legal in PIC relocation models.
3698 const {
3699 return HTM.getRelocationModel() == Reloc::Static;
3700}
3701
3702/// isLegalICmpImmediate - Return true if the specified immediate is legal
3703/// icmp immediate, that is the target has icmp instructions which can compare
3704/// a register against the immediate without having to materialize the
3705/// immediate into a register.
3707 return Imm >= -512 && Imm <= 511;
3708}
3709
3710/// IsEligibleForTailCallOptimization - Check whether the call is eligible
3711/// for tail call optimization. Targets which want to do tail call
3712/// optimization should implement this function.
3714 SDValue Callee,
3715 CallingConv::ID CalleeCC,
3716 bool IsVarArg,
3717 bool IsCalleeStructRet,
3718 bool IsCallerStructRet,
3720 const SmallVectorImpl<SDValue> &OutVals,
3722 SelectionDAG& DAG) const {
3723 const Function &CallerF = DAG.getMachineFunction().getFunction();
3724 CallingConv::ID CallerCC = CallerF.getCallingConv();
3725 bool CCMatch = CallerCC == CalleeCC;
3726
3727 // ***************************************************************************
3728 // Look for obvious safe cases to perform tail call optimization that do not
3729 // require ABI changes.
3730 // ***************************************************************************
3731
3732 // If this is a tail call via a function pointer, then don't do it!
3733 if (!isa<GlobalAddressSDNode>(Callee) &&
3734 !isa<ExternalSymbolSDNode>(Callee)) {
3735 return false;
3736 }
3737
3738 // Do not optimize if the calling conventions do not match and the conventions
3739 // used are not C or Fast.
3740 if (!CCMatch) {
3741 bool R = (CallerCC == CallingConv::C || CallerCC == CallingConv::Fast);
3742 bool E = (CalleeCC == CallingConv::C || CalleeCC == CallingConv::Fast);
3743 // If R & E, then ok.
3744 if (!R || !E)
3745 return false;
3746 }
3747
3748 // Do not tail call optimize vararg calls.
3749 if (IsVarArg)
3750 return false;
3751
3752 // Also avoid tail call optimization if either caller or callee uses struct
3753 // return semantics.
3754 if (IsCalleeStructRet || IsCallerStructRet)
3755 return false;
3756
3757 // In addition to the cases above, we also disable Tail Call Optimization if
3758 // the calling convention code that at least one outgoing argument needs to
3759 // go on the stack. We cannot check that here because at this point that
3760 // information is not available.
3761 return true;
3762}
3763
3764/// Returns the target specific optimal type for load and store operations as
3765/// a result of memset, memcpy, and memmove lowering.
3766///
3767/// If DstAlign is zero that means it's safe to destination alignment can
3768/// satisfy any constraint. Similarly if SrcAlign is zero it means there isn't
3769/// a need to check it against alignment requirement, probably because the
3770/// source does not need to be loaded. If 'IsMemset' is true, that means it's
3771/// expanding a memset. If 'ZeroMemset' is true, that means it's a memset of
3772/// zero. 'MemcpyStrSrc' indicates whether the memcpy source is constant so it
3773/// does not need to be loaded. It returns EVT::Other if the type should be
3774/// determined using generic target-independent logic.
3776 const MemOp &Op, const AttributeList &FuncAttributes) const {
3777 if (Op.size() >= 8 && Op.isAligned(Align(8)))
3778 return MVT::i64;
3779 if (Op.size() >= 4 && Op.isAligned(Align(4)))
3780 return MVT::i32;
3781 if (Op.size() >= 2 && Op.isAligned(Align(2)))
3782 return MVT::i16;
3783 return MVT::Other;
3784}
3785
3787 LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace,
3788 Align Alignment, MachineMemOperand::Flags Flags, unsigned *Fast) const {
3789 if (!VT.isSimple())
3790 return false;
3791 MVT SVT = VT.getSimpleVT();
3792 if (Subtarget.isHVXVectorType(SVT, true))
3793 return allowsHvxMemoryAccess(SVT, Flags, Fast);
3795 Context, DL, VT, AddrSpace, Alignment, Flags, Fast);
3796}
3797
3799 EVT VT, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags,
3800 unsigned *Fast) const {
3801 if (!VT.isSimple())
3802 return false;
3803 MVT SVT = VT.getSimpleVT();
3804 if (Subtarget.isHVXVectorType(SVT, true))
3805 return allowsHvxMisalignedMemoryAccesses(SVT, Flags, Fast);
3806 if (Fast)
3807 *Fast = 0;
3808 return false;
3809}
3810
3811std::pair<const TargetRegisterClass*, uint8_t>
3812HexagonTargetLowering::findRepresentativeClass(const TargetRegisterInfo *TRI,
3813 MVT VT) const {
3814 if (Subtarget.isHVXVectorType(VT, true)) {
3815 unsigned BitWidth = VT.getSizeInBits();
3816 unsigned VecWidth = Subtarget.getVectorLength() * 8;
3817
3818 if (VT.getVectorElementType() == MVT::i1)
3819 return std::make_pair(&Hexagon::HvxQRRegClass, 1);
3820 if (BitWidth == VecWidth)
3821 return std::make_pair(&Hexagon::HvxVRRegClass, 1);
3822 assert(BitWidth == 2 * VecWidth);
3823 return std::make_pair(&Hexagon::HvxWRRegClass, 1);
3824 }
3825
3827}
3828
3830 ISD::LoadExtType ExtTy, EVT NewVT) const {
3831 // TODO: This may be worth removing. Check regression tests for diffs.
3832 if (!TargetLoweringBase::shouldReduceLoadWidth(Load, ExtTy, NewVT))
3833 return false;
3834
3835 auto *L = cast<LoadSDNode>(Load);
3836 std::pair<SDValue,int> BO = getBaseAndOffset(L->getBasePtr());
3837 // Small-data object, do not shrink.
3838 if (BO.first.getOpcode() == HexagonISD::CONST32_GP)
3839 return false;
3840 if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(BO.first)) {
3841 auto &HTM = static_cast<const HexagonTargetMachine&>(getTargetMachine());
3842 const auto *GO = dyn_cast_or_null<const GlobalObject>(GA->getGlobal());
3843 return !GO || !HTM.getObjFileLowering()->isGlobalInSmallSection(GO, HTM);
3844 }
3845 return true;
3846}
3847
3849 SDNode *Node) const {
3850 AdjustHvxInstrPostInstrSelection(MI, Node);
3851}
3852
3854 Type *ValueTy, Value *Addr,
3855 AtomicOrdering Ord) const {
3856 unsigned SZ = ValueTy->getPrimitiveSizeInBits();
3857 assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic loads supported");
3858 Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_L2_loadw_locked
3859 : Intrinsic::hexagon_L4_loadd_locked;
3860
3861 Value *Call =
3862 Builder.CreateIntrinsic(IntID, {}, Addr, /*FMFSource=*/nullptr, "larx");
3863
3864 return Builder.CreateBitCast(Call, ValueTy);
3865}
3866
3867/// Perform a store-conditional operation to Addr. Return the status of the
3868/// store. This should be 0 if the store succeeded, non-zero otherwise.
3870 Value *Val, Value *Addr,
3871 AtomicOrdering Ord) const {
3872 BasicBlock *BB = Builder.GetInsertBlock();
3873 Module *M = BB->getParent()->getParent();
3874 Type *Ty = Val->getType();
3875 unsigned SZ = Ty->getPrimitiveSizeInBits();
3876
3877 Type *CastTy = Builder.getIntNTy(SZ);
3878 assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic stores supported");
3879 Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_S2_storew_locked
3880 : Intrinsic::hexagon_S4_stored_locked;
3881
3882 Val = Builder.CreateBitCast(Val, CastTy);
3883
3884 Value *Call = Builder.CreateIntrinsic(IntID, {}, {Addr, Val},
3885 /*FMFSource=*/nullptr, "stcx");
3886 Value *Cmp = Builder.CreateICmpEQ(Call, Builder.getInt32(0), "");
3887 Value *Ext = Builder.CreateZExt(Cmp, Type::getInt32Ty(M->getContext()));
3888 return Ext;
3889}
3890
3893 // Do not expand loads and stores that don't exceed 64 bits.
3894 return LI->getType()->getPrimitiveSizeInBits() > 64
3897}
3898
3901 // Do not expand loads and stores that don't exceed 64 bits.
3902 return SI->getValueOperand()->getType()->getPrimitiveSizeInBits() > 64
3905}
3906
3909 AtomicCmpXchgInst *AI) const {
3911}
unsigned const MachineRegisterInfo * MRI
unsigned RegSize
aarch64 promote const
static const LLT S8
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define LLVM_DEBUG(...)
Definition: Debug.h:106
uint64_t Addr
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static cl::opt< int > MaxStoresPerMemcpyCL("max-store-memcpy", cl::Hidden, cl::init(6), cl::desc("Max #stores to inline memcpy"))
static Value * getUnderLyingObjectForBrevLdIntr(Value *V)
static bool CC_SkipOdd(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
static cl::opt< bool > AlignLoads("hexagon-align-loads", cl::Hidden, cl::init(false), cl::desc("Rewrite unaligned loads as a pair of aligned loads"))
static bool isBrevLdIntrinsic(const Value *Inst)
static cl::opt< int > MaxStoresPerMemmoveOptSizeCL("max-store-memmove-Os", cl::Hidden, cl::init(4), cl::desc("Max #stores to inline memmove"))
static cl::opt< int > MaxStoresPerMemmoveCL("max-store-memmove", cl::Hidden, cl::init(6), cl::desc("Max #stores to inline memmove"))
static Value * getBrevLdObject(Value *V)
static cl::opt< int > MaxStoresPerMemsetCL("max-store-memset", cl::Hidden, cl::init(8), cl::desc("Max #stores to inline memset"))
static cl::opt< bool > DisableArgsMinAlignment("hexagon-disable-args-min-alignment", cl::Hidden, cl::init(false), cl::desc("Disable minimum alignment of 1 for " "arguments passed by value on stack"))
static Value * returnEdge(const PHINode *PN, Value *IntrBaseVal)
static cl::opt< int > MaxStoresPerMemcpyOptSizeCL("max-store-memcpy-Os", cl::Hidden, cl::init(4), cl::desc("Max #stores to inline memcpy"))
static SDValue CreateCopyOfByValArgument(SDValue Src, SDValue Dst, SDValue Chain, ISD::ArgFlagsTy Flags, SelectionDAG &DAG, const SDLoc &dl)
CreateCopyOfByValArgument - Make a copy of an aggregate at address specified by "Src" to address "Dst...
static cl::opt< int > MaxStoresPerMemsetOptSizeCL("max-store-memset-Os", cl::Hidden, cl::init(4), cl::desc("Max #stores to inline memset"))
static cl::opt< bool > EmitJumpTables("hexagon-emit-jump-tables", cl::init(true), cl::Hidden, cl::desc("Control jump table emission on Hexagon target"))
static cl::opt< int > MinimumJumpTables("minimum-jump-tables", cl::Hidden, cl::init(5), cl::desc("Set minimum jump tables"))
static cl::opt< bool > EnableHexSDNodeSched("enable-hexagon-sdnode-sched", cl::Hidden, cl::desc("Enable Hexagon SDNode scheduling"))
static cl::opt< bool > EnableFastMath("ffast-math", cl::Hidden, cl::desc("Enable Fast Math processing"))
#define Hexagon_PointerSize
#define HEXAGON_LRFP_SIZE
#define HEXAGON_GOT_SYM_NAME
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define RegName(no)
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
#define H(x, y, z)
Definition: MD5.cpp:57
std::pair< MCSymbol *, MachineModuleInfoImpl::StubValueTy > PairTy
unsigned const TargetRegisterInfo * TRI
#define T1
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
#define P(N)
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static llvm::Type * getVectorElementType(llvm::Type *Ty)
Value * RHS
Value * LHS
APInt bitcastToAPInt() const
Definition: APFloat.h:1351
Class for arbitrary precision integers.
Definition: APInt.h:78
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1542
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:231
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:207
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:168
const T * data() const
Definition: ArrayRef.h:165
An instruction that atomically checks whether a specified value is in a memory location,...
Definition: Instructions.h:501
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:219
The address of a basic block.
Definition: Constants.h:893
CCState - This class holds information needed while lowering arguments and return values.
unsigned getFirstUnallocated(ArrayRef< MCPhysReg > Regs) const
getFirstUnallocated - Return the index of the first unallocated register in the set,...
void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeCallResult - Analyze the return values of a call, incorporating info about the passed values i...
MCRegister AllocateReg(MCPhysReg Reg)
AllocateReg - Attempt to allocate one register.
bool CheckReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
CheckReturn - Analyze the return values of a function, returning true if the return can be performed ...
void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeReturn - Analyze the returned values of a return, incorporating info about the result values i...
CCValAssign - Represent assignment of one arg/retval to a location.
bool isRegLoc() const
Register getLocReg() const
LocInfo getLocInfo() const
bool isMemLoc() const
int64_t getLocMemOffset() const
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1199
This class represents a function call, abstracting a target machine's calling convention.
bool isTailCall() const
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:271
const APFloat & getValueAPF() const
Definition: Constants.h:314
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition: Constants.h:208
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:148
MachineConstantPoolValue * getMachineCPVal() const
bool isMachineConstantPoolEntry() const
const Constant * getConstVal() const
int64_t getSExtValue() const
static Constant * get(ArrayRef< Constant * > V)
Definition: Constants.cpp:1421
This is an important base class in LLVM.
Definition: Constant.h:42
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
A debug info location.
Definition: DebugLoc.h:33
This is the base abstract class for diagnostic reporting in the backend.
Interface for custom diagnostic printing.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:144
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
Definition: Function.h:707
bool empty() const
Definition: Function.h:859
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:216
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:277
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
Definition: Function.h:688
const GlobalValue * getGlobal() const
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:656
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:400
bool isValidAutoIncImm(const EVT VT, const int Offset) const
Hexagon target-specific information for each MachineFunction.
Register getFrameRegister(const MachineFunction &MF) const override
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
const HexagonInstrInfo * getInstrInfo() const override
const HexagonFrameLowering * getFrameLowering() const override
const HexagonRegisterInfo * getRegisterInfo() const override
bool isHVXVectorType(EVT VecTy, bool IncludeBool=false) const
Align getTypeAlignment(MVT Ty) const
unsigned getVectorLength() const
bool isEnvironmentMusl() const
SDValue getPICJumpTableRelocBase(SDValue Table, SelectionDAG &DAG) const override
Returns relocation base for the given PIC jumptable.
SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const
SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) const
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, LLVMContext &Context) const override
This hook should be implemented to check whether the return values described by the Outs array can fi...
SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const
void AdjustInstrPostInstrSelection(MachineInstr &MI, SDNode *Node) const override
This method should be implemented by targets that mark instructions with the 'hasPostISelHook' flag.
bool isTargetCanonicalConstantNode(SDValue Op) const override
Returns true if the given Opc is considered a canonical constant for the target, which should not be ...
ConstraintType getConstraintType(StringRef Constraint) const override
Given a constraint, return the type of constraint it is for this target.
bool isTruncateFree(Type *Ty1, Type *Ty2) const override
Return true if it's free to truncate a value of type FromTy to type ToTy.
SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const
EVT getOptimalMemOpType(const MemOp &Op, const AttributeList &FuncAttributes) const override
Returns the target specific optimal type for load and store operations as a result of memset,...
SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const
SDValue LowerUAddSubO(SDValue Op, SelectionDAG &DAG) const
Value * emitLoadLinked(IRBuilderBase &Builder, Type *ValueTy, Value *Addr, AtomicOrdering Ord) const override
Perform a load-linked operation on Addr, returning a "Value *" with the corresponding pointee type.
bool isLegalICmpImmediate(int64_t Imm) const override
isLegalICmpImmediate - Return true if the specified immediate is legal icmp immediate,...
bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AS, Instruction *I=nullptr) const override
isLegalAddressingMode - Return true if the addressing mode represented by AM is legal for this target...
SDValue LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const
AtomicExpansionKind shouldExpandAtomicStoreInIR(StoreInst *SI) const override
Returns how the given (atomic) store should be expanded by the IR-level AtomicExpand pass into.
SDValue GetDynamicTLSAddr(SelectionDAG &DAG, SDValue Chain, GlobalAddressSDNode *GA, SDValue InGlue, EVT PtrVT, unsigned ReturnReg, unsigned char OperandGlues) const
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &dl, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array,...
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const
bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, SDValue &Base, SDValue &Offset, ISD::MemIndexedMode &AM, SelectionDAG &DAG) const override
Returns true by value, base pointer and offset pointer and addressing mode by reference if this node ...
SDValue LowerUnalignedLoad(SDValue Op, SelectionDAG &DAG) const
SDValue LowerFDIV(SDValue Op, SelectionDAG &DAG) const
SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG) const
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array,...
bool isFPImmLegal(const APFloat &Imm, EVT VT, bool ForCodeSize) const override
isFPImmLegal - Returns true if the target can instruction select the specified FP immediate natively.
bool mayBeEmittedAsTailCall(const CallInst *CI) const override
Return true if the target may be able emit the call instruction as a tail call.
AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override
Returns how the given (atomic) load should be expanded by the IR-level AtomicExpand pass.
SDValue LowerCallResult(SDValue Chain, SDValue InGlue, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals, const SmallVectorImpl< SDValue > &OutVals, SDValue Callee) const
LowerCallResult - Lower the result values of an ISD::CALL into the appropriate copies out of appropri...
SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const
SDValue LowerToTLSInitialExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG) const
SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, SelectionDAG &DAG) const
bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags, unsigned *Fast) const override
Return true if the target supports a memory access of this type for the given address space and align...
SDValue LowerINSERT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const
bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT, unsigned Index) const override
Return true if EXTRACT_SUBVECTOR is cheap for extracting this result type from this source type with ...
SDValue LowerROTL(SDValue Op, SelectionDAG &DAG) const
SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const
SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const
SDValue LowerLoad(SDValue Op, SelectionDAG &DAG) const
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
bool isShuffleMaskLegal(ArrayRef< int > Mask, EVT VT) const override
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations,...
LegalizeAction getCustomOperationAction(SDNode &Op) const override
How to legalize this custom operation?
SDValue LowerToTLSLocalExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG) const
SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const
bool allowTruncateForTailCall(Type *Ty1, Type *Ty2) const override
Return true if a truncation from FromTy to ToTy is permitted when deciding whether a call is in tail ...
SDValue LowerUAddSubOCarry(SDValue Op, SelectionDAG &DAG) const
bool shouldExpandBuildVectorWithShuffles(EVT VT, unsigned DefinedValues) const override
SDValue LowerREADCYCLECOUNTER(SDValue Op, SelectionDAG &DAG) const
SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const
SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
LowerCall - Functions arguments are copied from virtual regs to (physical regs)/(stack frame),...
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags, unsigned *Fast) const override
Determine if the target supports unaligned memory accesses.
const char * getTargetNodeName(unsigned Opcode) const override
This method returns the name of a target specific DAG node.
SDValue LowerStore(SDValue Op, SelectionDAG &DAG) const
SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG) const
SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const
void ReplaceNodeResults(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
This callback is invoked when a node result type is illegal for the target, and the operation was reg...
Value * emitStoreConditional(IRBuilderBase &Builder, Value *Val, Value *Addr, AtomicOrdering Ord) const override
Perform a store-conditional operation to Addr.
bool hasBitTest(SDValue X, SDValue Y) const override
Return true if the target has a bit-test instruction: (X & (1 << Y)) ==/!= 0 This knowledge can be us...
HexagonTargetLowering(const TargetMachine &TM, const HexagonSubtarget &ST)
SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override
Return true if folding a constant offset with the given GlobalAddress is legal.
bool IsEligibleForTailCallOptimization(SDValue Callee, CallingConv::ID CalleeCC, bool isVarArg, bool isCalleeStructRet, bool isCallerStructRet, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SmallVectorImpl< ISD::InputArg > &Ins, SelectionDAG &DAG) const
IsEligibleForTailCallOptimization - Check whether the call is eligible for tail call optimization.
SDValue LowerVSELECT(SDValue Op, SelectionDAG &DAG) const
void LowerOperationWrapper(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
This callback is invoked by the type legalizer to legalize nodes with an illegal operand type but leg...
SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const
SDValue LowerVECTOR_SHIFT(SDValue Op, SelectionDAG &DAG) const
SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const
SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const
bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I, MachineFunction &MF, unsigned Intrinsic) const override
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
AtomicExpansionKind shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *AI) const override
Returns how the given atomic cmpxchg should be expanded by the IR-level AtomicExpand pass.
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
SDValue LowerBITCAST(SDValue Op, SelectionDAG &DAG) const
bool isFMAFasterThanFMulAndFAdd(const MachineFunction &, EVT) const override
Return true if an FMA operation is faster than a pair of mul and add instructions.
SDValue LowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const
SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const
LegalizeTypeAction getPreferredVectorAction(MVT VT) const override
Return the preferred vector type legalization action.
SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const
Register getRegisterByName(const char *RegName, LLT VT, const MachineFunction &MF) const override
Return the register ID of the name passed in.
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const
bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy, EVT NewVT) const override
Return true if it is profitable to reduce a load to a smaller type.
SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG) const
SDValue LowerREADSTEADYCOUNTER(SDValue Op, SelectionDAG &DAG) const
HexagonTargetObjectFile * getObjFileLowering() const override
bool isGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM) const
Return true if this global value should be placed into small data/bss section.
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:113
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Definition: IRBuilder.h:558
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
Definition: IRBuilder.h:495
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:193
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
Definition: IRBuilder.cpp:900
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition: IRBuilder.h:505
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:2270
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:2152
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Definition: IRBuilder.h:2033
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2705
Class to represent integer types.
Definition: DerivedTypes.h:42
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:311
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Base class for LoadSDNode and StoreSDNode.
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc,...
bool isUnindexed() const
Return true if this is NOT a pre/post inc/dec load/store.
bool isIndexed() const
Return true if this is a pre/post inc/dec load/store.
An instruction for reading from memory.
Definition: Instructions.h:176
This class is used to represent ISD::LOAD nodes.
const SDValue & getBasePtr() const
const SDValue & getOffset() const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
Machine Value Type.
unsigned getVectorMinNumElements() const
Given a vector type, return the minimum number of elements it contains.
SimpleValueType SimpleTy
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
bool isInteger() const
Return true if this is an integer or a vector integer type.
bool isScalableVector() const
Return true if this is a vector value type where the runtime length is machine dependent.
static MVT getVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
Definition: ValueTypes.cpp:237
static auto integer_valuetypes()
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
static auto fixedlen_vector_valuetypes()
bool isScalarInteger() const
Return true if this is an integer, not including vectors.
TypeSize getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
static MVT getVectorVT(MVT VT, unsigned NumElements)
MVT getVectorElementType() const
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
static MVT getIntegerVT(unsigned BitWidth)
static auto fp_valuetypes()
void print(raw_ostream &OS, const SlotIndexes *=nullptr, bool IsStandalone=true) const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
void ensureMaxAlignment(Align Alignment)
Make sure the function is at least Align bytes aligned.
void setFrameAddressIsTaken(bool T)
void setHasTailCall(bool V=true)
void setReturnAddressIsTaken(bool s)
unsigned getNumFixedObjects() const
Return the number of fixed objects.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Register addLiveIn(MCRegister PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
Representation of each machine instruction.
Definition: MachineInstr.h:69
A description of a memory reference used in the backend.
Flags
Flags values. These may be or'd together.
@ MOVolatile
The memory access is volatile.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
Flags getFlags() const
Return the raw flags of the source value,.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const MDNode * getRanges() const
Returns the Ranges that describes the dereference.
Align getAlign() const
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
const MachinePointerInfo & getPointerInfo() const
const SDValue & getChain() const
EVT getMemoryVT() const
Return the type of the in-memory value.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:310
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Definition: Operator.h:42
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
const DebugLoc & getDebugLoc() const
Represents one node in the SelectionDAG.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
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
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
const SDValue & getOperand(unsigned i) const
unsigned getOpcode() const
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:228
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:750
const TargetSubtargetInfo & getSubtarget() const
Definition: SelectionDAG.h:499
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, SDValue N)
Definition: SelectionDAG.h:801
SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
SDValue getMemcpy(SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size, Align Alignment, bool isVol, bool AlwaysInline, const CallInst *CI, std::optional< bool > OverrideTailCall, MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo, const AAMDNodes &AAInfo=AAMDNodes(), AAResults *AA=nullptr)
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false)
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
SDValue getRegister(Register Reg, EVT VT)
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
SDValue getGLOBAL_OFFSET_TABLE(EVT VT)
Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc.
SDValue getTargetJumpTable(int JTI, EVT VT, unsigned TargetFlags=0)
Definition: SelectionDAG.h:760
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, SDValue InGlue, const SDLoc &DL)
Return a new CALLSEQ_END node, which always must have a glue result (to ensure it's not CSE'd).
SDValue getBitcast(EVT VT, SDValue V)
Return a bitcast using the SDLoc of the value operand, and casting to the provided type.
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, Register Reg, EVT VT)
Definition: SelectionDAG.h:827
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build Select's if you just have operands and don't want to check...
SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT VT)
Return the expression required to zero extend the Op value assuming it was the smaller SrcTy value.
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:497
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
SDValue getMemBasePlusOffset(SDValue Base, TypeSize Offset, const SDLoc &DL, const SDNodeFlags Flags=SDNodeFlags())
Returns sum of the base pointer and offset.
SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, EVT SVT, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, const SDLoc &DL)
Return a new CALLSEQ_START node, that starts new call frame, in which InSize bytes are set up inside ...
SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either sign-extending or trunca...
SDValue getIndexedStore(SDValue OrigStore, const SDLoc &dl, SDValue Base, SDValue Offset, ISD::MemIndexedMode AM)
SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either any-extending or truncat...
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:796
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.getNode() alone.
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:492
SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
SDValue getRegisterMask(const uint32_t *RegMask)
SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
LLVMContext * getContext() const
Definition: SelectionDAG.h:510
SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned TargetFlags=0)
SDValue getTargetConstantPool(const Constant *C, EVT VT, MaybeAlign Align=std::nullopt, int Offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:767
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:580
SDValue getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1, SDValue N2, ArrayRef< int > Mask)
Return an ISD::VECTOR_SHUFFLE node.
SDValue getLogicalNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a logical NOT operation as (XOR Val, BooleanOne).
static void commuteMask(MutableArrayRef< int > Mask)
Change values in a shuffle permute mask assuming the two vector operands have swapped position.
bool empty() const
Definition: SmallVector.h:81
size_t size() const
Definition: SmallVector.h:78
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
An instruction for storing to memory.
Definition: Instructions.h:292
This class is used to represent ISD::STORE nodes.
const SDValue & getBasePtr() const
const SDValue & getOffset() const
const SDValue & getValue() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:150
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
void setBooleanVectorContents(BooleanContent Ty)
Specify how the target extends the result of a vector boolean value from a vector of i1 to a wider ty...
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
LegalizeAction
This enum indicates whether operations are valid for a target, and if not, what action should be used...
unsigned MaxStoresPerMemcpyOptSize
Likewise for functions with the OptSize attribute.
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
const TargetMachine & getTargetMachine() const
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
void setIndexedLoadAction(ArrayRef< unsigned > IdxModes, MVT VT, LegalizeAction Action)
Indicate that the specified indexed load does or does not work with the specified type and indicate w...
void setPrefLoopAlignment(Align Alignment)
Set the target's preferred loop alignment.
void setMaxAtomicSizeInBitsSupported(unsigned SizeInBits)
Set the maximum atomic operation size supported by the backend.
void setMinFunctionAlignment(Align Alignment)
Set the target's minimum function alignment.
unsigned MaxStoresPerMemsetOptSize
Likewise for functions with the OptSize attribute.
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
unsigned MaxStoresPerMemmove
Specify maximum number of store instructions per memmove call.
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose.
unsigned MaxStoresPerMemmoveOptSize
Likewise for functions with the OptSize attribute.
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type.
void setIndexedStoreAction(ArrayRef< unsigned > IdxModes, MVT VT, LegalizeAction Action)
Indicate that the specified indexed store does or does not work with the specified type and indicate ...
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
void setLibcallName(RTLIB::Libcall Call, const char *Name)
Rename the default libcall routine name for the specified libcall.
void setPrefFunctionAlignment(Align Alignment)
Set the target's preferred function alignment.
unsigned MaxStoresPerMemset
Specify maximum number of store instructions per memset call.
virtual bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtTy, EVT NewVT) const
Return true if it is profitable to reduce a load to a smaller type.
void setMinimumJumpTableEntries(unsigned Val)
Indicate the minimum number of blocks to generate jump tables.
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
bool isOperationLegalOrCustom(unsigned Op, EVT VT, bool LegalOnly=false) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
virtual bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *Fast=nullptr) const
Return true if the target supports a memory access of this type for the given address space and align...
void setMinCmpXchgSizeInBits(unsigned SizeInBits)
Sets the minimum cmpxchg or ll/sc size supported by the backend.
void setStackPointerRegisterToSaveRestore(Register R)
If set to a physical register, this specifies the register that llvm.savestack/llvm....
void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
If Opc/OrigVT is specified as being promoted, the promotion code defaults to trying a larger integer/...
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
void setCondCodeAction(ArrayRef< ISD::CondCode > CCs, MVT VT, LegalizeAction Action)
Indicate that the specified condition code is or isn't supported on the target and indicate what to d...
virtual std::pair< const TargetRegisterClass *, uint8_t > findRepresentativeClass(const TargetRegisterInfo *TRI, MVT VT) const
Return the largest legal super-reg register class of the register class for the specified type and it...
void setTargetDAGCombine(ArrayRef< ISD::NodeType > NTs)
Targets should invoke this method for each target independent node that they want to provide a custom...
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
bool allowsMemoryAccessForAlignment(LLVMContext &Context, const DataLayout &DL, EVT VT, unsigned AddrSpace=0, Align Alignment=Align(1), MachineMemOperand::Flags Flags=MachineMemOperand::MONone, unsigned *Fast=nullptr) const
This function returns true if the memory access is aligned or if the target allows this specific unal...
unsigned MaxStoresPerMemcpy
Specify maximum number of store instructions per memcpy call.
void setSchedulingPreference(Sched::Preference Pref)
Specify the target scheduling preference.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
virtual bool isTargetCanonicalConstantNode(SDValue Op) const
Returns true if the given Opc is considered a canonical constant for the target, which should not be ...
SDValue expandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG) const
Expands an unaligned store to 2 half-size stores for integer values, and possibly more for vectors.
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
std::pair< SDValue, SDValue > expandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG) const
Expands an unaligned load to 2 half-size loads for an integer, and possibly more for vectors.
bool isPositionIndependent() const
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
bool verifyReturnAddressArgumentIsConstant(SDValue Op, SelectionDAG &DAG) const
virtual void LowerOperationWrapper(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const
This callback is invoked by the type legalizer to legalize nodes with an illegal operand type but leg...
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
TLSModel::Model getTLSModel(const GlobalValue *GV) const
Returns the TLS model which should be used for the given global variable.
Reloc::Model getRelocationModel() const
Returns the code generation relocation model.
bool shouldAssumeDSOLocal(const GlobalValue *GV) const
unsigned getID() const
Return the register class ID number.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition: TypeSize.h:345
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition: Type.h:310
static IntegerType * getInt32Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:237
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
const ParentTy * getParent() const
Definition: ilist_node.h:32
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:125
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:41
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ MO_PCREL
MO_PCREL - On a symbol operand, indicates a PC-relative relocation Used for computing a global addres...
@ MO_GOT
MO_GOT - Indicates a GOT-relative relocation.
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:780
@ STACKRESTORE
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain.
Definition: ISDOpcodes.h:1197
@ STACKSAVE
STACKSAVE - STACKSAVE has one operand, an input chain.
Definition: ISDOpcodes.h:1193
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:257
@ INSERT_SUBVECTOR
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1.
Definition: ISDOpcodes.h:574
@ BSWAP
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:744
@ VAEND
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE.
Definition: ISDOpcodes.h:1226
@ ConstantFP
Definition: ISDOpcodes.h:77
@ ADD
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:246
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:1102
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:814
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition: ISDOpcodes.h:498
@ INTRINSIC_VOID
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
Definition: ISDOpcodes.h:205
@ GlobalAddress
Definition: ISDOpcodes.h:78
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:841
@ CONCAT_VECTORS
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
Definition: ISDOpcodes.h:558
@ FADD
Simple binary floating point operators.
Definition: ISDOpcodes.h:397
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
Definition: ISDOpcodes.h:717
@ ATOMIC_FENCE
OUTCHAIN = ATOMIC_FENCE(INCHAIN, ordering, scope) This corresponds to the fence instruction.
Definition: ISDOpcodes.h:1304
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:262
@ FP16_TO_FP
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
Definition: ISDOpcodes.h:964
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:954
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition: ISDOpcodes.h:236
@ FLDEXP
FLDEXP - ldexp, inspired by libm (op0 * 2**op1).
Definition: ISDOpcodes.h:997
@ GlobalTLSAddress
Definition: ISDOpcodes.h:79
@ EH_RETURN
OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 'eh_return' gcc dwarf builtin,...
Definition: ISDOpcodes.h:141
@ SIGN_EXTEND
Conversion operators.
Definition: ISDOpcodes.h:805
@ SCALAR_TO_VECTOR
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
Definition: ISDOpcodes.h:635
@ READSTEADYCOUNTER
READSTEADYCOUNTER - This corresponds to the readfixedcounter intrinsic.
Definition: ISDOpcodes.h:1259
@ PREFETCH
PREFETCH - This corresponds to a prefetch intrinsic.
Definition: ISDOpcodes.h:1292
@ FSINCOS
FSINCOS - Compute both fsin and fcos as a single operation.
Definition: ISDOpcodes.h:1059
@ FNEG
Perform various unary floating-point operations inspired by libm.
Definition: ISDOpcodes.h:981
@ BR_CC
BR_CC - Conditional branch.
Definition: ISDOpcodes.h:1148
@ SSUBO
Same for subtraction.
Definition: ISDOpcodes.h:334
@ BR_JT
BR_JT - Jumptable branch.
Definition: ISDOpcodes.h:1127
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:757
@ SPLAT_VECTOR
SPLAT_VECTOR(VAL) - Returns a vector with the scalar value VAL duplicated in all lanes.
Definition: ISDOpcodes.h:642
@ VACOPY
VACOPY - VACOPY has 5 operands: an input chain, a destination pointer, a source pointer,...
Definition: ISDOpcodes.h:1222
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition: ISDOpcodes.h:330
@ SHL
Shift and rotation operations.
Definition: ISDOpcodes.h:735
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition: ISDOpcodes.h:615
@ EXTRACT_SUBVECTOR
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR.
Definition: ISDOpcodes.h:588
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:550
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:811
@ DEBUGTRAP
DEBUGTRAP - Trap intended to get the attention of a debugger.
Definition: ISDOpcodes.h:1282
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:772
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition: ISDOpcodes.h:1031
@ DYNAMIC_STACKALLOC
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary.
Definition: ISDOpcodes.h:1112
@ ConstantPool
Definition: ISDOpcodes.h:82
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:849
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition: ISDOpcodes.h:697
@ GLOBAL_OFFSET_TABLE
The address of the GOT.
Definition: ISDOpcodes.h:93
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition: ISDOpcodes.h:766
@ UADDO_CARRY
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:310
@ INLINEASM_BR
INLINEASM_BR - Branching version of inline asm. Used by asm-goto.
Definition: ISDOpcodes.h:1168
@ FRAMEADDR
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG.
Definition: ISDOpcodes.h:100
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:887
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
Definition: ISDOpcodes.h:1253
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:709
@ TRAP
TRAP - Trapping instruction.
Definition: ISDOpcodes.h:1279
@ INTRINSIC_WO_CHAIN
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition: ISDOpcodes.h:190
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
Definition: ISDOpcodes.h:539
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition: ISDOpcodes.h:52
@ INLINEASM
INLINEASM - Represents an inline asm block.
Definition: ISDOpcodes.h:1165
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:817
@ VAARG
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
Definition: ISDOpcodes.h:1217
@ BlockAddress
Definition: ISDOpcodes.h:84
@ SHL_PARTS
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations.
Definition: ISDOpcodes.h:794
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition: ISDOpcodes.h:61
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:508
@ INTRINSIC_W_CHAIN
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
Definition: ISDOpcodes.h:198
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition: ISDOpcodes.h:530
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
Definition: ISDOpcodes.h:1555
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition: ISDOpcodes.h:1606
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
Definition: ISDOpcodes.h:1586
@ GeneralDynamic
Definition: CodeGen.h:46
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
constexpr double e
Definition: MathExtras.h:47
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1739
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1697
bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
Definition: Alignment.h:145
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition: bit.h:215
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:291
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition: Format.h:187
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
DWARFExpression::Operation Op
int getNextAvailablePluginDiagnosticKind()
Get the next available kind ID for a plugin diagnostic.
unsigned M0(unsigned Val)
Definition: VE.h:375
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:217
@ DS_Remark
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1766
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:208
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
Extended Value Type.
Definition: ValueTypes.h:35
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition: ValueTypes.h:137
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
Definition: ValueTypes.h:279
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:368
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
Definition: ValueTypes.cpp:289
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:311
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:323
This class contains a discriminated union of information about pointers in memory operands,...
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
unsigned int NumVTs
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*...
This structure contains all information that is necessary for lowering calls.
SmallVector< ISD::InputArg, 32 > Ins
SmallVector< ISD::OutputArg, 32 > Outs
SmallVector< SDValue, 32 > OutVals