LLVM 23.0.0git
XtensaISelLowering.cpp
Go to the documentation of this file.
1//===- XtensaISelLowering.cpp - Xtensa 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 defines the interfaces that Xtensa uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#include "XtensaISelLowering.h"
16#include "XtensaInstrInfo.h"
19#include "XtensaSubtarget.h"
20#include "XtensaTargetMachine.h"
28#include "llvm/Support/Debug.h"
32#include <deque>
33
34using namespace llvm;
35
36#define DEBUG_TYPE "xtensa-lower"
37
38// Return true if we must use long (in fact, indirect) function call.
39// It's simplified version, production implimentation must
40// resolve a functions in ROM (usually glibc functions)
41static bool isLongCall(const char *str) {
42 // Currently always use long calls
43 return true;
44}
45
46// The calling conventions in XtensaCallingConv.td are described in terms of the
47// callee's register window. This function translates registers to the
48// corresponding caller window %o register.
49static unsigned toCallerWindow(unsigned Reg) {
50 if (Reg >= Xtensa::A2 && Reg <= Xtensa::A7)
51 return Reg - Xtensa::A2 + Xtensa::A10;
52 return Reg;
53}
54
56 const XtensaSubtarget &STI)
57 : TargetLowering(TM, STI), Subtarget(STI) {
58 MVT PtrVT = MVT::i32;
59 // Set up the register classes.
60 addRegisterClass(MVT::i32, &Xtensa::ARRegClass);
61
62 if (Subtarget.hasSingleFloat()) {
63 addRegisterClass(MVT::f32, &Xtensa::FPRRegClass);
64 }
65
66 if (Subtarget.hasBoolean()) {
67 addRegisterClass(MVT::v1i1, &Xtensa::BRRegClass);
68 }
69
70 // Set up special registers.
72
74
76
81
83
85 setOperationAction(ISD::SIGN_EXTEND_INREG, {MVT::i8, MVT::i16},
86 Subtarget.hasSEXT() ? Legal : Expand);
87
94
95 // No sign extend instructions for i1 and sign extend load i8
96 for (MVT VT : MVT::integer_valuetypes()) {
101 }
102
108
109 // Expand jump table branches as address arithmetic followed by an
110 // indirect jump.
112
115
119
120 if (Subtarget.hasSingleFloat()) {
123 } else {
126 }
127
130
135
136 if (Subtarget.hasMul32())
138 else
140
141 if (Subtarget.hasMul32High()) {
144 } else {
147 }
148
151
152 if (Subtarget.hasDiv32()) {
157 } else {
162 }
163
166
170
179
181 Subtarget.hasMINMAX() ? Legal : Expand);
182
183 // Implement custom stack allocations
185 // Implement custom stack save and restore
188
189 // VASTART, VAARG and VACOPY need to deal with the Xtensa-specific varargs
190 // structure, but VAEND is a no-op.
195
196 // Handle floating-point types.
197 for (unsigned I = MVT::FIRST_FP_VALUETYPE; I <= MVT::LAST_FP_VALUETYPE; ++I) {
199 if (isTypeLegal(VT)) {
200 if (VT.getSizeInBits() == 32 && Subtarget.hasSingleFloat()) {
207 } else {
214 }
215
216 // TODO: once implemented in InstrInfo uncomment
225 }
226 }
227
228 // Handle floating-point types.
229 if (Subtarget.hasSingleFloat()) {
236 } else {
243 }
244
245 // Floating-point truncation and stores need to be done separately.
246 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
247
248 if (Subtarget.hasS32C1I()) {
251 } else if (Subtarget.hasForcedAtomics()) {
253 } else {
255 }
256
257 // Compute derived properties from the register classes
259}
260
262 const Constant *PersonalityFn) const {
263 return Xtensa::A2;
264}
265
267 const Constant *PersonalityFn) const {
268 return Xtensa::A3;
269}
270
272 const GlobalAddressSDNode *GA) const {
273 // The Xtensa target isn't yet aware of offsets.
274 return false;
275}
276
278 bool ForCodeSize) const {
279 return false;
280}
281
282//===----------------------------------------------------------------------===//
283// Inline asm support
284//===----------------------------------------------------------------------===//
287 if (Constraint.size() == 1) {
288 switch (Constraint[0]) {
289 case 'r':
290 return C_RegisterClass;
291 default:
292 break;
293 }
294 }
295 return TargetLowering::getConstraintType(Constraint);
296}
297
300 AsmOperandInfo &Info, const char *Constraint) const {
302 Value *CallOperandVal = Info.CallOperandVal;
303 // If we don't have a value, we can't do a match,
304 // but allow it at the lowest weight.
305 if (!CallOperandVal)
306 return CW_Default;
307
308 Type *Ty = CallOperandVal->getType();
309
310 // Look at the constraint type.
311 switch (*Constraint) {
312 default:
313 Weight = TargetLowering::getSingleConstraintMatchWeight(Info, Constraint);
314 break;
315 case 'r':
316 if (Ty->isIntegerTy())
317 Weight = CW_Register;
318 break;
319 }
320 return Weight;
321}
322
323std::pair<unsigned, const TargetRegisterClass *>
325 const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const {
326 if (Constraint.size() == 1) {
327 // GCC Constraint Letters
328 switch (Constraint[0]) {
329 default:
330 break;
331 case 'r': // General-purpose register
332 return std::make_pair(0U, &Xtensa::ARRegClass);
333 }
334 }
336}
337
339 SDValue Op, StringRef Constraint, std::vector<SDValue> &Ops,
340 SelectionDAG &DAG) const {
341 SDLoc DL(Op);
342
343 // Only support length 1 constraints for now.
344 if (Constraint.size() > 1)
345 return;
346
348}
349
350//===----------------------------------------------------------------------===//
351// Calling conventions
352//===----------------------------------------------------------------------===//
353
354#include "XtensaGenCallingConv.inc"
355
356static const MCPhysReg IntRegs[] = {Xtensa::A2, Xtensa::A3, Xtensa::A4,
357 Xtensa::A5, Xtensa::A6, Xtensa::A7};
358
359static bool CC_Xtensa_Custom(unsigned ValNo, MVT ValVT, MVT LocVT,
360 CCValAssign::LocInfo LocInfo,
361 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
362 CCState &State) {
363 if (ArgFlags.isByVal()) {
364 Align ByValAlign = ArgFlags.getNonZeroByValAlign();
365 unsigned ByValSize = ArgFlags.getByValSize();
366 if (ByValSize < 4) {
367 ByValSize = 4;
368 }
369 if (ByValAlign < Align(4)) {
370 ByValAlign = Align(4);
371 }
372 unsigned Offset = State.AllocateStack(ByValSize, ByValAlign);
373 State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
374 // Mark all unused registers as allocated to avoid misuse
375 // of such registers.
376 while (State.AllocateReg(IntRegs))
377 ;
378 return false;
379 }
380
381 // Promote i8 and i16
382 if (LocVT == MVT::i8 || LocVT == MVT::i16) {
383 LocVT = MVT::i32;
384 if (ArgFlags.isSExt())
385 LocInfo = CCValAssign::SExt;
386 else if (ArgFlags.isZExt())
387 LocInfo = CCValAssign::ZExt;
388 else
389 LocInfo = CCValAssign::AExt;
390 }
391
392 unsigned Register;
393
394 Align OrigAlign = ArgFlags.getNonZeroOrigAlign();
395 bool needs64BitAlign = (ValVT == MVT::i32 && OrigAlign == Align(8));
396 bool needs128BitAlign = (ValVT == MVT::i32 && OrigAlign == Align(16));
397
398 if (ValVT == MVT::i32) {
399 Register = State.AllocateReg(IntRegs);
400 // If this is the first part of an i64 arg,
401 // the allocated register must be either A2, A4 or A6.
402 if (needs64BitAlign && (Register == Xtensa::A3 || Register == Xtensa::A5 ||
403 Register == Xtensa::A7))
404 Register = State.AllocateReg(IntRegs);
405 // arguments with 16byte alignment must be passed in the first register or
406 // passed via stack
407 if (needs128BitAlign && (Register != Xtensa::A2))
408 while ((Register = State.AllocateReg(IntRegs)))
409 ;
410 LocVT = MVT::i32;
411 } else if (ValVT == MVT::f64) {
412 // Allocate int register and shadow next int register.
413 Register = State.AllocateReg(IntRegs);
414 if (Register == Xtensa::A3 || Register == Xtensa::A5 ||
415 Register == Xtensa::A7)
416 Register = State.AllocateReg(IntRegs);
417 State.AllocateReg(IntRegs);
418 LocVT = MVT::i32;
419 } else {
420 report_fatal_error("Cannot handle this ValVT.");
421 }
422
423 if (!Register) {
424 unsigned Offset = State.AllocateStack(ValVT.getStoreSize(), OrigAlign);
425 State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
426 } else {
427 State.addLoc(CCValAssign::getReg(ValNo, ValVT, Register, LocVT, LocInfo));
428 }
429
430 return false;
431}
432
433/// Return the register type for a given MVT
436 EVT VT) const {
437 if (VT.isFloatingPoint())
438 return MVT::i32;
439
440 return TargetLowering::getRegisterTypeForCallingConv(Context, CC, VT);
441}
442
443CCAssignFn *XtensaTargetLowering::CCAssignFnForCall(CallingConv::ID CC,
444 bool IsVarArg) const {
445 return CC_Xtensa_Custom;
446}
447
449 SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
450 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
451 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
453 MachineFrameInfo &MFI = MF.getFrameInfo();
455
456 // Used with vargs to acumulate store chains.
457 std::vector<SDValue> OutChains;
458
459 // Assign locations to all of the incoming arguments.
461 CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
462 *DAG.getContext());
463
464 CCInfo.AnalyzeFormalArguments(Ins, CCAssignFnForCall(CallConv, IsVarArg));
465
466 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
467 CCValAssign &VA = ArgLocs[i];
468 // Arguments stored on registers
469 if (VA.isRegLoc()) {
470 EVT RegVT = VA.getLocVT();
471
472 if (RegVT != MVT::i32)
473 report_fatal_error("RegVT not supported by FormalArguments Lowering");
474
475 // Transform the arguments stored on
476 // physical registers into virtual ones
477 Register Reg = 0;
478 MCRegister FrameReg = Subtarget.getRegisterInfo()->getFrameRegister(MF);
479
480 // Argument passed in FrameReg in Windowed ABI we save in A8 (in
481 // emitPrologue), so load argument from A8
482 if (Subtarget.isWindowedABI() && (VA.getLocReg() == FrameReg)) {
483 Reg = MF.addLiveIn(Xtensa::A8, &Xtensa::ARRegClass);
484 XtensaFI->setSaveFrameRegister();
485 } else {
486 Reg = MF.addLiveIn(VA.getLocReg(), &Xtensa::ARRegClass);
487 }
488
489 SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegVT);
490
491 // If this is an 8 or 16-bit value, it has been passed promoted
492 // to 32 bits. Insert an assert[sz]ext to capture this, then
493 // truncate to the right size.
494 if (VA.getLocInfo() != CCValAssign::Full) {
495 unsigned Opcode = 0;
496 if (VA.getLocInfo() == CCValAssign::SExt)
497 Opcode = ISD::AssertSext;
498 else if (VA.getLocInfo() == CCValAssign::ZExt)
499 Opcode = ISD::AssertZext;
500 if (Opcode)
501 ArgValue = DAG.getNode(Opcode, DL, RegVT, ArgValue,
502 DAG.getValueType(VA.getValVT()));
503 ArgValue = DAG.getNode((VA.getValVT() == MVT::f32) ? ISD::BITCAST
505 DL, VA.getValVT(), ArgValue);
506 }
507
508 InVals.push_back(ArgValue);
509
510 } else {
511 assert(VA.isMemLoc());
512
513 EVT ValVT = VA.getValVT();
514
515 // The stack pointer offset is relative to the caller stack frame.
516 int FI = MFI.CreateFixedObject(ValVT.getStoreSize(), VA.getLocMemOffset(),
517 true);
518
519 if (Ins[VA.getValNo()].Flags.isByVal()) {
520 // Assume that in this case load operation is created
521 SDValue FIN = DAG.getFrameIndex(FI, MVT::i32);
522 InVals.push_back(FIN);
523 } else {
524 // Create load nodes to retrieve arguments from the stack
525 SDValue FIN =
527 InVals.push_back(DAG.getLoad(
528 ValVT, DL, Chain, FIN,
530 }
531 }
532 }
533
534 if (IsVarArg) {
535 unsigned Idx = CCInfo.getFirstUnallocated(IntRegs);
536 unsigned ArgRegsNum = std::size(IntRegs);
537 const TargetRegisterClass *RC = &Xtensa::ARRegClass;
538 MachineFrameInfo &MFI = MF.getFrameInfo();
539 MachineRegisterInfo &RegInfo = MF.getRegInfo();
540 unsigned RegSize = 4;
541 MVT RegTy = MVT::i32;
542 MVT FITy = getFrameIndexTy(DAG.getDataLayout());
543
544 XtensaFI->setVarArgsFirstGPR(Idx + 2); // 2 - number of a2 register
545
547 MFI.CreateFixedObject(4, CCInfo.getStackSize(), true));
548
549 // Offset of the first variable argument from stack pointer, and size of
550 // the vararg save area. For now, the varargs save area is either zero or
551 // large enough to hold a0-a7.
552 int VaArgOffset, VarArgsSaveSize;
553
554 // If all registers are allocated, then all varargs must be passed on the
555 // stack and we don't need to save any argregs.
556 if (ArgRegsNum == Idx) {
557 VaArgOffset = CCInfo.getStackSize();
558 VarArgsSaveSize = 0;
559 } else {
560 VarArgsSaveSize = RegSize * (ArgRegsNum - Idx);
561 VaArgOffset = -VarArgsSaveSize;
562
563 // Record the frame index of the first variable argument
564 // which is a value necessary to VASTART.
565 int FI = MFI.CreateFixedObject(RegSize, VaArgOffset, true);
566 XtensaFI->setVarArgsInRegsFrameIndex(FI);
567
568 // Copy the integer registers that may have been used for passing varargs
569 // to the vararg save area.
570 for (unsigned I = Idx; I < ArgRegsNum; ++I, VaArgOffset += RegSize) {
571 const Register Reg = RegInfo.createVirtualRegister(RC);
572 RegInfo.addLiveIn(IntRegs[I], Reg);
573
574 SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegTy);
575 FI = MFI.CreateFixedObject(RegSize, VaArgOffset, true);
576 SDValue PtrOff = DAG.getFrameIndex(FI, FITy);
577 SDValue Store = DAG.getStore(Chain, DL, ArgValue, PtrOff,
579 OutChains.push_back(Store);
580 }
581 }
582 }
583
584 // All stores are grouped in one node to allow the matching between
585 // the size of Ins and InVals. This only happens when on varg functions
586 if (!OutChains.empty()) {
587 OutChains.push_back(Chain);
588 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, OutChains);
589 }
590
591 return Chain;
592}
593
596 SmallVectorImpl<SDValue> &InVals) const {
597 SelectionDAG &DAG = CLI.DAG;
598 SDLoc &DL = CLI.DL;
600 SmallVector<SDValue, 32> &OutVals = CLI.OutVals;
602 SDValue Chain = CLI.Chain;
603 SDValue Callee = CLI.Callee;
604 bool &IsTailCall = CLI.IsTailCall;
605 CallingConv::ID CallConv = CLI.CallConv;
606 bool IsVarArg = CLI.IsVarArg;
607
609 EVT PtrVT = getPointerTy(DAG.getDataLayout());
610 const TargetFrameLowering *TFL = Subtarget.getFrameLowering();
611
612 // TODO: Support tail call optimization.
613 IsTailCall = false;
614
615 // Analyze the operands of the call, assigning locations to each operand.
617 CCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext());
618
619 CCAssignFn *CC = CCAssignFnForCall(CallConv, IsVarArg);
620
621 CCInfo.AnalyzeCallOperands(Outs, CC);
622
623 // Get a count of how many bytes are to be pushed on the stack.
624 unsigned NumBytes = CCInfo.getStackSize();
625
626 Align StackAlignment = TFL->getStackAlign();
627 unsigned NextStackOffset = alignTo(NumBytes, StackAlignment);
628
629 Chain = DAG.getCALLSEQ_START(Chain, NextStackOffset, 0, DL);
630
631 // Copy argument values to their designated locations.
632 std::deque<std::pair<unsigned, SDValue>> RegsToPass;
633 SmallVector<SDValue, 8> MemOpChains;
634 SDValue StackPtr;
635 for (unsigned I = 0, E = ArgLocs.size(); I != E; ++I) {
636 CCValAssign &VA = ArgLocs[I];
637 SDValue ArgValue = OutVals[I];
638 ISD::ArgFlagsTy Flags = Outs[I].Flags;
639
640 if (VA.isRegLoc())
641 // Queue up the argument copies and emit them at the end.
642 RegsToPass.push_back(std::make_pair(VA.getLocReg(), ArgValue));
643 else if (Flags.isByVal()) {
644 assert(VA.isMemLoc());
645 assert(Flags.getByValSize() &&
646 "ByVal args of size 0 should have been ignored by front-end.");
647 assert(!IsTailCall &&
648 "Do not tail-call optimize if there is a byval argument.");
649
650 if (!StackPtr.getNode())
651 StackPtr = DAG.getCopyFromReg(Chain, DL, Xtensa::SP, PtrVT);
652 unsigned Offset = VA.getLocMemOffset();
653 SDValue Address = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr,
655 SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), DL, MVT::i32);
656 SDValue Memcpy = DAG.getMemcpy(
657 Chain, DL, Address, ArgValue, SizeNode, Flags.getNonZeroByValAlign(),
658 /*isVolatile=*/false, /*AlwaysInline=*/false,
659 /*CI=*/nullptr, std::nullopt, MachinePointerInfo(),
661 MemOpChains.push_back(Memcpy);
662 } else {
663 assert(VA.isMemLoc() && "Argument not register or memory");
664
665 // Work out the address of the stack slot. Unpromoted ints and
666 // floats are passed as right-justified 8-byte values.
667 if (!StackPtr.getNode())
668 StackPtr = DAG.getCopyFromReg(Chain, DL, Xtensa::SP, PtrVT);
669 unsigned Offset = VA.getLocMemOffset();
670 SDValue Address = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr,
672
673 // Emit the store.
674 MemOpChains.push_back(
675 DAG.getStore(Chain, DL, ArgValue, Address, MachinePointerInfo()));
676 }
677 }
678
679 // Join the stores, which are independent of one another.
680 if (!MemOpChains.empty())
681 Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOpChains);
682
683 // Build a sequence of copy-to-reg nodes, chained and glued together.
684 SDValue Glue;
685 for (unsigned I = 0, E = RegsToPass.size(); I != E; ++I) {
686 unsigned Reg = RegsToPass[I].first;
687 if (Subtarget.isWindowedABI())
688 Reg = toCallerWindow(Reg);
689 Chain = DAG.getCopyToReg(Chain, DL, Reg, RegsToPass[I].second, Glue);
690 Glue = Chain.getValue(1);
691 }
692 std::string name;
693 unsigned char TF = 0;
694
695 // Accept direct calls by converting symbolic call addresses to the
696 // associated Target* opcodes.
698 name = E->getSymbol();
699 TF = E->getTargetFlags();
700 if (isPositionIndependent()) {
701 report_fatal_error("PIC relocations is not supported");
702 } else
703 Callee = DAG.getTargetExternalSymbol(E->getSymbol(), PtrVT, TF);
705 const GlobalValue *GV = G->getGlobal();
706 name = GV->getName().str();
707 }
708
709 if ((!name.empty()) && isLongCall(name.c_str())) {
710 // Create a constant pool entry for the callee address
712 XtensaMachineFunctionInfo *XtensaFI =
714 unsigned LabelId = XtensaFI->createCPLabelId();
715
717 *DAG.getContext(), name.c_str(), LabelId, false, Modifier);
718
719 // Get the address of the callee into a register
720 SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, Align(4), 0, TF);
721 SDValue CPWrap = getAddrPCRel(CPAddr, DAG);
722 Callee = DAG.getLoad(
723 PtrVT, DL, DAG.getEntryNode(), CPWrap,
725 }
726
727 // The first call operand is the chain and the second is the target address.
729 Ops.push_back(Chain);
730 Ops.push_back(Callee);
731
732 // Add a register mask operand representing the call-preserved registers.
733 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
734 const uint32_t *Mask = TRI->getCallPreservedMask(MF, CallConv);
735 assert(Mask && "Missing call preserved mask for calling convention");
736 Ops.push_back(DAG.getRegisterMask(Mask));
737
738 // Add argument registers to the end of the list so that they are
739 // known live into the call.
740 for (unsigned I = 0, E = RegsToPass.size(); I != E; ++I) {
741 unsigned Reg = RegsToPass[I].first;
742 if (Subtarget.isWindowedABI())
743 Reg = toCallerWindow(Reg);
744 Ops.push_back(DAG.getRegister(Reg, RegsToPass[I].second.getValueType()));
745 }
746
747 // Glue the call to the argument copies, if any.
748 if (Glue.getNode())
749 Ops.push_back(Glue);
750
751 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
752 Chain = DAG.getNode(Subtarget.isWindowedABI() ? XtensaISD::CALLW8
753 : XtensaISD::CALL,
754 DL, NodeTys, Ops);
755 Glue = Chain.getValue(1);
756
757 // Mark the end of the call, which is glued to the call itself.
758 Chain = DAG.getCALLSEQ_END(Chain, DAG.getConstant(NumBytes, DL, PtrVT, true),
759 DAG.getConstant(0, DL, PtrVT, true), Glue, DL);
760 Glue = Chain.getValue(1);
761
762 // Assign locations to each value returned by this call.
764 CCState RetCCInfo(CallConv, IsVarArg, MF, RetLocs, *DAG.getContext());
765 RetCCInfo.AnalyzeCallResult(Ins, Subtarget.isWindowedABI() ? RetCCW8_Xtensa
766 : RetCC_Xtensa);
767
768 // Copy all of the result registers out of their specified physreg.
769 for (unsigned I = 0, E = RetLocs.size(); I != E; ++I) {
770 CCValAssign &VA = RetLocs[I];
771
772 // Copy the value out, gluing the copy to the end of the call sequence.
773 unsigned Reg = VA.getLocReg();
774 SDValue RetValue = DAG.getCopyFromReg(Chain, DL, Reg, VA.getLocVT(), Glue);
775 Chain = RetValue.getValue(1);
776 Glue = RetValue.getValue(2);
777
778 InVals.push_back(RetValue);
779 }
780 return Chain;
781}
782
784 CallingConv::ID CallConv, MachineFunction &MF, bool IsVarArg,
785 const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context,
786 const Type *RetTy) const {
788 CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
789 return CCInfo.CheckReturn(Outs, RetCC_Xtensa);
790}
791
794 bool IsVarArg,
796 const SmallVectorImpl<SDValue> &OutVals,
797 const SDLoc &DL, SelectionDAG &DAG) const {
799
800 // Assign locations to each returned value.
802 CCState RetCCInfo(CallConv, IsVarArg, MF, RetLocs, *DAG.getContext());
803 RetCCInfo.AnalyzeReturn(Outs, RetCC_Xtensa);
804
805 SDValue Glue;
806 // Quick exit for void returns
807 if (RetLocs.empty())
808 return DAG.getNode(Subtarget.isWindowedABI() ? XtensaISD::RETW
809 : XtensaISD::RET,
810 DL, MVT::Other, Chain);
811
812 // Copy the result values into the output registers.
814 RetOps.push_back(Chain);
815 for (unsigned I = 0, E = RetLocs.size(); I != E; ++I) {
816 CCValAssign &VA = RetLocs[I];
817 SDValue RetValue = OutVals[I];
818
819 // Make the return register live on exit.
820 assert(VA.isRegLoc() && "Can only return in registers!");
821
822 // Chain and glue the copies together.
823 unsigned Register = VA.getLocReg();
824 Chain = DAG.getCopyToReg(Chain, DL, Register, RetValue, Glue);
825 Glue = Chain.getValue(1);
826 RetOps.push_back(DAG.getRegister(Register, VA.getLocVT()));
827 }
828
829 // Update chain and glue.
830 RetOps[0] = Chain;
831 if (Glue.getNode())
832 RetOps.push_back(Glue);
833
834 return DAG.getNode(Subtarget.isWindowedABI() ? XtensaISD::RETW
835 : XtensaISD::RET,
836 DL, MVT::Other, RetOps);
837}
838
840 switch (Cond) {
841 case ISD::SETEQ:
842 return Xtensa::BEQ;
843 case ISD::SETNE:
844 return Xtensa::BNE;
845 case ISD::SETLT:
846 return Xtensa::BLT;
847 case ISD::SETLE:
848 return Xtensa::BGE;
849 case ISD::SETGT:
850 return Xtensa::BLT;
851 case ISD::SETGE:
852 return Xtensa::BGE;
853 case ISD::SETULT:
854 return Xtensa::BLTU;
855 case ISD::SETULE:
856 return Xtensa::BGEU;
857 case ISD::SETUGT:
858 return Xtensa::BLTU;
859 case ISD::SETUGE:
860 return Xtensa::BGEU;
861 default:
862 llvm_unreachable("Unknown branch kind");
863 }
864}
865
866static std::pair<unsigned, unsigned> getFPBranchKind(ISD::CondCode Cond) {
867 switch (Cond) {
868 case ISD::SETUNE:
869 return std::make_pair(Xtensa::BF, Xtensa::OEQ_S);
870 case ISD::SETUO:
871 return std::make_pair(Xtensa::BT, Xtensa::UN_S);
872 case ISD::SETO:
873 return std::make_pair(Xtensa::BF, Xtensa::UN_S);
874 case ISD::SETUEQ:
875 return std::make_pair(Xtensa::BT, Xtensa::UEQ_S);
876 case ISD::SETULE:
877 return std::make_pair(Xtensa::BT, Xtensa::ULE_S);
878 case ISD::SETULT:
879 return std::make_pair(Xtensa::BT, Xtensa::ULT_S);
880 case ISD::SETEQ:
881 case ISD::SETOEQ:
882 return std::make_pair(Xtensa::BT, Xtensa::OEQ_S);
883 case ISD::SETNE:
884 return std::make_pair(Xtensa::BF, Xtensa::OEQ_S);
885 case ISD::SETLE:
886 case ISD::SETOLE:
887 return std::make_pair(Xtensa::BT, Xtensa::OLE_S);
888 case ISD::SETLT:
889 case ISD::SETOLT:
890 return std::make_pair(Xtensa::BT, Xtensa::OLT_S);
891 case ISD::SETGE:
892 return std::make_pair(Xtensa::BF, Xtensa::OLT_S);
893 case ISD::SETGT:
894 return std::make_pair(Xtensa::BF, Xtensa::OLE_S);
895 case ISD::SETOGT:
896 return std::make_pair(Xtensa::BF, Xtensa::ULE_S);
897 case ISD::SETOGE:
898 return std::make_pair(Xtensa::BF, Xtensa::ULT_S);
899 case ISD::SETONE:
900 return std::make_pair(Xtensa::BF, Xtensa::UEQ_S);
901 case ISD::SETUGT:
902 return std::make_pair(Xtensa::BF, Xtensa::OLE_S);
903 case ISD::SETUGE:
904 return std::make_pair(Xtensa::BF, Xtensa::OLT_S);
905 default:
906 llvm_unreachable("Invalid condition!");
907 }
908}
909
910SDValue XtensaTargetLowering::LowerSELECT_CC(SDValue Op,
911 SelectionDAG &DAG) const {
912 SDLoc DL(Op);
913 EVT Ty = Op.getValueType();
914 SDValue LHS = Op.getOperand(0);
915 SDValue RHS = Op.getOperand(1);
916 SDValue TrueValue = Op.getOperand(2);
917 SDValue FalseValue = Op.getOperand(3);
918 ISD::CondCode CC = cast<CondCodeSDNode>(Op->getOperand(4))->get();
919
920 if (LHS.getValueType() == MVT::i32) {
921 unsigned BrOpcode = getBranchOpcode(CC);
922 SDValue TargetCC = DAG.getConstant(BrOpcode, DL, MVT::i32);
923
924 SDValue Res = DAG.getNode(XtensaISD::SELECT_CC, DL, Ty, LHS, RHS, TrueValue,
925 FalseValue, TargetCC, Op->getFlags());
926 return Res;
927 }
928 assert(LHS.getValueType() == MVT::f32 &&
929 "We expect MVT::f32 type of the LHS Operand in SELECT_CC");
930 unsigned BrOpcode;
931 unsigned CmpOpCode;
932 std::tie(BrOpcode, CmpOpCode) = getFPBranchKind(CC);
933 SDValue TargetCC = DAG.getConstant(CmpOpCode, DL, MVT::i32);
934 SDValue TargetBC = DAG.getConstant(BrOpcode, DL, MVT::i32);
935 return DAG.getNode(XtensaISD::SELECT_CC_FP, DL, Ty,
936 {LHS, RHS, TrueValue, FalseValue, TargetCC, TargetBC},
937 Op->getFlags());
938}
939
940SDValue XtensaTargetLowering::LowerRETURNADDR(SDValue Op,
941 SelectionDAG &DAG) const {
942 // This nodes represent llvm.returnaddress on the DAG.
943 // It takes one operand, the index of the return address to return.
944 // An index of zero corresponds to the current function's return address.
945 // An index of one to the parent's return address, and so on.
946 // Depths > 0 not supported yet!
947 if (Op.getConstantOperandVal(0) != 0)
948 return SDValue();
949
950 MachineFunction &MF = DAG.getMachineFunction();
951 MachineFrameInfo &MFI = MF.getFrameInfo();
952 EVT VT = Op.getValueType();
953 MFI.setReturnAddressIsTaken(true);
954
955 // Return RA, which contains the return address. Mark it an implicit
956 // live-in.
957 Register RA = MF.addLiveIn(Xtensa::A0, getRegClassFor(MVT::i32));
958 return DAG.getCopyFromReg(DAG.getEntryNode(), SDLoc(Op), RA, VT);
959}
960
961SDValue XtensaTargetLowering::LowerImmediate(SDValue Op,
962 SelectionDAG &DAG) const {
963 const ConstantSDNode *CN = cast<ConstantSDNode>(Op);
964 SDLoc DL(CN);
965 APInt APVal = CN->getAPIntValue();
966 int64_t Value = APVal.getSExtValue();
967 if (Op.getValueType() == MVT::i32) {
968 // Check if use node maybe lowered to the MOVI instruction
969 if (Value > -2048 && Value <= 2047)
970 return Op;
971 // Check if use node maybe lowered to the ADDMI instruction
972 SDNode &OpNode = *Op.getNode();
973 if ((OpNode.hasOneUse() && OpNode.user_begin()->getOpcode() == ISD::ADD) &&
975 return Op;
976 Type *Ty = Type::getInt32Ty(*DAG.getContext());
978 SDValue CP = DAG.getConstantPool(CV, MVT::i32);
979 SDValue Res =
980 DAG.getLoad(MVT::i32, DL, DAG.getEntryNode(), CP, MachinePointerInfo());
981 return Res;
982 }
983 return Op;
984}
985
986SDValue XtensaTargetLowering::LowerGlobalAddress(SDValue Op,
987 SelectionDAG &DAG) const {
988 const GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Op);
989 SDLoc DL(Op);
990 auto PtrVT = Op.getValueType();
991 const GlobalValue *GV = G->getGlobal();
992
993 SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, Align(4));
994 SDValue CPWrap = getAddrPCRel(CPAddr, DAG);
995 SDValue Res = DAG.getLoad(
996 PtrVT, DL, DAG.getEntryNode(), CPWrap,
998 return Res;
999}
1000
1001SDValue XtensaTargetLowering::LowerGlobalTLSAddress(SDValue Op,
1002 SelectionDAG &DAG) const {
1003 const GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Op);
1004 SDLoc DL(Op);
1005 EVT PtrVT = Op.getValueType();
1006 const GlobalValue *GV = G->getGlobal();
1007
1008 if (DAG.getTarget().useEmulatedTLS())
1009 return LowerToTLSEmulatedModel(G, DAG);
1010
1012
1013 if (!Subtarget.hasTHREADPTR()) {
1014 DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
1015 DAG.getMachineFunction().getFunction(), "only emulated TLS supported",
1016 DL.getDebugLoc()));
1017 return DAG.getPOISON(Op->getValueType(0));
1018 }
1019
1020 if (model == TLSModel::LocalExec || model == TLSModel::InitialExec) {
1021 bool Priv = GV->isPrivateLinkage(GV->getLinkage());
1022 MachineFunction &MF = DAG.getMachineFunction();
1023 XtensaMachineFunctionInfo *XtensaFI =
1024 MF.getInfo<XtensaMachineFunctionInfo>();
1025 unsigned LabelId = XtensaFI->createCPLabelId();
1026
1027 // Create a constant pool entry for the callee address
1028 XtensaConstantPoolValue *CPV = XtensaConstantPoolSymbol::Create(
1029 *DAG.getContext(), GV->getName().str().c_str(), LabelId, Priv,
1031
1032 // Get the address of the callee into a register
1033 SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, Align(4));
1034 SDValue CPWrap = getAddrPCRel(CPAddr, DAG);
1035 SDValue Addr = DAG.getLoad(
1036 PtrVT, DL, DAG.getEntryNode(), CPWrap,
1038
1039 SDValue TPRegister = DAG.getRegister(Xtensa::THREADPTR, MVT::i32);
1040 SDValue ThreadPointer =
1041 DAG.getNode(XtensaISD::RUR, DL, MVT::i32, TPRegister);
1042
1043 return DAG.getNode(ISD::ADD, DL, PtrVT, ThreadPointer, Addr);
1044 }
1045
1046 DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
1048 "only local-exec and initial-exec TLS mode supported", DL.getDebugLoc()));
1049
1050 return DAG.getPOISON(Op->getValueType(0));
1051}
1052
1053SDValue XtensaTargetLowering::LowerBlockAddress(SDValue Op,
1054 SelectionDAG &DAG) const {
1055 BlockAddressSDNode *Node = cast<BlockAddressSDNode>(Op);
1056 SDLoc DL(Op);
1057 const BlockAddress *BA = Node->getBlockAddress();
1058 EVT PtrVT = Op.getValueType();
1059 MachineFunction &MF = DAG.getMachineFunction();
1060 XtensaMachineFunctionInfo *XtensaFI = MF.getInfo<XtensaMachineFunctionInfo>();
1061 unsigned LabelId = XtensaFI->createCPLabelId();
1062
1063 XtensaConstantPoolValue *CPV =
1065 SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, Align(4));
1066 SDValue CPWrap = getAddrPCRel(CPAddr, DAG);
1067 SDValue Res = DAG.getLoad(
1068 PtrVT, DL, DAG.getEntryNode(), CPWrap,
1070 return Res;
1071}
1072
1073SDValue XtensaTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const {
1074 SDValue Chain = Op.getOperand(0);
1075 SDValue Table = Op.getOperand(1);
1076 SDValue Index = Op.getOperand(2);
1077 SDLoc DL(Op);
1078 JumpTableSDNode *JT = cast<JumpTableSDNode>(Table);
1079 MachineFunction &MF = DAG.getMachineFunction();
1080 const MachineJumpTableInfo *MJTI = MF.getJumpTableInfo();
1081 SDValue TargetJT = DAG.getTargetJumpTable(JT->getIndex(), MVT::i32);
1082 const DataLayout &TD = DAG.getDataLayout();
1083 EVT PtrVT = Table.getValueType();
1084 unsigned EntrySize = MJTI->getEntrySize(TD);
1085
1086 assert((MJTI->getEntrySize(TD) == 4) && "Unsupported jump-table entry size");
1087
1088 Index = DAG.getNode(
1089 ISD::SHL, DL, Index.getValueType(), Index,
1090 DAG.getConstant(Log2_32(EntrySize), DL, Index.getValueType()));
1091
1092 SDValue Addr = DAG.getNode(ISD::ADD, DL, Index.getValueType(), Index, Table);
1093 SDValue LD =
1094 DAG.getLoad(PtrVT, DL, Chain, Addr,
1096
1097 return DAG.getNode(XtensaISD::BR_JT, DL, MVT::Other, LD.getValue(1), LD,
1098 TargetJT);
1099}
1100
1101SDValue XtensaTargetLowering::LowerJumpTable(SDValue Op,
1102 SelectionDAG &DAG) const {
1103 JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
1104 EVT PtrVT = Op.getValueType();
1105 SDLoc DL(Op);
1106
1107 // Create a constant pool entry for the jumptable address
1108 XtensaConstantPoolValue *CPV =
1110
1111 // Get the address of the jumptable into a register
1112 SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, Align(4));
1113
1114 SDValue Res = DAG.getLoad(
1115 PtrVT, DL, DAG.getEntryNode(), getAddrPCRel(CPAddr, DAG),
1117 return Res;
1118}
1119
1120SDValue XtensaTargetLowering::getAddrPCRel(SDValue Op,
1121 SelectionDAG &DAG) const {
1122 SDLoc DL(Op);
1123 EVT Ty = Op.getValueType();
1124 return DAG.getNode(XtensaISD::PCREL_WRAPPER, DL, Ty, Op);
1125}
1126
1127SDValue XtensaTargetLowering::LowerConstantPool(SDValue Op,
1128 SelectionDAG &DAG) const {
1129 EVT PtrVT = Op.getValueType();
1130 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
1132
1133 if (!CP->isMachineConstantPoolEntry()) {
1134 Result = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, CP->getAlign(),
1135 CP->getOffset());
1136 } else {
1137 report_fatal_error("This constantpool type is not supported yet");
1138 }
1139
1140 return getAddrPCRel(Result, DAG);
1141}
1142
1143SDValue XtensaTargetLowering::LowerSTACKSAVE(SDValue Op,
1144 SelectionDAG &DAG) const {
1145 return DAG.getCopyFromReg(Op.getOperand(0), SDLoc(Op), Xtensa::SP,
1146 Op.getValueType());
1147}
1148
1149SDValue XtensaTargetLowering::LowerSTACKRESTORE(SDValue Op,
1150 SelectionDAG &DAG) const {
1151 SDValue Chain = Op.getOperand(0);
1152 SDValue NewSP = Op.getOperand(1);
1153
1154 if (Subtarget.isWindowedABI()) {
1155 return DAG.getNode(XtensaISD::MOVSP, SDLoc(Op), MVT::Other, Chain, NewSP);
1156 }
1157
1158 return DAG.getCopyToReg(Chain, SDLoc(Op), Xtensa::SP, NewSP);
1159}
1160
1161SDValue XtensaTargetLowering::LowerFRAMEADDR(SDValue Op,
1162 SelectionDAG &DAG) const {
1163 // This nodes represent llvm.frameaddress on the DAG.
1164 // It takes one operand, the index of the frame address to return.
1165 // An index of zero corresponds to the current function's frame address.
1166 // An index of one to the parent's frame address, and so on.
1167 // Depths > 0 not supported yet!
1168 if (Op.getConstantOperandVal(0) != 0)
1169 return SDValue();
1170
1171 MachineFunction &MF = DAG.getMachineFunction();
1172 MachineFrameInfo &MFI = MF.getFrameInfo();
1173 MFI.setFrameAddressIsTaken(true);
1174 EVT VT = Op.getValueType();
1175 SDLoc DL(Op);
1176
1177 MCRegister FrameRegister = Subtarget.getRegisterInfo()->getFrameRegister(MF);
1178 SDValue FrameAddr =
1179 DAG.getCopyFromReg(DAG.getEntryNode(), DL, FrameRegister, VT);
1180 return FrameAddr;
1181}
1182
1183SDValue XtensaTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op,
1184 SelectionDAG &DAG) const {
1185 SDValue Chain = Op.getOperand(0); // Legalize the chain.
1186 SDValue Size = Op.getOperand(1); // Legalize the size.
1187 EVT VT = Size->getValueType(0);
1188 SDLoc DL(Op);
1189
1190 // Round up Size to 32
1191 SDValue SizeTmp =
1192 DAG.getNode(ISD::ADD, DL, VT, Size, DAG.getConstant(31, DL, MVT::i32));
1193 SDValue SizeRoundUp = DAG.getNode(ISD::AND, DL, VT, SizeTmp,
1194 DAG.getSignedConstant(~31, DL, MVT::i32));
1195
1196 MCRegister SPReg = Xtensa::SP;
1197 SDValue SP = DAG.getCopyFromReg(Chain, DL, SPReg, VT);
1198 SDValue NewSP = DAG.getNode(ISD::SUB, DL, VT, SP, SizeRoundUp); // Value
1199 if (Subtarget.isWindowedABI()) {
1200 Chain = DAG.getNode(XtensaISD::MOVSP, SDLoc(Op), MVT::Other, SP.getValue(1),
1201 NewSP);
1202 } else {
1203 Chain = DAG.getCopyToReg(SP.getValue(1), DL, SPReg, NewSP); // Output chain
1204 }
1205
1206 SDValue NewVal = DAG.getCopyFromReg(Chain, DL, SPReg, MVT::i32);
1207 Chain = NewVal.getValue(1);
1208
1209 SDValue Ops[2] = {NewVal, Chain};
1210 return DAG.getMergeValues(Ops, DL);
1211}
1212
1213SDValue XtensaTargetLowering::LowerVASTART(SDValue Op,
1214 SelectionDAG &DAG) const {
1215 MachineFunction &MF = DAG.getMachineFunction();
1216 XtensaMachineFunctionInfo *XtensaFI = MF.getInfo<XtensaMachineFunctionInfo>();
1217 SDValue Chain = Op.getOperand(0);
1218 SDValue Addr = Op.getOperand(1);
1219 EVT PtrVT = Addr.getValueType();
1220 SDLoc DL(Op);
1221
1222 // Struct va_list_tag
1223 // int32 *va_stk - points to the arguments passed in memory
1224 // int32 *va_reg - points to the registers with arguments saved in memory
1225 // int32 va_ndx - offset from va_stk or va_reg pointers which points to the
1226 // next variable argument
1227
1228 SDValue VAIndex;
1229 SDValue StackOffsetFI =
1230 DAG.getFrameIndex(XtensaFI->getVarArgsOnStackFrameIndex(), PtrVT);
1231 unsigned ArgWords = XtensaFI->getVarArgsFirstGPR() - 2;
1232
1233 // If first variable argument passed in registers (maximum words in registers
1234 // is 6) then set va_ndx to the position of this argument in registers area
1235 // stored in memory (va_reg pointer). Otherwise va_ndx should point to the
1236 // position of the first variable argument on stack (va_stk pointer).
1237 if (ArgWords < 6) {
1238 VAIndex = DAG.getConstant(ArgWords * 4, DL, MVT::i32);
1239 } else {
1240 VAIndex = DAG.getConstant(32, DL, MVT::i32);
1241 }
1242
1244 DAG.getFrameIndex(XtensaFI->getVarArgsInRegsFrameIndex(), PtrVT);
1245 uint64_t FrameOffset = PtrVT.getStoreSize();
1246 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
1247
1248 // Store pointer to arguments given on stack (va_stk)
1249 SDValue StackPtr = DAG.getNode(ISD::SUB, DL, PtrVT, StackOffsetFI,
1250 DAG.getConstant(32, DL, PtrVT));
1251
1252 SDValue StoreStackPtr =
1253 DAG.getStore(Chain, DL, StackPtr, Addr, MachinePointerInfo(SV));
1254
1255 uint64_t NextOffset = FrameOffset;
1256 SDValue NextPtr =
1257 DAG.getObjectPtrOffset(DL, Addr, TypeSize::getFixed(NextOffset));
1258
1259 // Store pointer to arguments given on registers (va_reg)
1260 SDValue StoreRegPtr = DAG.getStore(StoreStackPtr, DL, FrameIndex, NextPtr,
1261 MachinePointerInfo(SV, NextOffset));
1262 NextOffset += FrameOffset;
1263 NextPtr = DAG.getObjectPtrOffset(DL, Addr, TypeSize::getFixed(NextOffset));
1264
1265 // Store third word : position in bytes of the first VA argument (va_ndx)
1266 return DAG.getStore(StoreRegPtr, DL, VAIndex, NextPtr,
1267 MachinePointerInfo(SV, NextOffset));
1268}
1269
1270SDValue XtensaTargetLowering::LowerVACOPY(SDValue Op, SelectionDAG &DAG) const {
1271 // Size of the va_list_tag structure
1272 constexpr unsigned VAListSize = 3 * 4;
1273 SDValue Chain = Op.getOperand(0);
1274 SDValue DstPtr = Op.getOperand(1);
1275 SDValue SrcPtr = Op.getOperand(2);
1276 const Value *DstSV = cast<SrcValueSDNode>(Op.getOperand(3))->getValue();
1277 const Value *SrcSV = cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
1278 SDLoc DL(Op);
1279
1280 return DAG.getMemcpy(Chain, DL, DstPtr, SrcPtr,
1281 DAG.getConstant(VAListSize, SDLoc(Op), MVT::i32),
1282 Align(4), /*isVolatile*/ false, /*AlwaysInline*/ true,
1283 /*CI=*/nullptr, std::nullopt, MachinePointerInfo(DstSV),
1284 MachinePointerInfo(SrcSV));
1285}
1286
1287SDValue XtensaTargetLowering::LowerVAARG(SDValue Op, SelectionDAG &DAG) const {
1288 SDNode *Node = Op.getNode();
1289 EVT VT = Node->getValueType(0);
1290 Type *Ty = VT.getTypeForEVT(*DAG.getContext());
1291 EVT PtrVT = Op.getValueType();
1292 SDValue InChain = Node->getOperand(0);
1293 SDValue VAListPtr = Node->getOperand(1);
1294 const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
1295 SDLoc DL(Node);
1296 auto &TD = DAG.getDataLayout();
1297 Align ArgAlignment = TD.getABITypeAlign(Ty);
1298 unsigned ArgAlignInBytes = ArgAlignment.value();
1299 unsigned ArgSizeInBytes = TD.getTypeAllocSize(Ty);
1300 unsigned VASizeInBytes = llvm::alignTo(ArgSizeInBytes, 4);
1301
1302 // va_stk
1303 SDValue VAStack =
1304 DAG.getLoad(MVT::i32, DL, InChain, VAListPtr, MachinePointerInfo());
1305 InChain = VAStack.getValue(1);
1306
1307 // va_reg
1308 SDValue VARegPtr =
1309 DAG.getObjectPtrOffset(DL, VAListPtr, TypeSize::getFixed(4));
1310 SDValue VAReg =
1311 DAG.getLoad(MVT::i32, DL, InChain, VARegPtr, MachinePointerInfo());
1312 InChain = VAReg.getValue(1);
1313
1314 // va_ndx
1315 SDValue VarArgIndexPtr =
1316 DAG.getObjectPtrOffset(DL, VARegPtr, TypeSize::getFixed(4));
1317 SDValue VAIndex =
1318 DAG.getLoad(MVT::i32, DL, InChain, VarArgIndexPtr, MachinePointerInfo());
1319 InChain = VAIndex.getValue(1);
1320
1321 SDValue OrigIndex = VAIndex;
1322
1323 if (ArgAlignInBytes > 4) {
1324 OrigIndex = DAG.getNode(ISD::ADD, DL, PtrVT, OrigIndex,
1325 DAG.getConstant(ArgAlignInBytes - 1, DL, MVT::i32));
1326 OrigIndex =
1327 DAG.getNode(ISD::AND, DL, PtrVT, OrigIndex,
1328 DAG.getSignedConstant(-ArgAlignInBytes, DL, MVT::i32));
1329 }
1330
1331 VAIndex = DAG.getNode(ISD::ADD, DL, PtrVT, OrigIndex,
1332 DAG.getConstant(VASizeInBytes, DL, MVT::i32));
1333
1334 SDValue CC = DAG.getSetCC(DL, MVT::i32, OrigIndex,
1335 DAG.getConstant(6 * 4, DL, MVT::i32), ISD::SETLE);
1336
1337 SDValue StkIndex =
1338 DAG.getNode(ISD::ADD, DL, PtrVT, VAIndex,
1339 DAG.getConstant(32 + VASizeInBytes, DL, MVT::i32));
1340
1341 CC = DAG.getSetCC(DL, MVT::i32, VAIndex, DAG.getConstant(6 * 4, DL, MVT::i32),
1342 ISD::SETLE);
1343
1344 SDValue Array = DAG.getNode(ISD::SELECT, DL, MVT::i32, CC, VAReg, VAStack);
1345
1346 VAIndex = DAG.getNode(ISD::SELECT, DL, MVT::i32, CC, VAIndex, StkIndex);
1347
1348 CC = DAG.getSetCC(DL, MVT::i32, VAIndex, DAG.getConstant(6 * 4, DL, MVT::i32),
1349 ISD::SETLE);
1350
1351 SDValue VAIndexStore = DAG.getStore(InChain, DL, VAIndex, VarArgIndexPtr,
1352 MachinePointerInfo(SV));
1353 InChain = VAIndexStore;
1354
1355 SDValue Addr = DAG.getNode(ISD::SUB, DL, PtrVT, VAIndex,
1356 DAG.getConstant(VASizeInBytes, DL, MVT::i32));
1357
1358 Addr = DAG.getNode(ISD::ADD, DL, PtrVT, Array, Addr);
1359
1360 return DAG.getLoad(VT, DL, InChain, Addr, MachinePointerInfo());
1361}
1362
1363SDValue XtensaTargetLowering::LowerShiftLeftParts(SDValue Op,
1364 SelectionDAG &DAG) const {
1365 SDLoc DL(Op);
1366 MVT VT = MVT::i32;
1367 SDValue Lo = Op.getOperand(0), Hi = Op.getOperand(1);
1368 SDValue Shamt = Op.getOperand(2);
1369
1370 // if Shamt - register size < 0: // Shamt < register size
1371 // Lo = Lo << Shamt
1372 // Hi = (Hi << Shamt) | (Lo >>u (register size - Shamt))
1373 // else:
1374 // Lo = 0
1375 // Hi = Lo << (Shamt - register size)
1376
1377 SDValue MinusRegisterSize = DAG.getSignedConstant(-32, DL, VT);
1378 SDValue ShamtMinusRegisterSize =
1379 DAG.getNode(ISD::ADD, DL, VT, Shamt, MinusRegisterSize);
1380
1381 SDValue LoTrue = DAG.getNode(ISD::SHL, DL, VT, Lo, Shamt);
1382 SDValue HiTrue = DAG.getNode(XtensaISD::SRCL, DL, VT, Hi, Lo, Shamt);
1383 SDValue Zero = DAG.getConstant(0, DL, VT);
1384 SDValue HiFalse = DAG.getNode(ISD::SHL, DL, VT, Lo, ShamtMinusRegisterSize);
1385
1386 SDValue Cond = DAG.getSetCC(DL, VT, ShamtMinusRegisterSize, Zero, ISD::SETLT);
1387 Lo = DAG.getNode(ISD::SELECT, DL, VT, Cond, LoTrue, Zero);
1388 Hi = DAG.getNode(ISD::SELECT, DL, VT, Cond, HiTrue, HiFalse);
1389
1390 return DAG.getMergeValues({Lo, Hi}, DL);
1391}
1392
1393SDValue XtensaTargetLowering::LowerShiftRightParts(SDValue Op,
1394 SelectionDAG &DAG,
1395 bool IsSRA) const {
1396 SDLoc DL(Op);
1397 SDValue Lo = Op.getOperand(0), Hi = Op.getOperand(1);
1398 SDValue Shamt = Op.getOperand(2);
1399 MVT VT = MVT::i32;
1400
1401 // SRA expansion:
1402 // if Shamt - register size < 0: // Shamt < register size
1403 // Lo = (Lo >>u Shamt) | (Hi << u (register size - Shamt))
1404 // Hi = Hi >>s Shamt
1405 // else:
1406 // Lo = Hi >>s (Shamt - register size);
1407 // Hi = Hi >>s (register size - 1)
1408 //
1409 // SRL expansion:
1410 // if Shamt - register size < 0: // Shamt < register size
1411 // Lo = (Lo >>u Shamt) | (Hi << u (register size - Shamt))
1412 // Hi = Hi >>u Shamt
1413 // else:
1414 // Lo = Hi >>u (Shamt - register size);
1415 // Hi = 0;
1416
1417 unsigned ShiftRightOp = IsSRA ? ISD::SRA : ISD::SRL;
1418 SDValue MinusRegisterSize = DAG.getSignedConstant(-32, DL, VT);
1419 SDValue RegisterSizeMinus1 = DAG.getConstant(32 - 1, DL, VT);
1420 SDValue ShamtMinusRegisterSize =
1421 DAG.getNode(ISD::ADD, DL, VT, Shamt, MinusRegisterSize);
1422
1423 SDValue LoTrue = DAG.getNode(XtensaISD::SRCR, DL, VT, Hi, Lo, Shamt);
1424 SDValue HiTrue = DAG.getNode(ShiftRightOp, DL, VT, Hi, Shamt);
1425 SDValue Zero = DAG.getConstant(0, DL, VT);
1426 SDValue LoFalse =
1427 DAG.getNode(ShiftRightOp, DL, VT, Hi, ShamtMinusRegisterSize);
1428 SDValue HiFalse;
1429
1430 if (IsSRA) {
1431 HiFalse = DAG.getNode(ShiftRightOp, DL, VT, Hi, RegisterSizeMinus1);
1432 } else {
1433 HiFalse = Zero;
1434 }
1435
1436 SDValue Cond = DAG.getSetCC(DL, VT, ShamtMinusRegisterSize, Zero, ISD::SETLT);
1437 Lo = DAG.getNode(ISD::SELECT, DL, VT, Cond, LoTrue, LoFalse);
1438 Hi = DAG.getNode(ISD::SELECT, DL, VT, Cond, HiTrue, HiFalse);
1439
1440 return DAG.getMergeValues({Lo, Hi}, DL);
1441}
1442
1443SDValue XtensaTargetLowering::LowerCTPOP(SDValue Op, SelectionDAG &DAG) const {
1444 auto &TLI = DAG.getTargetLoweringInfo();
1445 return TLI.expandCTPOP(Op.getNode(), DAG);
1446}
1447
1449 SDValue C) const {
1450 APInt Imm;
1451 unsigned EltSizeInBits;
1452
1453 if (ISD::isConstantSplatVector(C.getNode(), Imm)) {
1454 EltSizeInBits = VT.getScalarSizeInBits();
1455 } else if (VT.isScalarInteger()) {
1456 EltSizeInBits = VT.getSizeInBits();
1457 if (auto *ConstNode = dyn_cast<ConstantSDNode>(C.getNode()))
1458 Imm = ConstNode->getAPIntValue();
1459 else
1460 return false;
1461 } else {
1462 return false;
1463 }
1464
1465 // Omit if data size exceeds.
1466 if (EltSizeInBits > 32)
1467 return false;
1468
1469 // Convert MULT to LSL.
1470 if (Imm.isPowerOf2() && Imm.isIntN(5))
1471 return true;
1472
1473 return false;
1474}
1475
1477 SelectionDAG &DAG) const {
1478 switch (Op.getOpcode()) {
1479 case ISD::BR_JT:
1480 return LowerBR_JT(Op, DAG);
1481 case ISD::Constant:
1482 return LowerImmediate(Op, DAG);
1483 case ISD::RETURNADDR:
1484 return LowerRETURNADDR(Op, DAG);
1485 case ISD::GlobalAddress:
1486 return LowerGlobalAddress(Op, DAG);
1488 return LowerGlobalTLSAddress(Op, DAG);
1489 case ISD::BlockAddress:
1490 return LowerBlockAddress(Op, DAG);
1491 case ISD::JumpTable:
1492 return LowerJumpTable(Op, DAG);
1493 case ISD::CTPOP:
1494 return LowerCTPOP(Op, DAG);
1495 case ISD::ConstantPool:
1496 return LowerConstantPool(Op, DAG);
1497 case ISD::SELECT_CC:
1498 return LowerSELECT_CC(Op, DAG);
1499 case ISD::STACKSAVE:
1500 return LowerSTACKSAVE(Op, DAG);
1501 case ISD::STACKRESTORE:
1502 return LowerSTACKRESTORE(Op, DAG);
1503 case ISD::FRAMEADDR:
1504 return LowerFRAMEADDR(Op, DAG);
1506 return LowerDYNAMIC_STACKALLOC(Op, DAG);
1507 case ISD::VASTART:
1508 return LowerVASTART(Op, DAG);
1509 case ISD::VAARG:
1510 return LowerVAARG(Op, DAG);
1511 case ISD::VACOPY:
1512 return LowerVACOPY(Op, DAG);
1513 case ISD::SHL_PARTS:
1514 return LowerShiftLeftParts(Op, DAG);
1515 case ISD::SRA_PARTS:
1516 return LowerShiftRightParts(Op, DAG, true);
1517 case ISD::SRL_PARTS:
1518 return LowerShiftRightParts(Op, DAG, false);
1519 default:
1520 report_fatal_error("Unexpected node to lower");
1521 }
1522}
1523
1528
1529//===----------------------------------------------------------------------===//
1530// Custom insertion
1531//===----------------------------------------------------------------------===//
1532
1534XtensaTargetLowering::emitSelectCC(MachineInstr &MI,
1535 MachineBasicBlock *MBB) const {
1536 const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
1537 DebugLoc DL = MI.getDebugLoc();
1538
1539 MachineOperand &LHS = MI.getOperand(1);
1540 MachineOperand &RHS = MI.getOperand(2);
1541 MachineOperand &TrueValue = MI.getOperand(3);
1542 MachineOperand &FalseValue = MI.getOperand(4);
1543
1544 // To "insert" a SELECT_CC instruction, we actually have to insert
1545 // CopyMBB and SinkMBB blocks and add branch to MBB. We build phi
1546 // operation in SinkMBB like phi (TrueVakue,FalseValue), where TrueValue
1547 // is passed from MMB and FalseValue is passed from CopyMBB.
1548 // MBB
1549 // | \
1550 // | CopyMBB
1551 // | /
1552 // SinkMBB
1553 // The incoming instruction knows the
1554 // destination vreg to set, the condition code register to branch on, the
1555 // true/false values to select between, and a branch opcode to use.
1556 const BasicBlock *LLVM_BB = MBB->getBasicBlock();
1557 MachineFunction::iterator It = ++MBB->getIterator();
1558
1559 MachineFunction *F = MBB->getParent();
1560 MachineBasicBlock *CopyMBB = F->CreateMachineBasicBlock(LLVM_BB);
1561 MachineBasicBlock *SinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
1562
1563 F->insert(It, CopyMBB);
1564 F->insert(It, SinkMBB);
1565
1566 // Transfer the remainder of MBB and its successor edges to SinkMBB.
1567 SinkMBB->splice(SinkMBB->begin(), MBB,
1568 std::next(MachineBasicBlock::iterator(MI)), MBB->end());
1570
1571 MBB->addSuccessor(CopyMBB);
1572 MBB->addSuccessor(SinkMBB);
1573
1574 if (MI.getOpcode() == Xtensa::SELECT_CC_FP_FP ||
1575 MI.getOpcode() == Xtensa::SELECT_CC_FP_INT) {
1576 unsigned CmpKind = MI.getOperand(5).getImm();
1577 unsigned BrKind = MI.getOperand(6).getImm();
1578 MCPhysReg BReg = Xtensa::B0;
1579
1580 BuildMI(MBB, DL, TII.get(CmpKind), BReg)
1581 .addReg(LHS.getReg())
1582 .addReg(RHS.getReg());
1583 BuildMI(MBB, DL, TII.get(BrKind))
1584 .addReg(BReg, RegState::Kill)
1585 .addMBB(SinkMBB);
1586 } else {
1587 unsigned BrKind = MI.getOperand(5).getImm();
1588 BuildMI(MBB, DL, TII.get(BrKind))
1589 .addReg(LHS.getReg())
1590 .addReg(RHS.getReg())
1591 .addMBB(SinkMBB);
1592 }
1593
1594 CopyMBB->addSuccessor(SinkMBB);
1595
1596 // SinkMBB:
1597 // %Result = phi [ %FalseValue, CopyMBB ], [ %TrueValue, MBB ]
1598 // ...
1599
1600 BuildMI(*SinkMBB, SinkMBB->begin(), DL, TII.get(Xtensa::PHI),
1601 MI.getOperand(0).getReg())
1602 .addReg(FalseValue.getReg())
1603 .addMBB(CopyMBB)
1604 .addReg(TrueValue.getReg())
1605 .addMBB(MBB);
1606
1607 MI.eraseFromParent(); // The pseudo instruction is gone now.
1608 return SinkMBB;
1609}
1610
1613 DebugLoc DL = MI.getDebugLoc();
1614 const XtensaInstrInfo &TII = *Subtarget.getInstrInfo();
1615
1616 switch (MI.getOpcode()) {
1617 case Xtensa::BRCC_FP: {
1618 MachineOperand &Cond = MI.getOperand(0);
1619 MachineOperand &LHS = MI.getOperand(1);
1620 MachineOperand &RHS = MI.getOperand(2);
1621 MachineBasicBlock *TargetBB = MI.getOperand(3).getMBB();
1622 unsigned BrKind = 0;
1623 unsigned CmpKind = 0;
1624 ISD::CondCode CondCode = (ISD::CondCode)Cond.getImm();
1625 MCPhysReg BReg = Xtensa::B0;
1626
1627 std::tie(BrKind, CmpKind) = getFPBranchKind(CondCode);
1628 BuildMI(*MBB, MI, DL, TII.get(CmpKind), BReg)
1629 .addReg(LHS.getReg())
1630 .addReg(RHS.getReg());
1631 BuildMI(*MBB, MI, DL, TII.get(BrKind))
1632 .addReg(BReg, RegState::Kill)
1633 .addMBB(TargetBB);
1634
1635 MI.eraseFromParent();
1636 return MBB;
1637 }
1638 case Xtensa::SELECT_CC_FP_FP:
1639 case Xtensa::SELECT_CC_FP_INT:
1640 case Xtensa::SELECT_CC_INT_FP:
1641 case Xtensa::SELECT:
1642 return emitSelectCC(MI, MBB);
1643 case Xtensa::S8I:
1644 case Xtensa::S16I:
1645 case Xtensa::S32I:
1646 case Xtensa::S32I_N:
1647 case Xtensa::SSI:
1648 case Xtensa::SSIP:
1649 case Xtensa::SSX:
1650 case Xtensa::SSXP:
1651 case Xtensa::L8UI:
1652 case Xtensa::L16SI:
1653 case Xtensa::L16UI:
1654 case Xtensa::L32I:
1655 case Xtensa::L32I_N:
1656 case Xtensa::LSI:
1657 case Xtensa::LSIP:
1658 case Xtensa::LSX:
1659 case Xtensa::LSXP: {
1660 // Insert memory wait instruction "memw" before volatile load/store as it is
1661 // implemented in gcc. If memoperands is empty then assume that it aslo
1662 // maybe volatile load/store and insert "memw".
1663 if (MI.memoperands_empty() || (*MI.memoperands_begin())->isVolatile()) {
1664 BuildMI(*MBB, MI, DL, TII.get(Xtensa::MEMW));
1665 }
1666 return MBB;
1667 }
1668 case Xtensa::MOVSP_P: {
1669 MachineOperand &NewSP = MI.getOperand(0);
1670
1671 BuildMI(*MBB, MI, DL, TII.get(Xtensa::MOVSP), Xtensa::SP)
1672 .addReg(NewSP.getReg());
1673 MI.eraseFromParent();
1674
1675 return MBB;
1676 }
1677 case Xtensa::ATOMIC_CMP_SWAP_32_P: {
1678 MachineOperand &R = MI.getOperand(0);
1679 MachineOperand &Addr = MI.getOperand(1);
1680 MachineOperand &Cmp = MI.getOperand(2);
1681 MachineOperand &Swap = MI.getOperand(3);
1682
1683 BuildMI(*MBB, MI, DL, TII.get(Xtensa::WSR), Xtensa::SCOMPARE1)
1684 .addReg(Cmp.getReg());
1685
1686 BuildMI(*MBB, MI, DL, TII.get(Xtensa::S32C1I), R.getReg())
1687 .addReg(Swap.getReg())
1688 .addReg(Addr.getReg())
1689 .addImm(0);
1690
1691 MI.eraseFromParent();
1692 return MBB;
1693 }
1694 default:
1695 llvm_unreachable("Unexpected instr type to insert");
1696 }
1697}
return SDValue()
unsigned RegSize
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
static constexpr MCPhysReg SPReg
const SmallVectorImpl< MachineOperand > & Cond
SI optimize exec mask operations pre RA
static const char * name
static const MCPhysReg IntRegs[32]
static unsigned toCallerWindow(unsigned Reg)
Value * RHS
Value * LHS
static bool isLongCall(const char *str)
static unsigned toCallerWindow(unsigned Reg)
static std::pair< unsigned, unsigned > getFPBranchKind(ISD::CondCode Cond)
static unsigned getBranchOpcode(ISD::CondCode Cond)
static bool CC_Xtensa_Custom(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
Class for arbitrary precision integers.
Definition APInt.h:78
int64_t getSExtValue() const
Get sign extended value.
Definition APInt.h:1585
an instruction that atomically reads a memory location, combines it with another value,...
LLVM Basic Block Representation.
Definition BasicBlock.h:62
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,...
LLVM_ABI void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeCallResult - Analyze the return values of a call, incorporating info about the passed values i...
LLVM_ABI 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 ...
LLVM_ABI void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeReturn - Analyze the returned values of a return, incorporating info about the result values i...
LLVM_ABI void AnalyzeCallOperands(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeCallOperands - Analyze the outgoing arguments to a call, incorporating info about the passed v...
uint64_t getStackSize() const
Returns the size of the currently allocated portion of the stack.
LLVM_ABI void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeFormalArguments - Analyze an array of argument values, incorporating info about the formals in...
CCValAssign - Represent assignment of one arg/retval to a location.
Register getLocReg() const
LocInfo getLocInfo() const
static CCValAssign getReg(unsigned ValNo, MVT ValVT, MCRegister Reg, MVT LocVT, LocInfo HTP, bool IsCustom=false)
static CCValAssign getMem(unsigned ValNo, MVT ValVT, int64_t Offset, MVT LocVT, LocInfo HTP, bool IsCustom=false)
int64_t getLocMemOffset() const
unsigned getValNo() const
static ConstantInt * getSigned(IntegerType *Ty, int64_t V, bool ImplicitTrunc=false)
Return a ConstantInt with the specified value for the specified type.
Definition Constants.h:135
const Constant * getConstVal() const
const APInt & getAPIntValue() const
This is an important base class in LLVM.
Definition Constant.h:43
LLVM_ABI Align getABITypeAlign(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
A debug info location.
Definition DebugLoc.h:124
LinkageTypes getLinkage() const
static bool isPrivateLinkage(LinkageTypes Linkage)
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Machine Value Type.
static auto integer_valuetypes()
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI 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 setFrameAddressIsTaken(bool T)
void setReturnAddressIsTaken(bool s)
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
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...
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Representation of each machine instruction.
LLVM_ABI unsigned getEntrySize(const DataLayout &TD) const
getEntrySize - Return the size of each entry in the jump table.
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool hasOneUse() const
Return true if there is exactly one use of this node.
user_iterator user_begin() const
Provide iteration support to walk over all users of an SDNode.
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.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, SDValue N)
LLVM_ABI SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI SDValue getConstantPool(const Constant *C, EVT VT, MaybeAlign Align=std::nullopt, int Offs=0, bool isT=false, unsigned TargetFlags=0)
LLVM_ABI SDValue getRegister(Register Reg, EVT VT)
LLVM_ABI 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 getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false, SDNodeFlags Flags={})
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
LLVM_ABI 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(), BatchAAResults *BatchAA=nullptr)
const TargetLowering & getTargetLoweringInfo() const
SDValue getTargetJumpTable(int JTI, EVT VT, unsigned TargetFlags=0)
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 getCopyFromReg(SDValue Chain, const SDLoc &dl, Register Reg, EVT VT)
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
LLVM_ABI 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.
LLVM_ABI SDValue getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
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 ...
const TargetMachine & getTarget() const
LLVM_ABI SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
LLVM_ABI SDValue getValueType(EVT)
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
MachineFunction & getMachineFunction() const
SDValue getPOISON(EVT VT)
Return a POISON node. POISON does not have a useful SDLoc.
LLVM_ABI SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
LLVM_ABI SDValue getRegisterMask(const uint32_t *RegMask)
SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Ptr, TypeSize Offset)
Create an add instruction with appropriate flags when used for addressing some offset of an object.
LLVMContext * getContext() const
LLVM_ABI 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)
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
Information about stack frame layout on the target.
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
TargetInstrInfo - Interface to description of machine instruction set.
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...
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
virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
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.
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose.
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
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 setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
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....
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...
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...
MVT getFrameIndexTy(const DataLayout &DL) const
Return the type for frame index, which is determined by the alloca address space specified through th...
void setSchedulingPreference(Sched::Preference Pref)
Specify the target scheduling preference.
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
virtual SDValue LowerToTLSEmulatedModel(const GlobalAddressSDNode *GA, SelectionDAG &DAG) const
Lower TLS global address SDNode for target independent emulated TLS model.
SDValue expandCTPOP(SDNode *N, SelectionDAG &DAG) const
Expand CTPOP nodes.
bool isPositionIndependent() const
virtual ConstraintWeight getSingleConstraintMatchWeight(AsmOperandInfo &info, const char *constraint) const
Examine constraint string and operand type and determine a weight value.
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
TargetLowering(const TargetLowering &)=delete
virtual void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const
Lower the specified operand into the Ops vector.
Primary interface to the complete machine description for the target machine.
TLSModel::Model getTLSModel(const GlobalValue *GV) const
Returns the TLS model which should be used for the given global variable.
bool useEmulatedTLS() const
Returns true if this target uses emulated TLS.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:309
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:318
static XtensaConstantPoolConstant * Create(const Constant *C, unsigned ID, XtensaCP::XtensaCPKind Kind)
static XtensaConstantPoolJumpTable * Create(LLVMContext &C, unsigned Idx)
static XtensaConstantPoolSymbol * Create(LLVMContext &C, const char *S, unsigned ID, bool PrivLinkage, XtensaCP::XtensaCPModifier Modifier=XtensaCP::no_modifier)
XtensaConstantPoolValue - Xtensa specific constantpool value.
const XtensaInstrInfo * getInstrInfo() const override
const XtensaRegisterInfo * getRegisterInfo() const override
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, LLVMContext &Context, const Type *RetTy) const override
This hook should be implemented to check whether the return values described by the Outs array can fi...
TargetLowering::ConstraintWeight getSingleConstraintMatchWeight(AsmOperandInfo &Info, const char *Constraint) const override
Examine constraint string and operand type and determine a weight value.
AtomicExpansionKind shouldExpandAtomicRMWInIR(const AtomicRMWInst *) const override
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all.
TargetLowering::ConstraintType getConstraintType(StringRef Constraint) const override
Given a constraint, return the type of constraint it is for this target.
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override
Return true if folding a constant offset with the given GlobalAddress is legal.
bool decomposeMulByConstant(LLVMContext &Context, EVT VT, SDValue C) const override
Return true if it is profitable to transform an integer multiplication-by-constant into simpler opera...
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *BB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
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,...
SDValue LowerCall(CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower calls into the specified DAG.
bool isFPImmLegal(const APFloat &Imm, EVT VT, bool ForCodeSize) const override
Returns true if the target can instruction select the specified FP immediate natively.
XtensaTargetLowering(const TargetMachine &TM, const XtensaSubtarget &STI)
Register getExceptionPointerRegister(const Constant *PersonalityFn) const override
If a physical register, this returns the register that receives the exception address on entry to an ...
void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const override
Lower the specified operand into the Ops vector.
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
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,...
MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Return the register type for a given MVT.
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...
Register getExceptionSelectorRegister(const Constant *PersonalityFn) const override
If a physical register, this returns the register that receives the exception typeid on entry to a la...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition ISDOpcodes.h:823
@ STACKRESTORE
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain.
@ STACKSAVE
STACKSAVE - STACKSAVE has one operand, an input chain.
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition ISDOpcodes.h:275
@ BSWAP
Byte Swap and Counting operators.
Definition ISDOpcodes.h:783
@ VAEND
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE.
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:264
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition ISDOpcodes.h:518
@ GlobalAddress
Definition ISDOpcodes.h:88
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition ISDOpcodes.h:884
@ FADD
Simple binary floating point operators.
Definition ISDOpcodes.h:417
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition ISDOpcodes.h:280
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition ISDOpcodes.h:997
@ GlobalTLSAddress
Definition ISDOpcodes.h:89
@ CTLZ_ZERO_POISON
Definition ISDOpcodes.h:792
@ FNEG
Perform various unary floating-point operations inspired by libm.
@ BR_CC
BR_CC - Conditional branch.
@ BR_JT
BR_JT - Jumptable branch.
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition ISDOpcodes.h:800
@ VACOPY
VACOPY - VACOPY has 5 operands: an input chain, a destination pointer, a source pointer,...
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition ISDOpcodes.h:704
@ SHL
Shift and rotation operations.
Definition ISDOpcodes.h:769
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition ISDOpcodes.h:815
@ DYNAMIC_STACKALLOC
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary.
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition ISDOpcodes.h:892
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition ISDOpcodes.h:727
@ FRAMEADDR
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG.
Definition ISDOpcodes.h:110
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:930
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:739
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition ISDOpcodes.h:53
@ CTTZ_ZERO_POISON
Bit counting operators with a poisoned result for zero inputs.
Definition ISDOpcodes.h:791
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition ISDOpcodes.h:860
@ VAARG
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
@ SHL_PARTS
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations.
Definition ISDOpcodes.h:837
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition ISDOpcodes.h:62
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition ISDOpcodes.h:534
LLVM_ABI bool isConstantSplatVector(const SDNode *N, APInt &SplatValue)
Node predicates.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:558
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Kill
The last use of a register.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition MathExtras.h:331
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
DWARFExpression::Operation Op
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
Definition MathExtras.h:182
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:77
Extended Value Type.
Definition ValueTypes.h:35
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition ValueTypes.h:418
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition ValueTypes.h:155
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:396
uint64_t getScalarSizeInBits() const
Definition ValueTypes.h:408
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
bool isScalarInteger() const
Return true if this is an integer, but not a vector.
Definition ValueTypes.h:165
Align getNonZeroOrigAlign() const
unsigned getByValSize() const
Align getNonZeroByValAlign() const
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getJumpTable(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a jump table entry.
static LLVM_ABI MachinePointerInfo getConstantPool(MachineFunction &MF)
Return a MachinePointerInfo record that refers to the constant pool.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
This contains information for each constraint that we are lowering.
This structure contains all information that is necessary for lowering calls.
SmallVector< ISD::InputArg, 32 > Ins
SmallVector< ISD::OutputArg, 32 > Outs