2013-07-10 18:40:49 +00:00
|
|
|
//===-- FastISel.h - Definition of the FastISel class ---*- C++ -*---------===//
|
2008-08-13 20:19:35 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-07-09 20:08:46 +00:00
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// This file defines the FastISel class.
|
|
|
|
///
|
2008-08-13 20:19:35 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2011-03-11 21:33:55 +00:00
|
|
|
|
2008-08-13 20:19:35 +00:00
|
|
|
#ifndef LLVM_CODEGEN_FASTISEL_H
|
|
|
|
#define LLVM_CODEGEN_FASTISEL_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2010-07-10 09:00:22 +00:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2008-08-13 20:19:35 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2008-09-10 20:11:02 +00:00
|
|
|
class AllocaInst;
|
2011-11-14 17:45:03 +00:00
|
|
|
class Constant;
|
2008-08-27 01:09:54 +00:00
|
|
|
class ConstantFP;
|
2014-03-12 08:00:24 +00:00
|
|
|
class DataLayout;
|
2010-07-07 16:29:44 +00:00
|
|
|
class FunctionLoweringInfo;
|
2008-10-14 23:54:11 +00:00
|
|
|
class Instruction;
|
2011-11-14 17:45:03 +00:00
|
|
|
class LoadInst;
|
2014-03-12 08:00:24 +00:00
|
|
|
class MVT;
|
2008-09-05 00:06:23 +00:00
|
|
|
class MachineConstantPool;
|
2014-03-12 08:00:24 +00:00
|
|
|
class MachineFrameInfo;
|
2008-08-13 20:19:35 +00:00
|
|
|
class MachineFunction;
|
2010-04-22 20:46:50 +00:00
|
|
|
class MachineInstr;
|
2008-08-20 21:05:57 +00:00
|
|
|
class MachineRegisterInfo;
|
2008-08-13 20:19:35 +00:00
|
|
|
class TargetInstrInfo;
|
2012-08-03 04:06:28 +00:00
|
|
|
class TargetLibraryInfo;
|
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;
|
2010-06-18 23:28:01 +00:00
|
|
|
class TargetRegisterInfo;
|
2011-11-14 17:45:03 +00:00
|
|
|
class User;
|
|
|
|
class Value;
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// 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-09-03 23:32:19 +00:00
|
|
|
DenseMap<const Value *, unsigned> LocalValueMap;
|
2010-07-07 16:29:44 +00:00
|
|
|
FunctionLoweringInfo &FuncInfo;
|
2008-08-20 21:05:57 +00:00
|
|
|
MachineRegisterInfo &MRI;
|
2008-09-10 20:11:02 +00:00
|
|
|
MachineFrameInfo &MFI;
|
|
|
|
MachineConstantPool &MCP;
|
2014-02-18 22:05:46 +00:00
|
|
|
DebugLoc DbgLoc;
|
2008-08-22 00:20:26 +00:00
|
|
|
const TargetMachine &TM;
|
2014-02-18 22:05:46 +00:00
|
|
|
const DataLayout &DL;
|
2008-08-20 21:05:57 +00:00
|
|
|
const TargetInstrInfo &TII;
|
2008-08-22 00:20:26 +00:00
|
|
|
const TargetLowering &TLI;
|
2010-06-18 23:28:01 +00:00
|
|
|
const TargetRegisterInfo &TRI;
|
2012-08-03 04:06:28 +00:00
|
|
|
const TargetLibraryInfo *LibInfo;
|
2011-08-18 22:06:10 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// The position of the last instruction for materializing constants for use
|
|
|
|
/// in the current block. It resets to EmitStartPt when it makes sense (for
|
|
|
|
/// example, it's usually profitable to avoid function calls between the
|
|
|
|
/// definition and the use)
|
2010-07-10 09:00:22 +00:00
|
|
|
MachineInstr *LastLocalValue;
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// The top most instruction in the current block that is allowed for emitting
|
|
|
|
/// local variables. LastLocalValue resets to EmitStartPt when it makes sense
|
|
|
|
/// (for example, on function calls)
|
2011-08-18 22:06:10 +00:00
|
|
|
MachineInstr *EmitStartPt;
|
|
|
|
|
2008-08-13 20:19:35 +00:00
|
|
|
public:
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Return the position of the last instruction emitted for materializing
|
|
|
|
/// constants for use in the current block.
|
2010-07-10 09:00:22 +00:00
|
|
|
MachineInstr *getLastLocalValue() { return LastLocalValue; }
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Update the position of the last instruction emitted for materializing
|
|
|
|
/// constants for use in the current block.
|
2011-08-18 22:06:10 +00:00
|
|
|
void setLastLocalValue(MachineInstr *I) {
|
|
|
|
EmitStartPt = I;
|
|
|
|
LastLocalValue = I;
|
|
|
|
}
|
2010-07-10 09:00:22 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Set the current block to which generated machine instructions will be
|
|
|
|
/// appended, and clear the local CSE map.
|
2010-07-10 09:00:22 +00:00
|
|
|
void startNewBlock();
|
2008-10-04 00:56:36 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Return current debug location information.
|
2014-02-18 22:05:46 +00:00
|
|
|
DebugLoc getCurDebugLoc() const { return DbgLoc; }
|
2013-02-11 01:27:15 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Do "fast" instruction selection for function arguments and append machine
|
|
|
|
/// instructions to the current block. Return true if it is successful.
|
2013-02-11 01:27:15 +00:00
|
|
|
bool LowerArguments();
|
2009-04-16 01:33:10 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// 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.
|
2010-04-15 01:51:59 +00:00
|
|
|
bool SelectInstruction(const Instruction *I);
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// 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.
|
2010-04-15 01:51:59 +00:00
|
|
|
bool SelectOperator(const User *I, unsigned Opcode);
|
2008-09-05 18:18:20 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Create a virtual register and arrange for it to be assigned the value for
|
|
|
|
/// the given LLVM value.
|
2010-04-15 01:51:59 +00:00
|
|
|
unsigned getRegForValue(const Value *V);
|
2008-08-28 23:21:34 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// 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.
|
2010-04-15 01:51:59 +00:00
|
|
|
unsigned lookUpRegForValue(const Value *V);
|
2008-09-09 01:26:59 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// This is a wrapper around getRegForValue that also takes care of truncating
|
|
|
|
/// or sign-extending the given getelementptr index value.
|
2010-05-11 23:54:07 +00:00
|
|
|
std::pair<unsigned, bool> getRegForGEPIndex(const Value *V);
|
2008-12-08 07:57:47 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// \brief We're checking to see if we can fold \p LI into \p FoldInst. Note
|
|
|
|
/// that we could have a sequence where multiple LLVM IR instructions are
|
|
|
|
/// folded into the same machineinstr. For example we could have:
|
|
|
|
///
|
2013-04-19 22:29:18 +00:00
|
|
|
/// A: x = load i32 *P
|
|
|
|
/// B: y = icmp A, 42
|
|
|
|
/// C: br y, ...
|
|
|
|
///
|
2013-07-09 20:08:46 +00:00
|
|
|
/// In this scenario, \p LI is "A", and \p FoldInst is "C". We know about "B"
|
|
|
|
/// (and any other folded instructions) because it is between A and C.
|
2013-04-19 22:29:18 +00:00
|
|
|
///
|
|
|
|
/// If we succeed folding, return true.
|
|
|
|
bool tryToFoldLoad(const LoadInst *LI, const Instruction *FoldInst);
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// \brief The specified machine instr operand is a vreg, and that vreg is
|
|
|
|
/// being provided by the specified load instruction. If possible, try to
|
|
|
|
/// fold the load as an operand to the instruction, returning true if
|
implement rdar://6653118 - fastisel should fold loads where possible.
Since mem2reg isn't run at -O0, we get a ton of reloads from the stack,
for example, before, this code:
int foo(int x, int y, int z) {
return x+y+z;
}
used to compile into:
_foo: ## @foo
subq $12, %rsp
movl %edi, 8(%rsp)
movl %esi, 4(%rsp)
movl %edx, (%rsp)
movl 8(%rsp), %edx
movl 4(%rsp), %esi
addl %edx, %esi
movl (%rsp), %edx
addl %esi, %edx
movl %edx, %eax
addq $12, %rsp
ret
Now we produce:
_foo: ## @foo
subq $12, %rsp
movl %edi, 8(%rsp)
movl %esi, 4(%rsp)
movl %edx, (%rsp)
movl 8(%rsp), %edx
addl 4(%rsp), %edx ## Folded load
addl (%rsp), %edx ## Folded load
movl %edx, %eax
addq $12, %rsp
ret
Fewer instructions and less register use = faster compiles.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113102 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-05 02:18:34 +00:00
|
|
|
/// possible.
|
2013-07-09 20:08:46 +00:00
|
|
|
///
|
2013-04-19 22:29:18 +00:00
|
|
|
/// This method should be implemented by targets.
|
|
|
|
virtual bool tryToFoldLoadIntoMI(MachineInstr * /*MI*/, unsigned /*OpNo*/,
|
|
|
|
const LoadInst * /*LI*/) {
|
implement rdar://6653118 - fastisel should fold loads where possible.
Since mem2reg isn't run at -O0, we get a ton of reloads from the stack,
for example, before, this code:
int foo(int x, int y, int z) {
return x+y+z;
}
used to compile into:
_foo: ## @foo
subq $12, %rsp
movl %edi, 8(%rsp)
movl %esi, 4(%rsp)
movl %edx, (%rsp)
movl 8(%rsp), %edx
movl 4(%rsp), %esi
addl %edx, %esi
movl (%rsp), %edx
addl %esi, %edx
movl %edx, %eax
addq $12, %rsp
ret
Now we produce:
_foo: ## @foo
subq $12, %rsp
movl %edi, 8(%rsp)
movl %esi, 4(%rsp)
movl %edx, (%rsp)
movl 8(%rsp), %edx
addl 4(%rsp), %edx ## Folded load
addl (%rsp), %edx ## Folded load
movl %edx, %eax
addq $12, %rsp
ret
Fewer instructions and less register use = faster compiles.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113102 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-05 02:18:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-11 21:33:55 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Reset InsertPt to prepare for inserting instructions into the current
|
|
|
|
/// block.
|
2010-07-10 09:00:22 +00:00
|
|
|
void recomputeInsertPt();
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Remove all dead instructions between the I and E.
|
2012-12-11 00:18:02 +00:00
|
|
|
void removeDeadCode(MachineBasicBlock::iterator I,
|
|
|
|
MachineBasicBlock::iterator E);
|
|
|
|
|
2012-10-03 08:10:01 +00:00
|
|
|
struct SavePoint {
|
|
|
|
MachineBasicBlock::iterator InsertPt;
|
|
|
|
DebugLoc DL;
|
|
|
|
};
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Prepare InsertPt to begin inserting instructions into the local value area
|
|
|
|
/// and return the old insert position.
|
2012-10-03 08:10:01 +00:00
|
|
|
SavePoint enterLocalValueArea();
|
2010-07-10 09:00:22 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Reset InsertPt to the given old insert position.
|
2012-10-03 08:10:01 +00:00
|
|
|
void leaveLocalValueArea(SavePoint Old);
|
2010-07-10 09:00:22 +00:00
|
|
|
|
2008-08-20 00:56:17 +00:00
|
|
|
virtual ~FastISel();
|
|
|
|
|
2008-08-13 20:19:35 +00:00
|
|
|
protected:
|
2012-08-03 04:06:28 +00:00
|
|
|
explicit FastISel(FunctionLoweringInfo &funcInfo,
|
|
|
|
const TargetLibraryInfo *libInfo);
|
2008-08-14 21:51:29 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// 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.
|
2009-12-05 01:27:58 +00:00
|
|
|
virtual bool
|
2010-04-15 01:51:59 +00:00
|
|
|
TargetSelectInstruction(const Instruction *I) = 0;
|
2013-02-11 01:27:15 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// This method is called by target-independent code to do target specific
|
|
|
|
/// argument lowering. It returns true if it was successful.
|
2013-02-11 01:27:15 +00:00
|
|
|
virtual bool FastLowerArguments();
|
2009-12-05 01:27:58 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// This method is called by target-independent code to request that an
|
|
|
|
/// instruction with the given type and opcode be emitted.
|
2009-08-11 20:47:22 +00:00
|
|
|
virtual unsigned FastEmit_(MVT VT,
|
|
|
|
MVT RetVT,
|
2010-01-05 22:26:32 +00:00
|
|
|
unsigned Opcode);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// This method is called by target-independent code to request that an
|
|
|
|
/// instruction with the given type, opcode, and register operand be emitted.
|
2009-08-11 20:47:22 +00:00
|
|
|
virtual unsigned FastEmit_r(MVT VT,
|
|
|
|
MVT RetVT,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Opcode,
|
|
|
|
unsigned Op0, bool Op0IsKill);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// This method is called by target-independent code to request that an
|
|
|
|
/// instruction with the given type, opcode, and register operands be emitted.
|
2009-08-11 20:47:22 +00:00
|
|
|
virtual unsigned FastEmit_rr(MVT VT,
|
|
|
|
MVT RetVT,
|
2010-01-05 22:26:32 +00:00
|
|
|
unsigned Opcode,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill);
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// 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.
|
2009-08-11 20:47:22 +00:00
|
|
|
virtual unsigned FastEmit_ri(MVT VT,
|
|
|
|
MVT RetVT,
|
2010-01-05 22:26:32 +00:00
|
|
|
unsigned Opcode,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
uint64_t Imm);
|
2008-08-21 01:41:07 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// 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.
|
2009-08-11 20:47:22 +00:00
|
|
|
virtual unsigned FastEmit_rf(MVT VT,
|
|
|
|
MVT RetVT,
|
2010-01-05 22:26:32 +00:00
|
|
|
unsigned Opcode,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
const ConstantFP *FPImm);
|
2008-08-27 01:09:54 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// 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.
|
2009-08-11 20:47:22 +00:00
|
|
|
virtual unsigned FastEmit_rri(MVT VT,
|
|
|
|
MVT RetVT,
|
2010-01-05 22:26:32 +00:00
|
|
|
unsigned Opcode,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill,
|
|
|
|
uint64_t Imm);
|
2008-08-20 22:45:34 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// \brief 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.
|
2009-08-11 20:47:22 +00:00
|
|
|
unsigned FastEmit_ri_(MVT VT,
|
2010-01-05 22:26:32 +00:00
|
|
|
unsigned Opcode,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
uint64_t Imm, MVT ImmType);
|
2011-03-11 21:33:55 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// This method is called by target-independent code to request that an
|
|
|
|
/// instruction with the given type, opcode, and immediate operand be emitted.
|
2009-08-11 20:47:22 +00:00
|
|
|
virtual unsigned FastEmit_i(MVT VT,
|
|
|
|
MVT RetVT,
|
2010-01-05 22:26:32 +00:00
|
|
|
unsigned Opcode,
|
2008-08-25 20:20:32 +00:00
|
|
|
uint64_t Imm);
|
2008-08-20 22:45:34 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// 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.
|
2009-08-11 20:47:22 +00:00
|
|
|
virtual unsigned FastEmit_f(MVT VT,
|
|
|
|
MVT RetVT,
|
2010-01-05 22:26:32 +00:00
|
|
|
unsigned Opcode,
|
2010-04-15 01:51:59 +00:00
|
|
|
const ConstantFP *FPImm);
|
2008-08-27 01:09:54 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// 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
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr with one register operand 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,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr with two register operands 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,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr with three register operands and a result register in
|
|
|
|
/// the given register class.
|
2011-05-05 17:59:04 +00:00
|
|
|
unsigned FastEmitInst_rrr(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill,
|
|
|
|
unsigned Op2, bool Op2IsKill);
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr with a register operand, an immediate, and a result
|
|
|
|
/// register in the given register class.
|
2008-08-21 01:41:07 +00:00
|
|
|
unsigned FastEmitInst_ri(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
uint64_t Imm);
|
2008-08-21 01:41:07 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr with one register operand and two immediate operands.
|
2011-03-11 21:33:55 +00:00
|
|
|
unsigned FastEmitInst_rii(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
uint64_t Imm1, uint64_t Imm2);
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr with two register operands and a result register in
|
|
|
|
/// the given register class.
|
2008-08-27 01:09:54 +00:00
|
|
|
unsigned FastEmitInst_rf(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
const ConstantFP *FPImm);
|
2008-08-27 01:09:54 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr with two register operands, an immediate, and a result
|
|
|
|
/// register in the given register class.
|
2008-08-21 01:41:07 +00:00
|
|
|
unsigned FastEmitInst_rri(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill,
|
|
|
|
uint64_t Imm);
|
2011-03-11 21:33:55 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr with two register operands, two immediates operands,
|
|
|
|
/// and a result register in the given register class.
|
2012-06-01 19:33:18 +00:00
|
|
|
unsigned FastEmitInst_rrii(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill,
|
|
|
|
uint64_t Imm1, uint64_t Imm2);
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr with a single immediate operand, and a result register
|
|
|
|
/// in the given register class.
|
2008-08-25 20:20:32 +00:00
|
|
|
unsigned FastEmitInst_i(unsigned MachineInstrOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
uint64_t Imm);
|
2011-04-22 23:38:06 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr with a two immediate operands.
|
2011-04-22 23:38:06 +00:00
|
|
|
unsigned FastEmitInst_ii(unsigned MachineInstrOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
uint64_t Imm1, uint64_t Imm2);
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a MachineInstr for an extract_subreg from a specified index of a
|
|
|
|
/// superregister to a specified type.
|
2009-08-11 20:47:22 +00:00
|
|
|
unsigned FastEmitInst_extractsubreg(MVT RetVT,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
uint32_t Idx);
|
2008-08-27 22:30:02 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit MachineInstrs to compute the value of Op with all but the least
|
|
|
|
/// significant bit set to zero.
|
2009-08-11 20:47:22 +00:00
|
|
|
unsigned FastEmitZExtFromI1(MVT VT,
|
2010-05-11 23:54:07 +00:00
|
|
|
unsigned Op0, bool Op0IsKill);
|
2009-03-13 20:42:20 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit an unconditional branch to the given block, unless it is the
|
|
|
|
/// immediate (fall-through) successor, and update the CFG.
|
2010-06-17 22:43:56 +00:00
|
|
|
void FastEmitBranch(MachineBasicBlock *MBB, DebugLoc DL);
|
2008-10-02 22:15:21 +00:00
|
|
|
|
2011-05-16 21:06:17 +00:00
|
|
|
void UpdateValueMap(const Value* I, unsigned Reg, unsigned NumRegs = 1);
|
2008-09-03 06:43:10 +00:00
|
|
|
|
2008-08-21 00:19:05 +00:00
|
|
|
unsigned createResultReg(const TargetRegisterClass *RC);
|
2011-03-11 21:33:55 +00:00
|
|
|
|
2014-04-15 13:59:49 +00:00
|
|
|
/// Try to constrain Op so that it is usable by argument OpNum of the provided
|
|
|
|
/// MCInstrDesc. If this fails, create a new virtual register in the correct
|
|
|
|
/// class and COPY the value there.
|
|
|
|
unsigned constrainOperandRegClass(const MCInstrDesc &II, unsigned Op,
|
|
|
|
unsigned OpNum);
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit a constant in a register using target-specific logic, such as
|
|
|
|
/// constant pool loads.
|
2010-04-15 01:51:59 +00:00
|
|
|
virtual unsigned TargetMaterializeConstant(const Constant* C) {
|
2008-09-10 20:11:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Emit an alloca address in a register using target-specific logic.
|
2010-04-15 01:51:59 +00:00
|
|
|
virtual unsigned TargetMaterializeAlloca(const AllocaInst* C) {
|
2008-09-05 00:06:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-08-21 00:19:05 +00:00
|
|
|
|
2011-04-27 22:41:55 +00:00
|
|
|
virtual unsigned TargetMaterializeFloatZero(const ConstantFP* CF) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-15 19:09:27 +00:00
|
|
|
/// \brief Check if \c Add is an add that can be safely folded into \c GEP.
|
|
|
|
///
|
|
|
|
/// \c Add can be folded into \c GEP if:
|
|
|
|
/// - \c Add is an add,
|
|
|
|
/// - \c Add's size matches \c GEP's,
|
|
|
|
/// - \c Add is in the same basic block as \c GEP, and
|
|
|
|
/// - \c Add has a constant operand.
|
|
|
|
bool canFoldAddIntoGEP(const User *GEP, const Value *Add);
|
|
|
|
|
2008-09-03 06:43:10 +00:00
|
|
|
private:
|
2010-04-15 01:51:59 +00:00
|
|
|
bool SelectBinaryOp(const User *I, unsigned ISDOpcode);
|
2008-08-20 00:11:48 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
bool SelectFNeg(const User *I);
|
2009-09-03 22:53:57 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
bool SelectGetElementPtr(const User *I);
|
2008-08-26 21:28:54 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
bool SelectCall(const User *I);
|
2008-09-25 17:05:24 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
bool SelectBitCast(const User *I);
|
2011-03-11 21:33:55 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
bool SelectCast(const User *I, unsigned Opcode);
|
2010-04-23 15:29:50 +00:00
|
|
|
|
2011-05-16 20:27:46 +00:00
|
|
|
bool SelectExtractValue(const User *I);
|
|
|
|
|
2011-12-09 20:09:54 +00:00
|
|
|
bool SelectInsertValue(const User *I);
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// \brief Handle PHI nodes in successor blocks.
|
|
|
|
///
|
2010-04-23 15:29:50 +00:00
|
|
|
/// Emit code to ensure constants are copied into registers when needed.
|
|
|
|
/// Remember the virtual registers that need to be added to the Machine PHI
|
2013-07-09 20:08:46 +00:00
|
|
|
/// nodes as input. We cannot just directly add them, because expansion might
|
|
|
|
/// result in multiple MBB's for one BB. As such, the start of the BB might
|
|
|
|
/// correspond to a different MBB than the end.
|
2010-04-23 15:29:50 +00:00
|
|
|
bool HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB);
|
2010-05-03 23:36:34 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Helper for getRegForVale. This function is called when the value isn't
|
|
|
|
/// already available in a register and must be materialized with new
|
|
|
|
/// instructions.
|
2010-05-03 23:36:34 +00:00
|
|
|
unsigned materializeRegForValue(const Value *V, MVT VT);
|
2010-05-11 23:54:07 +00:00
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Clears LocalValueMap and moves the area for the new local variables to the
|
|
|
|
/// beginning of the block. It helps to avoid spilling cached variables across
|
|
|
|
/// heavy instructions like calls.
|
2011-08-18 22:06:10 +00:00
|
|
|
void flushLocalValueMap();
|
|
|
|
|
2013-07-09 20:08:46 +00:00
|
|
|
/// Test whether the given value has exactly one use.
|
2010-05-11 23:54:07 +00:00
|
|
|
bool hasTrivialKill(const Value *V) const;
|
2008-08-13 20:19:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|