blob: 8f53e396eaafeb54810e4739972637791922dc01 [file] [log] [blame]
Evan Cheng10043e22007-01-19 07:51:42 +00001//===-- ARMISelLowering.h - ARM DAG Lowering Interface ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Cheng10043e22007-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 Espindolafa0df552007-11-05 23:12:20 +000018#include "ARMSubtarget.h"
Evan Cheng10043e22007-01-19 07:51:42 +000019#include "llvm/Target/TargetLowering.h"
20#include "llvm/CodeGen/SelectionDAG.h"
Bob Wilsona4c22902009-04-17 19:07:39 +000021#include "llvm/CodeGen/CallingConvLower.h"
Evan Cheng10043e22007-01-19 07:51:42 +000022#include <vector>
23
24namespace llvm {
25 class ARMConstantPoolValue;
Evan Cheng10043e22007-01-19 07:51:42 +000026
27 namespace ARMISD {
28 // ARM Specific DAG Nodes
29 enum NodeType {
Jim Grosbach91fa7812009-05-13 22:32:43 +000030 // Start the numbering where the builtin ops and target ops leave off.
Dan Gohmaned1cf1a2008-09-23 18:42:32 +000031 FIRST_NUMBER = ISD::BUILTIN_OP_END,
Evan Cheng10043e22007-01-19 07:51:42 +000032
33 Wrapper, // Wrapper - A wrapper node for TargetConstantPool,
34 // TargetExternalSymbol, and TargetGlobalAddress.
Evan Cheng10043e22007-01-19 07:51:42 +000035 WrapperJT, // WrapperJT - A wrapper node for TargetJumpTable
Jim Grosbach91fa7812009-05-13 22:32:43 +000036
Evan Cheng10043e22007-01-19 07:51:42 +000037 CALL, // Function call.
Evan Chengc3c949b42007-06-19 21:05:09 +000038 CALL_PRED, // Function call that's predicable.
Evan Cheng10043e22007-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 Venancio6be85332007-04-02 01:30:03 +000048 CMPNZ, // ARM compare that uses only N or Z flags.
Evan Cheng10043e22007-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.
Jim Grosbach91fa7812009-05-13 22:32:43 +000054
Evan Cheng10043e22007-01-19 07:51:42 +000055 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 Cheng10043e22007-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.
Jim Grosbach91fa7812009-05-13 22:32:43 +000063
Evan Cheng10043e22007-01-19 07:51:42 +000064 FMRRD, // double to two gprs.
Bob Wilsondd0e2362009-05-20 16:30:25 +000065 FMDRR, // Two gprs to double.
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000066
Jim Grosbach06928192009-05-14 00:46:35 +000067 EH_SJLJ_SETJMP, // SjLj exception handling setjmp
68 EH_SJLJ_LONGJMP, // SjLj exception handling longjmp
Jim Grosbachaeca45d2009-05-12 23:59:14 +000069
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000070 THREAD_POINTER
Evan Cheng10043e22007-01-19 07:51:42 +000071 };
72 }
73
Bob Wilsondd0e2362009-05-20 16:30:25 +000074 //===--------------------------------------------------------------------===//
Dale Johannesen8447d342007-03-20 00:30:56 +000075 // ARMTargetLowering - ARM Implementation of the TargetLowering interface
Jim Grosbach91fa7812009-05-13 22:32:43 +000076
Evan Cheng10043e22007-01-19 07:51:42 +000077 class ARMTargetLowering : public TargetLowering {
78 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
79 public:
Dan Gohman5f6a9da52007-08-02 21:21:54 +000080 explicit ARMTargetLowering(TargetMachine &TM);
Evan Cheng10043e22007-01-19 07:51:42 +000081
Dan Gohman2ce6f2a2008-07-27 21:46:04 +000082 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
Duncan Sands6ed40142008-12-01 11:39:25 +000083
84 /// ReplaceNodeResults - Replace the results of node with an illegal result
85 /// type with new values built out of custom code.
86 ///
87 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
88 SelectionDAG &DAG);
89
Dan Gohman2ce6f2a2008-07-27 21:46:04 +000090 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Jim Grosbach91fa7812009-05-13 22:32:43 +000091
Evan Cheng10043e22007-01-19 07:51:42 +000092 virtual const char *getTargetNodeName(unsigned Opcode) const;
93
Evan Cheng29cfb672008-01-30 18:18:23 +000094 virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
Dan Gohman747e55b2009-02-07 16:15:20 +000095 MachineBasicBlock *MBB) const;
Evan Cheng10043e22007-01-19 07:51:42 +000096
Chris Lattner1eb94d92007-03-30 23:15:24 +000097 /// isLegalAddressingMode - Return true if the addressing mode represented
98 /// by AM is legal for this target, for a load/store of the specified type.
99 virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty)const;
Jim Grosbach91fa7812009-05-13 22:32:43 +0000100
Evan Cheng10043e22007-01-19 07:51:42 +0000101 /// getPreIndexedAddressParts - returns true by value, base pointer and
102 /// offset pointer and addressing mode by reference if the node's address
103 /// can be legally represented as pre-indexed load / store address.
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000104 virtual bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
105 SDValue &Offset,
Evan Cheng10043e22007-01-19 07:51:42 +0000106 ISD::MemIndexedMode &AM,
Dan Gohman02b93132009-01-15 16:29:45 +0000107 SelectionDAG &DAG) const;
Evan Cheng10043e22007-01-19 07:51:42 +0000108
109 /// getPostIndexedAddressParts - returns true by value, base pointer and
110 /// offset pointer and addressing mode by reference if this node can be
111 /// combined with a load / store to form a post-indexed load / store.
112 virtual bool getPostIndexedAddressParts(SDNode *N, SDNode *Op,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000113 SDValue &Base, SDValue &Offset,
Evan Cheng10043e22007-01-19 07:51:42 +0000114 ISD::MemIndexedMode &AM,
Dan Gohman02b93132009-01-15 16:29:45 +0000115 SelectionDAG &DAG) const;
Evan Cheng10043e22007-01-19 07:51:42 +0000116
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000117 virtual void computeMaskedBitsForTargetNode(const SDValue Op,
Dan Gohmane1d9ee62008-02-13 22:28:48 +0000118 const APInt &Mask,
Jim Grosbach91fa7812009-05-13 22:32:43 +0000119 APInt &KnownZero,
Dan Gohmanf990faf2008-02-13 00:35:47 +0000120 APInt &KnownOne,
Dan Gohman309d3d52007-06-22 14:59:07 +0000121 const SelectionDAG &DAG,
Evan Cheng10043e22007-01-19 07:51:42 +0000122 unsigned Depth) const;
Chris Lattnerd6855142007-03-25 02:14:49 +0000123 ConstraintType getConstraintType(const std::string &Constraint) const;
Jim Grosbach91fa7812009-05-13 22:32:43 +0000124 std::pair<unsigned, const TargetRegisterClass*>
Evan Cheng10043e22007-01-19 07:51:42 +0000125 getRegForInlineAsmConstraint(const std::string &Constraint,
Duncan Sands13237ac2008-06-06 12:08:01 +0000126 MVT VT) const;
Evan Cheng10043e22007-01-19 07:51:42 +0000127 std::vector<unsigned>
128 getRegClassForInlineAsmConstraint(const std::string &Constraint,
Duncan Sands13237ac2008-06-06 12:08:01 +0000129 MVT VT) const;
Rafael Espindolafa0df552007-11-05 23:12:20 +0000130
Bob Wilsoncf1ec2c2009-04-01 17:58:54 +0000131 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
132 /// vector. If it is invalid, don't add anything to Ops. If hasMemory is
133 /// true it means one of the asm constraint of the inline asm instruction
134 /// being processed is 'm'.
135 virtual void LowerAsmOperandForConstraint(SDValue Op,
136 char ConstraintLetter,
137 bool hasMemory,
138 std::vector<SDValue> &Ops,
139 SelectionDAG &DAG) const;
Jim Grosbach91fa7812009-05-13 22:32:43 +0000140
Dan Gohman544ab2c2008-04-12 04:36:06 +0000141 virtual const ARMSubtarget* getSubtarget() {
142 return Subtarget;
Rafael Espindolafa0df552007-11-05 23:12:20 +0000143 }
144
Evan Cheng10043e22007-01-19 07:51:42 +0000145 private:
146 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
147 /// make the right decision when generating code for different targets.
148 const ARMSubtarget *Subtarget;
149
150 /// ARMPCLabelIndex - Keep track the number of ARM PC labels created.
151 ///
152 unsigned ARMPCLabelIndex;
153
Anton Korobeynikova8fd40b2009-06-16 18:50:49 +0000154 CCAssignFn *CCAssignFnForNode(unsigned CC, bool Return) const;
Bob Wilsona4c22902009-04-17 19:07:39 +0000155 SDValue LowerMemOpCallTo(CallSDNode *TheCall, SelectionDAG &DAG,
156 const SDValue &StackPtr, const CCValAssign &VA,
Bob Wilsonea09d4a2009-04-17 20:35:10 +0000157 SDValue Chain, SDValue Arg, ISD::ArgFlagsTy Flags);
158 SDNode *LowerCallResult(SDValue Chain, SDValue InFlag, CallSDNode *TheCall,
Bob Wilsona4c22902009-04-17 19:07:39 +0000159 unsigned CallingConv, SelectionDAG &DAG);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000160 SDValue LowerCALL(SDValue Op, SelectionDAG &DAG);
Jim Grosbachaeca45d2009-05-12 23:59:14 +0000161 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG);
Bob Wilsona4c22902009-04-17 19:07:39 +0000162 SDValue LowerRET(SDValue Op, SelectionDAG &DAG);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000163 SDValue LowerGlobalAddressDarwin(SDValue Op, SelectionDAG &DAG);
164 SDValue LowerGlobalAddressELF(SDValue Op, SelectionDAG &DAG);
165 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG);
166 SDValue LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +0000167 SelectionDAG &DAG);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000168 SDValue LowerToTLSExecModels(GlobalAddressSDNode *GA,
Evan Cheng1f2dd352007-10-22 22:11:27 +0000169 SelectionDAG &DAG);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000170 SDValue LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG);
171 SDValue LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG);
172 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG);
Jim Grosbachaeca45d2009-05-12 23:59:14 +0000173 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG);
Rafael Espindola18a831d2007-10-19 14:35:17 +0000174
Dale Johannesenabf66b82009-02-03 22:26:09 +0000175 SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl,
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000176 SDValue Chain,
177 SDValue Dst, SDValue Src,
178 SDValue Size, unsigned Align,
Dan Gohman544ab2c2008-04-12 04:36:06 +0000179 bool AlwaysInline,
Dan Gohmanda440542008-04-28 17:15:20 +0000180 const Value *DstSV, uint64_t DstSVOff,
181 const Value *SrcSV, uint64_t SrcSVOff);
Evan Cheng10043e22007-01-19 07:51:42 +0000182 };
183}
184
185#endif // ARMISELLOWERING_H