2005-01-07 07:46:03 +00:00
|
|
|
//===-- llvm/CodeGen/SelectionDAGISel.h - Common Base Class------*- C++ -*-===//
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2005-01-07 07:46:03 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2005-01-07 07:46:03 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the SelectionDAGISel class, which is used as the common
|
|
|
|
// base class for SelectionDAG-based instruction selectors.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_SELECTIONDAG_ISEL_H
|
|
|
|
#define LLVM_CODEGEN_SELECTIONDAG_ISEL_H
|
|
|
|
|
2008-08-23 02:25:05 +00:00
|
|
|
#include "llvm/BasicBlock.h"
|
2005-01-07 07:46:03 +00:00
|
|
|
#include "llvm/Pass.h"
|
2006-08-07 22:16:08 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2009-07-31 18:16:33 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2005-01-07 07:46:03 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2008-09-03 23:12:08 +00:00
|
|
|
class FastISel;
|
2009-11-23 18:04:58 +00:00
|
|
|
class SelectionDAGBuilder;
|
2008-07-27 21:46:04 +00:00
|
|
|
class SDValue;
|
2007-12-31 04:13:23 +00:00
|
|
|
class MachineRegisterInfo;
|
2005-01-07 07:46:03 +00:00
|
|
|
class MachineBasicBlock;
|
|
|
|
class MachineFunction;
|
|
|
|
class MachineInstr;
|
|
|
|
class TargetLowering;
|
2008-10-14 23:54:11 +00:00
|
|
|
class TargetInstrInfo;
|
2005-01-07 07:46:03 +00:00
|
|
|
class FunctionLoweringInfo;
|
2009-01-15 22:18:12 +00:00
|
|
|
class ScheduleHazardRecognizer;
|
2008-08-17 18:44:35 +00:00
|
|
|
class GCFunctionInfo;
|
2009-02-11 04:27:20 +00:00
|
|
|
class ScheduleDAGSDNodes;
|
2007-03-07 16:25:09 +00:00
|
|
|
|
2005-01-07 07:46:03 +00:00
|
|
|
/// SelectionDAGISel - This is the common base class used for SelectionDAG-based
|
|
|
|
/// pattern-matching instruction selectors.
|
2009-07-31 18:16:33 +00:00
|
|
|
class SelectionDAGISel : public MachineFunctionPass {
|
2005-01-07 07:46:03 +00:00
|
|
|
public:
|
2009-01-15 19:20:50 +00:00
|
|
|
const TargetMachine &TM;
|
2010-04-17 15:26:15 +00:00
|
|
|
const TargetLowering &TLI;
|
2008-08-27 23:52:12 +00:00
|
|
|
FunctionLoweringInfo *FuncInfo;
|
2009-01-15 19:20:50 +00:00
|
|
|
MachineFunction *MF;
|
|
|
|
MachineRegisterInfo *RegInfo;
|
2005-01-07 07:46:03 +00:00
|
|
|
SelectionDAG *CurDAG;
|
2009-11-23 18:04:58 +00:00
|
|
|
SelectionDAGBuilder *SDB;
|
2007-08-27 16:26:13 +00:00
|
|
|
AliasAnalysis *AA;
|
2008-08-17 18:44:35 +00:00
|
|
|
GCFunctionInfo *GFI;
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OptLevel;
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2005-01-07 07:46:03 +00:00
|
|
|
|
2010-04-21 01:34:56 +00:00
|
|
|
explicit SelectionDAGISel(const TargetMachine &tm,
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OL = CodeGenOpt::Default);
|
2008-08-27 23:52:12 +00:00
|
|
|
virtual ~SelectionDAGISel();
|
2006-08-01 19:14:14 +00:00
|
|
|
|
2010-04-17 15:26:15 +00:00
|
|
|
const TargetLowering &getTargetLowering() { return TLI; }
|
2005-01-07 07:46:03 +00:00
|
|
|
|
2005-08-17 06:46:50 +00:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
2005-01-07 07:46:03 +00:00
|
|
|
|
2009-07-31 18:16:33 +00:00
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF);
|
2005-01-07 07:46:03 +00:00
|
|
|
|
2010-04-14 20:17:22 +00:00
|
|
|
virtual void EmitFunctionEntryCode() {}
|
2008-06-30 20:45:06 +00:00
|
|
|
|
2010-03-02 06:34:30 +00:00
|
|
|
/// PreprocessISelDAG - This hook allows targets to hack on the graph before
|
|
|
|
/// instruction selection starts.
|
|
|
|
virtual void PreprocessISelDAG() {}
|
|
|
|
|
|
|
|
/// PostprocessISelDAG() - This hook allows the target to hack on the graph
|
|
|
|
/// right after selection.
|
|
|
|
virtual void PostprocessISelDAG() {}
|
|
|
|
|
|
|
|
/// Select - Main hook targets implement to select a node.
|
|
|
|
virtual SDNode *Select(SDNode *N) = 0;
|
|
|
|
|
2006-02-24 02:12:52 +00:00
|
|
|
/// SelectInlineAsmMemoryOperand - Select the specified address as a target
|
|
|
|
/// addressing mode, according to the specified constraint code. If this does
|
|
|
|
/// not match or is not implemented, return true. The resultant operands
|
|
|
|
/// (which will appear in the machine instruction) should be added to the
|
|
|
|
/// OutOps vector.
|
2008-07-27 21:46:04 +00:00
|
|
|
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
|
2006-02-24 02:12:52 +00:00
|
|
|
char ConstraintCode,
|
2008-08-23 02:25:05 +00:00
|
|
|
std::vector<SDValue> &OutOps) {
|
2006-02-24 02:12:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
2006-07-27 06:36:49 +00:00
|
|
|
|
2010-02-15 19:41:07 +00:00
|
|
|
/// IsProfitableToFold - Returns true if it's profitable to fold the specific
|
|
|
|
/// operand node N of U during instruction selection that starts at Root.
|
|
|
|
virtual bool IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const;
|
|
|
|
|
|
|
|
/// IsLegalToFold - Returns true if the specific operand node N of
|
|
|
|
/// U can be folded during instruction selection that starts at Root.
|
2010-04-17 15:26:15 +00:00
|
|
|
/// FIXME: This is a static member function because the PIC16 target,
|
|
|
|
/// which uses it during lowering.
|
|
|
|
static bool IsLegalToFold(SDValue N, SDNode *U, SDNode *Root,
|
|
|
|
CodeGenOpt::Level OptLevel,
|
|
|
|
bool IgnoreChains = false);
|
2009-05-08 18:51:58 +00:00
|
|
|
|
2006-08-01 18:29:48 +00:00
|
|
|
/// CreateTargetHazardRecognizer - Return a newly allocated hazard recognizer
|
|
|
|
/// to use for this target when scheduling the DAG.
|
2009-01-15 22:18:12 +00:00
|
|
|
virtual ScheduleHazardRecognizer *CreateTargetHazardRecognizer();
|
2006-08-01 18:29:48 +00:00
|
|
|
|
2010-02-28 21:58:42 +00:00
|
|
|
|
|
|
|
// Opcodes used by the DAG state machine:
|
|
|
|
enum BuiltinOpcodes {
|
|
|
|
OPC_Scope,
|
|
|
|
OPC_RecordNode,
|
|
|
|
OPC_RecordChild0, OPC_RecordChild1, OPC_RecordChild2, OPC_RecordChild3,
|
|
|
|
OPC_RecordChild4, OPC_RecordChild5, OPC_RecordChild6, OPC_RecordChild7,
|
|
|
|
OPC_RecordMemRef,
|
|
|
|
OPC_CaptureFlagInput,
|
|
|
|
OPC_MoveChild,
|
|
|
|
OPC_MoveParent,
|
|
|
|
OPC_CheckSame,
|
|
|
|
OPC_CheckPatternPredicate,
|
|
|
|
OPC_CheckPredicate,
|
|
|
|
OPC_CheckOpcode,
|
2010-03-01 06:59:22 +00:00
|
|
|
OPC_SwitchOpcode,
|
2010-02-28 21:58:42 +00:00
|
|
|
OPC_CheckType,
|
2010-03-03 06:28:15 +00:00
|
|
|
OPC_SwitchType,
|
2010-02-28 21:58:42 +00:00
|
|
|
OPC_CheckChild0Type, OPC_CheckChild1Type, OPC_CheckChild2Type,
|
|
|
|
OPC_CheckChild3Type, OPC_CheckChild4Type, OPC_CheckChild5Type,
|
|
|
|
OPC_CheckChild6Type, OPC_CheckChild7Type,
|
2010-02-28 22:14:32 +00:00
|
|
|
OPC_CheckInteger,
|
2010-02-28 21:58:42 +00:00
|
|
|
OPC_CheckCondCode,
|
|
|
|
OPC_CheckValueType,
|
|
|
|
OPC_CheckComplexPat,
|
2010-02-28 22:14:32 +00:00
|
|
|
OPC_CheckAndImm, OPC_CheckOrImm,
|
2010-02-28 21:58:42 +00:00
|
|
|
OPC_CheckFoldableChainNode,
|
|
|
|
|
2010-02-28 22:14:32 +00:00
|
|
|
OPC_EmitInteger,
|
2010-02-28 21:58:42 +00:00
|
|
|
OPC_EmitRegister,
|
|
|
|
OPC_EmitConvertToTarget,
|
|
|
|
OPC_EmitMergeInputChains,
|
2010-03-28 05:50:16 +00:00
|
|
|
OPC_EmitMergeInputChains1_0,
|
|
|
|
OPC_EmitMergeInputChains1_1,
|
2010-02-28 21:58:42 +00:00
|
|
|
OPC_EmitCopyToReg,
|
|
|
|
OPC_EmitNodeXForm,
|
|
|
|
OPC_EmitNode,
|
|
|
|
OPC_MorphNodeTo,
|
|
|
|
OPC_MarkFlagResults,
|
|
|
|
OPC_CompleteMatch
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
OPFL_None = 0, // Node has no chain or flag input and isn't variadic.
|
|
|
|
OPFL_Chain = 1, // Node has a chain input.
|
|
|
|
OPFL_FlagInput = 2, // Node has a flag input.
|
|
|
|
OPFL_FlagOutput = 4, // Node has a flag output.
|
|
|
|
OPFL_MemRefs = 8, // Node gets accumulated MemRefs.
|
|
|
|
OPFL_Variadic0 = 1<<4, // Node is variadic, root has 0 fixed inputs.
|
|
|
|
OPFL_Variadic1 = 2<<4, // Node is variadic, root has 1 fixed inputs.
|
|
|
|
OPFL_Variadic2 = 3<<4, // Node is variadic, root has 2 fixed inputs.
|
|
|
|
OPFL_Variadic3 = 4<<4, // Node is variadic, root has 3 fixed inputs.
|
|
|
|
OPFL_Variadic4 = 5<<4, // Node is variadic, root has 4 fixed inputs.
|
|
|
|
OPFL_Variadic5 = 6<<4, // Node is variadic, root has 5 fixed inputs.
|
|
|
|
OPFL_Variadic6 = 7<<4, // Node is variadic, root has 6 fixed inputs.
|
|
|
|
|
|
|
|
OPFL_VariadicInfo = OPFL_Variadic6
|
|
|
|
};
|
|
|
|
|
2010-02-28 22:37:22 +00:00
|
|
|
/// getNumFixedFromVariadicInfo - Transform an EmitNode flags word into the
|
|
|
|
/// number of fixed arity values that should be skipped when copying from the
|
|
|
|
/// root.
|
|
|
|
static inline int getNumFixedFromVariadicInfo(unsigned Flags) {
|
|
|
|
return ((Flags&OPFL_VariadicInfo) >> 4)-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-18 18:44:33 +00:00
|
|
|
protected:
|
2008-07-01 18:49:06 +00:00
|
|
|
/// DAGSize - Size of DAG being instruction selected.
|
|
|
|
///
|
|
|
|
unsigned DAGSize;
|
2010-03-02 06:04:12 +00:00
|
|
|
|
|
|
|
/// ISelPosition - Node iterator marking the current position of
|
|
|
|
/// instruction selection as it procedes through the topologically-sorted
|
|
|
|
/// node list.
|
|
|
|
SelectionDAG::allnodes_iterator ISelPosition;
|
|
|
|
|
|
|
|
|
|
|
|
/// ISelUpdater - helper class to handle updates of the
|
|
|
|
/// instruction selection graph.
|
|
|
|
class ISelUpdater : public SelectionDAG::DAGUpdateListener {
|
|
|
|
SelectionDAG::allnodes_iterator &ISelPosition;
|
|
|
|
public:
|
|
|
|
explicit ISelUpdater(SelectionDAG::allnodes_iterator &isp)
|
|
|
|
: ISelPosition(isp) {}
|
|
|
|
|
|
|
|
/// NodeDeleted - Handle nodes deleted from the graph. If the
|
|
|
|
/// node being deleted is the current ISelPosition node, update
|
|
|
|
/// ISelPosition.
|
|
|
|
///
|
|
|
|
virtual void NodeDeleted(SDNode *N, SDNode *E) {
|
|
|
|
if (ISelPosition == SelectionDAG::allnodes_iterator(N))
|
|
|
|
++ISelPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// NodeUpdated - Ignore updates for now.
|
|
|
|
virtual void NodeUpdated(SDNode *N) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// ReplaceUses - replace all uses of the old node F with the use
|
|
|
|
/// of the new node T.
|
|
|
|
void ReplaceUses(SDValue F, SDValue T) {
|
|
|
|
ISelUpdater ISU(ISelPosition);
|
|
|
|
CurDAG->ReplaceAllUsesOfValueWith(F, T, &ISU);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ReplaceUses - replace all uses of the old nodes F with the use
|
|
|
|
/// of the new nodes T.
|
|
|
|
void ReplaceUses(const SDValue *F, const SDValue *T, unsigned Num) {
|
|
|
|
ISelUpdater ISU(ISelPosition);
|
|
|
|
CurDAG->ReplaceAllUsesOfValuesWith(F, T, Num, &ISU);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ReplaceUses - replace all uses of the old node F with the use
|
|
|
|
/// of the new node T.
|
|
|
|
void ReplaceUses(SDNode *F, SDNode *T) {
|
|
|
|
ISelUpdater ISU(ISelPosition);
|
|
|
|
CurDAG->ReplaceAllUsesWith(F, T, &ISU);
|
|
|
|
}
|
|
|
|
|
2008-07-01 18:49:06 +00:00
|
|
|
|
2006-02-24 02:12:52 +00:00
|
|
|
/// SelectInlineAsmMemoryOperands - Calls to this are automatically generated
|
|
|
|
/// by tblgen. Others should not call it.
|
2008-08-23 02:25:05 +00:00
|
|
|
void SelectInlineAsmMemoryOperands(std::vector<SDValue> &Ops);
|
2006-07-27 06:36:49 +00:00
|
|
|
|
2010-03-03 07:31:15 +00:00
|
|
|
|
|
|
|
public:
|
2006-10-11 03:58:02 +00:00
|
|
|
// Calls to these predicates are generated by tblgen.
|
2008-07-27 21:46:04 +00:00
|
|
|
bool CheckAndMask(SDValue LHS, ConstantSDNode *RHS,
|
2007-07-24 23:00:27 +00:00
|
|
|
int64_t DesiredMaskS) const;
|
2008-07-27 21:46:04 +00:00
|
|
|
bool CheckOrMask(SDValue LHS, ConstantSDNode *RHS,
|
2007-07-24 23:00:27 +00:00
|
|
|
int64_t DesiredMaskS) const;
|
2006-10-11 03:58:02 +00:00
|
|
|
|
2010-02-16 07:21:10 +00:00
|
|
|
|
|
|
|
/// CheckPatternPredicate - This function is generated by tblgen in the
|
|
|
|
/// target. It runs the specified pattern predicate and returns true if it
|
|
|
|
/// succeeds or false if it fails. The number is a private implementation
|
|
|
|
/// detail to the code tblgen produces.
|
|
|
|
virtual bool CheckPatternPredicate(unsigned PredNo) const {
|
|
|
|
assert(0 && "Tblgen should generate the implementation of this!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// CheckNodePredicate - This function is generated by tblgen in the target.
|
|
|
|
/// It runs node predicate number PredNo and returns true if it succeeds or
|
2010-02-16 07:21:10 +00:00
|
|
|
/// false if it fails. The number is a private implementation
|
|
|
|
/// detail to the code tblgen produces.
|
|
|
|
virtual bool CheckNodePredicate(SDNode *N, unsigned PredNo) const {
|
|
|
|
assert(0 && "Tblgen should generate the implementation of this!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-17 00:41:34 +00:00
|
|
|
virtual bool CheckComplexPattern(SDNode *Root, SDValue N, unsigned PatternNo,
|
|
|
|
SmallVectorImpl<SDValue> &Result) {
|
|
|
|
assert(0 && "Tblgen should generate the implementation of this!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-21 03:15:11 +00:00
|
|
|
virtual SDValue RunSDNodeXForm(SDValue V, unsigned XFormNo) {
|
|
|
|
assert(0 && "Tblgen shoudl generate this!");
|
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
|
2010-03-03 07:31:15 +00:00
|
|
|
SDNode *SelectCodeCommon(SDNode *NodeToMatch,
|
|
|
|
const unsigned char *MatcherTable,
|
|
|
|
unsigned TableSize);
|
|
|
|
|
|
|
|
private:
|
2010-02-21 03:15:11 +00:00
|
|
|
|
2009-10-29 22:30:23 +00:00
|
|
|
// Calls to these functions are generated by tblgen.
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *Select_INLINEASM(SDNode *N);
|
|
|
|
SDNode *Select_UNDEF(SDNode *N);
|
|
|
|
void CannotYetSelect(SDNode *N);
|
2009-10-29 22:30:23 +00:00
|
|
|
|
2005-01-17 17:14:43 +00:00
|
|
|
private:
|
2010-03-02 06:34:30 +00:00
|
|
|
void DoInstructionSelection();
|
2010-03-02 06:55:04 +00:00
|
|
|
SDNode *MorphNode(SDNode *Node, unsigned TargetOpc, SDVTList VTs,
|
|
|
|
const SDValue *Ops, unsigned NumOps, unsigned EmitNodeInfo);
|
2010-03-02 06:34:30 +00:00
|
|
|
|
2010-04-14 19:53:31 +00:00
|
|
|
void PrepareEHLandingPad(MachineBasicBlock *BB);
|
2010-04-15 01:51:59 +00:00
|
|
|
void SelectAllBasicBlocks(const Function &Fn);
|
2010-04-20 00:29:35 +00:00
|
|
|
void FinishBasicBlock(MachineBasicBlock *BB);
|
2005-04-21 20:39:54 +00:00
|
|
|
|
2010-04-20 00:29:35 +00:00
|
|
|
MachineBasicBlock *SelectBasicBlock(MachineBasicBlock *BB,
|
|
|
|
const BasicBlock *LLVMBB,
|
|
|
|
BasicBlock::const_iterator Begin,
|
|
|
|
BasicBlock::const_iterator End,
|
|
|
|
bool &HadTailCall);
|
|
|
|
MachineBasicBlock *CodeGenAndEmitDAG(MachineBasicBlock *BB);
|
2010-04-15 01:51:59 +00:00
|
|
|
void LowerArguments(const BasicBlock *BB);
|
2008-06-17 06:09:18 +00:00
|
|
|
|
2010-01-06 19:38:29 +00:00
|
|
|
void ShrinkDemandedOps();
|
2008-08-23 02:25:05 +00:00
|
|
|
void ComputeLiveOutVRegInfo();
|
|
|
|
|
2009-02-06 18:26:51 +00:00
|
|
|
/// Create the scheduler. If a specific scheduler was specified
|
|
|
|
/// via the SchedulerRegistry, use it, otherwise select the
|
|
|
|
/// one preferred by the target.
|
|
|
|
///
|
2009-02-11 04:27:20 +00:00
|
|
|
ScheduleDAGSDNodes *CreateScheduler();
|
2010-03-01 18:47:11 +00:00
|
|
|
|
|
|
|
/// OpcodeOffset - This is a cache used to dispatch efficiently into isel
|
|
|
|
/// state machines that start with a OPC_SwitchOpcode node.
|
|
|
|
std::vector<unsigned> OpcodeOffset;
|
2010-03-02 07:50:03 +00:00
|
|
|
|
|
|
|
void UpdateChainsAndFlags(SDNode *NodeToMatch, SDValue InputChain,
|
|
|
|
const SmallVectorImpl<SDNode*> &ChainNodesMatched,
|
|
|
|
SDValue InputFlag,const SmallVectorImpl<SDNode*> &F,
|
|
|
|
bool isMorphNodeTo);
|
|
|
|
|
2005-01-07 07:46:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LLVM_CODEGEN_SELECTIONDAG_ISEL_H */
|