blob: 4c49350c327505c31acee01de1ed1b7f917e2e94 [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===-- ARMISelLowering.h - ARM DAG Lowering Interface ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the interfaces that ARM uses to lower LLVM code into a
11// selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef ARMISELLOWERING_H
16#define ARMISELLOWERING_H
17
Rafael Espindolaf1ba1ca2007-11-05 23:12:20 +000018#include "ARMSubtarget.h"
Evan Chenga8e29892007-01-19 07:51:42 +000019#include "llvm/Target/TargetLowering.h"
20#include "llvm/CodeGen/SelectionDAG.h"
Bob Wilson1f595bb2009-04-17 19:07:39 +000021#include "llvm/CodeGen/CallingConvLower.h"
Evan Chenga8e29892007-01-19 07:51:42 +000022#include <vector>
23
24namespace llvm {
25 class ARMConstantPoolValue;
Evan Chenga8e29892007-01-19 07:51:42 +000026
27 namespace ARMISD {
28 // ARM Specific DAG Nodes
29 enum NodeType {
30 // Start the numbering where the builting ops and target ops leave off.
Dan Gohman0ba2bcf2008-09-23 18:42:32 +000031 FIRST_NUMBER = ISD::BUILTIN_OP_END,
Evan Chenga8e29892007-01-19 07:51:42 +000032
33 Wrapper, // Wrapper - A wrapper node for TargetConstantPool,
34 // TargetExternalSymbol, and TargetGlobalAddress.
Evan Chenga8e29892007-01-19 07:51:42 +000035 WrapperJT, // WrapperJT - A wrapper node for TargetJumpTable
36
37 CALL, // Function call.
Evan Cheng277f0742007-06-19 21:05:09 +000038 CALL_PRED, // Function call that's predicable.
Evan Chenga8e29892007-01-19 07:51:42 +000039 CALL_NOLINK, // Function call with branch not branch-and-link.
40 tCALL, // Thumb function call.
41 BRCOND, // Conditional branch.
42 BR_JT, // Jumptable branch.
43 RET_FLAG, // Return with a flag operand.
44
45 PIC_ADD, // Add with a PC operand and a PIC label.
46
47 CMP, // ARM compare instructions.
Lauro Ramos Venancio99966632007-04-02 01:30:03 +000048 CMPNZ, // ARM compare that uses only N or Z flags.
Evan Chenga8e29892007-01-19 07:51:42 +000049 CMPFP, // ARM VFP compare instruction, sets FPSCR.
50 CMPFPw0, // ARM VFP compare against zero instruction, sets FPSCR.
51 FMSTAT, // ARM fmstat instruction.
52 CMOV, // ARM conditional move instructions.
53 CNEG, // ARM conditional negate instructions.
54
55 FTOSI, // FP to sint within a FP register.
56 FTOUI, // FP to uint within a FP register.
57 SITOF, // sint to FP within a FP register.
58 UITOF, // uint to FP within a FP register.
59
Evan Chenga8e29892007-01-19 07:51:42 +000060 SRL_FLAG, // V,Flag = srl_flag X -> srl X, 1 + save carry out.
61 SRA_FLAG, // V,Flag = sra_flag X -> sra X, 1 + save carry out.
62 RRX, // V = RRX X, Flag -> srl X, 1 + shift in carry flag.
63
64 FMRRD, // double to two gprs.
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000065 FMDRR, // Two gprs to double.
66
67 THREAD_POINTER
Evan Chenga8e29892007-01-19 07:51:42 +000068 };
69 }
70
71 //===----------------------------------------------------------------------===//
Dale Johannesen80dae192007-03-20 00:30:56 +000072 // ARMTargetLowering - ARM Implementation of the TargetLowering interface
Evan Chenga8e29892007-01-19 07:51:42 +000073
74 class ARMTargetLowering : public TargetLowering {
75 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
76 public:
Dan Gohman61e729e2007-08-02 21:21:54 +000077 explicit ARMTargetLowering(TargetMachine &TM);
Evan Chenga8e29892007-01-19 07:51:42 +000078
Dan Gohman475871a2008-07-27 21:46:04 +000079 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
Duncan Sands1607f052008-12-01 11:39:25 +000080
81 /// ReplaceNodeResults - Replace the results of node with an illegal result
82 /// type with new values built out of custom code.
83 ///
84 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
85 SelectionDAG &DAG);
86
Dan Gohman475871a2008-07-27 21:46:04 +000087 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Chris Lattnerf1b1c5e2007-11-27 22:36:16 +000088
Evan Chenga8e29892007-01-19 07:51:42 +000089 virtual const char *getTargetNodeName(unsigned Opcode) const;
90
Evan Chengff9b3732008-01-30 18:18:23 +000091 virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
Dan Gohman1fdbc1d2009-02-07 16:15:20 +000092 MachineBasicBlock *MBB) const;
Evan Chenga8e29892007-01-19 07:51:42 +000093
Chris Lattnerc9addb72007-03-30 23:15:24 +000094 /// isLegalAddressingMode - Return true if the addressing mode represented
95 /// by AM is legal for this target, for a load/store of the specified type.
96 virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty)const;
97
Evan Chenga8e29892007-01-19 07:51:42 +000098 /// getPreIndexedAddressParts - returns true by value, base pointer and
99 /// offset pointer and addressing mode by reference if the node's address
100 /// can be legally represented as pre-indexed load / store address.
Dan Gohman475871a2008-07-27 21:46:04 +0000101 virtual bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
102 SDValue &Offset,
Evan Chenga8e29892007-01-19 07:51:42 +0000103 ISD::MemIndexedMode &AM,
Dan Gohman73e09142009-01-15 16:29:45 +0000104 SelectionDAG &DAG) const;
Evan Chenga8e29892007-01-19 07:51:42 +0000105
106 /// getPostIndexedAddressParts - returns true by value, base pointer and
107 /// offset pointer and addressing mode by reference if this node can be
108 /// combined with a load / store to form a post-indexed load / store.
109 virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
Dan Gohman475871a2008-07-27 21:46:04 +0000110 SDValue &Base, SDValue &Offset,
Evan Chenga8e29892007-01-19 07:51:42 +0000111 ISD::MemIndexedMode &AM,
Dan Gohman73e09142009-01-15 16:29:45 +0000112 SelectionDAG &DAG) const;
Evan Chenga8e29892007-01-19 07:51:42 +0000113
Dan Gohman475871a2008-07-27 21:46:04 +0000114 virtual void computeMaskedBitsForTargetNode(const SDValue Op,
Dan Gohman977a76f2008-02-13 22:28:48 +0000115 const APInt &Mask,
Dan Gohmanfd29e0e2008-02-13 00:35:47 +0000116 APInt &KnownZero,
117 APInt &KnownOne,
Dan Gohmanea859be2007-06-22 14:59:07 +0000118 const SelectionDAG &DAG,
Evan Chenga8e29892007-01-19 07:51:42 +0000119 unsigned Depth) const;
Chris Lattner4234f572007-03-25 02:14:49 +0000120 ConstraintType getConstraintType(const std::string &Constraint) const;
Evan Chenga8e29892007-01-19 07:51:42 +0000121 std::pair<unsigned, const TargetRegisterClass*>
122 getRegForInlineAsmConstraint(const std::string &Constraint,
Duncan Sands83ec4b62008-06-06 12:08:01 +0000123 MVT VT) const;
Evan Chenga8e29892007-01-19 07:51:42 +0000124 std::vector<unsigned>
125 getRegClassForInlineAsmConstraint(const std::string &Constraint,
Duncan Sands83ec4b62008-06-06 12:08:01 +0000126 MVT VT) const;
Rafael Espindolaf1ba1ca2007-11-05 23:12:20 +0000127
Bob Wilsonbf6396b2009-04-01 17:58:54 +0000128 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
129 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is
130 /// true it means one of the asm constraint of the inline asm instruction
131 /// being processed is 'm'.
132 virtual void LowerAsmOperandForConstraint(SDValue Op,
133 char ConstraintLetter,
134 bool hasMemory,
135 std::vector<SDValue> &Ops,
136 SelectionDAG &DAG) const;
137
Dan Gohman707e0182008-04-12 04:36:06 +0000138 virtual const ARMSubtarget* getSubtarget() {
139 return Subtarget;
Rafael Espindolaf1ba1ca2007-11-05 23:12:20 +0000140 }
141
Evan Chenga8e29892007-01-19 07:51:42 +0000142 private:
143 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
144 /// make the right decision when generating code for different targets.
145 const ARMSubtarget *Subtarget;
146
147 /// ARMPCLabelIndex - Keep track the number of ARM PC labels created.
148 ///
149 unsigned ARMPCLabelIndex;
150
Bob Wilson1f595bb2009-04-17 19:07:39 +0000151 SDValue LowerMemOpCallTo(CallSDNode *TheCall, SelectionDAG &DAG,
152 const SDValue &StackPtr, const CCValAssign &VA,
Bob Wilsondee46d72009-04-17 20:35:10 +0000153 SDValue Chain, SDValue Arg, ISD::ArgFlagsTy Flags);
154 SDNode *LowerCallResult(SDValue Chain, SDValue InFlag, CallSDNode *TheCall,
Bob Wilson1f595bb2009-04-17 19:07:39 +0000155 unsigned CallingConv, SelectionDAG &DAG);
Dan Gohman475871a2008-07-27 21:46:04 +0000156 SDValue LowerCALL(SDValue Op, SelectionDAG &DAG);
Bob Wilson1f595bb2009-04-17 19:07:39 +0000157 SDValue LowerRET(SDValue Op, SelectionDAG &DAG);
Dan Gohman475871a2008-07-27 21:46:04 +0000158 SDValue LowerGlobalAddressDarwin(SDValue Op, SelectionDAG &DAG);
159 SDValue LowerGlobalAddressELF(SDValue Op, SelectionDAG &DAG);
160 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG);
161 SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000162 SelectionDAG &DAG);
Dan Gohman475871a2008-07-27 21:46:04 +0000163 SDValue LowerToTLSExecModels(GlobalAddressSDNode *GA,
Evan Cheng4102eb52007-10-22 22:11:27 +0000164 SelectionDAG &DAG);
Dan Gohman475871a2008-07-27 21:46:04 +0000165 SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG);
166 SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG);
167 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG);
Rafael Espindola7b73a5d2007-10-19 14:35:17 +0000168
Dale Johannesen0f502f62009-02-03 22:26:09 +0000169 SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl,
Dan Gohman475871a2008-07-27 21:46:04 +0000170 SDValue Chain,
171 SDValue Dst, SDValue Src,
172 SDValue Size, unsigned Align,
Dan Gohman707e0182008-04-12 04:36:06 +0000173 bool AlwaysInline,
Dan Gohman1f13c682008-04-28 17:15:20 +0000174 const Value *DstSV, uint64_t DstSVOff,
175 const Value *SrcSV, uint64_t SrcSVOff);
Evan Chenga8e29892007-01-19 07:51:42 +0000176 };
177}
178
179#endif // ARMISELLOWERING_H