2008-05-14 10:17:11 +00:00
|
|
|
//==-llvm/CodeGen/DAGISelHeader.h - Common DAG ISel definitions -*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides definitions of the common, target-independent methods and
|
|
|
|
// data, which is used by SelectionDAG-based instruction selectors.
|
|
|
|
//
|
|
|
|
// *** NOTE: This file is #included into the middle of the target
|
2008-10-28 18:47:37 +00:00
|
|
|
// instruction selector class. These functions are really methods.
|
|
|
|
// This is a little awkward, but it allows this code to be shared
|
|
|
|
// by all the targets while still being able to call into
|
|
|
|
// target-specific code without using a virtual function call.
|
|
|
|
//
|
2008-05-14 10:17:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_DAGISEL_HEADER_H
|
|
|
|
#define LLVM_CODEGEN_DAGISEL_HEADER_H
|
|
|
|
|
Eliminate the ISel priority queue, which used the topological order for a
priority function. Instead, just iterate over the AllNodes list, which is
already in topological order. This eliminates a fair amount of bookkeeping,
and speeds up the isel phase by about 15% on many testcases.
The impact on most targets is that AddToISelQueue calls can be simply removed.
In the x86 target, there are two additional notable changes.
The rule-bending AND+SHIFT optimization in MatchAddress that creates new
pre-isel nodes during isel is now a little more verbose, but more robust.
Instead of either creating an invalid DAG or creating an invalid topological
sort, as it has historically done, it can now just insert the new nodes into
the node list at a position where they will be consistent with the topological
ordering.
Also, the address-matching code has logic that checked to see if a node was
"already selected". However, when a node is selected, it has all its uses
taken away via ReplaceAllUsesWith or equivalent, so it won't recieve any
further visits from MatchAddress. This code is now removed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-05 04:14:16 +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;
|
2008-05-14 10:17:11 +00:00
|
|
|
|
|
|
|
/// IsChainCompatible - Returns true if Chain is Op or Chain does
|
|
|
|
/// not reach Op.
|
|
|
|
static bool IsChainCompatible(SDNode *Chain, SDNode *Op) {
|
|
|
|
if (Chain->getOpcode() == ISD::EntryToken)
|
|
|
|
return true;
|
2009-01-28 18:03:09 +00:00
|
|
|
if (Chain->getOpcode() == ISD::TokenFactor)
|
2008-05-14 10:17:11 +00:00
|
|
|
return false;
|
2009-01-28 18:03:09 +00:00
|
|
|
if (Chain->getNumOperands() > 0) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue C0 = Chain->getOperand(0);
|
2009-08-11 20:47:22 +00:00
|
|
|
if (C0.getValueType() == MVT::Other)
|
2008-08-28 21:40:38 +00:00
|
|
|
return C0.getNode() != Op && IsChainCompatible(C0.getNode(), Op);
|
2008-05-14 10:17:11 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Eliminate the ISel priority queue, which used the topological order for a
priority function. Instead, just iterate over the AllNodes list, which is
already in topological order. This eliminates a fair amount of bookkeeping,
and speeds up the isel phase by about 15% on many testcases.
The impact on most targets is that AddToISelQueue calls can be simply removed.
In the x86 target, there are two additional notable changes.
The rule-bending AND+SHIFT optimization in MatchAddress that creates new
pre-isel nodes during isel is now a little more verbose, but more robust.
Instead of either creating an invalid DAG or creating an invalid topological
sort, as it has historically done, it can now just insert the new nodes into
the node list at a position where they will be consistent with the topological
ordering.
Also, the address-matching code has logic that checked to see if a node was
"already selected". However, when a node is selected, it has all its uses
taken away via ReplaceAllUsesWith or equivalent, so it won't recieve any
further visits from MatchAddress. This code is now removed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-05 04:14:16 +00:00
|
|
|
/// ISelUpdater - helper class to handle updates of the
|
|
|
|
/// instruciton selection graph.
|
|
|
|
class VISIBILITY_HIDDEN ISelUpdater : public SelectionDAG::DAGUpdateListener {
|
|
|
|
SelectionDAG::allnodes_iterator &ISelPosition;
|
|
|
|
public:
|
|
|
|
explicit ISelUpdater(SelectionDAG::allnodes_iterator &isp)
|
|
|
|
: ISelPosition(isp) {}
|
|
|
|
|
2008-11-05 17:13:57 +00:00
|
|
|
/// NodeDeleted - Handle nodes deleted from the graph. If the
|
|
|
|
/// node being deleted is the current ISelPosition node, update
|
|
|
|
/// ISelPosition.
|
|
|
|
///
|
Eliminate the ISel priority queue, which used the topological order for a
priority function. Instead, just iterate over the AllNodes list, which is
already in topological order. This eliminates a fair amount of bookkeeping,
and speeds up the isel phase by about 15% on many testcases.
The impact on most targets is that AddToISelQueue calls can be simply removed.
In the x86 target, there are two additional notable changes.
The rule-bending AND+SHIFT optimization in MatchAddress that creates new
pre-isel nodes during isel is now a little more verbose, but more robust.
Instead of either creating an invalid DAG or creating an invalid topological
sort, as it has historically done, it can now just insert the new nodes into
the node list at a position where they will be consistent with the topological
ordering.
Also, the address-matching code has logic that checked to see if a node was
"already selected". However, when a node is selected, it has all its uses
taken away via ReplaceAllUsesWith or equivalent, so it won't recieve any
further visits from MatchAddress. This code is now removed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-05 04:14:16 +00:00
|
|
|
virtual void NodeDeleted(SDNode *N, SDNode *E) {
|
|
|
|
if (ISelPosition == SelectionDAG::allnodes_iterator(N))
|
|
|
|
++ISelPosition;
|
2008-05-14 10:17:11 +00:00
|
|
|
}
|
|
|
|
|
Eliminate the ISel priority queue, which used the topological order for a
priority function. Instead, just iterate over the AllNodes list, which is
already in topological order. This eliminates a fair amount of bookkeeping,
and speeds up the isel phase by about 15% on many testcases.
The impact on most targets is that AddToISelQueue calls can be simply removed.
In the x86 target, there are two additional notable changes.
The rule-bending AND+SHIFT optimization in MatchAddress that creates new
pre-isel nodes during isel is now a little more verbose, but more robust.
Instead of either creating an invalid DAG or creating an invalid topological
sort, as it has historically done, it can now just insert the new nodes into
the node list at a position where they will be consistent with the topological
ordering.
Also, the address-matching code has logic that checked to see if a node was
"already selected". However, when a node is selected, it has all its uses
taken away via ReplaceAllUsesWith or equivalent, so it won't recieve any
further visits from MatchAddress. This code is now removed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-05 04:14:16 +00:00
|
|
|
/// NodeUpdated - Ignore updates for now.
|
|
|
|
virtual void NodeUpdated(SDNode *N) {}
|
|
|
|
};
|
2008-05-14 10:17:11 +00:00
|
|
|
|
|
|
|
/// ReplaceUses - replace all uses of the old node F with the use
|
|
|
|
/// of the new node T.
|
2009-11-14 16:37:18 +00:00
|
|
|
DISABLE_INLINE void ReplaceUses(SDValue F, SDValue T) {
|
Eliminate the ISel priority queue, which used the topological order for a
priority function. Instead, just iterate over the AllNodes list, which is
already in topological order. This eliminates a fair amount of bookkeeping,
and speeds up the isel phase by about 15% on many testcases.
The impact on most targets is that AddToISelQueue calls can be simply removed.
In the x86 target, there are two additional notable changes.
The rule-bending AND+SHIFT optimization in MatchAddress that creates new
pre-isel nodes during isel is now a little more verbose, but more robust.
Instead of either creating an invalid DAG or creating an invalid topological
sort, as it has historically done, it can now just insert the new nodes into
the node list at a position where they will be consistent with the topological
ordering.
Also, the address-matching code has logic that checked to see if a node was
"already selected". However, when a node is selected, it has all its uses
taken away via ReplaceAllUsesWith or equivalent, so it won't recieve any
further visits from MatchAddress. This code is now removed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-05 04:14:16 +00:00
|
|
|
ISelUpdater ISU(ISelPosition);
|
|
|
|
CurDAG->ReplaceAllUsesOfValueWith(F, T, &ISU);
|
2008-05-14 10:17:11 +00:00
|
|
|
}
|
|
|
|
|
2008-07-17 19:10:17 +00:00
|
|
|
/// ReplaceUses - replace all uses of the old nodes F with the use
|
|
|
|
/// of the new nodes T.
|
2009-11-14 16:37:18 +00:00
|
|
|
DISABLE_INLINE void ReplaceUses(const SDValue *F, const SDValue *T,
|
|
|
|
unsigned Num) {
|
Eliminate the ISel priority queue, which used the topological order for a
priority function. Instead, just iterate over the AllNodes list, which is
already in topological order. This eliminates a fair amount of bookkeeping,
and speeds up the isel phase by about 15% on many testcases.
The impact on most targets is that AddToISelQueue calls can be simply removed.
In the x86 target, there are two additional notable changes.
The rule-bending AND+SHIFT optimization in MatchAddress that creates new
pre-isel nodes during isel is now a little more verbose, but more robust.
Instead of either creating an invalid DAG or creating an invalid topological
sort, as it has historically done, it can now just insert the new nodes into
the node list at a position where they will be consistent with the topological
ordering.
Also, the address-matching code has logic that checked to see if a node was
"already selected". However, when a node is selected, it has all its uses
taken away via ReplaceAllUsesWith or equivalent, so it won't recieve any
further visits from MatchAddress. This code is now removed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-05 04:14:16 +00:00
|
|
|
ISelUpdater ISU(ISelPosition);
|
|
|
|
CurDAG->ReplaceAllUsesOfValuesWith(F, T, Num, &ISU);
|
2008-07-17 19:10:17 +00:00
|
|
|
}
|
|
|
|
|
2008-05-14 10:17:11 +00:00
|
|
|
/// ReplaceUses - replace all uses of the old node F with the use
|
|
|
|
/// of the new node T.
|
2009-11-14 16:37:18 +00:00
|
|
|
DISABLE_INLINE void ReplaceUses(SDNode *F, SDNode *T) {
|
Eliminate the ISel priority queue, which used the topological order for a
priority function. Instead, just iterate over the AllNodes list, which is
already in topological order. This eliminates a fair amount of bookkeeping,
and speeds up the isel phase by about 15% on many testcases.
The impact on most targets is that AddToISelQueue calls can be simply removed.
In the x86 target, there are two additional notable changes.
The rule-bending AND+SHIFT optimization in MatchAddress that creates new
pre-isel nodes during isel is now a little more verbose, but more robust.
Instead of either creating an invalid DAG or creating an invalid topological
sort, as it has historically done, it can now just insert the new nodes into
the node list at a position where they will be consistent with the topological
ordering.
Also, the address-matching code has logic that checked to see if a node was
"already selected". However, when a node is selected, it has all its uses
taken away via ReplaceAllUsesWith or equivalent, so it won't recieve any
further visits from MatchAddress. This code is now removed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-05 04:14:16 +00:00
|
|
|
ISelUpdater ISU(ISelPosition);
|
2009-04-15 20:06:30 +00:00
|
|
|
CurDAG->ReplaceAllUsesWith(F, T, &ISU);
|
2008-05-14 10:17:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// SelectRoot - Top level entry to DAG instruction selector.
|
|
|
|
/// Selects instructions starting at the root of the current DAG.
|
2008-10-27 21:56:29 +00:00
|
|
|
void SelectRoot(SelectionDAG &DAG) {
|
2008-05-14 10:17:11 +00:00
|
|
|
SelectRootInit();
|
|
|
|
|
|
|
|
// Create a dummy node (which is not added to allnodes), that adds
|
|
|
|
// a reference to the root node, preventing it from being deleted,
|
|
|
|
// and tracking any changes of the root.
|
|
|
|
HandleSDNode Dummy(CurDAG->getRoot());
|
2009-12-03 00:50:42 +00:00
|
|
|
ISelPosition = llvm::next(SelectionDAG::allnodes_iterator(CurDAG->getRoot().getNode()));
|
2008-05-14 10:17:11 +00:00
|
|
|
|
2008-11-05 17:13:57 +00:00
|
|
|
// The AllNodes list is now topological-sorted. Visit the
|
|
|
|
// nodes by starting at the end of the list (the root of the
|
|
|
|
// graph) and preceding back toward the beginning (the entry
|
|
|
|
// node).
|
Eliminate the ISel priority queue, which used the topological order for a
priority function. Instead, just iterate over the AllNodes list, which is
already in topological order. This eliminates a fair amount of bookkeeping,
and speeds up the isel phase by about 15% on many testcases.
The impact on most targets is that AddToISelQueue calls can be simply removed.
In the x86 target, there are two additional notable changes.
The rule-bending AND+SHIFT optimization in MatchAddress that creates new
pre-isel nodes during isel is now a little more verbose, but more robust.
Instead of either creating an invalid DAG or creating an invalid topological
sort, as it has historically done, it can now just insert the new nodes into
the node list at a position where they will be consistent with the topological
ordering.
Also, the address-matching code has logic that checked to see if a node was
"already selected". However, when a node is selected, it has all its uses
taken away via ReplaceAllUsesWith or equivalent, so it won't recieve any
further visits from MatchAddress. This code is now removed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-05 04:14:16 +00:00
|
|
|
while (ISelPosition != CurDAG->allnodes_begin()) {
|
|
|
|
SDNode *Node = --ISelPosition;
|
2008-11-05 22:56:47 +00:00
|
|
|
// Skip dead nodes. DAGCombiner is expected to eliminate all dead nodes,
|
|
|
|
// but there are currently some corner cases that it misses. Also, this
|
|
|
|
// makes it theoretically possible to disable the DAGCombiner.
|
|
|
|
if (Node->use_empty())
|
|
|
|
continue;
|
2008-10-31 16:12:56 +00:00
|
|
|
#if 0
|
2008-10-27 21:56:29 +00:00
|
|
|
DAG.setSubgraphColor(Node, "red");
|
2008-10-28 17:23:13 +00:00
|
|
|
#endif
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *ResNode = Select(Node);
|
2009-12-13 01:00:59 +00:00
|
|
|
// If node should not be replaced, continue with the next one.
|
2008-05-14 10:17:11 +00:00
|
|
|
if (ResNode == Node)
|
|
|
|
continue;
|
|
|
|
// Replace node.
|
2008-10-27 21:56:29 +00:00
|
|
|
if (ResNode) {
|
2008-10-31 16:12:56 +00:00
|
|
|
#if 0
|
2008-10-27 21:56:29 +00:00
|
|
|
DAG.setSubgraphColor(ResNode, "yellow");
|
|
|
|
DAG.setSubgraphColor(ResNode, "black");
|
2008-10-28 17:23:13 +00:00
|
|
|
#endif
|
2008-05-14 10:17:11 +00:00
|
|
|
ReplaceUses(Node, ResNode);
|
2008-10-27 21:56:29 +00:00
|
|
|
}
|
2008-05-14 10:17:11 +00:00
|
|
|
// If after the replacement this node is not used any more,
|
|
|
|
// remove this dead node.
|
|
|
|
if (Node->use_empty()) { // Don't delete EntryToken, etc.
|
Eliminate the ISel priority queue, which used the topological order for a
priority function. Instead, just iterate over the AllNodes list, which is
already in topological order. This eliminates a fair amount of bookkeeping,
and speeds up the isel phase by about 15% on many testcases.
The impact on most targets is that AddToISelQueue calls can be simply removed.
In the x86 target, there are two additional notable changes.
The rule-bending AND+SHIFT optimization in MatchAddress that creates new
pre-isel nodes during isel is now a little more verbose, but more robust.
Instead of either creating an invalid DAG or creating an invalid topological
sort, as it has historically done, it can now just insert the new nodes into
the node list at a position where they will be consistent with the topological
ordering.
Also, the address-matching code has logic that checked to see if a node was
"already selected". However, when a node is selected, it has all its uses
taken away via ReplaceAllUsesWith or equivalent, so it won't recieve any
further visits from MatchAddress. This code is now removed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-05 04:14:16 +00:00
|
|
|
ISelUpdater ISU(ISelPosition);
|
|
|
|
CurDAG->RemoveDeadNode(Node, &ISU);
|
2008-05-14 10:17:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-21 16:36:34 +00:00
|
|
|
CurDAG->setRoot(Dummy.getValue());
|
2008-05-14 10:17:11 +00:00
|
|
|
}
|
|
|
|
|
2010-02-15 08:04:42 +00:00
|
|
|
|
|
|
|
/// CheckInteger - Return true if the specified node is not a ConstantSDNode or
|
|
|
|
/// if it doesn't have the specified value.
|
|
|
|
static bool CheckInteger(SDValue V, int64_t Val) {
|
|
|
|
ConstantSDNode *C = dyn_cast<ConstantSDNode>(V);
|
|
|
|
return C == 0 || C->getSExtValue() != Val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CheckAndImmediate - Check to see if the specified node is an and with an
|
|
|
|
/// immediate returning true on failure.
|
|
|
|
///
|
|
|
|
/// FIXME: Inline this gunk into CheckAndMask.
|
|
|
|
bool CheckAndImmediate(SDValue V, int64_t Val) {
|
|
|
|
if (V->getOpcode() == ISD::AND)
|
|
|
|
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(V->getOperand(1)))
|
|
|
|
if (CheckAndMask(V.getOperand(0), C, Val))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CheckOrImmediate - Check to see if the specified node is an or with an
|
|
|
|
/// immediate returning true on failure.
|
|
|
|
///
|
|
|
|
/// FIXME: Inline this gunk into CheckOrMask.
|
|
|
|
bool CheckOrImmediate(SDValue V, int64_t Val) {
|
|
|
|
if (V->getOpcode() == ISD::OR)
|
|
|
|
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(V->getOperand(1)))
|
|
|
|
if (CheckOrMask(V.getOperand(0), C, Val))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-16 07:21:10 +00:00
|
|
|
// These functions are marked always inline so that Idx doesn't get pinned to
|
|
|
|
// the stack.
|
|
|
|
ALWAYS_INLINE static int8_t
|
|
|
|
GetInt1(const unsigned char *MatcherTable, unsigned &Idx) {
|
2010-02-15 08:04:42 +00:00
|
|
|
return MatcherTable[Idx++];
|
|
|
|
}
|
|
|
|
|
2010-02-16 07:21:10 +00:00
|
|
|
ALWAYS_INLINE static int16_t
|
|
|
|
GetInt2(const unsigned char *MatcherTable, unsigned &Idx) {
|
2010-02-15 08:04:42 +00:00
|
|
|
int16_t Val = GetInt1(MatcherTable, Idx);
|
|
|
|
Val |= int16_t(GetInt1(MatcherTable, Idx)) << 8;
|
|
|
|
return Val;
|
|
|
|
}
|
|
|
|
|
2010-02-16 07:21:10 +00:00
|
|
|
ALWAYS_INLINE static int32_t
|
|
|
|
GetInt4(const unsigned char *MatcherTable, unsigned &Idx) {
|
2010-02-15 08:04:42 +00:00
|
|
|
int32_t Val = GetInt2(MatcherTable, Idx);
|
|
|
|
Val |= int32_t(GetInt2(MatcherTable, Idx)) << 16;
|
|
|
|
return Val;
|
|
|
|
}
|
|
|
|
|
2010-02-16 07:21:10 +00:00
|
|
|
ALWAYS_INLINE static int64_t
|
|
|
|
GetInt8(const unsigned char *MatcherTable, unsigned &Idx) {
|
2010-02-15 08:04:42 +00:00
|
|
|
int64_t Val = GetInt4(MatcherTable, Idx);
|
|
|
|
Val |= int64_t(GetInt4(MatcherTable, Idx)) << 32;
|
|
|
|
return Val;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum BuiltinOpcodes {
|
|
|
|
OPC_Emit,
|
|
|
|
OPC_Push,
|
|
|
|
OPC_Record,
|
|
|
|
OPC_MoveChild,
|
|
|
|
OPC_MoveParent,
|
|
|
|
OPC_CheckSame,
|
|
|
|
OPC_CheckPatternPredicate,
|
|
|
|
OPC_CheckPredicate,
|
|
|
|
OPC_CheckOpcode,
|
|
|
|
OPC_CheckType,
|
|
|
|
OPC_CheckInteger1, OPC_CheckInteger2, OPC_CheckInteger4, OPC_CheckInteger8,
|
|
|
|
OPC_CheckCondCode,
|
|
|
|
OPC_CheckValueType,
|
|
|
|
OPC_CheckComplexPat,
|
|
|
|
OPC_CheckAndImm1, OPC_CheckAndImm2, OPC_CheckAndImm4, OPC_CheckAndImm8,
|
2010-02-16 06:10:58 +00:00
|
|
|
OPC_CheckOrImm1, OPC_CheckOrImm2, OPC_CheckOrImm4, OPC_CheckOrImm8,
|
2010-02-16 19:15:55 +00:00
|
|
|
OPC_CheckFoldableChainNode
|
2010-02-15 08:04:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MatchScope {
|
|
|
|
/// FailIndex - If this match fails, this is the index to continue with.
|
|
|
|
unsigned FailIndex;
|
|
|
|
|
|
|
|
/// NodeStackSize - The size of the node stack when the scope was formed.
|
|
|
|
unsigned NodeStackSize;
|
|
|
|
|
|
|
|
/// NumRecordedNodes - The number of recorded nodes when the scope was formed.
|
|
|
|
unsigned NumRecordedNodes;
|
|
|
|
};
|
|
|
|
|
|
|
|
SDNode *SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable,
|
|
|
|
unsigned TableSize) {
|
|
|
|
switch (NodeToMatch->getOpcode()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case ISD::EntryToken: // These nodes remain the same.
|
|
|
|
case ISD::BasicBlock:
|
|
|
|
case ISD::Register:
|
|
|
|
case ISD::HANDLENODE:
|
|
|
|
case ISD::TargetConstant:
|
|
|
|
case ISD::TargetConstantFP:
|
|
|
|
case ISD::TargetConstantPool:
|
|
|
|
case ISD::TargetFrameIndex:
|
|
|
|
case ISD::TargetExternalSymbol:
|
|
|
|
case ISD::TargetBlockAddress:
|
|
|
|
case ISD::TargetJumpTable:
|
|
|
|
case ISD::TargetGlobalTLSAddress:
|
|
|
|
case ISD::TargetGlobalAddress:
|
|
|
|
case ISD::TokenFactor:
|
|
|
|
case ISD::CopyFromReg:
|
|
|
|
case ISD::CopyToReg:
|
|
|
|
return 0;
|
|
|
|
case ISD::AssertSext:
|
|
|
|
case ISD::AssertZext:
|
|
|
|
ReplaceUses(SDValue(NodeToMatch, 0), NodeToMatch->getOperand(0));
|
|
|
|
return 0;
|
|
|
|
case ISD::INLINEASM: return Select_INLINEASM(NodeToMatch);
|
|
|
|
case ISD::EH_LABEL: return Select_EH_LABEL(NodeToMatch);
|
|
|
|
case ISD::UNDEF: return Select_UNDEF(NodeToMatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!NodeToMatch->isMachineOpcode() && "Node already selected!");
|
|
|
|
|
|
|
|
SmallVector<MatchScope, 8> MatchScopes;
|
|
|
|
|
|
|
|
// RecordedNodes - This is the set of nodes that have been recorded by the
|
|
|
|
// state machine.
|
|
|
|
SmallVector<SDValue, 8> RecordedNodes;
|
|
|
|
|
|
|
|
// Set up the node stack with NodeToMatch as the only node on the stack.
|
|
|
|
SmallVector<SDValue, 8> NodeStack;
|
|
|
|
SDValue N = SDValue(NodeToMatch, 0);
|
|
|
|
NodeStack.push_back(N);
|
|
|
|
|
|
|
|
// Interpreter starts at opcode #0.
|
|
|
|
unsigned MatcherIndex = 0;
|
|
|
|
while (1) {
|
|
|
|
assert(MatcherIndex < TableSize && "Invalid index");
|
|
|
|
switch ((BuiltinOpcodes)MatcherTable[MatcherIndex++]) {
|
|
|
|
case OPC_Emit: {
|
|
|
|
errs() << "EMIT NODE\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case OPC_Push: {
|
|
|
|
unsigned NumToSkip = MatcherTable[MatcherIndex++];
|
|
|
|
MatchScope NewEntry;
|
|
|
|
NewEntry.FailIndex = MatcherIndex+NumToSkip;
|
|
|
|
NewEntry.NodeStackSize = NodeStack.size();
|
|
|
|
NewEntry.NumRecordedNodes = RecordedNodes.size();
|
|
|
|
MatchScopes.push_back(NewEntry);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case OPC_Record:
|
|
|
|
// Remember this node, it may end up being an operand in the pattern.
|
|
|
|
RecordedNodes.push_back(N);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OPC_MoveChild: {
|
|
|
|
unsigned Child = MatcherTable[MatcherIndex++];
|
|
|
|
if (Child >= N.getNumOperands())
|
|
|
|
break; // Match fails if out of range child #.
|
|
|
|
N = N.getOperand(Child);
|
|
|
|
NodeStack.push_back(N);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OPC_MoveParent:
|
|
|
|
// Pop the current node off the NodeStack.
|
|
|
|
NodeStack.pop_back();
|
|
|
|
assert(!NodeStack.empty() && "Node stack imbalance!");
|
|
|
|
N = NodeStack.back();
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OPC_CheckSame: {
|
|
|
|
// Accept if it is exactly the same as a previously recorded node.
|
|
|
|
unsigned RecNo = MatcherTable[MatcherIndex++];
|
|
|
|
assert(RecNo < RecordedNodes.size() && "Invalid CheckSame");
|
|
|
|
if (N != RecordedNodes[RecNo]) break;
|
|
|
|
continue;
|
|
|
|
}
|
2010-02-16 07:21:10 +00:00
|
|
|
case OPC_CheckPatternPredicate:
|
|
|
|
if (!CheckPatternPredicate(MatcherTable[MatcherIndex++])) break;
|
2010-02-15 08:04:42 +00:00
|
|
|
continue;
|
2010-02-16 07:21:10 +00:00
|
|
|
case OPC_CheckPredicate:
|
|
|
|
if (!CheckNodePredicate(N.getNode(), MatcherTable[MatcherIndex++])) break;
|
2010-02-15 08:04:42 +00:00
|
|
|
continue;
|
2010-02-17 00:41:34 +00:00
|
|
|
case OPC_CheckComplexPat:
|
|
|
|
if (!CheckComplexPattern(NodeToMatch, N,
|
|
|
|
MatcherTable[MatcherIndex++], RecordedNodes))
|
|
|
|
break;
|
2010-02-15 08:04:42 +00:00
|
|
|
continue;
|
|
|
|
case OPC_CheckOpcode:
|
|
|
|
if (N->getOpcode() != MatcherTable[MatcherIndex++]) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckType:
|
|
|
|
if (N.getValueType() !=
|
|
|
|
(MVT::SimpleValueType)MatcherTable[MatcherIndex++]) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckCondCode:
|
|
|
|
if (cast<CondCodeSDNode>(N)->get() !=
|
|
|
|
(ISD::CondCode)MatcherTable[MatcherIndex++]) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckValueType:
|
|
|
|
if (cast<VTSDNode>(N)->getVT() !=
|
|
|
|
(MVT::SimpleValueType)MatcherTable[MatcherIndex++]) break;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OPC_CheckInteger1:
|
|
|
|
if (CheckInteger(N, GetInt1(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckInteger2:
|
|
|
|
if (CheckInteger(N, GetInt2(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckInteger4:
|
|
|
|
if (CheckInteger(N, GetInt4(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckInteger8:
|
|
|
|
if (CheckInteger(N, GetInt8(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OPC_CheckAndImm1:
|
|
|
|
if (CheckAndImmediate(N, GetInt1(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckAndImm2:
|
|
|
|
if (CheckAndImmediate(N, GetInt2(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckAndImm4:
|
|
|
|
if (CheckAndImmediate(N, GetInt4(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckAndImm8:
|
|
|
|
if (CheckAndImmediate(N, GetInt8(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OPC_CheckOrImm1:
|
|
|
|
if (CheckOrImmediate(N, GetInt1(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckOrImm2:
|
|
|
|
if (CheckOrImmediate(N, GetInt2(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckOrImm4:
|
|
|
|
if (CheckOrImmediate(N, GetInt4(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
|
|
|
case OPC_CheckOrImm8:
|
|
|
|
if (CheckOrImmediate(N, GetInt8(MatcherTable, MatcherIndex))) break;
|
|
|
|
continue;
|
2010-02-16 06:10:58 +00:00
|
|
|
|
2010-02-16 19:15:55 +00:00
|
|
|
case OPC_CheckFoldableChainNode: {
|
2010-02-16 06:10:58 +00:00
|
|
|
assert(!NodeStack.size() == 1 && "No parent node");
|
2010-02-16 19:15:55 +00:00
|
|
|
// Verify that all intermediate nodes between the root and this one have
|
|
|
|
// a single use.
|
|
|
|
bool HasMultipleUses = false;
|
|
|
|
for (unsigned i = 1, e = NodeStack.size()-1; i != e; ++i)
|
|
|
|
if (!NodeStack[i].hasOneUse()) {
|
|
|
|
HasMultipleUses = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (HasMultipleUses) break;
|
|
|
|
|
|
|
|
// Check to see that the target thinks this is profitable to fold and that
|
|
|
|
// we can fold it without inducing cycles in the graph.
|
2010-02-16 06:10:58 +00:00
|
|
|
if (!IsProfitableToFold(N, NodeStack[NodeStack.size()-2].getNode(),
|
2010-02-16 19:15:55 +00:00
|
|
|
NodeToMatch) ||
|
|
|
|
!IsLegalToFold(N, NodeStack[NodeStack.size()-2].getNode(),
|
2010-02-16 06:10:58 +00:00
|
|
|
NodeToMatch))
|
|
|
|
break;
|
2010-02-16 19:15:55 +00:00
|
|
|
|
2010-02-16 06:10:58 +00:00
|
|
|
continue;
|
2010-02-15 08:04:42 +00:00
|
|
|
}
|
2010-02-16 19:15:55 +00:00
|
|
|
}
|
2010-02-15 08:04:42 +00:00
|
|
|
|
|
|
|
// If the code reached this point, then the match failed pop out to the next
|
|
|
|
// match scope.
|
|
|
|
if (MatchScopes.empty()) {
|
|
|
|
CannotYetSelect(NodeToMatch);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RecordedNodes.resize(MatchScopes.back().NumRecordedNodes);
|
|
|
|
NodeStack.resize(MatchScopes.back().NodeStackSize);
|
|
|
|
MatcherIndex = MatchScopes.back().FailIndex;
|
|
|
|
MatchScopes.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-14 10:17:11 +00:00
|
|
|
#endif /* LLVM_CODEGEN_DAGISEL_HEADER_H */
|