Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 1 | //===-- SystemZISelLowering.h - SystemZ DAG lowering interface --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the interfaces that SystemZ uses to lower LLVM code into a |
| 11 | // selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_TARGET_SystemZ_ISELLOWERING_H |
| 16 | #define LLVM_TARGET_SystemZ_ISELLOWERING_H |
| 17 | |
| 18 | #include "SystemZ.h" |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/SelectionDAG.h" |
| 21 | #include "llvm/Target/TargetLowering.h" |
| 22 | |
| 23 | namespace llvm { |
| 24 | namespace SystemZISD { |
| 25 | enum { |
| 26 | FIRST_NUMBER = ISD::BUILTIN_OP_END, |
| 27 | |
| 28 | // Return with a flag operand. Operand 0 is the chain operand. |
| 29 | RET_FLAG, |
| 30 | |
| 31 | // Calls a function. Operand 0 is the chain operand and operand 1 |
| 32 | // is the target address. The arguments start at operand 2. |
| 33 | // There is an optional glue operand at the end. |
| 34 | CALL, |
| 35 | |
| 36 | // Wraps a TargetGlobalAddress that should be loaded using PC-relative |
| 37 | // accesses (LARL). Operand 0 is the address. |
| 38 | PCREL_WRAPPER, |
| 39 | |
| 40 | // Signed integer and floating-point comparisons. The operands are the |
| 41 | // two values to compare. |
| 42 | CMP, |
| 43 | |
| 44 | // Likewise unsigned integer comparison. |
| 45 | UCMP, |
| 46 | |
| 47 | // Branches if a condition is true. Operand 0 is the chain operand; |
| 48 | // operand 1 is the 4-bit condition-code mask, with bit N in |
| 49 | // big-endian order meaning "branch if CC=N"; operand 2 is the |
| 50 | // target block and operand 3 is the flag operand. |
| 51 | BR_CCMASK, |
| 52 | |
| 53 | // Selects between operand 0 and operand 1. Operand 2 is the |
| 54 | // mask of condition-code values for which operand 0 should be |
| 55 | // chosen over operand 1; it has the same form as BR_CCMASK. |
| 56 | // Operand 3 is the flag operand. |
| 57 | SELECT_CCMASK, |
| 58 | |
| 59 | // Evaluates to the gap between the stack pointer and the |
| 60 | // base of the dynamically-allocatable area. |
| 61 | ADJDYNALLOC, |
| 62 | |
| 63 | // Extracts the value of a 32-bit access register. Operand 0 is |
| 64 | // the number of the register. |
| 65 | EXTRACT_ACCESS, |
| 66 | |
| 67 | // Wrappers around the ISD opcodes of the same name. The output and |
| 68 | // first input operands are GR128s. The trailing numbers are the |
| 69 | // widths of the second operand in bits. |
| 70 | UMUL_LOHI64, |
Richard Sandiford | e6e7885 | 2013-07-02 15:40:22 +0000 | [diff] [blame] | 71 | SDIVREM32, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 72 | SDIVREM64, |
| 73 | UDIVREM32, |
| 74 | UDIVREM64, |
| 75 | |
Richard Sandiford | d131ff8 | 2013-07-08 09:35:23 +0000 | [diff] [blame] | 76 | // Use MVC to copy bytes from one memory location to another. |
| 77 | // The first operand is the target address, the second operand is the |
| 78 | // source address, and the third operand is the constant length. |
| 79 | // This isn't a memory opcode because we'd need to attach two |
| 80 | // MachineMemOperands rather than one. |
| 81 | MVC, |
| 82 | |
Richard Sandiford | 761703a | 2013-08-12 10:17:33 +0000 | [diff] [blame] | 83 | // Use CLC to compare two blocks of memory, with the same comments |
| 84 | // as for MVC. |
| 85 | CLC, |
| 86 | |
Richard Sandiford | bb83a50 | 2013-08-16 11:29:37 +0000 | [diff] [blame] | 87 | // Use an MVST-based sequence to implement stpcpy(). |
| 88 | STPCPY, |
| 89 | |
Richard Sandiford | ca23271 | 2013-08-16 11:21:54 +0000 | [diff] [blame] | 90 | // Use a CLST-based sequence to implement strcmp(). The two input operands |
| 91 | // are the addresses of the strings to compare. |
| 92 | STRCMP, |
| 93 | |
Richard Sandiford | 0dec06a | 2013-08-16 11:41:43 +0000 | [diff] [blame^] | 94 | // Use an SRST-based sequence to search a block of memory. The first |
| 95 | // operand is the end address, the second is the start, and the third |
| 96 | // is the character to search for. CC is set to 1 on success and 2 |
| 97 | // on failure. |
| 98 | SEARCH_STRING, |
| 99 | |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 100 | // Store the CC value in bits 29 and 28 of an integer. |
| 101 | IPM, |
| 102 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 103 | // Wrappers around the inner loop of an 8- or 16-bit ATOMIC_SWAP or |
| 104 | // ATOMIC_LOAD_<op>. |
| 105 | // |
| 106 | // Operand 0: the address of the containing 32-bit-aligned field |
| 107 | // Operand 1: the second operand of <op>, in the high bits of an i32 |
| 108 | // for everything except ATOMIC_SWAPW |
| 109 | // Operand 2: how many bits to rotate the i32 left to bring the first |
| 110 | // operand into the high bits |
| 111 | // Operand 3: the negative of operand 2, for rotating the other way |
| 112 | // Operand 4: the width of the field in bits (8 or 16) |
| 113 | ATOMIC_SWAPW = ISD::FIRST_TARGET_MEMORY_OPCODE, |
| 114 | ATOMIC_LOADW_ADD, |
| 115 | ATOMIC_LOADW_SUB, |
| 116 | ATOMIC_LOADW_AND, |
| 117 | ATOMIC_LOADW_OR, |
| 118 | ATOMIC_LOADW_XOR, |
| 119 | ATOMIC_LOADW_NAND, |
| 120 | ATOMIC_LOADW_MIN, |
| 121 | ATOMIC_LOADW_MAX, |
| 122 | ATOMIC_LOADW_UMIN, |
| 123 | ATOMIC_LOADW_UMAX, |
| 124 | |
| 125 | // A wrapper around the inner loop of an ATOMIC_CMP_SWAP. |
| 126 | // |
| 127 | // Operand 0: the address of the containing 32-bit-aligned field |
| 128 | // Operand 1: the compare value, in the low bits of an i32 |
| 129 | // Operand 2: the swap value, in the low bits of an i32 |
| 130 | // Operand 3: how many bits to rotate the i32 left to bring the first |
| 131 | // operand into the high bits |
| 132 | // Operand 4: the negative of operand 2, for rotating the other way |
| 133 | // Operand 5: the width of the field in bits (8 or 16) |
| 134 | ATOMIC_CMP_SWAPW |
| 135 | }; |
| 136 | } |
| 137 | |
| 138 | class SystemZSubtarget; |
| 139 | class SystemZTargetMachine; |
| 140 | |
| 141 | class SystemZTargetLowering : public TargetLowering { |
| 142 | public: |
| 143 | explicit SystemZTargetLowering(SystemZTargetMachine &TM); |
| 144 | |
| 145 | // Override TargetLowering. |
| 146 | virtual MVT getScalarShiftAmountTy(EVT LHSTy) const LLVM_OVERRIDE { |
| 147 | return MVT::i32; |
| 148 | } |
Richard Sandiford | 791bea4 | 2013-07-31 12:58:26 +0000 | [diff] [blame] | 149 | virtual EVT getSetCCResultType(LLVMContext &, EVT) const LLVM_OVERRIDE { |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 150 | return MVT::i32; |
| 151 | } |
Stephen Lin | 73de7bf | 2013-07-09 18:16:56 +0000 | [diff] [blame] | 152 | virtual bool isFMAFasterThanFMulAndFAdd(EVT VT) const LLVM_OVERRIDE; |
Richard Sandiford | 791bea4 | 2013-07-31 12:58:26 +0000 | [diff] [blame] | 153 | virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const LLVM_OVERRIDE; |
| 154 | virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const |
| 155 | LLVM_OVERRIDE; |
| 156 | virtual bool allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const |
| 157 | LLVM_OVERRIDE; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 158 | virtual const char *getTargetNodeName(unsigned Opcode) const LLVM_OVERRIDE; |
| 159 | virtual std::pair<unsigned, const TargetRegisterClass *> |
| 160 | getRegForInlineAsmConstraint(const std::string &Constraint, |
Chad Rosier | 295bd43 | 2013-06-22 18:37:38 +0000 | [diff] [blame] | 161 | MVT VT) const LLVM_OVERRIDE; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 162 | virtual TargetLowering::ConstraintType |
| 163 | getConstraintType(const std::string &Constraint) const LLVM_OVERRIDE; |
| 164 | virtual TargetLowering::ConstraintWeight |
| 165 | getSingleConstraintMatchWeight(AsmOperandInfo &info, |
| 166 | const char *constraint) const LLVM_OVERRIDE; |
| 167 | virtual void |
| 168 | LowerAsmOperandForConstraint(SDValue Op, |
| 169 | std::string &Constraint, |
| 170 | std::vector<SDValue> &Ops, |
| 171 | SelectionDAG &DAG) const LLVM_OVERRIDE; |
| 172 | virtual MachineBasicBlock * |
| 173 | EmitInstrWithCustomInserter(MachineInstr *MI, |
| 174 | MachineBasicBlock *BB) const LLVM_OVERRIDE; |
| 175 | virtual SDValue LowerOperation(SDValue Op, |
| 176 | SelectionDAG &DAG) const LLVM_OVERRIDE; |
| 177 | virtual SDValue |
| 178 | LowerFormalArguments(SDValue Chain, |
| 179 | CallingConv::ID CallConv, bool isVarArg, |
| 180 | const SmallVectorImpl<ISD::InputArg> &Ins, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 181 | SDLoc DL, SelectionDAG &DAG, |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 182 | SmallVectorImpl<SDValue> &InVals) const LLVM_OVERRIDE; |
| 183 | virtual SDValue |
| 184 | LowerCall(CallLoweringInfo &CLI, |
| 185 | SmallVectorImpl<SDValue> &InVals) const LLVM_OVERRIDE; |
| 186 | |
| 187 | virtual SDValue |
| 188 | LowerReturn(SDValue Chain, |
| 189 | CallingConv::ID CallConv, bool IsVarArg, |
| 190 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 191 | const SmallVectorImpl<SDValue> &OutVals, |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 192 | SDLoc DL, SelectionDAG &DAG) const LLVM_OVERRIDE; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 193 | |
| 194 | private: |
| 195 | const SystemZSubtarget &Subtarget; |
| 196 | const SystemZTargetMachine &TM; |
| 197 | |
| 198 | // Implement LowerOperation for individual opcodes. |
| 199 | SDValue lowerBR_CC(SDValue Op, SelectionDAG &DAG) const; |
| 200 | SDValue lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const; |
| 201 | SDValue lowerGlobalAddress(GlobalAddressSDNode *Node, |
| 202 | SelectionDAG &DAG) const; |
| 203 | SDValue lowerGlobalTLSAddress(GlobalAddressSDNode *Node, |
| 204 | SelectionDAG &DAG) const; |
| 205 | SDValue lowerBlockAddress(BlockAddressSDNode *Node, |
| 206 | SelectionDAG &DAG) const; |
| 207 | SDValue lowerJumpTable(JumpTableSDNode *JT, SelectionDAG &DAG) const; |
| 208 | SDValue lowerConstantPool(ConstantPoolSDNode *CP, SelectionDAG &DAG) const; |
| 209 | SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const; |
| 210 | SDValue lowerVACOPY(SDValue Op, SelectionDAG &DAG) const; |
| 211 | SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const; |
| 212 | SDValue lowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const; |
| 213 | SDValue lowerSDIVREM(SDValue Op, SelectionDAG &DAG) const; |
| 214 | SDValue lowerUDIVREM(SDValue Op, SelectionDAG &DAG) const; |
| 215 | SDValue lowerBITCAST(SDValue Op, SelectionDAG &DAG) const; |
| 216 | SDValue lowerOR(SDValue Op, SelectionDAG &DAG) const; |
| 217 | SDValue lowerATOMIC_LOAD(SDValue Op, SelectionDAG &DAG, |
| 218 | unsigned Opcode) const; |
| 219 | SDValue lowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const; |
| 220 | SDValue lowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const; |
| 221 | SDValue lowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const; |
| 222 | |
Richard Sandiford | 0fb90ab | 2013-05-28 10:41:11 +0000 | [diff] [blame] | 223 | // If the last instruction before MBBI in MBB was some form of COMPARE, |
| 224 | // try to replace it with a COMPARE AND BRANCH just before MBBI. |
| 225 | // CCMask and Target are the BRC-like operands for the branch. |
| 226 | // Return true if the change was made. |
| 227 | bool convertPrevCompareToBranch(MachineBasicBlock *MBB, |
| 228 | MachineBasicBlock::iterator MBBI, |
| 229 | unsigned CCMask, |
| 230 | MachineBasicBlock *Target) const; |
| 231 | |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 232 | // Implement EmitInstrWithCustomInserter for individual operation types. |
| 233 | MachineBasicBlock *emitSelect(MachineInstr *MI, |
| 234 | MachineBasicBlock *BB) const; |
Richard Sandiford | b86a834 | 2013-06-27 09:27:40 +0000 | [diff] [blame] | 235 | MachineBasicBlock *emitCondStore(MachineInstr *MI, |
| 236 | MachineBasicBlock *BB, |
Richard Sandiford | a68e6f5 | 2013-07-25 08:57:02 +0000 | [diff] [blame] | 237 | unsigned StoreOpcode, unsigned STOCOpcode, |
| 238 | bool Invert) const; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 239 | MachineBasicBlock *emitExt128(MachineInstr *MI, |
| 240 | MachineBasicBlock *MBB, |
| 241 | bool ClearEven, unsigned SubReg) const; |
| 242 | MachineBasicBlock *emitAtomicLoadBinary(MachineInstr *MI, |
| 243 | MachineBasicBlock *BB, |
| 244 | unsigned BinOpcode, unsigned BitSize, |
| 245 | bool Invert = false) const; |
| 246 | MachineBasicBlock *emitAtomicLoadMinMax(MachineInstr *MI, |
| 247 | MachineBasicBlock *MBB, |
| 248 | unsigned CompareOpcode, |
| 249 | unsigned KeepOldMask, |
| 250 | unsigned BitSize) const; |
| 251 | MachineBasicBlock *emitAtomicCmpSwapW(MachineInstr *MI, |
| 252 | MachineBasicBlock *BB) const; |
Richard Sandiford | 564681c | 2013-08-12 10:28:10 +0000 | [diff] [blame] | 253 | MachineBasicBlock *emitMemMemWrapper(MachineInstr *MI, |
| 254 | MachineBasicBlock *BB, |
| 255 | unsigned Opcode) const; |
Richard Sandiford | ca23271 | 2013-08-16 11:21:54 +0000 | [diff] [blame] | 256 | MachineBasicBlock *emitStringWrapper(MachineInstr *MI, |
| 257 | MachineBasicBlock *BB, |
| 258 | unsigned Opcode) const; |
Ulrich Weigand | 5f613df | 2013-05-06 16:15:19 +0000 | [diff] [blame] | 259 | }; |
| 260 | } // end namespace llvm |
| 261 | |
| 262 | #endif // LLVM_TARGET_SystemZ_ISELLOWERING_H |