2008-08-13 20:19:35 +00:00
|
|
|
//===-- FastISel.h - Definition of the FastISel class ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the FastISel class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_FASTISEL_H
|
|
|
|
#define LLVM_CODEGEN_FASTISEL_H
|
|
|
|
|
|
|
|
#include "llvm/BasicBlock.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2008-10-14 23:54:11 +00:00
|
|
|
#include "llvm/ADT/SmallSet.h"
|
2008-08-13 20:19:35 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAGNodes.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2008-09-10 20:11:02 +00:00
|
|
|
class AllocaInst;
|
2008-08-27 01:09:54 +00:00
|
|
|
class ConstantFP;
|
2008-10-14 23:54:11 +00:00
|
|
|
class Instruction;
|
2008-08-13 20:19:35 +00:00
|
|
|
class MachineBasicBlock;
|
2008-09-05 00:06:23 +00:00
|
|
|
class MachineConstantPool;
|
2008-08-13 20:19:35 +00:00
|
|
|
class MachineFunction;
|
2008-09-10 20:11:02 +00:00
|
|
|
class MachineFrameInfo;
|
2008-09-23 21:53:34 +00:00
|
|
|
class MachineModuleInfo;
|
2008-08-20 21:05:57 +00:00
|
|
|
class MachineRegisterInfo;
|
2008-08-20 22:45:34 +00:00
|
|
|
class TargetData;
|
2008-08-13 20:19:35 +00:00
|
|
|
class TargetInstrInfo;
|
2008-08-20 22:45:34 +00:00
|
|
|
class TargetLowering;
|
2008-08-22 00:20:26 +00:00
|
|
|
class TargetMachine;
|
2008-08-13 20:19:35 +00:00
|
|
|
class TargetRegisterClass;
|
|
|
|
|
2008-08-18 23:41:46 +00:00
|
|
|
/// FastISel - This is a fast-path instruction selection class that
|
|
|
|
/// generates poor code and doesn't support illegal types or non-trivial
|
|
|
|
/// lowering, but runs quickly.
|
2008-08-13 20:19:35 +00:00
|
|
|
class FastISel {
|
2008-08-22 00:20:26 +00:00
|
|
|
protected:
|
2008-08-13 20:19:35 +00:00
|
|
|
MachineBasicBlock *MBB;
|
2008-09-03 23:32:19 +00:00
|
|
|
DenseMap<const Value *, unsigned> LocalValueMap;
|
2008-09-03 23:12:08 +00:00
|
|
|
DenseMap<const Value *, unsigned> &ValueMap;
|
|
|
|
DenseMap<const BasicBlock *, MachineBasicBlock *> &MBBMap;
|
2008-09-10 20:11:02 +00:00
|
|
|
DenseMap<const AllocaInst *, int> &StaticAllocaMap;
|
2008-10-14 23:54:11 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
SmallSet<Instruction*, 8> &CatchInfoLost;
|
|
|
|
#endif
|
2008-08-20 21:05:57 +00:00
|
|
|
MachineFunction &MF;
|
2008-09-23 21:53:34 +00:00
|
|
|
MachineModuleInfo *MMI;
|
2008-08-20 21:05:57 +00:00
|
|
|
MachineRegisterInfo &MRI;
|
2008-09-10 20:11:02 +00:00
|
|
|
MachineFrameInfo &MFI;
|
|
|
|
MachineConstantPool &MCP;
|
2008-08-22 00:20:26 +00:00
|
|
|
const TargetMachine &TM;
|
2008-08-20 22:45:34 +00:00
|
|
|
const TargetData &TD;
|
2008-08-20 21:05:57 +00:00
|
|
|
const TargetInstrInfo &TII;
|
2008-08-22 00:20:26 +00:00
|
|
|
const TargetLowering &TLI;
|
2008-08-13 20:19:35 +00:00
|
|
|
|
|
|
|
public:
|
2008-10-04 00:56:36 +00:00
|
|
|
/// startNewBlock - Set the current block, to which generated
|
|
|
|
/// machine instructions will be appended, and clear the local
|
|
|
|
/// CSE map.
|
|
|
|
///
|
|
|
|
void startNewBlock(MachineBasicBlock *mbb) {
|
|
|
|
setCurrentBlock(mbb);
|
|
|
|
LocalValueMap.clear();
|
|
|
|
}
|
|
|
|
|
2008-09-03 23:12:08 +00:00
|
|
|
/// setCurrentBlock - Set the current block, to which generated
|
|
|
|
/// machine instructions will be appended.
|
|
|
|
///
|
|
|
|
void setCurrentBlock(MachineBasicBlock *mbb) {
|
|
|
|
MBB = mbb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// SelectInstruction - Do "fast" instruction selection for the given
|
|
|
|
/// LLVM IR instruction, and append generated machine instructions to
|
|
|
|
/// the current block. Return true if selection was successful.
|
|
|
|
///
|
|
|
|
bool SelectInstruction(Instruction *I);
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2008-09-05 18:18:20 +00:00
|
|
|
/// SelectInstruction - Do "fast" instruction selection for the given
|
|
|
|
/// LLVM IR operator (Instruction or ConstantExpr), and append
|
|
|
|
/// generated machine instructions to the current block. Return true
|
|
|
|
/// if selection was successful.
|
|
|
|
///
|
|
|
|
bool SelectOperator(User *I, unsigned Opcode);
|
|
|
|
|
2008-08-28 23:21:34 +00:00
|
|
|
/// TargetSelectInstruction - This method is called by target-independent
|
|
|
|
/// code when the normal FastISel process fails to select an instruction.
|
|
|
|
/// This gives targets a chance to emit code for anything that doesn't
|
|
|
|
/// fit into FastISel's framework. It returns true if it was successful.
|
|
|
|
///
|
|
|
|
virtual bool
|
2008-09-03 23:12:08 +00:00
|
|
|
TargetSelectInstruction(Instruction *I) = 0;
|
|
|
|
|
|
|
|
/// getRegForValue - Create a virtual register and arrange for it to
|
|
|
|
/// be assigned the value for the given LLVM value.
|
|
|
|
unsigned getRegForValue(Value *V);
|
2008-08-28 23:21:34 +00:00
|
|
|
|
2008-09-09 01:26:59 +00:00
|
|
|
/// lookUpRegForValue - Look up the value to see if its value is already
|
|
|
|
/// cached in a register. It may be defined by instructions across blocks or
|
|
|
|
/// defined locally.
|
|
|
|
unsigned lookUpRegForValue(Value *V);
|
|
|
|
|
2008-08-20 00:56:17 +00:00
|
|
|
virtual ~FastISel();
|
|
|
|
|
2008-08-13 20:19:35 +00:00
|
|
|
protected:
|
2008-09-03 23:12:08 +00:00
|
|
|
FastISel(MachineFunction &mf,
|
2008-09-23 21:53:34 +00:00
|
|
|
MachineModuleInfo *mmi,
|
2008-09-03 23:12:08 +00:00
|
|
|
DenseMap<const Value *, unsigned> &vm,
|
2008-09-10 20:11:02 +00:00
|
|
|
DenseMap<const BasicBlock *, MachineBasicBlock *> &bm,
|
2008-10-14 23:54:11 +00:00
|
|
|
DenseMap<const AllocaInst *, int> &am
|
|
|
|
#ifndef NDEBUG
|
|
|
|
, SmallSet<Instruction*, 8> &cil
|
|
|
|
#endif
|
|
|
|
);
|
2008-08-14 21:51:29 +00:00
|
|
|
|
2008-08-20 00:11:48 +00:00
|
|
|
/// FastEmit_r - This method is called by target-independent code
|
|
|
|
/// to request that an instruction with the given type and opcode
|
|
|
|
/// be emitted.
|
2008-08-13 20:19:35 +00:00
|
|
|
virtual unsigned FastEmit_(MVT::SimpleValueType VT,
|
2008-08-25 23:58:18 +00:00
|
|
|
MVT::SimpleValueType RetVT,
|
2008-08-13 20:19:35 +00:00
|
|
|
ISD::NodeType Opcode);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
|
|
|
/// FastEmit_r - This method is called by target-independent code
|
|
|
|
/// to request that an instruction with the given type, opcode, and
|
|
|
|
/// register operand be emitted.
|
|
|
|
///
|
2008-08-13 20:19:35 +00:00
|
|
|
virtual unsigned FastEmit_r(MVT::SimpleValueType VT,
|
2008-08-25 23:58:18 +00:00
|
|
|
MVT::SimpleValueType RetVT,
|
2008-08-13 20:19:35 +00:00
|
|
|
ISD::NodeType Opcode, unsigned Op0);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
|
|
|
/// FastEmit_rr - This method is called by target-independent code
|
|
|
|
/// to request that an instruction with the given type, opcode, and
|
|
|
|
/// register operands be emitted.
|
|
|
|
///
|
2008-08-13 20:19:35 +00:00
|
|
|
virtual unsigned FastEmit_rr(MVT::SimpleValueType VT,
|
2008-08-25 23:58:18 +00:00
|
|
|
MVT::SimpleValueType RetVT,
|
2008-08-13 20:19:35 +00:00
|
|
|
ISD::NodeType Opcode,
|
|
|
|
unsigned Op0, unsigned Op1);
|
|
|
|
|
2008-08-20 22:45:34 +00:00
|
|
|
/// FastEmit_ri - This method is called by target-independent code
|
|
|
|
/// to request that an instruction with the given type, opcode, and
|
|
|
|
/// register and immediate operands be emitted.
|
|
|
|
///
|
|
|
|
virtual unsigned FastEmit_ri(MVT::SimpleValueType VT,
|
2008-08-25 23:58:18 +00:00
|
|
|
MVT::SimpleValueType RetVT,
|
2008-08-20 22:45:34 +00:00
|
|
|
ISD::NodeType Opcode,
|
2008-08-21 01:41:07 +00:00
|
|
|
unsigned Op0, uint64_t Imm);
|
|
|
|
|
2008-08-27 01:09:54 +00:00
|
|
|
/// FastEmit_rf - This method is called by target-independent code
|
|
|
|
/// to request that an instruction with the given type, opcode, and
|
|
|
|
/// register and floating-point immediate operands be emitted.
|
|
|
|
///
|
|
|
|
virtual unsigned FastEmit_rf(MVT::SimpleValueType VT,
|
|
|
|
MVT::SimpleValueType RetVT,
|
|
|
|
ISD::NodeType Opcode,
|
|
|
|
unsigned Op0, ConstantFP *FPImm);
|
|
|
|
|
2008-08-21 01:41:07 +00:00
|
|
|
/// FastEmit_rri - This method is called by target-independent code
|
|
|
|
/// to request that an instruction with the given type, opcode, and
|
|
|
|
/// register and immediate operands be emitted.
|
|
|
|
///
|
|
|
|
virtual unsigned FastEmit_rri(MVT::SimpleValueType VT,
|
2008-08-25 23:58:18 +00:00
|
|
|
MVT::SimpleValueType RetVT,
|
2008-08-21 01:41:07 +00:00
|
|
|
ISD::NodeType Opcode,
|
|
|
|
unsigned Op0, unsigned Op1, uint64_t Imm);
|
2008-08-20 22:45:34 +00:00
|
|
|
|
|
|
|
/// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries
|
|
|
|
/// to emit an instruction with an immediate operand using FastEmit_ri.
|
|
|
|
/// If that fails, it materializes the immediate into a register and try
|
|
|
|
/// FastEmit_rr instead.
|
|
|
|
unsigned FastEmit_ri_(MVT::SimpleValueType VT,
|
|
|
|
ISD::NodeType Opcode,
|
|
|
|
unsigned Op0, uint64_t Imm,
|
|
|
|
MVT::SimpleValueType ImmType);
|
2008-08-25 20:20:32 +00:00
|
|
|
|
2008-08-27 01:09:54 +00:00
|
|
|
/// FastEmit_rf_ - This method is a wrapper of FastEmit_rf. It first tries
|
|
|
|
/// to emit an instruction with an immediate operand using FastEmit_rf.
|
|
|
|
/// If that fails, it materializes the immediate into a register and try
|
|
|
|
/// FastEmit_rr instead.
|
|
|
|
unsigned FastEmit_rf_(MVT::SimpleValueType VT,
|
|
|
|
ISD::NodeType Opcode,
|
|
|
|
unsigned Op0, ConstantFP *FPImm,
|
|
|
|
MVT::SimpleValueType ImmType);
|
|
|
|
|
2008-08-25 20:20:32 +00:00
|
|
|
/// FastEmit_i - This method is called by target-independent code
|
|
|
|
/// to request that an instruction with the given type, opcode, and
|
|
|
|
/// immediate operand be emitted.
|
|
|
|
virtual unsigned FastEmit_i(MVT::SimpleValueType VT,
|
2008-08-25 23:58:18 +00:00
|
|
|
MVT::SimpleValueType RetVT,
|
2008-08-25 20:20:32 +00:00
|
|
|
ISD::NodeType Opcode,
|
|
|
|
uint64_t Imm);
|
2008-08-20 22:45:34 +00:00
|
|
|
|
2008-08-27 01:09:54 +00:00
|
|
|
/// FastEmit_f - This method is called by target-independent code
|
|
|
|
/// to request that an instruction with the given type, opcode, and
|
|
|
|
/// floating-point immediate operand be emitted.
|
|
|
|
virtual unsigned FastEmit_f(MVT::SimpleValueType VT,
|
|
|
|
MVT::SimpleValueType RetVT,
|
|
|
|
ISD::NodeType Opcode,
|
|
|
|
ConstantFP *FPImm);
|
|
|
|
|
2008-08-20 00:11:48 +00:00
|
|
|
/// FastEmitInst_ - Emit a MachineInstr with no operands and a
|
|
|
|
/// result register in the given register class.
|
|
|
|
///
|
2008-08-13 20:19:35 +00:00
|
|
|
unsigned FastEmitInst_(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
2008-08-21 01:41:07 +00:00
|
|
|
/// FastEmitInst_r - Emit a MachineInstr with one register operand
|
2008-08-20 00:11:48 +00:00
|
|
|
/// and a result register in the given register class.
|
|
|
|
///
|
2008-08-13 20:19:35 +00:00
|
|
|
unsigned FastEmitInst_r(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
2008-08-21 01:41:07 +00:00
|
|
|
/// FastEmitInst_rr - Emit a MachineInstr with two register operands
|
2008-08-20 00:11:48 +00:00
|
|
|
/// and a result register in the given register class.
|
|
|
|
///
|
2008-08-13 20:19:35 +00:00
|
|
|
unsigned FastEmitInst_rr(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, unsigned Op1);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
2008-08-21 01:41:07 +00:00
|
|
|
/// FastEmitInst_ri - Emit a MachineInstr with two register operands
|
|
|
|
/// and a result register in the given register class.
|
|
|
|
///
|
|
|
|
unsigned FastEmitInst_ri(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, uint64_t Imm);
|
|
|
|
|
2008-08-27 01:09:54 +00:00
|
|
|
/// FastEmitInst_rf - Emit a MachineInstr with two register operands
|
|
|
|
/// and a result register in the given register class.
|
|
|
|
///
|
|
|
|
unsigned FastEmitInst_rf(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, ConstantFP *FPImm);
|
|
|
|
|
2008-08-21 01:41:07 +00:00
|
|
|
/// FastEmitInst_rri - Emit a MachineInstr with two register operands,
|
|
|
|
/// an immediate, and a result register in the given register class.
|
|
|
|
///
|
|
|
|
unsigned FastEmitInst_rri(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, unsigned Op1, uint64_t Imm);
|
2008-08-25 20:20:32 +00:00
|
|
|
|
|
|
|
/// FastEmitInst_i - Emit a MachineInstr with a single immediate
|
|
|
|
/// operand, and a result register in the given register class.
|
|
|
|
unsigned FastEmitInst_i(unsigned MachineInstrOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
uint64_t Imm);
|
2008-08-21 01:41:07 +00:00
|
|
|
|
2008-08-27 22:30:02 +00:00
|
|
|
/// FastEmitInst_extractsubreg - Emit a MachineInstr for an extract_subreg
|
|
|
|
/// from a specified index of a superregister.
|
2008-08-28 17:47:37 +00:00
|
|
|
unsigned FastEmitInst_extractsubreg(unsigned Op0, uint32_t Idx);
|
2008-08-27 22:30:02 +00:00
|
|
|
|
2008-10-02 22:15:21 +00:00
|
|
|
/// FastEmitBranch - Emit an unconditional branch to the given block,
|
|
|
|
/// unless it is the immediate (fall-through) successor, and update
|
|
|
|
/// the CFG.
|
|
|
|
void FastEmitBranch(MachineBasicBlock *MBB);
|
|
|
|
|
2008-09-05 00:06:23 +00:00
|
|
|
void UpdateValueMap(Value* I, unsigned Reg);
|
2008-09-03 06:43:10 +00:00
|
|
|
|
2008-08-21 00:19:05 +00:00
|
|
|
unsigned createResultReg(const TargetRegisterClass *RC);
|
2008-09-05 00:06:23 +00:00
|
|
|
|
2008-09-05 20:49:33 +00:00
|
|
|
/// TargetMaterializeConstant - Emit a constant in a register using
|
|
|
|
/// target-specific logic, such as constant pool loads.
|
2008-09-10 20:11:02 +00:00
|
|
|
virtual unsigned TargetMaterializeConstant(Constant* C) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// TargetMaterializeAlloca - Emit an alloca address in a register using
|
|
|
|
/// target-specific logic.
|
|
|
|
virtual unsigned TargetMaterializeAlloca(AllocaInst* C) {
|
2008-09-05 00:06:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-08-21 00:19:05 +00:00
|
|
|
|
2008-09-03 06:43:10 +00:00
|
|
|
private:
|
2008-09-05 18:18:20 +00:00
|
|
|
bool SelectBinaryOp(User *I, ISD::NodeType ISDOpcode);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
2008-09-05 18:18:20 +00:00
|
|
|
bool SelectGetElementPtr(User *I);
|
2008-08-26 21:28:54 +00:00
|
|
|
|
2008-09-25 17:05:24 +00:00
|
|
|
bool SelectCall(User *I);
|
|
|
|
|
2008-09-05 18:18:20 +00:00
|
|
|
bool SelectBitCast(User *I);
|
2008-08-26 23:46:32 +00:00
|
|
|
|
2008-09-05 18:18:20 +00:00
|
|
|
bool SelectCast(User *I, ISD::NodeType Opcode);
|
2008-08-13 20:19:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|