LLVM 22.0.0git
MSP430ISelLowering.cpp
Go to the documentation of this file.
1//===-- MSP430ISelLowering.cpp - MSP430 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 MSP430TargetLowering class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "MSP430ISelLowering.h"
14#include "MSP430.h"
17#include "MSP430Subtarget.h"
18#include "MSP430TargetMachine.h"
26#include "llvm/IR/CallingConv.h"
28#include "llvm/IR/Function.h"
29#include "llvm/IR/Intrinsics.h"
31#include "llvm/Support/Debug.h"
34using namespace llvm;
35
36#define DEBUG_TYPE "msp430-lower"
37
39 "msp430-no-legal-immediate", cl::Hidden,
40 cl::desc("Enable non legal immediates (for testing purposes only)"),
41 cl::init(false));
42
44 const MSP430Subtarget &STI)
45 : TargetLowering(TM) {
46
47 // Set up the register classes.
48 addRegisterClass(MVT::i8, &MSP430::GR8RegClass);
49 addRegisterClass(MVT::i16, &MSP430::GR16RegClass);
50
51 // Compute derived properties from the register classes
53
54 // Provide all sorts of operation actions
57 setBooleanVectorContents(ZeroOrOneBooleanContent); // FIXME: Is this correct?
58
59 // We have post-incremented loads / stores.
62
63 for (MVT VT : MVT::integer_valuetypes()) {
69 }
70
71 // We don't have any truncstores
72 setTruncStoreAction(MVT::i16, MVT::i8, Expand);
73
102
109
116
118
119 // FIXME: Implement efficiently multiplication by a constant
130
143
144 // varargs support
150
151 if (STI.hasHWMult16()) {
152 const struct {
153 const RTLIB::Libcall Op;
154 const RTLIB::LibcallImpl Impl;
155 } LibraryCalls[] = {
156 // Integer Multiply - EABI Table 9
157 {RTLIB::MUL_I16, RTLIB::__mspabi_mpyi_hw},
158 {RTLIB::MUL_I32, RTLIB::__mspabi_mpyl_hw},
159 {RTLIB::MUL_I64, RTLIB::__mspabi_mpyll_hw},
160 // TODO The __mspabi_mpysl*_hw functions ARE implemented in libgcc
161 // TODO The __mspabi_mpyul*_hw functions ARE implemented in libgcc
162 };
163 for (const auto &LC : LibraryCalls) {
164 setLibcallImpl(LC.Op, LC.Impl);
165 }
166 } else if (STI.hasHWMult32()) {
167 const struct {
168 const RTLIB::Libcall Op;
169 const RTLIB::LibcallImpl Impl;
170 } LibraryCalls[] = {
171 // Integer Multiply - EABI Table 9
172 {RTLIB::MUL_I16, RTLIB::__mspabi_mpyi_hw},
173 {RTLIB::MUL_I32, RTLIB::__mspabi_mpyl_hw32},
174 {RTLIB::MUL_I64, RTLIB::__mspabi_mpyll_hw32},
175 // TODO The __mspabi_mpysl*_hw32 functions ARE implemented in libgcc
176 // TODO The __mspabi_mpyul*_hw32 functions ARE implemented in libgcc
177 };
178 for (const auto &LC : LibraryCalls) {
179 setLibcallImpl(LC.Op, LC.Impl);
180 }
181 } else if (STI.hasHWMultF5()) {
182 const struct {
183 const RTLIB::Libcall Op;
184 const RTLIB::LibcallImpl Impl;
185 } LibraryCalls[] = {
186 // Integer Multiply - EABI Table 9
187 {RTLIB::MUL_I16, RTLIB::__mspabi_mpyi_f5hw},
188 {RTLIB::MUL_I32, RTLIB::__mspabi_mpyl_f5hw},
189 {RTLIB::MUL_I64, RTLIB::__mspabi_mpyll_f5hw},
190 // TODO The __mspabi_mpysl*_f5hw functions ARE implemented in libgcc
191 // TODO The __mspabi_mpyul*_f5hw functions ARE implemented in libgcc
192 };
193 for (const auto &LC : LibraryCalls) {
194 setLibcallImpl(LC.Op, LC.Impl);
195 }
196 } else { // NoHWMult
197 const struct {
198 const RTLIB::Libcall Op;
199 const RTLIB::LibcallImpl Impl;
200 } LibraryCalls[] = {
201 // Integer Multiply - EABI Table 9
202 {RTLIB::MUL_I16, RTLIB::__mspabi_mpyi},
203 {RTLIB::MUL_I32, RTLIB::__mspabi_mpyl},
204 {RTLIB::MUL_I64, RTLIB::__mspabi_mpyll},
205 // The __mspabi_mpysl* functions are NOT implemented in libgcc
206 // The __mspabi_mpyul* functions are NOT implemented in libgcc
207 };
208 for (const auto &LC : LibraryCalls) {
209 setLibcallImpl(LC.Op, LC.Impl);
210 }
211 }
212
216}
217
219 SelectionDAG &DAG) const {
220 switch (Op.getOpcode()) {
221 case ISD::SHL: // FALLTHROUGH
222 case ISD::SRL:
223 case ISD::SRA: return LowerShifts(Op, DAG);
224 case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
225 case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
226 case ISD::ExternalSymbol: return LowerExternalSymbol(Op, DAG);
227 case ISD::SETCC: return LowerSETCC(Op, DAG);
228 case ISD::BR_CC: return LowerBR_CC(Op, DAG);
229 case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
230 case ISD::SIGN_EXTEND: return LowerSIGN_EXTEND(Op, DAG);
231 case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG);
232 case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG);
233 case ISD::VASTART: return LowerVASTART(Op, DAG);
234 case ISD::JumpTable: return LowerJumpTable(Op, DAG);
235 default:
236 llvm_unreachable("unimplemented operand");
237 }
238}
239
240// Define non profitable transforms into shifts
242 unsigned Amount) const {
243 return !(Amount == 8 || Amount == 9 || Amount<=2);
244}
245
246// Implemented to verify test case assertions in
247// tests/codegen/msp430/shift-amount-threshold-b.ll
250 return Immed >= -32 && Immed < 32;
252}
253
254//===----------------------------------------------------------------------===//
255// MSP430 Inline Assembly Support
256//===----------------------------------------------------------------------===//
257
258/// getConstraintType - Given a constraint letter, return the type of
259/// constraint it is for this target.
262 if (Constraint.size() == 1) {
263 switch (Constraint[0]) {
264 case 'r':
265 return C_RegisterClass;
266 default:
267 break;
268 }
269 }
270 return TargetLowering::getConstraintType(Constraint);
271}
272
273std::pair<unsigned, const TargetRegisterClass *>
275 const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const {
276 if (Constraint.size() == 1) {
277 // GCC Constraint Letters
278 switch (Constraint[0]) {
279 default: break;
280 case 'r': // GENERAL_REGS
281 if (VT == MVT::i8)
282 return std::make_pair(0U, &MSP430::GR8RegClass);
283
284 return std::make_pair(0U, &MSP430::GR16RegClass);
285 }
286 }
287
289}
290
291//===----------------------------------------------------------------------===//
292// Calling Convention Implementation
293//===----------------------------------------------------------------------===//
294
295#include "MSP430GenCallingConv.inc"
296
297/// For each argument in a function store the number of pieces it is composed
298/// of.
299template<typename ArgT>
302 unsigned CurrentArgIndex;
303
304 if (Args.empty())
305 return;
306
307 CurrentArgIndex = Args[0].OrigArgIndex;
308 Out.push_back(0);
309
310 for (auto &Arg : Args) {
311 if (CurrentArgIndex == Arg.OrigArgIndex) {
312 Out.back() += 1;
313 } else {
314 Out.push_back(1);
315 CurrentArgIndex = Arg.OrigArgIndex;
316 }
317 }
318}
319
320static void AnalyzeVarArgs(CCState &State,
322 State.AnalyzeCallOperands(Outs, CC_MSP430_AssignStack);
323}
324
325static void AnalyzeVarArgs(CCState &State,
327 State.AnalyzeFormalArguments(Ins, CC_MSP430_AssignStack);
328}
329
330/// Analyze incoming and outgoing function arguments. We need custom C++ code
331/// to handle special constraints in the ABI like reversing the order of the
332/// pieces of splitted arguments. In addition, all pieces of a certain argument
333/// have to be passed either using registers or the stack but never mixing both.
334template<typename ArgT>
335static void AnalyzeArguments(CCState &State,
337 const SmallVectorImpl<ArgT> &Args) {
338 static const MCPhysReg CRegList[] = {
339 MSP430::R12, MSP430::R13, MSP430::R14, MSP430::R15
340 };
341 static const unsigned CNbRegs = std::size(CRegList);
342 static const MCPhysReg BuiltinRegList[] = {
343 MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11,
344 MSP430::R12, MSP430::R13, MSP430::R14, MSP430::R15
345 };
346 static const unsigned BuiltinNbRegs = std::size(BuiltinRegList);
347
348 ArrayRef<MCPhysReg> RegList;
349 unsigned NbRegs;
350
351 bool Builtin = (State.getCallingConv() == CallingConv::MSP430_BUILTIN);
352 if (Builtin) {
353 RegList = BuiltinRegList;
354 NbRegs = BuiltinNbRegs;
355 } else {
356 RegList = CRegList;
357 NbRegs = CNbRegs;
358 }
359
360 if (State.isVarArg()) {
361 AnalyzeVarArgs(State, Args);
362 return;
363 }
364
365 SmallVector<unsigned, 4> ArgsParts;
366 ParseFunctionArgs(Args, ArgsParts);
367
368 if (Builtin) {
369 assert(ArgsParts.size() == 2 &&
370 "Builtin calling convention requires two arguments");
371 }
372
373 unsigned RegsLeft = NbRegs;
374 bool UsedStack = false;
375 unsigned ValNo = 0;
376
377 for (unsigned i = 0, e = ArgsParts.size(); i != e; i++) {
378 MVT ArgVT = Args[ValNo].VT;
379 ISD::ArgFlagsTy ArgFlags = Args[ValNo].Flags;
380 Type *OrigTy = Args[ValNo].OrigTy;
381 MVT LocVT = ArgVT;
383
384 // Promote i8 to i16
385 if (LocVT == MVT::i8) {
386 LocVT = MVT::i16;
387 if (ArgFlags.isSExt())
388 LocInfo = CCValAssign::SExt;
389 else if (ArgFlags.isZExt())
390 LocInfo = CCValAssign::ZExt;
391 else
392 LocInfo = CCValAssign::AExt;
393 }
394
395 // Handle byval arguments
396 if (ArgFlags.isByVal()) {
397 State.HandleByVal(ValNo++, ArgVT, LocVT, LocInfo, 2, Align(2), ArgFlags);
398 continue;
399 }
400
401 unsigned Parts = ArgsParts[i];
402
403 if (Builtin) {
404 assert(Parts == 4 &&
405 "Builtin calling convention requires 64-bit arguments");
406 }
407
408 if (!UsedStack && Parts == 2 && RegsLeft == 1) {
409 // Special case for 32-bit register split, see EABI section 3.3.3
410 MCRegister Reg = State.AllocateReg(RegList);
411 State.addLoc(CCValAssign::getReg(ValNo++, ArgVT, Reg, LocVT, LocInfo));
412 RegsLeft -= 1;
413
414 UsedStack = true;
415 CC_MSP430_AssignStack(ValNo++, ArgVT, LocVT, LocInfo, ArgFlags, OrigTy,
416 State);
417 } else if (Parts <= RegsLeft) {
418 for (unsigned j = 0; j < Parts; j++) {
419 MCRegister Reg = State.AllocateReg(RegList);
420 State.addLoc(CCValAssign::getReg(ValNo++, ArgVT, Reg, LocVT, LocInfo));
421 RegsLeft--;
422 }
423 } else {
424 UsedStack = true;
425 for (unsigned j = 0; j < Parts; j++)
426 CC_MSP430_AssignStack(ValNo++, ArgVT, LocVT, LocInfo, ArgFlags, OrigTy,
427 State);
428 }
429 }
430}
431
432static void AnalyzeRetResult(CCState &State,
434 State.AnalyzeCallResult(Ins, RetCC_MSP430);
435}
436
437static void AnalyzeRetResult(CCState &State,
439 State.AnalyzeReturn(Outs, RetCC_MSP430);
440}
441
442template<typename ArgT>
443static void AnalyzeReturnValues(CCState &State,
445 const SmallVectorImpl<ArgT> &Args) {
446 AnalyzeRetResult(State, Args);
447}
448
449SDValue MSP430TargetLowering::LowerFormalArguments(
450 SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
451 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
452 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
453
454 switch (CallConv) {
455 default:
456 report_fatal_error("Unsupported calling convention");
457 case CallingConv::C:
459 return LowerCCCArguments(Chain, CallConv, isVarArg, Ins, dl, DAG, InVals);
461 if (Ins.empty())
462 return Chain;
463 report_fatal_error("ISRs cannot have arguments");
464 }
465}
466
468MSP430TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
469 SmallVectorImpl<SDValue> &InVals) const {
470 SelectionDAG &DAG = CLI.DAG;
471 SDLoc &dl = CLI.DL;
473 SmallVectorImpl<SDValue> &OutVals = CLI.OutVals;
475 SDValue Chain = CLI.Chain;
476 SDValue Callee = CLI.Callee;
477 bool &isTailCall = CLI.IsTailCall;
478 CallingConv::ID CallConv = CLI.CallConv;
479 bool isVarArg = CLI.IsVarArg;
480
481 // MSP430 target does not yet support tail call optimization.
482 isTailCall = false;
483
484 switch (CallConv) {
485 default:
486 report_fatal_error("Unsupported calling convention");
489 case CallingConv::C:
490 return LowerCCCCallTo(Chain, Callee, CallConv, isVarArg, isTailCall,
491 Outs, OutVals, Ins, dl, DAG, InVals);
493 report_fatal_error("ISRs cannot be called directly");
494 }
495}
496
497/// LowerCCCArguments - transform physical registers into virtual registers and
498/// generate load operations for arguments places on the stack.
499// FIXME: struct return stuff
500SDValue MSP430TargetLowering::LowerCCCArguments(
501 SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
502 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
503 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
505 MachineFrameInfo &MFI = MF.getFrameInfo();
508
509 // Assign locations to all of the incoming arguments.
511 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
512 *DAG.getContext());
513 AnalyzeArguments(CCInfo, ArgLocs, Ins);
514
515 // Create frame index for the start of the first vararg value
516 if (isVarArg) {
517 unsigned Offset = CCInfo.getStackSize();
518 FuncInfo->setVarArgsFrameIndex(MFI.CreateFixedObject(1, Offset, true));
519 }
520
521 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
522 CCValAssign &VA = ArgLocs[i];
523 if (VA.isRegLoc()) {
524 // Arguments passed in registers
525 EVT RegVT = VA.getLocVT();
526 switch (RegVT.getSimpleVT().SimpleTy) {
527 default:
528 {
529#ifndef NDEBUG
530 errs() << "LowerFormalArguments Unhandled argument type: "
531 << RegVT << "\n";
532#endif
533 llvm_unreachable(nullptr);
534 }
535 case MVT::i16:
536 Register VReg = RegInfo.createVirtualRegister(&MSP430::GR16RegClass);
537 RegInfo.addLiveIn(VA.getLocReg(), VReg);
538 SDValue ArgValue = DAG.getCopyFromReg(Chain, dl, VReg, RegVT);
539
540 // If this is an 8-bit value, it is really passed promoted to 16
541 // bits. Insert an assert[sz]ext to capture this, then truncate to the
542 // right size.
543 if (VA.getLocInfo() == CCValAssign::SExt)
544 ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue,
545 DAG.getValueType(VA.getValVT()));
546 else if (VA.getLocInfo() == CCValAssign::ZExt)
547 ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue,
548 DAG.getValueType(VA.getValVT()));
549
550 if (VA.getLocInfo() != CCValAssign::Full)
551 ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue);
552
553 InVals.push_back(ArgValue);
554 }
555 } else {
556 // Only arguments passed on the stack should make it here.
557 assert(VA.isMemLoc());
558
559 SDValue InVal;
560 ISD::ArgFlagsTy Flags = Ins[i].Flags;
561
562 if (Flags.isByVal()) {
563 MVT PtrVT = VA.getLocVT();
564 int FI = MFI.CreateFixedObject(Flags.getByValSize(),
565 VA.getLocMemOffset(), true);
566 InVal = DAG.getFrameIndex(FI, PtrVT);
567 } else {
568 // Load the argument to a virtual register
569 unsigned ObjSize = VA.getLocVT().getSizeInBits()/8;
570 if (ObjSize > 2) {
571 errs() << "LowerFormalArguments Unhandled argument type: "
572 << VA.getLocVT() << "\n";
573 }
574 // Create the frame index object for this incoming parameter...
575 int FI = MFI.CreateFixedObject(ObjSize, VA.getLocMemOffset(), true);
576
577 // Create the SelectionDAG nodes corresponding to a load
578 //from this parameter
579 SDValue FIN = DAG.getFrameIndex(FI, MVT::i16);
580 InVal = DAG.getLoad(
581 VA.getLocVT(), dl, Chain, FIN,
583 }
584
585 InVals.push_back(InVal);
586 }
587 }
588
589 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
590 if (Ins[i].Flags.isSRet()) {
591 Register Reg = FuncInfo->getSRetReturnReg();
592 if (!Reg) {
594 getRegClassFor(MVT::i16));
595 FuncInfo->setSRetReturnReg(Reg);
596 }
597 SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[i]);
598 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
599 }
600 }
601
602 return Chain;
603}
604
605bool
606MSP430TargetLowering::CanLowerReturn(CallingConv::ID CallConv,
607 MachineFunction &MF,
608 bool IsVarArg,
610 LLVMContext &Context,
611 const Type *RetTy) const {
613 CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
614 return CCInfo.CheckReturn(Outs, RetCC_MSP430);
615}
616
618MSP430TargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
619 bool isVarArg,
621 const SmallVectorImpl<SDValue> &OutVals,
622 const SDLoc &dl, SelectionDAG &DAG) const {
623
625
626 // CCValAssign - represent the assignment of the return value to a location
628
629 // ISRs cannot return any value.
630 if (CallConv == CallingConv::MSP430_INTR && !Outs.empty())
631 report_fatal_error("ISRs cannot return any value");
632
633 // CCState - Info about the registers and stack slot.
634 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
635 *DAG.getContext());
636
637 // Analize return values.
638 AnalyzeReturnValues(CCInfo, RVLocs, Outs);
639
640 SDValue Glue;
641 SmallVector<SDValue, 4> RetOps(1, Chain);
642
643 // Copy the result values into the output registers.
644 for (unsigned i = 0; i != RVLocs.size(); ++i) {
645 CCValAssign &VA = RVLocs[i];
646 assert(VA.isRegLoc() && "Can only return in registers!");
647
648 Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(),
649 OutVals[i], Glue);
650
651 // Guarantee that all emitted copies are stuck together,
652 // avoiding something bad.
653 Glue = Chain.getValue(1);
654 RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
655 }
656
657 if (MF.getFunction().hasStructRetAttr()) {
659 Register Reg = FuncInfo->getSRetReturnReg();
660
661 if (!Reg)
662 llvm_unreachable("sret virtual register not created in entry block");
663
664 MVT PtrVT = getFrameIndexTy(DAG.getDataLayout());
665 SDValue Val =
666 DAG.getCopyFromReg(Chain, dl, Reg, PtrVT);
667 unsigned R12 = MSP430::R12;
668
669 Chain = DAG.getCopyToReg(Chain, dl, R12, Val, Glue);
670 Glue = Chain.getValue(1);
671 RetOps.push_back(DAG.getRegister(R12, PtrVT));
672 }
673
674 unsigned Opc = (CallConv == CallingConv::MSP430_INTR ?
675 MSP430ISD::RETI_GLUE : MSP430ISD::RET_GLUE);
676
677 RetOps[0] = Chain; // Update chain.
678
679 // Add the glue if we have it.
680 if (Glue.getNode())
681 RetOps.push_back(Glue);
682
683 return DAG.getNode(Opc, dl, MVT::Other, RetOps);
684}
685
686/// LowerCCCCallTo - functions arguments are copied from virtual regs to
687/// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted.
688SDValue MSP430TargetLowering::LowerCCCCallTo(
689 SDValue Chain, SDValue Callee, CallingConv::ID CallConv, bool isVarArg,
690 bool isTailCall, const SmallVectorImpl<ISD::OutputArg> &Outs,
691 const SmallVectorImpl<SDValue> &OutVals,
692 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
693 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
694 // Analyze operands of the call, assigning locations to each operand.
696 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
697 *DAG.getContext());
698 AnalyzeArguments(CCInfo, ArgLocs, Outs);
699
700 // Get a count of how many bytes are to be pushed on the stack.
701 unsigned NumBytes = CCInfo.getStackSize();
702 MVT PtrVT = getFrameIndexTy(DAG.getDataLayout());
703
704 Chain = DAG.getCALLSEQ_START(Chain, NumBytes, 0, dl);
705
707 SmallVector<SDValue, 12> MemOpChains;
709
710 // Walk the register/memloc assignments, inserting copies/loads.
711 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
712 CCValAssign &VA = ArgLocs[i];
713
714 SDValue Arg = OutVals[i];
715
716 // Promote the value if needed.
717 switch (VA.getLocInfo()) {
718 default: llvm_unreachable("Unknown loc info!");
719 case CCValAssign::Full: break;
721 Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
722 break;
724 Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
725 break;
727 Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
728 break;
729 }
730
731 // Arguments that can be passed on register must be kept at RegsToPass
732 // vector
733 if (VA.isRegLoc()) {
734 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
735 } else {
736 assert(VA.isMemLoc());
737
738 if (!StackPtr.getNode())
739 StackPtr = DAG.getCopyFromReg(Chain, dl, MSP430::SP, PtrVT);
740
741 SDValue PtrOff =
742 DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr,
743 DAG.getIntPtrConstant(VA.getLocMemOffset(), dl));
744
746 ISD::ArgFlagsTy Flags = Outs[i].Flags;
747
748 if (Flags.isByVal()) {
749 SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), dl, MVT::i16);
750 MemOp = DAG.getMemcpy(Chain, dl, PtrOff, Arg, SizeNode,
751 Flags.getNonZeroByValAlign(),
752 /*isVolatile*/ false,
753 /*AlwaysInline=*/true,
754 /*CI=*/nullptr, std::nullopt,
756 } else {
757 MemOp = DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo());
758 }
759
760 MemOpChains.push_back(MemOp);
761 }
762 }
763
764 // Transform all store nodes into one single node because all store nodes are
765 // independent of each other.
766 if (!MemOpChains.empty())
767 Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains);
768
769 // Build a sequence of copy-to-reg nodes chained together with token chain and
770 // flag operands which copy the outgoing args into registers. The InGlue in
771 // necessary since all emitted instructions must be stuck together.
772 SDValue InGlue;
773 for (const auto &[Reg, N] : RegsToPass) {
774 Chain = DAG.getCopyToReg(Chain, dl, Reg, N, InGlue);
775 InGlue = Chain.getValue(1);
776 }
777
778 // If the callee is a GlobalAddress node (quite common, every direct call is)
779 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
780 // Likewise ExternalSymbol -> TargetExternalSymbol.
781 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
782 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, MVT::i16);
783 else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
784 Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i16);
785
786 // Returns a chain & a flag for retval copy to use.
787 SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
789 Ops.push_back(Chain);
790 Ops.push_back(Callee);
791
792 // Add argument registers to the end of the list so that they are
793 // known live into the call.
794 for (const auto &[Reg, N] : RegsToPass)
795 Ops.push_back(DAG.getRegister(Reg, N.getValueType()));
796
797 if (InGlue.getNode())
798 Ops.push_back(InGlue);
799
800 Chain = DAG.getNode(MSP430ISD::CALL, dl, NodeTys, Ops);
801 InGlue = Chain.getValue(1);
802
803 // Create the CALLSEQ_END node.
804 Chain = DAG.getCALLSEQ_END(Chain, NumBytes, 0, InGlue, dl);
805 InGlue = Chain.getValue(1);
806
807 // Handle result values, copying them out of physregs into vregs that we
808 // return.
809 return LowerCallResult(Chain, InGlue, CallConv, isVarArg, Ins, dl,
810 DAG, InVals);
811}
812
813/// LowerCallResult - Lower the result values of a call into the
814/// appropriate copies out of appropriate physical registers.
815///
816SDValue MSP430TargetLowering::LowerCallResult(
817 SDValue Chain, SDValue InGlue, CallingConv::ID CallConv, bool isVarArg,
818 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
819 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
820
821 // Assign locations to each value returned by this call.
823 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
824 *DAG.getContext());
825
826 AnalyzeReturnValues(CCInfo, RVLocs, Ins);
827
828 // Copy all of the result registers out of their specified physreg.
829 for (unsigned i = 0; i != RVLocs.size(); ++i) {
830 Chain = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(),
831 RVLocs[i].getValVT(), InGlue).getValue(1);
832 InGlue = Chain.getValue(2);
833 InVals.push_back(Chain.getValue(0));
834 }
835
836 return Chain;
837}
838
840 SelectionDAG &DAG) const {
841 unsigned Opc = Op.getOpcode();
842 SDNode* N = Op.getNode();
843 EVT VT = Op.getValueType();
844 SDLoc dl(N);
845
846 // Expand non-constant shifts to loops:
847 if (!isa<ConstantSDNode>(N->getOperand(1)))
848 return Op;
849
850 uint64_t ShiftAmount = N->getConstantOperandVal(1);
851
852 // Expand the stuff into sequence of shifts.
853 SDValue Victim = N->getOperand(0);
854
855 if (ShiftAmount >= 8) {
856 assert(VT == MVT::i16 && "Can not shift i8 by 8 and more");
857 switch(Opc) {
858 default:
859 llvm_unreachable("Unknown shift");
860 case ISD::SHL:
861 // foo << (8 + N) => swpb(zext(foo)) << N
862 Victim = DAG.getZeroExtendInReg(Victim, dl, MVT::i8);
863 Victim = DAG.getNode(ISD::BSWAP, dl, VT, Victim);
864 break;
865 case ISD::SRA:
866 case ISD::SRL:
867 // foo >> (8 + N) => sxt(swpb(foo)) >> N
868 Victim = DAG.getNode(ISD::BSWAP, dl, VT, Victim);
869 Victim = (Opc == ISD::SRA)
870 ? DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, VT, Victim,
871 DAG.getValueType(MVT::i8))
872 : DAG.getZeroExtendInReg(Victim, dl, MVT::i8);
873 break;
874 }
875 ShiftAmount -= 8;
876 }
877
878 if (Opc == ISD::SRL && ShiftAmount) {
879 // Emit a special goodness here:
880 // srl A, 1 => clrc; rrc A
881 Victim = DAG.getNode(MSP430ISD::RRCL, dl, VT, Victim);
882 ShiftAmount -= 1;
883 }
884
885 while (ShiftAmount--)
886 Victim = DAG.getNode((Opc == ISD::SHL ? MSP430ISD::RLA : MSP430ISD::RRA),
887 dl, VT, Victim);
888
889 return Victim;
890}
891
893 SelectionDAG &DAG) const {
894 const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
895 int64_t Offset = cast<GlobalAddressSDNode>(Op)->getOffset();
896 EVT PtrVT = Op.getValueType();
897
898 // Create the TargetGlobalAddress node, folding in the constant offset.
899 SDValue Result = DAG.getTargetGlobalAddress(GV, SDLoc(Op), PtrVT, Offset);
900 return DAG.getNode(MSP430ISD::Wrapper, SDLoc(Op), PtrVT, Result);
901}
902
904 SelectionDAG &DAG) const {
905 SDLoc dl(Op);
906 const char *Sym = cast<ExternalSymbolSDNode>(Op)->getSymbol();
907 EVT PtrVT = Op.getValueType();
908 SDValue Result = DAG.getTargetExternalSymbol(Sym, PtrVT);
909
910 return DAG.getNode(MSP430ISD::Wrapper, dl, PtrVT, Result);
911}
912
914 SelectionDAG &DAG) const {
915 SDLoc dl(Op);
916 const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress();
917 EVT PtrVT = Op.getValueType();
918 SDValue Result = DAG.getTargetBlockAddress(BA, PtrVT);
919
920 return DAG.getNode(MSP430ISD::Wrapper, dl, PtrVT, Result);
921}
922
923static SDValue EmitCMP(SDValue &LHS, SDValue &RHS, SDValue &TargetCC,
924 ISD::CondCode CC, const SDLoc &dl, SelectionDAG &DAG) {
925 // FIXME: Handle bittests someday
926 assert(!LHS.getValueType().isFloatingPoint() && "We don't handle FP yet");
927
928 // FIXME: Handle jump negative someday
930 switch (CC) {
931 default: llvm_unreachable("Invalid integer condition!");
932 case ISD::SETEQ:
933 TCC = MSP430CC::COND_E; // aka COND_Z
934 // Minor optimization: if LHS is a constant, swap operands, then the
935 // constant can be folded into comparison.
936 if (LHS.getOpcode() == ISD::Constant)
937 std::swap(LHS, RHS);
938 break;
939 case ISD::SETNE:
940 TCC = MSP430CC::COND_NE; // aka COND_NZ
941 // Minor optimization: if LHS is a constant, swap operands, then the
942 // constant can be folded into comparison.
943 if (LHS.getOpcode() == ISD::Constant)
944 std::swap(LHS, RHS);
945 break;
946 case ISD::SETULE:
947 std::swap(LHS, RHS);
948 [[fallthrough]];
949 case ISD::SETUGE:
950 // Turn lhs u>= rhs with lhs constant into rhs u< lhs+1, this allows us to
951 // fold constant into instruction.
952 if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
953 LHS = RHS;
954 RHS = DAG.getConstant(C->getSExtValue() + 1, dl, C->getValueType(0));
955 TCC = MSP430CC::COND_LO;
956 break;
957 }
958 TCC = MSP430CC::COND_HS; // aka COND_C
959 break;
960 case ISD::SETUGT:
961 std::swap(LHS, RHS);
962 [[fallthrough]];
963 case ISD::SETULT:
964 // Turn lhs u< rhs with lhs constant into rhs u>= lhs+1, this allows us to
965 // fold constant into instruction.
966 if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
967 LHS = RHS;
968 RHS = DAG.getConstant(C->getSExtValue() + 1, dl, C->getValueType(0));
969 TCC = MSP430CC::COND_HS;
970 break;
971 }
972 TCC = MSP430CC::COND_LO; // aka COND_NC
973 break;
974 case ISD::SETLE:
975 std::swap(LHS, RHS);
976 [[fallthrough]];
977 case ISD::SETGE:
978 // Turn lhs >= rhs with lhs constant into rhs < lhs+1, this allows us to
979 // fold constant into instruction.
980 if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
981 LHS = RHS;
982 RHS = DAG.getConstant(C->getSExtValue() + 1, dl, C->getValueType(0));
983 TCC = MSP430CC::COND_L;
984 break;
985 }
986 TCC = MSP430CC::COND_GE;
987 break;
988 case ISD::SETGT:
989 std::swap(LHS, RHS);
990 [[fallthrough]];
991 case ISD::SETLT:
992 // Turn lhs < rhs with lhs constant into rhs >= lhs+1, this allows us to
993 // fold constant into instruction.
994 if (const ConstantSDNode * C = dyn_cast<ConstantSDNode>(LHS)) {
995 LHS = RHS;
996 RHS = DAG.getConstant(C->getSExtValue() + 1, dl, C->getValueType(0));
997 TCC = MSP430CC::COND_GE;
998 break;
999 }
1000 TCC = MSP430CC::COND_L;
1001 break;
1002 }
1003
1004 TargetCC = DAG.getConstant(TCC, dl, MVT::i8);
1005 return DAG.getNode(MSP430ISD::CMP, dl, MVT::Glue, LHS, RHS);
1006}
1007
1008
1010 SDValue Chain = Op.getOperand(0);
1011 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
1012 SDValue LHS = Op.getOperand(2);
1013 SDValue RHS = Op.getOperand(3);
1014 SDValue Dest = Op.getOperand(4);
1015 SDLoc dl (Op);
1016
1017 SDValue TargetCC;
1018 SDValue Flag = EmitCMP(LHS, RHS, TargetCC, CC, dl, DAG);
1019
1020 return DAG.getNode(MSP430ISD::BR_CC, dl, Op.getValueType(),
1021 Chain, Dest, TargetCC, Flag);
1022}
1023
1025 SDValue LHS = Op.getOperand(0);
1026 SDValue RHS = Op.getOperand(1);
1027 SDLoc dl (Op);
1028
1029 // If we are doing an AND and testing against zero, then the CMP
1030 // will not be generated. The AND (or BIT) will generate the condition codes,
1031 // but they are different from CMP.
1032 // FIXME: since we're doing a post-processing, use a pseudoinstr here, so
1033 // lowering & isel wouldn't diverge.
1034 bool andCC = isNullConstant(RHS) && LHS.hasOneUse() &&
1035 (LHS.getOpcode() == ISD::AND ||
1036 (LHS.getOpcode() == ISD::TRUNCATE &&
1037 LHS.getOperand(0).getOpcode() == ISD::AND));
1038 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
1039 SDValue TargetCC;
1040 SDValue Flag = EmitCMP(LHS, RHS, TargetCC, CC, dl, DAG);
1041
1042 // Get the condition codes directly from the status register, if its easy.
1043 // Otherwise a branch will be generated. Note that the AND and BIT
1044 // instructions generate different flags than CMP, the carry bit can be used
1045 // for NE/EQ.
1046 bool Invert = false;
1047 bool Shift = false;
1048 bool Convert = true;
1049 switch (TargetCC->getAsZExtVal()) {
1050 default:
1051 Convert = false;
1052 break;
1053 case MSP430CC::COND_HS:
1054 // Res = SR & 1, no processing is required
1055 break;
1056 case MSP430CC::COND_LO:
1057 // Res = ~(SR & 1)
1058 Invert = true;
1059 break;
1060 case MSP430CC::COND_NE:
1061 if (andCC) {
1062 // C = ~Z, thus Res = SR & 1, no processing is required
1063 } else {
1064 // Res = ~((SR >> 1) & 1)
1065 Shift = true;
1066 Invert = true;
1067 }
1068 break;
1069 case MSP430CC::COND_E:
1070 Shift = true;
1071 // C = ~Z for AND instruction, thus we can put Res = ~(SR & 1), however,
1072 // Res = (SR >> 1) & 1 is 1 word shorter.
1073 break;
1074 }
1075 EVT VT = Op.getValueType();
1076 SDValue One = DAG.getConstant(1, dl, VT);
1077 if (Convert) {
1078 SDValue SR = DAG.getCopyFromReg(DAG.getEntryNode(), dl, MSP430::SR,
1079 MVT::i16, Flag);
1080 if (Shift)
1081 // FIXME: somewhere this is turned into a SRL, lower it MSP specific?
1082 SR = DAG.getNode(ISD::SRA, dl, MVT::i16, SR, One);
1083 SR = DAG.getNode(ISD::AND, dl, MVT::i16, SR, One);
1084 if (Invert)
1085 SR = DAG.getNode(ISD::XOR, dl, MVT::i16, SR, One);
1086 return SR;
1087 } else {
1088 SDValue Zero = DAG.getConstant(0, dl, VT);
1089 SDValue Ops[] = {One, Zero, TargetCC, Flag};
1090 return DAG.getNode(MSP430ISD::SELECT_CC, dl, Op.getValueType(), Ops);
1091 }
1092}
1093
1095 SelectionDAG &DAG) const {
1096 SDValue LHS = Op.getOperand(0);
1097 SDValue RHS = Op.getOperand(1);
1098 SDValue TrueV = Op.getOperand(2);
1099 SDValue FalseV = Op.getOperand(3);
1100 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
1101 SDLoc dl (Op);
1102
1103 SDValue TargetCC;
1104 SDValue Flag = EmitCMP(LHS, RHS, TargetCC, CC, dl, DAG);
1105
1106 SDValue Ops[] = {TrueV, FalseV, TargetCC, Flag};
1107
1108 return DAG.getNode(MSP430ISD::SELECT_CC, dl, Op.getValueType(), Ops);
1109}
1110
1112 SelectionDAG &DAG) const {
1113 SDValue Val = Op.getOperand(0);
1114 EVT VT = Op.getValueType();
1115 SDLoc dl(Op);
1116
1117 assert(VT == MVT::i16 && "Only support i16 for now!");
1118
1119 return DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, VT,
1120 DAG.getNode(ISD::ANY_EXTEND, dl, VT, Val),
1121 DAG.getValueType(Val.getValueType()));
1122}
1123
1124SDValue
1128 int ReturnAddrIndex = FuncInfo->getRAIndex();
1129 MVT PtrVT = getFrameIndexTy(MF.getDataLayout());
1130
1131 if (ReturnAddrIndex == 0) {
1132 // Set up a frame object for the return address.
1133 uint64_t SlotSize = PtrVT.getStoreSize();
1134 ReturnAddrIndex = MF.getFrameInfo().CreateFixedObject(SlotSize, -SlotSize,
1135 true);
1136 FuncInfo->setRAIndex(ReturnAddrIndex);
1137 }
1138
1139 return DAG.getFrameIndex(ReturnAddrIndex, PtrVT);
1140}
1141
1143 SelectionDAG &DAG) const {
1145 MFI.setReturnAddressIsTaken(true);
1146
1147 unsigned Depth = Op.getConstantOperandVal(0);
1148 SDLoc dl(Op);
1149 EVT PtrVT = Op.getValueType();
1150
1151 if (Depth > 0) {
1152 SDValue FrameAddr = LowerFRAMEADDR(Op, DAG);
1153 SDValue Offset =
1154 DAG.getConstant(PtrVT.getStoreSize(), dl, MVT::i16);
1155 return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(),
1156 DAG.getNode(ISD::ADD, dl, PtrVT, FrameAddr, Offset),
1158 }
1159
1160 // Just load the return address.
1161 SDValue RetAddrFI = getReturnAddressFrameIndex(DAG);
1162 return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), RetAddrFI,
1164}
1165
1167 SelectionDAG &DAG) const {
1169 MFI.setFrameAddressIsTaken(true);
1170
1171 EVT VT = Op.getValueType();
1172 SDLoc dl(Op); // FIXME probably not meaningful
1173 unsigned Depth = Op.getConstantOperandVal(0);
1174 SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl,
1175 MSP430::R4, VT);
1176 while (Depth--)
1177 FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr,
1179 return FrameAddr;
1180}
1181
1183 SelectionDAG &DAG) const {
1186
1187 SDValue Ptr = Op.getOperand(1);
1188 EVT PtrVT = Ptr.getValueType();
1189
1190 // Frame index of first vararg argument
1191 SDValue FrameIndex =
1192 DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT);
1193 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
1194
1195 // Create a store of the frame index to the location operand
1196 return DAG.getStore(Op.getOperand(0), SDLoc(Op), FrameIndex, Ptr,
1197 MachinePointerInfo(SV));
1198}
1199
1201 SelectionDAG &DAG) const {
1202 JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
1203 EVT PtrVT = Op.getValueType();
1204 SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), PtrVT);
1205 return DAG.getNode(MSP430ISD::Wrapper, SDLoc(JT), PtrVT, Result);
1206}
1207
1208/// getPostIndexedAddressParts - returns true by value, base pointer and
1209/// offset pointer and addressing mode by reference if this node can be
1210/// combined with a load / store to form a post-indexed load / store.
1211bool MSP430TargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
1212 SDValue &Base,
1213 SDValue &Offset,
1215 SelectionDAG &DAG) const {
1216
1217 LoadSDNode *LD = cast<LoadSDNode>(N);
1218 if (LD->getExtensionType() != ISD::NON_EXTLOAD)
1219 return false;
1220
1221 EVT VT = LD->getMemoryVT();
1222 if (VT != MVT::i8 && VT != MVT::i16)
1223 return false;
1224
1225 if (Op->getOpcode() != ISD::ADD)
1226 return false;
1227
1228 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Op->getOperand(1))) {
1229 uint64_t RHSC = RHS->getZExtValue();
1230 if ((VT == MVT::i16 && RHSC != 2) ||
1231 (VT == MVT::i8 && RHSC != 1))
1232 return false;
1233
1234 Base = Op->getOperand(0);
1235 Offset = DAG.getConstant(RHSC, SDLoc(N), VT);
1236 AM = ISD::POST_INC;
1237 return true;
1238 }
1239
1240 return false;
1241}
1242
1244 Type *Ty2) const {
1245 if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy())
1246 return false;
1247
1248 return (Ty1->getPrimitiveSizeInBits().getFixedValue() >
1250}
1251
1253 if (!VT1.isInteger() || !VT2.isInteger())
1254 return false;
1255
1256 return (VT1.getFixedSizeInBits() > VT2.getFixedSizeInBits());
1257}
1258
1260 // MSP430 implicitly zero-extends 8-bit results in 16-bit registers.
1261 return false && Ty1->isIntegerTy(8) && Ty2->isIntegerTy(16);
1262}
1263
1265 // MSP430 implicitly zero-extends 8-bit results in 16-bit registers.
1266 return false && VT1 == MVT::i8 && VT2 == MVT::i16;
1267}
1268
1269//===----------------------------------------------------------------------===//
1270// Other Lowering Code
1271//===----------------------------------------------------------------------===//
1272
1275 MachineBasicBlock *BB) const {
1276 MachineFunction *F = BB->getParent();
1277 MachineRegisterInfo &RI = F->getRegInfo();
1278 DebugLoc dl = MI.getDebugLoc();
1279 const TargetInstrInfo &TII = *F->getSubtarget().getInstrInfo();
1280
1281 unsigned Opc;
1282 bool ClearCarry = false;
1283 const TargetRegisterClass * RC;
1284 switch (MI.getOpcode()) {
1285 default: llvm_unreachable("Invalid shift opcode!");
1286 case MSP430::Shl8:
1287 Opc = MSP430::ADD8rr;
1288 RC = &MSP430::GR8RegClass;
1289 break;
1290 case MSP430::Shl16:
1291 Opc = MSP430::ADD16rr;
1292 RC = &MSP430::GR16RegClass;
1293 break;
1294 case MSP430::Sra8:
1295 Opc = MSP430::RRA8r;
1296 RC = &MSP430::GR8RegClass;
1297 break;
1298 case MSP430::Sra16:
1299 Opc = MSP430::RRA16r;
1300 RC = &MSP430::GR16RegClass;
1301 break;
1302 case MSP430::Srl8:
1303 ClearCarry = true;
1304 Opc = MSP430::RRC8r;
1305 RC = &MSP430::GR8RegClass;
1306 break;
1307 case MSP430::Srl16:
1308 ClearCarry = true;
1309 Opc = MSP430::RRC16r;
1310 RC = &MSP430::GR16RegClass;
1311 break;
1312 case MSP430::Rrcl8:
1313 case MSP430::Rrcl16: {
1314 BuildMI(*BB, MI, dl, TII.get(MSP430::BIC16rc), MSP430::SR)
1315 .addReg(MSP430::SR).addImm(1);
1316 Register SrcReg = MI.getOperand(1).getReg();
1317 Register DstReg = MI.getOperand(0).getReg();
1318 unsigned RrcOpc = MI.getOpcode() == MSP430::Rrcl16
1319 ? MSP430::RRC16r : MSP430::RRC8r;
1320 BuildMI(*BB, MI, dl, TII.get(RrcOpc), DstReg)
1321 .addReg(SrcReg);
1322 MI.eraseFromParent(); // The pseudo instruction is gone now.
1323 return BB;
1324 }
1325 }
1326
1327 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1329
1330 // Create loop block
1331 MachineBasicBlock *LoopBB = F->CreateMachineBasicBlock(LLVM_BB);
1332 MachineBasicBlock *RemBB = F->CreateMachineBasicBlock(LLVM_BB);
1333
1334 F->insert(I, LoopBB);
1335 F->insert(I, RemBB);
1336
1337 // Update machine-CFG edges by transferring all successors of the current
1338 // block to the block containing instructions after shift.
1339 RemBB->splice(RemBB->begin(), BB, std::next(MachineBasicBlock::iterator(MI)),
1340 BB->end());
1342
1343 // Add edges BB => LoopBB => RemBB, BB => RemBB, LoopBB => LoopBB
1344 BB->addSuccessor(LoopBB);
1345 BB->addSuccessor(RemBB);
1346 LoopBB->addSuccessor(RemBB);
1347 LoopBB->addSuccessor(LoopBB);
1348
1349 Register ShiftAmtReg = RI.createVirtualRegister(&MSP430::GR8RegClass);
1350 Register ShiftAmtReg2 = RI.createVirtualRegister(&MSP430::GR8RegClass);
1351 Register ShiftReg = RI.createVirtualRegister(RC);
1352 Register ShiftReg2 = RI.createVirtualRegister(RC);
1353 Register ShiftAmtSrcReg = MI.getOperand(2).getReg();
1354 Register SrcReg = MI.getOperand(1).getReg();
1355 Register DstReg = MI.getOperand(0).getReg();
1356
1357 // BB:
1358 // cmp 0, N
1359 // je RemBB
1360 BuildMI(BB, dl, TII.get(MSP430::CMP8ri))
1361 .addReg(ShiftAmtSrcReg).addImm(0);
1362 BuildMI(BB, dl, TII.get(MSP430::JCC))
1363 .addMBB(RemBB)
1365
1366 // LoopBB:
1367 // ShiftReg = phi [%SrcReg, BB], [%ShiftReg2, LoopBB]
1368 // ShiftAmt = phi [%N, BB], [%ShiftAmt2, LoopBB]
1369 // ShiftReg2 = shift ShiftReg
1370 // ShiftAmt2 = ShiftAmt - 1;
1371 BuildMI(LoopBB, dl, TII.get(MSP430::PHI), ShiftReg)
1372 .addReg(SrcReg).addMBB(BB)
1373 .addReg(ShiftReg2).addMBB(LoopBB);
1374 BuildMI(LoopBB, dl, TII.get(MSP430::PHI), ShiftAmtReg)
1375 .addReg(ShiftAmtSrcReg).addMBB(BB)
1376 .addReg(ShiftAmtReg2).addMBB(LoopBB);
1377 if (ClearCarry)
1378 BuildMI(LoopBB, dl, TII.get(MSP430::BIC16rc), MSP430::SR)
1379 .addReg(MSP430::SR).addImm(1);
1380 if (Opc == MSP430::ADD8rr || Opc == MSP430::ADD16rr)
1381 BuildMI(LoopBB, dl, TII.get(Opc), ShiftReg2)
1382 .addReg(ShiftReg)
1383 .addReg(ShiftReg);
1384 else
1385 BuildMI(LoopBB, dl, TII.get(Opc), ShiftReg2)
1386 .addReg(ShiftReg);
1387 BuildMI(LoopBB, dl, TII.get(MSP430::SUB8ri), ShiftAmtReg2)
1388 .addReg(ShiftAmtReg).addImm(1);
1389 BuildMI(LoopBB, dl, TII.get(MSP430::JCC))
1390 .addMBB(LoopBB)
1392
1393 // RemBB:
1394 // DestReg = phi [%SrcReg, BB], [%ShiftReg, LoopBB]
1395 BuildMI(*RemBB, RemBB->begin(), dl, TII.get(MSP430::PHI), DstReg)
1396 .addReg(SrcReg).addMBB(BB)
1397 .addReg(ShiftReg2).addMBB(LoopBB);
1398
1399 MI.eraseFromParent(); // The pseudo instruction is gone now.
1400 return RemBB;
1401}
1402
1405 MachineBasicBlock *BB) const {
1406 unsigned Opc = MI.getOpcode();
1407
1408 if (Opc == MSP430::Shl8 || Opc == MSP430::Shl16 ||
1409 Opc == MSP430::Sra8 || Opc == MSP430::Sra16 ||
1410 Opc == MSP430::Srl8 || Opc == MSP430::Srl16 ||
1411 Opc == MSP430::Rrcl8 || Opc == MSP430::Rrcl16)
1412 return EmitShiftInstr(MI, BB);
1413
1415 DebugLoc dl = MI.getDebugLoc();
1416
1417 assert((Opc == MSP430::Select16 || Opc == MSP430::Select8) &&
1418 "Unexpected instr type to insert");
1419
1420 // To "insert" a SELECT instruction, we actually have to insert the diamond
1421 // control-flow pattern. The incoming instruction knows the destination vreg
1422 // to set, the condition code register to branch on, the true/false values to
1423 // select between, and a branch opcode to use.
1424 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1426
1427 // thisMBB:
1428 // ...
1429 // TrueVal = ...
1430 // cmpTY ccX, r1, r2
1431 // jCC copy1MBB
1432 // fallthrough --> copy0MBB
1433 MachineBasicBlock *thisMBB = BB;
1434 MachineFunction *F = BB->getParent();
1435 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
1436 MachineBasicBlock *copy1MBB = F->CreateMachineBasicBlock(LLVM_BB);
1437 F->insert(I, copy0MBB);
1438 F->insert(I, copy1MBB);
1439 // Update machine-CFG edges by transferring all successors of the current
1440 // block to the new block which will contain the Phi node for the select.
1441 copy1MBB->splice(copy1MBB->begin(), BB,
1442 std::next(MachineBasicBlock::iterator(MI)), BB->end());
1443 copy1MBB->transferSuccessorsAndUpdatePHIs(BB);
1444 // Next, add the true and fallthrough blocks as its successors.
1445 BB->addSuccessor(copy0MBB);
1446 BB->addSuccessor(copy1MBB);
1447
1448 BuildMI(BB, dl, TII.get(MSP430::JCC))
1449 .addMBB(copy1MBB)
1450 .addImm(MI.getOperand(3).getImm());
1451
1452 // copy0MBB:
1453 // %FalseValue = ...
1454 // # fallthrough to copy1MBB
1455 BB = copy0MBB;
1456
1457 // Update machine-CFG edges
1458 BB->addSuccessor(copy1MBB);
1459
1460 // copy1MBB:
1461 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1462 // ...
1463 BB = copy1MBB;
1464 BuildMI(*BB, BB->begin(), dl, TII.get(MSP430::PHI), MI.getOperand(0).getReg())
1465 .addReg(MI.getOperand(2).getReg())
1466 .addMBB(copy0MBB)
1467 .addReg(MI.getOperand(1).getReg())
1468 .addMBB(thisMBB);
1469
1470 MI.eraseFromParent(); // The pseudo instruction is gone now.
1471 return BB;
1472}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
return RetTy
Symbol * Sym
Definition: ELF_riscv.cpp:479
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#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
static void AnalyzeReturnValues(CCState &State, SmallVectorImpl< CCValAssign > &RVLocs, const SmallVectorImpl< ArgT > &Args)
static void AnalyzeVarArgs(CCState &State, const SmallVectorImpl< ISD::OutputArg > &Outs)
static void AnalyzeRetResult(CCState &State, const SmallVectorImpl< ISD::InputArg > &Ins)
static cl::opt< bool > MSP430NoLegalImmediate("msp430-no-legal-immediate", cl::Hidden, cl::desc("Enable non legal immediates (for testing purposes only)"), cl::init(false))
static void ParseFunctionArgs(const SmallVectorImpl< ArgT > &Args, SmallVectorImpl< unsigned > &Out)
For each argument in a function store the number of pieces it is composed of.
static void AnalyzeArguments(CCState &State, SmallVectorImpl< CCValAssign > &ArgLocs, const SmallVectorImpl< ArgT > &Args)
Analyze incoming and outgoing function arguments.
static SDValue EmitCMP(SDValue &LHS, SDValue &RHS, SDValue &TargetCC, ISD::CondCode CC, const SDLoc &dl, SelectionDAG &DAG)
Register const TargetRegisterInfo * TRI
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
LLVM Basic Block Representation.
Definition: BasicBlock.h:62
The address of a basic block.
Definition: Constants.h:899
CCState - This class holds information needed while lowering arguments and return values.
LLVM_ABI void HandleByVal(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, int MinSize, Align MinAlign, ISD::ArgFlagsTy ArgFlags)
Allocate space on the stack large enough to pass an argument by value.
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...
CallingConv::ID getCallingConv() const
MCRegister AllocateReg(MCPhysReg Reg)
AllocateReg - Attempt to allocate one register.
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...
bool isVarArg() const
LLVM_ABI void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeFormalArguments - Analyze an array of argument values, incorporating info about the formals in...
void addLoc(const CCValAssign &V)
CCValAssign - Represent assignment of one arg/retval to a location.
bool isRegLoc() const
Register getLocReg() const
LocInfo getLocInfo() const
static CCValAssign getReg(unsigned ValNo, MVT ValVT, MCRegister Reg, MVT LocVT, LocInfo HTP, bool IsCustom=false)
bool isMemLoc() const
int64_t getLocMemOffset() const
This class represents an Operation in the Expression.
A debug info location.
Definition: DebugLoc.h:124
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
Definition: Function.h:687
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
This class is used to represent ISD::LOAD nodes.
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
MSP430MachineFunctionInfo - This class is derived from MachineFunction and contains private MSP430 ta...
const MSP430RegisterInfo * getRegisterInfo() const override
bool hasHWMultF5() const
bool hasHWMult32() const
bool hasHWMult16() const
SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const
MSP430TargetLowering(const TargetMachine &TM, const MSP430Subtarget &STI)
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
LowerOperation - Provide custom lowering hooks for some operations.
MachineBasicBlock * EmitShiftInstr(MachineInstr &MI, MachineBasicBlock *BB) const
SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const
SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const
SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const
bool isTruncateFree(Type *Ty1, Type *Ty2) const override
isTruncateFree - Return true if it's free to truncate a value of type Ty1 to type Ty2.
SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const
SDValue LowerShifts(SDValue Op, SelectionDAG &DAG) const
SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
SDValue LowerSIGN_EXTEND(SDValue Op, SelectionDAG &DAG) const
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *BB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const
SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const
SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const
SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const
bool shouldAvoidTransformToShift(EVT VT, unsigned Amount) const override
Return true if creating a shift of the type by the given amount is not profitable.
bool isZExtFree(Type *Ty1, Type *Ty2) const override
isZExtFree - Return true if any actual instruction that defines a value of type Ty1 implicit zero-ext...
TargetLowering::ConstraintType getConstraintType(StringRef Constraint) const override
getConstraintType - Given a constraint letter, return the type of constraint it is for this target.
bool isLegalICmpImmediate(int64_t) const override
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
Machine Value Type.
SimpleValueType SimpleTy
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...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
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 '...
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)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Representation of each machine instruction.
Definition: MachineInstr.h:72
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
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...
Represents one node in the SelectionDAG.
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
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...
Definition: SelectionDAG.h:229
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:758
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, SDValue N)
Definition: SelectionDAG.h:813
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
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,...
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)
SDValue getTargetJumpTable(int JTI, EVT VT, unsigned TargetFlags=0)
Definition: SelectionDAG.h:768
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)
Definition: SelectionDAG.h:839
LLVM_ABI 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:498
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.
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 ...
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.
SDValue getTargetBlockAddress(const BlockAddress *BA, EVT VT, int64_t Offset=0, unsigned TargetFlags=0)
Definition: SelectionDAG.h:808
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:493
LLVM_ABI SDValue getFrameIndex(int FI, EVT VT, bool isTarget=false)
LLVMContext * getContext() const
Definition: SelectionDAG.h:511
LLVM_ABI SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned TargetFlags=0)
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:581
bool empty() const
Definition: SmallVector.h:82
size_t size() const
Definition: SmallVector.h:79
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:154
TargetInstrInfo - Interface to description of machine instruction set.
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...
virtual bool isLegalICmpImmediate(int64_t) const
Return true if the specified immediate is legal icmp immediate, that is the target has icmp instructi...
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
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 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.
void setPrefFunctionAlignment(Align Alignment)
Set the target's preferred function alignment.
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 setStackPointerRegisterToSaveRestore(Register R)
If set to a physical register, this specifies the register that llvm.savestack/llvm....
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...
void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl)
MVT getFrameIndexTy(const DataLayout &DL) const
Return the type for frame index, which is determined by the alloca address space specified through th...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:83
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:240
LLVM Value Representation.
Definition: Value.h:75
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition: Value.h:439
constexpr ScalarTy getFixedValue() const
Definition: TypeSize.h:203
self_iterator getIterator()
Definition: ilist_node.h:134
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
CondCodes
Definition: MSP430.h:22
@ COND_LO
Definition: MSP430.h:26
@ COND_L
Definition: MSP430.h:28
@ COND_INVALID
Definition: MSP430.h:32
@ COND_E
Definition: MSP430.h:23
@ COND_GE
Definition: MSP430.h:27
@ COND_NE
Definition: MSP430.h:24
@ COND_HS
Definition: MSP430.h:25
@ MSP430_BUILTIN
Used for special MSP430 rtlib functions which have an "optimized" convention using additional registe...
Definition: CallingConv.h:210
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:41
@ MSP430_INTR
Used for MSP430 interrupt routines.
Definition: CallingConv.h:117
@ 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:801
@ STACKRESTORE
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain.
Definition: ISDOpcodes.h:1236
@ STACKSAVE
STACKSAVE - STACKSAVE has one operand, an input chain.
Definition: ISDOpcodes.h:1232
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:270
@ BSWAP
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:765
@ VAEND
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE.
Definition: ISDOpcodes.h:1265
@ ADD
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:259
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:835
@ GlobalAddress
Definition: ISDOpcodes.h:88
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:275
@ SIGN_EXTEND
Conversion operators.
Definition: ISDOpcodes.h:826
@ BR_CC
BR_CC - Conditional branch.
Definition: ISDOpcodes.h:1187
@ BR_JT
BR_JT - Jumptable branch.
Definition: ISDOpcodes.h:1166
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:778
@ VACOPY
VACOPY - VACOPY has 5 operands: an input chain, a destination pointer, a source pointer,...
Definition: ISDOpcodes.h:1261
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition: ISDOpcodes.h:695
@ SHL
Shift and rotation operations.
Definition: ISDOpcodes.h:756
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:832
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:793
@ DYNAMIC_STACKALLOC
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary.
Definition: ISDOpcodes.h:1151
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:870
@ FRAMEADDR
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG.
Definition: ISDOpcodes.h:110
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:730
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
Definition: ISDOpcodes.h:53
@ ExternalSymbol
Definition: ISDOpcodes.h:93
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:838
@ VAARG
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
Definition: ISDOpcodes.h:1256
@ BRCOND
BRCOND - Conditional branch.
Definition: ISDOpcodes.h:1180
@ BlockAddress
Definition: ISDOpcodes.h:94
@ SHL_PARTS
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations.
Definition: ISDOpcodes.h:815
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition: ISDOpcodes.h:62
@ AssertZext
Definition: ISDOpcodes.h:63
MemIndexedMode
MemIndexedMode enum - This enum defines the load / store indexed addressing modes.
Definition: ISDOpcodes.h:1634
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition: ISDOpcodes.h:1685
Reg
All possible values of the reg field in the ModR/M byte.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:444
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM_ABI bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DWARFExpression::Operation Op
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:858
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
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:390
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:311
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
Definition: ValueTypes.h:376
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:152
This class contains a discriminated union of information about pointers in memory operands,...
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 structure contains all information that is necessary for lowering calls.
SmallVector< ISD::InputArg, 32 > Ins
SmallVector< ISD::OutputArg, 32 > Outs
SmallVector< SDValue, 32 > OutVals