1//===-- MSP430ISelLowering.h - MSP430 DAG Lowering Interface ----*- C++ -*-===//
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 MSP430 uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_MSP430_MSP430ISELLOWERING_H
15#define LLVM_LIB_TARGET_MSP430_MSP430ISELLOWERING_H
16
17#include "MSP430.h"
18#include "llvm/CodeGen/SelectionDAG.h"
19#include "llvm/CodeGen/TargetLowering.h"
20
21namespace llvm {
22 class MSP430Subtarget;
23 struct MSP430Options;
24 class MSP430TargetLowering : public TargetLowering {
25 const MSP430Options &CLOpts;
26
27 public:
28 explicit MSP430TargetLowering(const TargetMachine &TM,
29 const MSP430Subtarget &STI);
30
31 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
32 return MVT::i8;
33 }
34
35 IntegerType *getCmpLibcallReturnType(LLVMContext &Ctx) const override {
36 return Type::getInt16Ty(C&: Ctx);
37 }
38
39 /// LowerOperation - Provide custom lowering hooks for some operations.
40 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
41
42 SDValue LowerShifts(SDValue Op, SelectionDAG &DAG) const;
43 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
44 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
45 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
46 SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
47 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
48 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
49 SDValue LowerSIGN_EXTEND(SDValue Op, SelectionDAG &DAG) const;
50 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
51 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
52 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
53 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
54 SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const;
55
56 TargetLowering::ConstraintType
57 getConstraintType(StringRef Constraint) const override;
58 std::pair<unsigned, const TargetRegisterClass *>
59 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
60 StringRef Constraint, MVT VT) const override;
61
62 /// isTruncateFree - Return true if it's free to truncate a value of type
63 /// Ty1 to type Ty2. e.g. On msp430 it's free to truncate a i16 value in
64 /// register R15W to i8 by referencing its sub-register R15B.
65 bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
66 bool isTruncateFree(EVT VT1, EVT VT2) const override;
67
68 /// isZExtFree - Return true if any actual instruction that defines a value
69 /// of type Ty1 implicit zero-extends the value to Ty2 in the result
70 /// register. This does not necessarily include registers defined in unknown
71 /// ways, such as incoming arguments, or copies from unknown virtual
72 /// registers. Also, if isTruncateFree(Ty2, Ty1) is true, this does not
73 /// necessarily apply to truncate instructions. e.g. on msp430, all
74 /// instructions that define 8-bit values implicit zero-extend the result
75 /// out to 16 bits.
76 bool isZExtFree(Type *Ty1, Type *Ty2) const override;
77 bool isZExtFree(EVT VT1, EVT VT2) const override;
78
79 bool isLegalICmpImmediate(int64_t) const override;
80
81 /// If a physical register, this returns the register that receives the
82 /// exception address on entry to an EH pad.
83 Register
84 getExceptionPointerRegister(ExceptionHandling EH,
85 const Constant *PersonalityFn) const override;
86
87 /// If a physical register, this returns the register that receives the
88 /// exception typeid on entry to a landing pad.
89 Register
90 getExceptionSelectorRegister(ExceptionHandling EH,
91 const Constant *PersonalityFn) const override;
92 bool shouldAvoidTransformToShift(EVT VT, unsigned Amount) const override;
93
94 MachineBasicBlock *
95 EmitInstrWithCustomInserter(MachineInstr &MI,
96 MachineBasicBlock *BB) const override;
97 MachineBasicBlock *EmitShiftInstr(MachineInstr &MI,
98 MachineBasicBlock *BB) const;
99
100 private:
101 SDValue LowerCCCCallTo(SDValue Chain, SDValue Callee,
102 CallingConv::ID CallConv, bool isVarArg,
103 bool isTailCall,
104 const SmallVectorImpl<ISD::OutputArg> &Outs,
105 const SmallVectorImpl<SDValue> &OutVals,
106 const SmallVectorImpl<ISD::InputArg> &Ins,
107 const SDLoc &dl, SelectionDAG &DAG,
108 SmallVectorImpl<SDValue> &InVals) const;
109
110 SDValue LowerCCCArguments(SDValue Chain, CallingConv::ID CallConv,
111 bool isVarArg,
112 const SmallVectorImpl<ISD::InputArg> &Ins,
113 const SDLoc &dl, SelectionDAG &DAG,
114 SmallVectorImpl<SDValue> &InVals) const;
115
116 SDValue LowerCallResult(SDValue Chain, SDValue InGlue,
117 CallingConv::ID CallConv, bool isVarArg,
118 const SmallVectorImpl<ISD::InputArg> &Ins,
119 const SDLoc &dl, SelectionDAG &DAG,
120 SmallVectorImpl<SDValue> &InVals) const;
121
122 SDValue
123 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
124 const SmallVectorImpl<ISD::InputArg> &Ins,
125 const SDLoc &dl, SelectionDAG &DAG,
126 SmallVectorImpl<SDValue> &InVals) const override;
127 SDValue
128 LowerCall(TargetLowering::CallLoweringInfo &CLI,
129 SmallVectorImpl<SDValue> &InVals) const override;
130
131 bool CanLowerReturn(CallingConv::ID CallConv,
132 MachineFunction &MF,
133 bool IsVarArg,
134 const SmallVectorImpl<ISD::OutputArg> &Outs,
135 LLVMContext &Context, const Type *RetTy) const override;
136
137 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
138 const SmallVectorImpl<ISD::OutputArg> &Outs,
139 const SmallVectorImpl<SDValue> &OutVals,
140 const SDLoc &dl, SelectionDAG &DAG) const override;
141
142 bool getPostIndexedAddressParts(SDNode *N, SDNode *Op, SDValue &Base,
143 SDValue &Offset, ISD::MemIndexedMode &AM,
144 SelectionDAG &DAG) const override;
145 };
146} // namespace llvm
147
148#endif
149