FastISel.h revision 7f92ebddd27c8d099e04cc879cc8199dba88cec1
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/BasicBlock.h"
18b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#include "llvm/ADT/DenseMap.h"
19b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#include "llvm/CodeGen/SelectionDAGNodes.h"
20b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
21b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmannamespace llvm {
22b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
23b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass MachineBasicBlock;
24b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass MachineFunction;
25bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohmanclass MachineRegisterInfo;
2683785c80968165b30fcdd111ceb2c28d38bcff86Evan Chengclass TargetData;
27b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass TargetInstrInfo;
2883785c80968165b30fcdd111ceb2c28d38bcff86Evan Chengclass TargetLowering;
29b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass TargetRegisterClass;
30b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
3140610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// FastISel - This is a fast-path instruction selection class that
3240610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// generates poor code and doesn't support illegal types or non-trivial
3340610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// lowering, but runs quickly.
34b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass FastISel {
35b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  MachineBasicBlock *MBB;
36bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman  MachineFunction &MF;
37bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman  MachineRegisterInfo &MRI;
3883785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  const TargetData &TD;
39bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman  const TargetInstrInfo &TII;
4083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  TargetLowering &TLI;
41b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
42b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanpublic:
43b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  /// SelectInstructions - Do "fast" instruction selection over the
44b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  /// LLVM IR instructions in the range [Begin, N) where N is either
45b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  /// End or the first unsupported instruction. Return N.
46b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  /// ValueMap is filled in with a mapping of LLVM IR Values to
477f92ebddd27c8d099e04cc879cc8199dba88cec1Dan Gohman  /// virtual register numbers. MBB is a block to which to append
487f92ebddd27c8d099e04cc879cc8199dba88cec1Dan Gohman  /// the enerated MachineInstrs.
49b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  BasicBlock::iterator
50b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End,
51bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman                     DenseMap<const Value*, unsigned> &ValueMap,
527f92ebddd27c8d099e04cc879cc8199dba88cec1Dan Gohman                     MachineBasicBlock *MBB);
53b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
54cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman  virtual ~FastISel();
55cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman
56b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanprotected:
57bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman  explicit FastISel(MachineFunction &mf);
58e285a74f7cf9dd3ccf4fe758576cf83301f8a43eDan Gohman
59bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// FastEmit_r - This method is called by target-independent code
60bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// to request that an instruction with the given type and opcode
61bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// be emitted.
62b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  virtual unsigned FastEmit_(MVT::SimpleValueType VT,
63b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                             ISD::NodeType Opcode);
64bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
65bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// FastEmit_r - This method is called by target-independent code
66bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// to request that an instruction with the given type, opcode, and
67bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// register operand be emitted.
68bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  ///
69b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  virtual unsigned FastEmit_r(MVT::SimpleValueType VT,
70b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                              ISD::NodeType Opcode, unsigned Op0);
71bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
72bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// FastEmit_rr - This method is called by target-independent code
73bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// to request that an instruction with the given type, opcode, and
74bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// register operands be emitted.
75bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  ///
76b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  virtual unsigned FastEmit_rr(MVT::SimpleValueType VT,
77b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                               ISD::NodeType Opcode,
78b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                               unsigned Op0, unsigned Op1);
79b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
8083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// FastEmit_i - This method is called by target-independent code
8183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// to request that an instruction with the given type which materialize
8283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// the specified immediate value.
8383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  virtual unsigned FastEmit_i(MVT::SimpleValueType VT, uint64_t Imm);
8483785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng
8583785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// FastEmit_ri - This method is called by target-independent code
8683785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// to request that an instruction with the given type, opcode, and
8783785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// register and immediate operands be emitted.
8883785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  ///
8983785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  virtual unsigned FastEmit_ri(MVT::SimpleValueType VT,
9083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng                               ISD::NodeType Opcode,
9183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng                               unsigned Op0, uint64_t Imm,
9283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng                               MVT::SimpleValueType ImmType);
9383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng
9483785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries
9583785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// to emit an instruction with an immediate operand using FastEmit_ri.
9683785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// If that fails, it materializes the immediate into a register and try
9783785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  /// FastEmit_rr instead.
9883785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng  unsigned FastEmit_ri_(MVT::SimpleValueType VT,
9983785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng                        ISD::NodeType Opcode,
10083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng                        unsigned Op0, uint64_t Imm,
10183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng                        MVT::SimpleValueType ImmType);
10283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng
103bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// FastEmitInst_ - Emit a MachineInstr with no operands and a
104bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// result register in the given register class.
105bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  ///
106b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  unsigned FastEmitInst_(unsigned MachineInstOpcode,
107b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                         const TargetRegisterClass *RC);
108bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
109bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// FastEmitInst_ - Emit a MachineInstr with one register operand
110bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// and a result register in the given register class.
111bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  ///
112b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  unsigned FastEmitInst_r(unsigned MachineInstOpcode,
113b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                          const TargetRegisterClass *RC,
114b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                          unsigned Op0);
115bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
116bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// FastEmitInst_ - Emit a MachineInstr with two register operands
117bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  /// and a result register in the given register class.
118bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  ///
119b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman  unsigned FastEmitInst_rr(unsigned MachineInstOpcode,
120b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                           const TargetRegisterClass *RC,
121b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman                           unsigned Op0, unsigned Op1);
122bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
123bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohmanprivate:
124c7f72de3b4ef21828ea4780f0693bf0acd04e1c5Dan Gohman  unsigned createResultReg(const TargetRegisterClass *RC);
125c7f72de3b4ef21828ea4780f0693bf0acd04e1c5Dan Gohman
126bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  bool SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode,
127bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman                      DenseMap<const Value*, unsigned> &ValueMap);
128bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman
129bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman  bool SelectGetElementPtr(Instruction *I,
130bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman                           DenseMap<const Value*, unsigned> &ValueMap);
131b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman};
132b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
133b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman}
134b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman
135b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#endif
136