1b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne//===-- XCoreISelLowering.h - XCore DAG Lowering Interface ------*- C++ -*-===//
2b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne//
3b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne//                     The LLVM Compiler Infrastructure
4b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne//
5b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne// This file is distributed under the University of Illinois Open Source
6b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne// License. See LICENSE.TXT for details.
7b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne//
8b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne//===----------------------------------------------------------------------===//
9b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne//
10b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne// This file defines the interfaces that XCore uses to lower LLVM code into a
11b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne// selection DAG.
12b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne//
13b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne//===----------------------------------------------------------------------===//
14b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
15b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne#ifndef XCOREISELLOWERING_H
16b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne#define XCOREISELLOWERING_H
17b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
1879aa3417eb6f58d668aadfedf075240a41d35a26Craig Topper#include "XCore.h"
19b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne#include "llvm/CodeGen/SelectionDAG.h"
20b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne#include "llvm/Target/TargetLowering.h"
21b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
22b25baef26f03b9909b65dd5f762b38f93000445dRichard Osbornenamespace llvm {
2395771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson
24b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  // Forward delcarations
25b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  class XCoreSubtarget;
26b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  class XCoreTargetMachine;
2795771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson
28b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  namespace XCoreISD {
29b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    enum NodeType {
30b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      // Start the numbering where the builtin ops and target ops leave off.
31020bb08026943944166a3650eb2633c614e6d964Chris Lattner      FIRST_NUMBER = ISD::BUILTIN_OP_END,
32b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
33b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      // Branch and link (call)
34b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      BL,
35b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
36b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      // pc relative address
37b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      PCRelativeWrapper,
38b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
39b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      // dp relative address
40b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      DPRelativeWrapper,
4195771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson
42b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      // cp relative address
43b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      CPRelativeWrapper,
4495771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson
45b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      // Store word to stack
46b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      STWSP,
47b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
48b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      // Corresponds to retsp instruction
49b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      RETSP,
5095771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson
51b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      // Corresponds to LADD instruction
52b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      LADD,
53b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
54b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne      // Corresponds to LSUB instruction
5578700b0c55ccc2d355ba9ee2ac666d669052b0cbRichard Osborne      LSUB,
5678700b0c55ccc2d355ba9ee2ac666d669052b0cbRichard Osborne
57a2cc0613d05f9545947478942811c04f27601649Richard Osborne      // Corresponds to LMUL instruction
58a2cc0613d05f9545947478942811c04f27601649Richard Osborne      LMUL,
59a2cc0613d05f9545947478942811c04f27601649Richard Osborne
60ebc64cf780e6e0200cd462f26e9925dcc7632f2bRichard Osborne      // Corresponds to MACCU instruction
61ebc64cf780e6e0200cd462f26e9925dcc7632f2bRichard Osborne      MACCU,
62ebc64cf780e6e0200cd462f26e9925dcc7632f2bRichard Osborne
63ebc64cf780e6e0200cd462f26e9925dcc7632f2bRichard Osborne      // Corresponds to MACCS instruction
64ebc64cf780e6e0200cd462f26e9925dcc7632f2bRichard Osborne      MACCS,
65ebc64cf780e6e0200cd462f26e9925dcc7632f2bRichard Osborne
660f1bcedf5a871c360f2ca1354464d81cb81bdca7Richard Osborne      // Corresponds to CRC8 instruction
670f1bcedf5a871c360f2ca1354464d81cb81bdca7Richard Osborne      CRC8,
680f1bcedf5a871c360f2ca1354464d81cb81bdca7Richard Osborne
6978700b0c55ccc2d355ba9ee2ac666d669052b0cbRichard Osborne      // Jumptable branch.
7078700b0c55ccc2d355ba9ee2ac666d669052b0cbRichard Osborne      BR_JT,
7178700b0c55ccc2d355ba9ee2ac666d669052b0cbRichard Osborne
7278700b0c55ccc2d355ba9ee2ac666d669052b0cbRichard Osborne      // Jumptable branch using long branches for each entry.
7378700b0c55ccc2d355ba9ee2ac666d669052b0cbRichard Osborne      BR_JT32
74b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    };
75b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  }
76b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
77b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  //===--------------------------------------------------------------------===//
78b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  // TargetLowering Implementation
79b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  //===--------------------------------------------------------------------===//
8095771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson  class XCoreTargetLowering : public TargetLowering
81b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  {
82b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  public:
83b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
84b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    explicit XCoreTargetLowering(XCoreTargetMachine &TM);
85b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
86f766ce55805d45c4ad21c4b452fb26187aeb1b1bRichard Osborne    virtual unsigned getJumpTableEncoding() const;
87a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao    virtual MVT getScalarShiftAmountTy(EVT LHSTy) const { return MVT::i32; }
88f766ce55805d45c4ad21c4b452fb26187aeb1b1bRichard Osborne
89b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    /// LowerOperation - Provide custom lowering hooks for some operations.
90d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
91223fd6efc86ec79bbe26a92e780976ae527f2f61Richard Osborne
921607f05cb7d77d01ce521a30232faa389dbed4e2Duncan Sands    /// ReplaceNodeResults - Replace the results of node with an illegal result
931607f05cb7d77d01ce521a30232faa389dbed4e2Duncan Sands    /// type with new values built out of custom code.
941607f05cb7d77d01ce521a30232faa389dbed4e2Duncan Sands    ///
951607f05cb7d77d01ce521a30232faa389dbed4e2Duncan Sands    virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
96d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman                                    SelectionDAG &DAG) const;
97b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
9895771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson    /// getTargetNodeName - This method returns the name of a target specific
99b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    //  DAG node.
100b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    virtual const char *getTargetNodeName(unsigned Opcode) const;
10195771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson
102af1d8ca44a18f304f207e209b3bdb94b590f86ffDan Gohman    virtual MachineBasicBlock *
103af1d8ca44a18f304f207e209b3bdb94b590f86ffDan Gohman      EmitInstrWithCustomInserter(MachineInstr *MI,
104af1d8ca44a18f304f207e209b3bdb94b590f86ffDan Gohman                                  MachineBasicBlock *MBB) const;
105b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
106b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    virtual bool isLegalAddressingMode(const AddrMode &AM,
107db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner                                       Type *Ty) const;
108b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
109b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  private:
110b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    const XCoreTargetMachine &TM;
111b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    const XCoreSubtarget &Subtarget;
11295771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson
113b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    // Lower Operand helpers
11498ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman    SDValue LowerCCCArguments(SDValue Chain,
11565c3c8f323198b99b88b109654194540cf9b3fa5Sandeep Patel                              CallingConv::ID CallConv,
11698ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                              bool isVarArg,
11798ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                              const SmallVectorImpl<ISD::InputArg> &Ins,
11898ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                              DebugLoc dl, SelectionDAG &DAG,
119d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman                              SmallVectorImpl<SDValue> &InVals) const;
12098ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman    SDValue LowerCCCCallTo(SDValue Chain, SDValue Callee,
12165c3c8f323198b99b88b109654194540cf9b3fa5Sandeep Patel                           CallingConv::ID CallConv, bool isVarArg,
12298ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                           bool isTailCall,
12398ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                           const SmallVectorImpl<ISD::OutputArg> &Outs,
124c9403659a98bf6487ab6fbf40b81628b5695c02eDan Gohman                           const SmallVectorImpl<SDValue> &OutVals,
12598ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                           const SmallVectorImpl<ISD::InputArg> &Ins,
12698ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                           DebugLoc dl, SelectionDAG &DAG,
127d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman                           SmallVectorImpl<SDValue> &InVals) const;
12898ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman    SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
12965c3c8f323198b99b88b109654194540cf9b3fa5Sandeep Patel                            CallingConv::ID CallConv, bool isVarArg,
13098ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                            const SmallVectorImpl<ISD::InputArg> &Ins,
13198ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                            DebugLoc dl, SelectionDAG &DAG,
132d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman                            SmallVectorImpl<SDValue> &InVals) const;
133d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const;
13446510a73e977273ec67747eb34cbdb43f815e451Dan Gohman    SDValue getGlobalAddressWrapper(SDValue GA, const GlobalValue *GV,
135d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman                                    SelectionDAG &DAG) const;
136b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
137b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    // Lower Operand specifics
138d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
139d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
140d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
141d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
142d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
143d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
144d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const;
145d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
146d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) const;
147d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
148d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
149d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
150d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
1514a544a79bd735967f1d33fe675ae4566dbd17813Duncan Sands    SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
1524a544a79bd735967f1d33fe675ae4566dbd17813Duncan Sands    SDValue LowerADJUST_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
1530f1bcedf5a871c360f2ca1354464d81cb81bdca7Richard Osborne    SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
15495771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson
155b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    // Inline asm support
156ca42299619cf47371a42c2bda87d067e003657eaEric Christopher    std::pair<unsigned, const TargetRegisterClass*>
157ca42299619cf47371a42c2bda87d067e003657eaEric Christopher    getRegForInlineAsmConstraint(const std::string &Constraint,
15856cb2298663017eb77aa4f4dda8db7ecd1b58173Bill Wendling                                 EVT VT) const;
15995771afbfd604ad003fa3723cac66c9370fed55dOwen Anderson
160b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne    // Expand specifics
161d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue TryExpandADDWithMul(SDNode *Op, SelectionDAG &DAG) const;
162d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman    SDValue ExpandADDSUB(SDNode *Op, SelectionDAG &DAG) const;
163db9e697725e81edb4c5cb80f8dc7b412431be0d0Richard Osborne
164db9e697725e81edb4c5cb80f8dc7b412431be0d0Richard Osborne    virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
16598ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman
1667b871b3464a5f84f8984786c665f70f5384fb0d6Richard Osborne    virtual void computeMaskedBitsForTargetNode(const SDValue Op,
1677b871b3464a5f84f8984786c665f70f5384fb0d6Richard Osborne                                                APInt &KnownZero,
1687b871b3464a5f84f8984786c665f70f5384fb0d6Richard Osborne                                                APInt &KnownOne,
1697b871b3464a5f84f8984786c665f70f5384fb0d6Richard Osborne                                                const SelectionDAG &DAG,
1707b871b3464a5f84f8984786c665f70f5384fb0d6Richard Osborne                                                unsigned Depth = 0) const;
1717b871b3464a5f84f8984786c665f70f5384fb0d6Richard Osborne
17298ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman    virtual SDValue
17398ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman      LowerFormalArguments(SDValue Chain,
17465c3c8f323198b99b88b109654194540cf9b3fa5Sandeep Patel                           CallingConv::ID CallConv,
17598ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                           bool isVarArg,
17698ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                           const SmallVectorImpl<ISD::InputArg> &Ins,
17798ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                           DebugLoc dl, SelectionDAG &DAG,
178d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman                           SmallVectorImpl<SDValue> &InVals) const;
17998ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman
18098ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman    virtual SDValue
181d2ea0e10cbd158c93fb870cdd03001b9cd1156b8Justin Holewinski      LowerCall(TargetLowering::CallLoweringInfo &CLI,
182d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman                SmallVectorImpl<SDValue> &InVals) const;
18398ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman
18498ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman    virtual SDValue
18598ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman      LowerReturn(SDValue Chain,
18665c3c8f323198b99b88b109654194540cf9b3fa5Sandeep Patel                  CallingConv::ID CallConv, bool isVarArg,
18798ca4f2a325f72374a477f9deba7d09e8999c29bDan Gohman                  const SmallVectorImpl<ISD::OutputArg> &Outs,
188c9403659a98bf6487ab6fbf40b81628b5695c02eDan Gohman                  const SmallVectorImpl<SDValue> &OutVals,
189d858e90f039f5fcdc2fa93035e911a5a9505cc50Dan Gohman                  DebugLoc dl, SelectionDAG &DAG) const;
19013c4fabf99366fe9c3b6d7d3e4e7f7e0539624a8Richard Osborne
19113c4fabf99366fe9c3b6d7d3e4e7f7e0539624a8Richard Osborne    virtual bool
192471e4224809f51652c71f319532697a879a75a0dEric Christopher      CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
19356cb2298663017eb77aa4f4dda8db7ecd1b58173Bill Wendling                     bool isVarArg,
19484023e0fbefc406a4c611d3d64a10df5d3a97dd7Dan Gohman                     const SmallVectorImpl<ISD::OutputArg> &ArgsFlags,
195c9af33c6854afe7b082af2d892ec5f05dfa383c7Dan Gohman                     LLVMContext &Context) const;
196b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne  };
197b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne}
198b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne
199b25baef26f03b9909b65dd5f762b38f93000445dRichard Osborne#endif // XCOREISELLOWERING_H
200