FastISel.h revision 3d45a853db014fdddcdb79424e663dfed5eccbc7
1b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//===-- FastISel.h - Definition of the FastISel class ---------------------===//
2b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//
3b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//                     The LLVM Compiler Infrastructure
4b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//
5b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// This file is distributed under the University of Illinois Open Source
6b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// License. See LICENSE.TXT for details.
7b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//
8b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//===----------------------------------------------------------------------===//
9b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//
10b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// This file defines the FastISel class.
11b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//
12b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//===----------------------------------------------------------------------===//
13b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
14b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#ifndef LLVM_CODEGEN_FASTISEL_H
15b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#define LLVM_CODEGEN_FASTISEL_H
16b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
17b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#include "llvm/ADT/DenseMap.h"
18dd5b58ad7be78be90390074f0df138778af5c895Dan Gohman#include "llvm/ADT/SmallSet.h"
19b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#include "llvm/CodeGen/SelectionDAGNodes.h"
20b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
21b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmannamespace llvm {
22b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
230586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohmanclass AllocaInst;
2410df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohmanclass ConstantFP;
25dd5b58ad7be78be90390074f0df138778af5c895Dan Gohmanclass Instruction;
26b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass MachineBasicBlock;
2795267a1e671efc3c14e916b6978bbb15973b4cdcOwen Andersonclass MachineConstantPool;
28b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass MachineFunction;
290586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohmanclass MachineFrameInfo;
30d57dd5f4e6740520820bc0fca42a540e31c27a73Dan Gohmanclass MachineModuleInfo;
3183489bb7700c69b7a4a8da59365c42d3f5c8129bDevang Patelclass DwarfWriter;
32bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohmanclass MachineRegisterInfo;
3383785c80968165b30fcdd111ceb2c28d38bcff86Evan Chengclass TargetData;
34b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass TargetInstrInfo;
3583785c80968165b30fcdd111ceb2c28d38bcff86Evan Chengclass TargetLowering;
3622bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohmanclass TargetMachine;
37b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass TargetRegisterClass;
38b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
3940610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// FastISel - This is a fast-path instruction selection class that
4040610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// generates poor code and doesn't support illegal types or non-trivial
4140610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// lowering, but runs quickly.
42b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass FastISel {
4322bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohmanprotected:
44b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  MachineBasicBlock *MBB;
45104e4ce1629ea84736691bd1ee7867bdf90e8a2eDan Gohman  DenseMap<const Value *, unsigned> LocalValueMap;
463df24e667f04a7003342b534310919abc9c87418Dan Gohman  DenseMap<const Value *, unsigned> &ValueMap;
473df24e667f04a7003342b534310919abc9c87418Dan Gohman  DenseMap<const BasicBlock *, MachineBasicBlock *> &MBBMap;
480586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman  DenseMap<const AllocaInst *, int> &StaticAllocaMap;
49dd5b58ad7be78be90390074f0df138778af5c895Dan Gohman#ifndef NDEBUG
50dd5b58ad7be78be90390074f0df138778af5c895Dan Gohman  SmallSet<Instruction*, 8> &CatchInfoLost;
51dd5b58ad7be78be90390074f0df138778af5c895Dan Gohman#endif
52bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman  MachineFunction &MF;
53d57dd5f4e6740520820bc0fca42a540e31c27a73Dan Gohman  MachineModuleInfo *MMI;
5483489bb7700c69b7a4a8da59365c42d3f5c8129bDevang Patel  DwarfWriter *DW;
55bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman  MachineRegisterInfo &MRI;
560586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman  MachineFrameInfo &MFI;
570586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman  MachineConstantPool &MCP;
589bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling  DebugLoc DL;
5922bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohman  const TargetMachine &TM;
6083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  const TargetData &TD;
61bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman  const TargetInstrInfo &TII;
6222bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohman  const TargetLowering &TLI;
63b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
64b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanpublic:
659bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling  /// startNewBlock - Set the current block to which generated machine
669bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling  /// instructions will be appended, and clear the local CSE map.
67241f464d24a6c22721607841069bbeb17b3f71e6Dan Gohman  ///
68241f464d24a6c22721607841069bbeb17b3f71e6Dan Gohman  void startNewBlock(MachineBasicBlock *mbb) {
69241f464d24a6c22721607841069bbeb17b3f71e6Dan Gohman    setCurrentBlock(mbb);
70241f464d24a6c22721607841069bbeb17b3f71e6Dan Gohman    LocalValueMap.clear();
71241f464d24a6c22721607841069bbeb17b3f71e6Dan Gohman  }
72241f464d24a6c22721607841069bbeb17b3f71e6Dan Gohman
739bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling  /// setCurrentBlock - Set the current block to which generated machine
749bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling  /// instructions will be appended.
753df24e667f04a7003342b534310919abc9c87418Dan Gohman  ///
763df24e667f04a7003342b534310919abc9c87418Dan Gohman  void setCurrentBlock(MachineBasicBlock *mbb) {
773df24e667f04a7003342b534310919abc9c87418Dan Gohman    MBB = mbb;
783df24e667f04a7003342b534310919abc9c87418Dan Gohman  }
793df24e667f04a7003342b534310919abc9c87418Dan Gohman
809bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling  /// setCurDebugLoc - Set the current debug location information, which is used
819bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling  /// when creating a machine instruction.
829bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling  ///
839bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling  void setCurDebugLoc(DebugLoc dl) { DL = dl; }
849bc96a57206cbebaa9b0ba9979f949eb10c1592cBill Wendling
85390f3ace34855a3d4c9e0adf468976375f8c6dc1Devang Patel  /// getCurDebugLoc() - Return current debug location information.
86390f3ace34855a3d4c9e0adf468976375f8c6dc1Devang Patel  DebugLoc getCurDebugLoc() const { return DL; }
87390f3ace34855a3d4c9e0adf468976375f8c6dc1Devang Patel
883df24e667f04a7003342b534310919abc9c87418Dan Gohman  /// SelectInstruction - Do "fast" instruction selection for the given
893df24e667f04a7003342b534310919abc9c87418Dan Gohman  /// LLVM IR instruction, and append generated machine instructions to
903df24e667f04a7003342b534310919abc9c87418Dan Gohman  /// the current block. Return true if selection was successful.
913df24e667f04a7003342b534310919abc9c87418Dan Gohman  ///
923df24e667f04a7003342b534310919abc9c87418Dan Gohman  bool SelectInstruction(Instruction *I);
93b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
9440b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman  /// SelectInstruction - Do "fast" instruction selection for the given
9540b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman  /// LLVM IR operator (Instruction or ConstantExpr), and append
9640b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman  /// generated machine instructions to the current block. Return true
9740b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman  /// if selection was successful.
9840b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman  ///
9940b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman  bool SelectOperator(User *I, unsigned Opcode);
10040b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman
10199b218218c0ca3ebfdd568ddfeafa07842e9d69dDan Gohman  /// TargetSelectInstruction - This method is called by target-independent
10299b218218c0ca3ebfdd568ddfeafa07842e9d69dDan Gohman  /// code when the normal FastISel process fails to select an instruction.
10399b218218c0ca3ebfdd568ddfeafa07842e9d69dDan Gohman  /// This gives targets a chance to emit code for anything that doesn't
10499b218218c0ca3ebfdd568ddfeafa07842e9d69dDan Gohman  /// fit into FastISel's framework. It returns true if it was successful.
10599b218218c0ca3ebfdd568ddfeafa07842e9d69dDan Gohman  ///
10699b218218c0ca3ebfdd568ddfeafa07842e9d69dDan Gohman  virtual bool
1073df24e667f04a7003342b534310919abc9c87418Dan Gohman  TargetSelectInstruction(Instruction *I) = 0;
1083df24e667f04a7003342b534310919abc9c87418Dan Gohman
1093df24e667f04a7003342b534310919abc9c87418Dan Gohman  /// getRegForValue - Create a virtual register and arrange for it to
1103df24e667f04a7003342b534310919abc9c87418Dan Gohman  /// be assigned the value for the given LLVM value.
1113df24e667f04a7003342b534310919abc9c87418Dan Gohman  unsigned getRegForValue(Value *V);
11299b218218c0ca3ebfdd568ddfeafa07842e9d69dDan Gohman
11359fbc80f6b3b5c71dfb84149f589625f7ed510e3Evan Cheng  /// lookUpRegForValue - Look up the value to see if its value is already
11459fbc80f6b3b5c71dfb84149f589625f7ed510e3Evan Cheng  /// cached in a register. It may be defined by instructions across blocks or
11559fbc80f6b3b5c71dfb84149f589625f7ed510e3Evan Cheng  /// defined locally.
11659fbc80f6b3b5c71dfb84149f589625f7ed510e3Evan Cheng  unsigned lookUpRegForValue(Value *V);
11759fbc80f6b3b5c71dfb84149f589625f7ed510e3Evan Cheng
118c8a1a3c426209e9c7b35e279e1578a89edc40af6Dan Gohman  /// getRegForGEPIndex - This is a wrapper around getRegForValue that also
119c8a1a3c426209e9c7b35e279e1578a89edc40af6Dan Gohman  /// takes care of truncating or sign-extending the given getelementptr
120c8a1a3c426209e9c7b35e279e1578a89edc40af6Dan Gohman  /// index value.
121c8a1a3c426209e9c7b35e279e1578a89edc40af6Dan Gohman  unsigned getRegForGEPIndex(Value *V);
122c8a1a3c426209e9c7b35e279e1578a89edc40af6Dan Gohman
123cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman  virtual ~FastISel();
124cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman
125b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanprotected:
1263df24e667f04a7003342b534310919abc9c87418Dan Gohman  FastISel(MachineFunction &mf,
127d57dd5f4e6740520820bc0fca42a540e31c27a73Dan Gohman           MachineModuleInfo *mmi,
12883489bb7700c69b7a4a8da59365c42d3f5c8129bDevang Patel           DwarfWriter *dw,
1293df24e667f04a7003342b534310919abc9c87418Dan Gohman           DenseMap<const Value *, unsigned> &vm,
1300586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman           DenseMap<const BasicBlock *, MachineBasicBlock *> &bm,
131dd5b58ad7be78be90390074f0df138778af5c895Dan Gohman           DenseMap<const AllocaInst *, int> &am
132dd5b58ad7be78be90390074f0df138778af5c895Dan Gohman#ifndef NDEBUG
133dd5b58ad7be78be90390074f0df138778af5c895Dan Gohman           , SmallSet<Instruction*, 8> &cil
134dd5b58ad7be78be90390074f0df138778af5c895Dan Gohman#endif
135dd5b58ad7be78be90390074f0df138778af5c895Dan Gohman           );
136e285a74f7cf9dd3ccf4fe758576cf83301f8a43eDan Gohman
137bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// FastEmit_r - This method is called by target-independent code
138bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// to request that an instruction with the given type and opcode
139bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// be emitted.
140825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  virtual unsigned FastEmit_(MVT VT,
141825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson                             MVT RetVT,
142b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                             ISD::NodeType Opcode);
143bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
144bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// FastEmit_r - This method is called by target-independent code
145bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// to request that an instruction with the given type, opcode, and
146bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// register operand be emitted.
147bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  ///
148825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  virtual unsigned FastEmit_r(MVT VT,
149825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson                              MVT RetVT,
150b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                              ISD::NodeType Opcode, unsigned Op0);
151bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
152bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// FastEmit_rr - This method is called by target-independent code
153bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// to request that an instruction with the given type, opcode, and
154bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// register operands be emitted.
155bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  ///
156825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  virtual unsigned FastEmit_rr(MVT VT,
157825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson                               MVT RetVT,
158b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                               ISD::NodeType Opcode,
159b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                               unsigned Op0, unsigned Op1);
160b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
16183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// FastEmit_ri - This method is called by target-independent code
16283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// to request that an instruction with the given type, opcode, and
16383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// register and immediate operands be emitted.
16483785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  ///
165825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  virtual unsigned FastEmit_ri(MVT VT,
166825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson                               MVT RetVT,
16783785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng                               ISD::NodeType Opcode,
168d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman                               unsigned Op0, uint64_t Imm);
169d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman
17010df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// FastEmit_rf - This method is called by target-independent code
17110df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// to request that an instruction with the given type, opcode, and
17210df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// register and floating-point immediate operands be emitted.
17310df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  ///
174825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  virtual unsigned FastEmit_rf(MVT VT,
175825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson                               MVT RetVT,
17610df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman                               ISD::NodeType Opcode,
17710df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman                               unsigned Op0, ConstantFP *FPImm);
17810df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman
179d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  /// FastEmit_rri - This method is called by target-independent code
180d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  /// to request that an instruction with the given type, opcode, and
181d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  /// register and immediate operands be emitted.
182d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  ///
183825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  virtual unsigned FastEmit_rri(MVT VT,
184825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson                                MVT RetVT,
185d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman                                ISD::NodeType Opcode,
186d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman                                unsigned Op0, unsigned Op1, uint64_t Imm);
18783785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng
18883785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries
18983785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// to emit an instruction with an immediate operand using FastEmit_ri.
19083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// If that fails, it materializes the immediate into a register and try
19183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// FastEmit_rr instead.
192825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  unsigned FastEmit_ri_(MVT VT,
19383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng                        ISD::NodeType Opcode,
19483785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng                        unsigned Op0, uint64_t Imm,
195825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson                        MVT ImmType);
1966d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson
19710df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// FastEmit_rf_ - This method is a wrapper of FastEmit_rf. It first tries
19810df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// to emit an instruction with an immediate operand using FastEmit_rf.
19910df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// If that fails, it materializes the immediate into a register and try
20010df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// FastEmit_rr instead.
201825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  unsigned FastEmit_rf_(MVT VT,
20210df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman                        ISD::NodeType Opcode,
20310df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman                        unsigned Op0, ConstantFP *FPImm,
204825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson                        MVT ImmType);
20510df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman
2066d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson  /// FastEmit_i - This method is called by target-independent code
2076d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson  /// to request that an instruction with the given type, opcode, and
2086d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson  /// immediate operand be emitted.
209825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  virtual unsigned FastEmit_i(MVT VT,
210825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson                              MVT RetVT,
2116d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson                              ISD::NodeType Opcode,
2126d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson                              uint64_t Imm);
21383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng
21410df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// FastEmit_f - This method is called by target-independent code
21510df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// to request that an instruction with the given type, opcode, and
21610df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// floating-point immediate operand be emitted.
217825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  virtual unsigned FastEmit_f(MVT VT,
218825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson                              MVT RetVT,
21910df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman                              ISD::NodeType Opcode,
22010df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman                              ConstantFP *FPImm);
22110df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman
222bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// FastEmitInst_ - Emit a MachineInstr with no operands and a
223bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// result register in the given register class.
224bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  ///
225b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  unsigned FastEmitInst_(unsigned MachineInstOpcode,
226b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                         const TargetRegisterClass *RC);
227bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
228d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  /// FastEmitInst_r - Emit a MachineInstr with one register operand
229bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// and a result register in the given register class.
230bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  ///
231b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  unsigned FastEmitInst_r(unsigned MachineInstOpcode,
232b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                          const TargetRegisterClass *RC,
233b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                          unsigned Op0);
234bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
235d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  /// FastEmitInst_rr - Emit a MachineInstr with two register operands
236bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// and a result register in the given register class.
237bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  ///
238b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  unsigned FastEmitInst_rr(unsigned MachineInstOpcode,
239b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                           const TargetRegisterClass *RC,
240b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                           unsigned Op0, unsigned Op1);
241bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
242d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  /// FastEmitInst_ri - Emit a MachineInstr with two register operands
243d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  /// and a result register in the given register class.
244d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  ///
245d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  unsigned FastEmitInst_ri(unsigned MachineInstOpcode,
246d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman                           const TargetRegisterClass *RC,
247d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman                           unsigned Op0, uint64_t Imm);
248d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman
24910df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// FastEmitInst_rf - Emit a MachineInstr with two register operands
25010df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  /// and a result register in the given register class.
25110df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  ///
25210df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman  unsigned FastEmitInst_rf(unsigned MachineInstOpcode,
25310df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman                           const TargetRegisterClass *RC,
25410df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman                           unsigned Op0, ConstantFP *FPImm);
25510df0fa73e396bbc93a8940e8b53827390c54d10Dan Gohman
256d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  /// FastEmitInst_rri - Emit a MachineInstr with two register operands,
257d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  /// an immediate, and a result register in the given register class.
258d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  ///
259d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman  unsigned FastEmitInst_rri(unsigned MachineInstOpcode,
260d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman                            const TargetRegisterClass *RC,
261d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman                            unsigned Op0, unsigned Op1, uint64_t Imm);
2626d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson
2636d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson  /// FastEmitInst_i - Emit a MachineInstr with a single immediate
2646d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson  /// operand, and a result register in the given register class.
2656d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson  unsigned FastEmitInst_i(unsigned MachineInstrOpcode,
2666d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson                          const TargetRegisterClass *RC,
2676d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson                          uint64_t Imm);
268d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman
2698970f00deff00ffce1f35cf00883357e1582daa1Owen Anderson  /// FastEmitInst_extractsubreg - Emit a MachineInstr for an extract_subreg
270536ab130ec95cbb7bf30530251dafa7dfecc8471Evan Cheng  /// from a specified index of a superregister to a specified type.
271825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  unsigned FastEmitInst_extractsubreg(MVT RetVT,
272536ab130ec95cbb7bf30530251dafa7dfecc8471Evan Cheng                                      unsigned Op0, uint32_t Idx);
2738970f00deff00ffce1f35cf00883357e1582daa1Owen Anderson
27414ea1ec2324cb595f2e035bbf54ddcd483f17c11Dan Gohman  /// FastEmitZExtFromI1 - Emit MachineInstrs to compute the value of Op
27514ea1ec2324cb595f2e035bbf54ddcd483f17c11Dan Gohman  /// with all but the least significant bit set to zero.
276825b72b0571821bf2d378749f69d6c4cfb52d2f9Owen Anderson  unsigned FastEmitZExtFromI1(MVT VT,
27714ea1ec2324cb595f2e035bbf54ddcd483f17c11Dan Gohman                              unsigned Op);
27814ea1ec2324cb595f2e035bbf54ddcd483f17c11Dan Gohman
279d98d6203e429b2d7208b6687931e9079e85e95ecDan Gohman  /// FastEmitBranch - Emit an unconditional branch to the given block,
280d98d6203e429b2d7208b6687931e9079e85e95ecDan Gohman  /// unless it is the immediate (fall-through) successor, and update
281d98d6203e429b2d7208b6687931e9079e85e95ecDan Gohman  /// the CFG.
282d98d6203e429b2d7208b6687931e9079e85e95ecDan Gohman  void FastEmitBranch(MachineBasicBlock *MBB);
283d98d6203e429b2d7208b6687931e9079e85e95ecDan Gohman
284c5040ab6065d5c569a1af0848b6e672b22b174b7Chris Lattner  unsigned UpdateValueMap(Value* I, unsigned Reg);
285ea09f4f4691a0db65772b54fe8163a48c9dce01dEvan Cheng
286c7f72de3b4ef21828ea4780f0693bf0acd04e1c5Dan Gohman  unsigned createResultReg(const TargetRegisterClass *RC);
28795267a1e671efc3c14e916b6978bbb15973b4cdcOwen Anderson
2889c7216f984111eb8f1716741bc9039ed86ec4a9bOwen Anderson  /// TargetMaterializeConstant - Emit a constant in a register using
2899c7216f984111eb8f1716741bc9039ed86ec4a9bOwen Anderson  /// target-specific logic, such as constant pool loads.
2900586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman  virtual unsigned TargetMaterializeConstant(Constant* C) {
2910586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman    return 0;
2920586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman  }
2930586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman
2940586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman  /// TargetMaterializeAlloca - Emit an alloca address in a register using
2950586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman  /// target-specific logic.
2960586d91bb3e516d5826826522d9a90ed6ef74d86Dan Gohman  virtual unsigned TargetMaterializeAlloca(AllocaInst* C) {
29795267a1e671efc3c14e916b6978bbb15973b4cdcOwen Anderson    return 0;
29895267a1e671efc3c14e916b6978bbb15973b4cdcOwen Anderson  }
299c7f72de3b4ef21828ea4780f0693bf0acd04e1c5Dan Gohman
300ea09f4f4691a0db65772b54fe8163a48c9dce01dEvan Chengprivate:
30140b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman  bool SelectBinaryOp(User *I, ISD::NodeType ISDOpcode);
302bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
3033d45a853db014fdddcdb79424e663dfed5eccbc7Dan Gohman  bool SelectFNeg(User *I);
3043d45a853db014fdddcdb79424e663dfed5eccbc7Dan Gohman
30540b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman  bool SelectGetElementPtr(User *I);
306763d89343be210eb62a13318ca0cc9321ce46bfbDan Gohman
30733134c4a75558288d663267c8991f6bd37a530afDan Gohman  bool SelectCall(User *I);
30833134c4a75558288d663267c8991f6bd37a530afDan Gohman
30940b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman  bool SelectBitCast(User *I);
310d0533c9998d3baf41848ba559a9b2f2c65296d14Owen Anderson
31140b189e4e257924d90aaf63bf2e12bc7bbca961aDan Gohman  bool SelectCast(User *I, ISD::NodeType Opcode);
312b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman};
313b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
314b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman}
315b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
316b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#endif
317