2010-02-15 09:04:42 +01:00
|
|
|
//===- DAGISelMatcherGen.cpp - Matcher generator --------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DAGISelMatcher.h"
|
|
|
|
#include "CodeGenDAGPatterns.h"
|
2011-03-11 03:19:02 +01:00
|
|
|
#include "CodeGenRegisters.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2010-02-17 03:16:19 +01:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2010-02-15 09:04:42 +01:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2012-12-04 11:37:14 +01:00
|
|
|
#include "llvm/TableGen/Error.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
#include <utility>
|
2010-02-15 09:04:42 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2010-02-19 01:27:40 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
/// getRegisterValueType - Look up and return the ValueType of the specified
|
|
|
|
/// register. If the register is a member of multiple register classes which
|
|
|
|
/// have different associated types, return MVT::Other.
|
|
|
|
static MVT::SimpleValueType getRegisterValueType(Record *R,
|
|
|
|
const CodeGenTarget &T) {
|
|
|
|
bool FoundRC = false;
|
|
|
|
MVT::SimpleValueType VT = MVT::Other;
|
2011-06-15 06:50:36 +02:00
|
|
|
const CodeGenRegister *Reg = T.getRegBank().getReg(R);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2014-12-03 20:58:45 +01:00
|
|
|
for (const auto &RC : T.getRegBank().getRegClasses()) {
|
|
|
|
if (!RC.contains(Reg))
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
continue;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
if (!FoundRC) {
|
|
|
|
FoundRC = true;
|
2014-12-03 20:58:45 +01:00
|
|
|
VT = RC.getValueTypeNum(0);
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
continue;
|
|
|
|
}
|
2010-03-01 23:49:06 +01:00
|
|
|
|
|
|
|
// If this occurs in multiple register classes, they all have to agree.
|
2014-12-03 20:58:45 +01:00
|
|
|
assert(VT == RC.getValueTypeNum(0));
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
}
|
|
|
|
return VT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
2010-02-15 09:04:42 +01:00
|
|
|
class MatcherGen {
|
|
|
|
const PatternToMatch &Pattern;
|
|
|
|
const CodeGenDAGPatterns &CGP;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
/// PatWithNoTypes - This is a clone of Pattern.getSrcPattern() that starts
|
|
|
|
/// out with all of the types removed. This allows us to insert type checks
|
|
|
|
/// as we scan the tree.
|
|
|
|
TreePatternNode *PatWithNoTypes;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
/// VariableMap - A map from variable names ('$dst') to the recorded operand
|
|
|
|
/// number that they were captured as. These are biased by 1 to make
|
|
|
|
/// insertion easier.
|
|
|
|
StringMap<unsigned> VariableMap;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2014-05-20 13:52:46 +02:00
|
|
|
/// This maintains the recorded operand number that OPC_CheckComplexPattern
|
|
|
|
/// drops each sub-operand into. We don't want to insert these into
|
|
|
|
/// VariableMap because that leads to identity checking if they are
|
|
|
|
/// encountered multiple times. Biased by 1 like VariableMap for
|
|
|
|
/// consistency.
|
|
|
|
StringMap<unsigned> NamedComplexPatternOperands;
|
|
|
|
|
2010-02-19 01:27:40 +01:00
|
|
|
/// NextRecordedOperandNo - As we emit opcodes to record matched values in
|
|
|
|
/// the RecordedNodes array, this keeps track of which slot will be next to
|
|
|
|
/// record into.
|
2010-02-15 09:04:42 +01:00
|
|
|
unsigned NextRecordedOperandNo;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
/// MatchedChainNodes - This maintains the position in the recorded nodes
|
|
|
|
/// array of all of the recorded input nodes that have chains.
|
|
|
|
SmallVector<unsigned, 2> MatchedChainNodes;
|
2010-02-24 06:33:42 +01:00
|
|
|
|
2010-12-23 18:03:20 +01:00
|
|
|
/// MatchedGlueResultNodes - This maintains the position in the recorded
|
|
|
|
/// nodes array of all of the recorded input nodes that have glue results.
|
|
|
|
SmallVector<unsigned, 2> MatchedGlueResultNodes;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-04 02:23:08 +01:00
|
|
|
/// MatchedComplexPatterns - This maintains a list of all of the
|
2014-05-20 13:52:46 +02:00
|
|
|
/// ComplexPatterns that we need to check. The second element of each pair
|
|
|
|
/// is the recorded operand number of the input node.
|
2010-03-04 02:23:08 +01:00
|
|
|
SmallVector<std::pair<const TreePatternNode*,
|
|
|
|
unsigned>, 2> MatchedComplexPatterns;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
/// PhysRegInputs - List list has an entry for each explicitly specified
|
|
|
|
/// physreg input to the pattern. The first elt is the Register node, the
|
|
|
|
/// second is the recorded slot number the input pattern match saved it in.
|
|
|
|
SmallVector<std::pair<Record*, unsigned>, 2> PhysRegInputs;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-17 03:16:19 +01:00
|
|
|
/// Matcher - This is the top level of the generated matcher, the result.
|
2010-02-25 03:04:40 +01:00
|
|
|
Matcher *TheMatcher;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-17 03:16:19 +01:00
|
|
|
/// CurPredicate - As we emit matcher nodes, this points to the latest check
|
2010-02-18 03:53:41 +01:00
|
|
|
/// which should have future checks stuck into its Next position.
|
2010-02-25 03:04:40 +01:00
|
|
|
Matcher *CurPredicate;
|
2010-02-15 09:04:42 +01:00
|
|
|
public:
|
|
|
|
MatcherGen(const PatternToMatch &pattern, const CodeGenDAGPatterns &cgp);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
~MatcherGen() {
|
|
|
|
delete PatWithNoTypes;
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-01 08:17:40 +01:00
|
|
|
bool EmitMatcherCode(unsigned Variant);
|
2010-02-18 07:47:49 +01:00
|
|
|
void EmitResultCode();
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-25 03:04:40 +01:00
|
|
|
Matcher *GetMatcher() const { return TheMatcher; }
|
2010-02-15 09:04:42 +01:00
|
|
|
private:
|
2010-02-25 03:04:40 +01:00
|
|
|
void AddMatcher(Matcher *NewNode);
|
2010-02-15 09:04:42 +01:00
|
|
|
void InferPossibleTypes();
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-18 07:47:49 +01:00
|
|
|
// Matcher Generation.
|
2010-02-15 09:04:42 +01:00
|
|
|
void EmitMatchCode(const TreePatternNode *N, TreePatternNode *NodeNoTypes);
|
|
|
|
void EmitLeafMatchCode(const TreePatternNode *N);
|
|
|
|
void EmitOperatorMatchCode(const TreePatternNode *N,
|
|
|
|
TreePatternNode *NodeNoTypes);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2014-05-20 13:52:46 +02:00
|
|
|
/// If this is the first time a node with unique identifier Name has been
|
|
|
|
/// seen, record it. Otherwise, emit a check to make sure this is the same
|
|
|
|
/// node. Returns true if this is the first encounter.
|
|
|
|
bool recordUniqueNode(std::string Name);
|
|
|
|
|
2010-02-18 07:47:49 +01:00
|
|
|
// Result Code Generation.
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
unsigned getNamedArgumentSlot(StringRef Name) {
|
|
|
|
unsigned VarMapEntry = VariableMap[Name];
|
|
|
|
assert(VarMapEntry != 0 &&
|
|
|
|
"Variable referenced but not defined and not caught earlier!");
|
|
|
|
return VarMapEntry-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GetInstPatternNode - Get the pattern for an instruction.
|
|
|
|
const TreePatternNode *GetInstPatternNode(const DAGInstruction &Ins,
|
|
|
|
const TreePatternNode *N);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-18 07:47:49 +01:00
|
|
|
void EmitResultOperand(const TreePatternNode *N,
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
SmallVectorImpl<unsigned> &ResultOps);
|
|
|
|
void EmitResultOfNamedOperand(const TreePatternNode *N,
|
|
|
|
SmallVectorImpl<unsigned> &ResultOps);
|
2010-02-18 07:47:49 +01:00
|
|
|
void EmitResultLeafAsOperand(const TreePatternNode *N,
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
SmallVectorImpl<unsigned> &ResultOps);
|
2010-02-18 07:47:49 +01:00
|
|
|
void EmitResultInstructionAsOperand(const TreePatternNode *N,
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
SmallVectorImpl<unsigned> &ResultOps);
|
|
|
|
void EmitResultSDNodeXFormAsOperand(const TreePatternNode *N,
|
|
|
|
SmallVectorImpl<unsigned> &ResultOps);
|
|
|
|
};
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
} // end anon namespace.
|
|
|
|
|
|
|
|
MatcherGen::MatcherGen(const PatternToMatch &pattern,
|
|
|
|
const CodeGenDAGPatterns &cgp)
|
2010-02-19 01:33:13 +01:00
|
|
|
: Pattern(pattern), CGP(cgp), NextRecordedOperandNo(0),
|
2014-04-15 09:20:03 +02:00
|
|
|
TheMatcher(nullptr), CurPredicate(nullptr) {
|
2010-02-15 09:04:42 +01:00
|
|
|
// We need to produce the matcher tree for the patterns source pattern. To do
|
|
|
|
// this we need to match the structure as well as the types. To do the type
|
|
|
|
// matching, we want to figure out the fewest number of type checks we need to
|
|
|
|
// emit. For example, if there is only one integer type supported by a
|
|
|
|
// target, there should be no type comparisons at all for integer patterns!
|
|
|
|
//
|
|
|
|
// To figure out the fewest number of type checks needed, clone the pattern,
|
|
|
|
// remove the types, then perform type inference on the pattern as a whole.
|
|
|
|
// If there are unresolved types, emit an explicit check for those types,
|
|
|
|
// apply the type to the tree, then rerun type inference. Iterate until all
|
|
|
|
// types are resolved.
|
|
|
|
//
|
|
|
|
PatWithNoTypes = Pattern.getSrcPattern()->clone();
|
|
|
|
PatWithNoTypes->RemoveAllTypes();
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
// If there are types that are manifestly known, infer them.
|
|
|
|
InferPossibleTypes();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// InferPossibleTypes - As we emit the pattern, we end up generating type
|
|
|
|
/// checks and applying them to the 'PatWithNoTypes' tree. As we do this, we
|
|
|
|
/// want to propagate implied types as far throughout the tree as possible so
|
|
|
|
/// that we avoid doing redundant type checks. This does the type propagation.
|
|
|
|
void MatcherGen::InferPossibleTypes() {
|
|
|
|
// TP - Get *SOME* tree pattern, we don't care which. It is only used for
|
|
|
|
// diagnostics, which we know are impossible at this point.
|
|
|
|
TreePattern &TP = *CGP.pf_begin()->second;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2012-10-25 22:33:17 +02:00
|
|
|
bool MadeChange = true;
|
|
|
|
while (MadeChange)
|
|
|
|
MadeChange = PatWithNoTypes->ApplyTypeConstraints(TP,
|
|
|
|
true/*Ignore reg constraints*/);
|
2010-02-15 09:04:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 17:16:00 +01:00
|
|
|
/// AddMatcher - Add a matcher node to the current graph we're building.
|
2010-02-25 03:04:40 +01:00
|
|
|
void MatcherGen::AddMatcher(Matcher *NewNode) {
|
2014-04-15 09:20:03 +02:00
|
|
|
if (CurPredicate)
|
2010-02-18 03:53:41 +01:00
|
|
|
CurPredicate->setNext(NewNode);
|
2010-02-15 09:04:42 +01:00
|
|
|
else
|
2010-02-25 03:04:40 +01:00
|
|
|
TheMatcher = NewNode;
|
2010-02-15 09:04:42 +01:00
|
|
|
CurPredicate = NewNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-18 07:47:49 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pattern Match Generation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-02-15 09:04:42 +01:00
|
|
|
|
|
|
|
/// EmitLeafMatchCode - Generate matching code for leaf nodes.
|
|
|
|
void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
|
|
|
|
assert(N->isLeaf() && "Not a leaf?");
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
// Direct match against an integer constant.
|
2012-10-10 22:24:43 +02:00
|
|
|
if (IntInit *II = dyn_cast<IntInit>(N->getLeafValue())) {
|
2010-03-01 08:27:07 +01:00
|
|
|
// If this is the root of the dag we're matching, we emit a redundant opcode
|
|
|
|
// check to ensure that this gets folded into the normal top-level
|
|
|
|
// OpcodeSwitch.
|
|
|
|
if (N == Pattern.getSrcPattern()) {
|
|
|
|
const SDNodeInfo &NI = CGP.getSDNodeInfo(CGP.getSDNodeNamed("imm"));
|
|
|
|
AddMatcher(new CheckOpcodeMatcher(NI));
|
|
|
|
}
|
|
|
|
|
2010-02-25 03:04:40 +01:00
|
|
|
return AddMatcher(new CheckIntegerMatcher(II->getValue()));
|
2010-03-01 08:27:07 +01:00
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2013-03-24 20:37:00 +01:00
|
|
|
// An UnsetInit represents a named node without any constraints.
|
2015-04-22 04:09:45 +02:00
|
|
|
if (isa<UnsetInit>(N->getLeafValue())) {
|
2013-03-24 20:37:00 +01:00
|
|
|
assert(N->hasName() && "Unnamed ? leaf");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-10 22:24:43 +02:00
|
|
|
DefInit *DI = dyn_cast<DefInit>(N->getLeafValue());
|
2014-04-15 09:20:03 +02:00
|
|
|
if (!DI) {
|
2012-03-26 21:11:51 +02:00
|
|
|
errs() << "Unknown leaf kind: " << *N << "\n";
|
2010-02-15 09:04:42 +01:00
|
|
|
abort();
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
Record *LeafRec = DI->getDef();
|
2013-03-23 21:35:01 +01:00
|
|
|
|
|
|
|
// A ValueType leaf node can represent a register when named, or itself when
|
|
|
|
// unnamed.
|
|
|
|
if (LeafRec->isSubClassOf("ValueType")) {
|
|
|
|
// A named ValueType leaf always matches: (add i32:$a, i32:$b).
|
|
|
|
if (N->hasName())
|
|
|
|
return;
|
|
|
|
// An unnamed ValueType as in (sext_inreg GPR:$foo, i8).
|
|
|
|
return AddMatcher(new CheckValueTypeMatcher(LeafRec->getName()));
|
|
|
|
}
|
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
if (// Handle register references. Nothing to do here, they always match.
|
2010-12-21 17:16:00 +01:00
|
|
|
LeafRec->isSubClassOf("RegisterClass") ||
|
2011-06-27 23:06:21 +02:00
|
|
|
LeafRec->isSubClassOf("RegisterOperand") ||
|
2010-02-15 09:04:42 +01:00
|
|
|
LeafRec->isSubClassOf("PointerLikeRegClass") ||
|
2010-05-24 16:48:12 +02:00
|
|
|
LeafRec->isSubClassOf("SubRegIndex") ||
|
2010-02-15 09:04:42 +01:00
|
|
|
// Place holder for SRCVALUE nodes. Nothing to do here.
|
|
|
|
LeafRec->getName() == "srcvalue")
|
|
|
|
return;
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
|
|
|
|
// If we have a physreg reference like (mul gpr:$src, EAX) then we need to
|
2010-12-21 17:16:00 +01:00
|
|
|
// record the register
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
if (LeafRec->isSubClassOf("Register")) {
|
2010-03-01 03:24:17 +01:00
|
|
|
AddMatcher(new RecordMatcher("physreg input "+LeafRec->getName(),
|
|
|
|
NextRecordedOperandNo));
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
PhysRegInputs.push_back(std::make_pair(LeafRec, NextRecordedOperandNo++));
|
|
|
|
return;
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
if (LeafRec->isSubClassOf("CondCode"))
|
2010-02-25 03:04:40 +01:00
|
|
|
return AddMatcher(new CheckCondCodeMatcher(LeafRec->getName()));
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
if (LeafRec->isSubClassOf("ComplexPattern")) {
|
2010-02-17 01:11:30 +01:00
|
|
|
// We can't model ComplexPattern uses that don't have their name taken yet.
|
|
|
|
// The OPC_CheckComplexPattern operation implicitly records the results.
|
|
|
|
if (N->getName().empty()) {
|
2015-05-12 00:17:13 +02:00
|
|
|
std::string S;
|
|
|
|
raw_string_ostream OS(S);
|
|
|
|
OS << "We expect complex pattern uses to have names: " << *N;
|
|
|
|
PrintFatalError(OS.str());
|
2010-02-17 00:16:25 +01:00
|
|
|
}
|
2010-02-22 23:18:05 +01:00
|
|
|
|
2010-03-04 02:23:08 +01:00
|
|
|
// Remember this ComplexPattern so that we can emit it after all the other
|
|
|
|
// structural matches are done.
|
2014-05-20 13:52:46 +02:00
|
|
|
unsigned InputOperand = VariableMap[N->getName()] - 1;
|
|
|
|
MatchedComplexPatterns.push_back(std::make_pair(N, InputOperand));
|
2010-02-17 07:08:25 +01:00
|
|
|
return;
|
2010-02-15 09:04:42 +01:00
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
errs() << "Unknown leaf kind: " << *N << "\n";
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N,
|
|
|
|
TreePatternNode *NodeNoTypes) {
|
|
|
|
assert(!N->isLeaf() && "Not an operator?");
|
2014-05-20 13:52:46 +02:00
|
|
|
|
|
|
|
if (N->getOperator()->isSubClassOf("ComplexPattern")) {
|
|
|
|
// The "name" of a non-leaf complex pattern (MY_PAT $op1, $op2) is
|
|
|
|
// "MY_PAT:op1:op2". We should already have validated that the uses are
|
|
|
|
// consistent.
|
|
|
|
std::string PatternName = N->getOperator()->getName();
|
|
|
|
for (unsigned i = 0; i < N->getNumChildren(); ++i) {
|
|
|
|
PatternName += ":";
|
|
|
|
PatternName += N->getChild(i)->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recordUniqueNode(PatternName)) {
|
|
|
|
auto NodeAndOpNum = std::make_pair(N, NextRecordedOperandNo - 1);
|
|
|
|
MatchedComplexPatterns.push_back(NodeAndOpNum);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
const SDNodeInfo &CInfo = CGP.getSDNodeInfo(N->getOperator());
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
// If this is an 'and R, 1234' where the operation is AND/OR and the RHS is
|
|
|
|
// a constant without a predicate fn that has more that one bit set, handle
|
|
|
|
// this as a special case. This is usually for targets that have special
|
|
|
|
// handling of certain large constants (e.g. alpha with it's 8/16/32-bit
|
|
|
|
// handling stuff). Using these instructions is often far more efficient
|
|
|
|
// than materializing the constant. Unfortunately, both the instcombiner
|
|
|
|
// and the dag combiner can often infer that bits are dead, and thus drop
|
|
|
|
// them from the mask in the dag. For example, it might turn 'AND X, 255'
|
|
|
|
// into 'AND X, 254' if it knows the low bit is set. Emit code that checks
|
|
|
|
// to handle this.
|
2010-12-21 17:16:00 +01:00
|
|
|
if ((N->getOperator()->getName() == "and" ||
|
2010-02-15 09:04:42 +01:00
|
|
|
N->getOperator()->getName() == "or") &&
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
N->getChild(1)->isLeaf() && N->getChild(1)->getPredicateFns().empty() &&
|
|
|
|
N->getPredicateFns().empty()) {
|
2012-10-10 22:24:43 +02:00
|
|
|
if (IntInit *II = dyn_cast<IntInit>(N->getChild(1)->getLeafValue())) {
|
2010-02-15 09:04:42 +01:00
|
|
|
if (!isPowerOf2_32(II->getValue())) { // Don't bother with single bits.
|
2010-03-01 03:15:34 +01:00
|
|
|
// If this is at the root of the pattern, we emit a redundant
|
|
|
|
// CheckOpcode so that the following checks get factored properly under
|
|
|
|
// a single opcode check.
|
|
|
|
if (N == Pattern.getSrcPattern())
|
|
|
|
AddMatcher(new CheckOpcodeMatcher(CInfo));
|
|
|
|
|
|
|
|
// Emit the CheckAndImm/CheckOrImm node.
|
2010-02-15 09:04:42 +01:00
|
|
|
if (N->getOperator()->getName() == "and")
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new CheckAndImmMatcher(II->getValue()));
|
2010-02-15 09:04:42 +01:00
|
|
|
else
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new CheckOrImmMatcher(II->getValue()));
|
2010-02-15 09:04:42 +01:00
|
|
|
|
|
|
|
// Match the LHS of the AND as appropriate.
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new MoveChildMatcher(0));
|
2010-02-15 09:04:42 +01:00
|
|
|
EmitMatchCode(N->getChild(0), NodeNoTypes->getChild(0));
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new MoveParentMatcher());
|
2010-02-15 09:04:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
// Check that the current opcode lines up.
|
2010-02-27 22:48:43 +01:00
|
|
|
AddMatcher(new CheckOpcodeMatcher(CInfo));
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// If this node has memory references (i.e. is a load or store), tell the
|
|
|
|
// interpreter to capture them in the memref array.
|
|
|
|
if (N->NodeHasProperty(SDNPMemOperand, CGP))
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new RecordMemRefMatcher());
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
// If this node has a chain, then the chain is operand #0 is the SDNode, and
|
|
|
|
// the child numbers of the node are all offset by one.
|
|
|
|
unsigned OpNo = 0;
|
2010-02-16 20:19:58 +01:00
|
|
|
if (N->NodeHasProperty(SDNPHasChain, CGP)) {
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// Record the node and remember it in our chained nodes list.
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new RecordMatcher("'" + N->getOperator()->getName() +
|
2010-03-01 03:24:17 +01:00
|
|
|
"' chained node",
|
|
|
|
NextRecordedOperandNo));
|
2010-02-17 03:16:19 +01:00
|
|
|
// Remember all of the input chains our pattern will match.
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
MatchedChainNodes.push_back(NextRecordedOperandNo++);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-17 02:34:15 +01:00
|
|
|
// Don't look at the input chain when matching the tree pattern to the
|
|
|
|
// SDNode.
|
2010-02-15 09:04:42 +01:00
|
|
|
OpNo = 1;
|
|
|
|
|
2010-02-16 20:19:58 +01:00
|
|
|
// If this node is not the root and the subtree underneath it produces a
|
|
|
|
// chain, then the result of matching the node is also produce a chain.
|
|
|
|
// Beyond that, this means that we're also folding (at least) the root node
|
|
|
|
// into the node that produce the chain (for example, matching
|
|
|
|
// "(add reg, (load ptr))" as a add_with_memory on X86). This is
|
|
|
|
// problematic, if the 'reg' node also uses the load (say, its chain).
|
|
|
|
// Graphically:
|
|
|
|
//
|
|
|
|
// [LD]
|
|
|
|
// ^ ^
|
|
|
|
// | \ DAG's like cheese.
|
|
|
|
// / |
|
|
|
|
// / [YY]
|
|
|
|
// | ^
|
|
|
|
// [XX]--/
|
|
|
|
//
|
|
|
|
// It would be invalid to fold XX and LD. In this case, folding the two
|
|
|
|
// nodes together would induce a cycle in the DAG, making it a 'cyclic DAG'
|
|
|
|
// To prevent this, we emit a dynamic check for legality before allowing
|
|
|
|
// this to be folded.
|
|
|
|
//
|
|
|
|
const TreePatternNode *Root = Pattern.getSrcPattern();
|
|
|
|
if (N != Root) { // Not the root of the pattern.
|
2010-02-16 07:10:58 +01:00
|
|
|
// If there is a node between the root and this node, then we definitely
|
|
|
|
// need to emit the check.
|
|
|
|
bool NeedCheck = !Root->hasChild(N);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-16 07:10:58 +01:00
|
|
|
// If it *is* an immediate child of the root, we can still need a check if
|
|
|
|
// the root SDNode has multiple inputs. For us, this means that it is an
|
|
|
|
// intrinsic, has multiple operands, or has other inputs like chain or
|
2010-12-23 18:03:20 +01:00
|
|
|
// glue).
|
2010-02-16 07:10:58 +01:00
|
|
|
if (!NeedCheck) {
|
|
|
|
const SDNodeInfo &PInfo = CGP.getSDNodeInfo(Root->getOperator());
|
|
|
|
NeedCheck =
|
|
|
|
Root->getOperator() == CGP.get_intrinsic_void_sdnode() ||
|
|
|
|
Root->getOperator() == CGP.get_intrinsic_w_chain_sdnode() ||
|
|
|
|
Root->getOperator() == CGP.get_intrinsic_wo_chain_sdnode() ||
|
|
|
|
PInfo.getNumOperands() > 1 ||
|
|
|
|
PInfo.hasProperty(SDNPHasChain) ||
|
2010-12-23 19:28:41 +01:00
|
|
|
PInfo.hasProperty(SDNPInGlue) ||
|
|
|
|
PInfo.hasProperty(SDNPOptInGlue);
|
2010-02-16 07:10:58 +01:00
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-16 07:10:58 +01:00
|
|
|
if (NeedCheck)
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new CheckFoldableChainNodeMatcher());
|
2010-02-16 07:10:58 +01:00
|
|
|
}
|
2010-02-15 09:04:42 +01:00
|
|
|
}
|
2010-02-24 06:33:42 +01:00
|
|
|
|
2010-12-23 18:03:20 +01:00
|
|
|
// If this node has an output glue and isn't the root, remember it.
|
2010-12-23 19:28:41 +01:00
|
|
|
if (N->NodeHasProperty(SDNPOutGlue, CGP) &&
|
2010-02-24 06:33:42 +01:00
|
|
|
N != Pattern.getSrcPattern()) {
|
2010-12-23 18:03:20 +01:00
|
|
|
// TODO: This redundantly records nodes with both glues and chains.
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-24 06:33:42 +01:00
|
|
|
// Record the node and remember it in our chained nodes list.
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new RecordMatcher("'" + N->getOperator()->getName() +
|
2010-12-23 18:03:20 +01:00
|
|
|
"' glue output node",
|
2010-03-01 03:24:17 +01:00
|
|
|
NextRecordedOperandNo));
|
2010-12-23 18:03:20 +01:00
|
|
|
// Remember all of the nodes with output glue our pattern will match.
|
|
|
|
MatchedGlueResultNodes.push_back(NextRecordedOperandNo++);
|
2010-02-24 06:33:42 +01:00
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-12-23 18:03:20 +01:00
|
|
|
// If this node is known to have an input glue or if it *might* have an input
|
|
|
|
// glue, capture it as the glue input of the pattern.
|
2010-12-23 19:28:41 +01:00
|
|
|
if (N->NodeHasProperty(SDNPOptInGlue, CGP) ||
|
|
|
|
N->NodeHasProperty(SDNPInGlue, CGP))
|
2010-12-23 18:03:20 +01:00
|
|
|
AddMatcher(new CaptureGlueInputMatcher());
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i, ++OpNo) {
|
|
|
|
// Get the code suitable for matching this child. Move to the child, check
|
|
|
|
// it then move back to the parent.
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new MoveChildMatcher(OpNo));
|
2010-02-15 09:04:42 +01:00
|
|
|
EmitMatchCode(N->getChild(i), NodeNoTypes->getChild(i));
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new MoveParentMatcher());
|
2010-02-15 09:04:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-20 13:52:46 +02:00
|
|
|
bool MatcherGen::recordUniqueNode(std::string Name) {
|
|
|
|
unsigned &VarMapEntry = VariableMap[Name];
|
|
|
|
if (VarMapEntry == 0) {
|
|
|
|
// If it is a named node, we must emit a 'Record' opcode.
|
|
|
|
AddMatcher(new RecordMatcher("$" + Name, NextRecordedOperandNo));
|
|
|
|
VarMapEntry = ++NextRecordedOperandNo;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here, this is a second reference to a specific name. Since
|
|
|
|
// we already have checked that the first reference is valid, we don't
|
|
|
|
// have to recursively match it, just check that it's the same as the
|
|
|
|
// previously named thing.
|
|
|
|
AddMatcher(new CheckSameMatcher(VarMapEntry-1));
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-15 09:04:42 +01:00
|
|
|
|
|
|
|
void MatcherGen::EmitMatchCode(const TreePatternNode *N,
|
|
|
|
TreePatternNode *NodeNoTypes) {
|
|
|
|
// If N and NodeNoTypes don't agree on a type, then this is a case where we
|
2014-01-25 18:34:23 +01:00
|
|
|
// need to do a type check. Emit the check, apply the type to NodeNoTypes and
|
2010-02-15 09:04:42 +01:00
|
|
|
// reinfer any correlated types.
|
2010-03-24 01:41:19 +01:00
|
|
|
SmallVector<unsigned, 2> ResultsToTypeCheck;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-24 01:41:19 +01:00
|
|
|
for (unsigned i = 0, e = NodeNoTypes->getNumTypes(); i != e; ++i) {
|
|
|
|
if (NodeNoTypes->getExtType(i) == N->getExtType(i)) continue;
|
|
|
|
NodeNoTypes->setType(i, N->getExtType(i));
|
2010-02-15 09:04:42 +01:00
|
|
|
InferPossibleTypes();
|
2010-03-24 01:41:19 +01:00
|
|
|
ResultsToTypeCheck.push_back(i);
|
2010-02-15 09:04:42 +01:00
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
// If this node has a name associated with it, capture it in VariableMap. If
|
|
|
|
// we already saw this in the pattern, emit code to verify dagness.
|
2014-05-20 13:52:46 +02:00
|
|
|
if (!N->getName().empty())
|
|
|
|
if (!recordUniqueNode(N->getName()))
|
2010-02-15 09:04:42 +01:00
|
|
|
return;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
if (N->isLeaf())
|
|
|
|
EmitLeafMatchCode(N);
|
|
|
|
else
|
|
|
|
EmitOperatorMatchCode(N, NodeNoTypes);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-07 08:20:49 +01:00
|
|
|
// If there are node predicates for this node, generate their checks.
|
|
|
|
for (unsigned i = 0, e = N->getPredicateFns().size(); i != e; ++i)
|
|
|
|
AddMatcher(new CheckPredicateMatcher(N->getPredicateFns()[i]));
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-24 01:41:19 +01:00
|
|
|
for (unsigned i = 0, e = ResultsToTypeCheck.size(); i != e; ++i)
|
|
|
|
AddMatcher(new CheckTypeMatcher(N->getType(ResultsToTypeCheck[i]),
|
|
|
|
ResultsToTypeCheck[i]));
|
2010-02-15 09:04:42 +01:00
|
|
|
}
|
|
|
|
|
2010-03-01 08:17:40 +01:00
|
|
|
/// EmitMatcherCode - Generate the code that matches the predicate of this
|
|
|
|
/// pattern for the specified Variant. If the variant is invalid this returns
|
|
|
|
/// true and does not generate code, if it is valid, it returns false.
|
|
|
|
bool MatcherGen::EmitMatcherCode(unsigned Variant) {
|
|
|
|
// If the root of the pattern is a ComplexPattern and if it is specified to
|
|
|
|
// match some number of root opcodes, these are considered to be our variants.
|
|
|
|
// Depending on which variant we're generating code for, emit the root opcode
|
|
|
|
// check.
|
|
|
|
if (const ComplexPattern *CP =
|
|
|
|
Pattern.getSrcPattern()->getComplexPatternInfo(CGP)) {
|
|
|
|
const std::vector<Record*> &OpNodes = CP->getRootNodes();
|
2010-03-01 23:29:19 +01:00
|
|
|
assert(!OpNodes.empty() &&"Complex Pattern must specify what it can match");
|
|
|
|
if (Variant >= OpNodes.size()) return true;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-01 23:29:19 +01:00
|
|
|
AddMatcher(new CheckOpcodeMatcher(CGP.getSDNodeInfo(OpNodes[Variant])));
|
2010-03-01 08:17:40 +01:00
|
|
|
} else {
|
|
|
|
if (Variant != 0) return true;
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-04 02:25:36 +01:00
|
|
|
// Emit the matcher for the pattern structure and types.
|
|
|
|
EmitMatchCode(Pattern.getSrcPattern(), PatWithNoTypes);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
// If the pattern has a predicate on it (e.g. only enabled when a subtarget
|
|
|
|
// feature is around, do the check).
|
|
|
|
if (!Pattern.getPredicateCheck().empty())
|
2010-03-01 08:17:40 +01:00
|
|
|
AddMatcher(new CheckPatternPredicateMatcher(Pattern.getPredicateCheck()));
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-04 02:23:08 +01:00
|
|
|
// Now that we've completed the structural type match, emit any ComplexPattern
|
|
|
|
// checks (e.g. addrmode matches). We emit this after the structural match
|
|
|
|
// because they are generally more expensive to evaluate and more difficult to
|
|
|
|
// factor.
|
|
|
|
for (unsigned i = 0, e = MatchedComplexPatterns.size(); i != e; ++i) {
|
|
|
|
const TreePatternNode *N = MatchedComplexPatterns[i].first;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-04 02:23:08 +01:00
|
|
|
// Remember where the results of this match get stuck.
|
2014-05-20 13:52:46 +02:00
|
|
|
if (N->isLeaf()) {
|
|
|
|
NamedComplexPatternOperands[N->getName()] = NextRecordedOperandNo + 1;
|
|
|
|
} else {
|
|
|
|
unsigned CurOp = NextRecordedOperandNo;
|
|
|
|
for (unsigned i = 0; i < N->getNumChildren(); ++i) {
|
|
|
|
NamedComplexPatternOperands[N->getChild(i)->getName()] = CurOp + 1;
|
|
|
|
CurOp += N->getChild(i)->getNumMIResults(CGP);
|
|
|
|
}
|
|
|
|
}
|
2010-03-04 02:23:08 +01:00
|
|
|
|
|
|
|
// Get the slot we recorded the value in from the name on the node.
|
2014-05-20 13:52:46 +02:00
|
|
|
unsigned RecNodeEntry = MatchedComplexPatterns[i].second;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2014-05-20 13:52:46 +02:00
|
|
|
const ComplexPattern &CP = *N->getComplexPatternInfo(CGP);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-04 02:23:08 +01:00
|
|
|
// Emit a CheckComplexPat operation, which does the match (aborting if it
|
|
|
|
// fails) and pushes the matched operands onto the recorded nodes list.
|
|
|
|
AddMatcher(new CheckComplexPatMatcher(CP, RecNodeEntry,
|
|
|
|
N->getName(), NextRecordedOperandNo));
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-04 02:23:08 +01:00
|
|
|
// Record the right number of operands.
|
|
|
|
NextRecordedOperandNo += CP.getNumOperands();
|
|
|
|
if (CP.hasProperty(SDNPHasChain)) {
|
|
|
|
// If the complex pattern has a chain, then we need to keep track of the
|
|
|
|
// fact that we just recorded a chain input. The chain input will be
|
|
|
|
// matched as the last operand of the predicate if it was successful.
|
|
|
|
++NextRecordedOperandNo; // Chained node operand.
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-04 02:23:08 +01:00
|
|
|
// It is the last operand recorded.
|
|
|
|
assert(NextRecordedOperandNo > 1 &&
|
|
|
|
"Should have recorded input/result chains at least!");
|
|
|
|
MatchedChainNodes.push_back(NextRecordedOperandNo-1);
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-12-23 18:03:20 +01:00
|
|
|
// TODO: Complex patterns can't have output glues, if they did, we'd want
|
2010-03-04 02:23:08 +01:00
|
|
|
// to record them.
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-01 08:17:40 +01:00
|
|
|
return false;
|
2010-02-15 09:04:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-18 07:47:49 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Node Result Generation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
void MatcherGen::EmitResultOfNamedOperand(const TreePatternNode *N,
|
|
|
|
SmallVectorImpl<unsigned> &ResultOps){
|
|
|
|
assert(!N->getName().empty() && "Operand not named!");
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2014-05-20 13:52:46 +02:00
|
|
|
if (unsigned SlotNo = NamedComplexPatternOperands[N->getName()]) {
|
|
|
|
// Complex operands have already been completely selected, just find the
|
|
|
|
// right slot ant add the arguments directly.
|
|
|
|
for (unsigned i = 0; i < N->getNumMIResults(CGP); ++i)
|
|
|
|
ResultOps.push_back(SlotNo - 1 + i);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-04 02:23:08 +01:00
|
|
|
unsigned SlotNo = getNamedArgumentSlot(N->getName());
|
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// If this is an 'imm' or 'fpimm' node, make sure to convert it to the target
|
|
|
|
// version of the immediate so that it doesn't get selected due to some other
|
|
|
|
// node use.
|
|
|
|
if (!N->isLeaf()) {
|
|
|
|
StringRef OperatorName = N->getOperator()->getName();
|
|
|
|
if (OperatorName == "imm" || OperatorName == "fpimm") {
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new EmitConvertToTargetMatcher(SlotNo));
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
ResultOps.push_back(NextRecordedOperandNo++);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2014-05-20 13:52:46 +02:00
|
|
|
for (unsigned i = 0; i < N->getNumMIResults(CGP); ++i)
|
|
|
|
ResultOps.push_back(SlotNo + i);
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
}
|
|
|
|
|
2010-02-18 07:47:49 +01:00
|
|
|
void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N,
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
SmallVectorImpl<unsigned> &ResultOps) {
|
2010-02-18 23:03:03 +01:00
|
|
|
assert(N->isLeaf() && "Must be a leaf");
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2012-10-10 22:24:43 +02:00
|
|
|
if (IntInit *II = dyn_cast<IntInit>(N->getLeafValue())) {
|
2010-03-19 22:37:09 +01:00
|
|
|
AddMatcher(new EmitIntegerMatcher(II->getValue(), N->getType(0)));
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
ResultOps.push_back(NextRecordedOperandNo++);
|
2010-02-18 23:03:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-18 23:03:03 +01:00
|
|
|
// If this is an explicit register reference, handle it.
|
2012-10-10 22:24:43 +02:00
|
|
|
if (DefInit *DI = dyn_cast<DefInit>(N->getLeafValue())) {
|
2011-06-27 23:06:21 +02:00
|
|
|
Record *Def = DI->getDef();
|
|
|
|
if (Def->isSubClassOf("Register")) {
|
2011-06-18 06:26:06 +02:00
|
|
|
const CodeGenRegister *Reg =
|
2011-06-27 23:06:21 +02:00
|
|
|
CGP.getTargetInfo().getRegBank().getReg(Def);
|
2011-06-18 06:26:06 +02:00
|
|
|
AddMatcher(new EmitRegisterMatcher(Reg, N->getType(0)));
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
ResultOps.push_back(NextRecordedOperandNo++);
|
2010-02-18 23:03:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2011-06-27 23:06:21 +02:00
|
|
|
if (Def->getName() == "zero_reg") {
|
2014-04-15 09:20:03 +02:00
|
|
|
AddMatcher(new EmitRegisterMatcher(nullptr, N->getType(0)));
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
ResultOps.push_back(NextRecordedOperandNo++);
|
2010-02-18 23:03:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// Handle a reference to a register class. This is used
|
|
|
|
// in COPY_TO_SUBREG instructions.
|
2011-06-27 23:06:21 +02:00
|
|
|
if (Def->isSubClassOf("RegisterOperand"))
|
|
|
|
Def = Def->getValueAsDef("RegClass");
|
|
|
|
if (Def->isSubClassOf("RegisterClass")) {
|
|
|
|
std::string Value = getQualifiedName(Def) + "RegClassID";
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32));
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
ResultOps.push_back(NextRecordedOperandNo++);
|
|
|
|
return;
|
2010-02-18 23:03:03 +01:00
|
|
|
}
|
2010-05-24 16:48:12 +02:00
|
|
|
|
|
|
|
// Handle a subregister index. This is used for INSERT_SUBREG etc.
|
2011-06-27 23:06:21 +02:00
|
|
|
if (Def->isSubClassOf("SubRegIndex")) {
|
|
|
|
std::string Value = getQualifiedName(Def);
|
2010-05-24 16:48:12 +02:00
|
|
|
AddMatcher(new EmitStringIntegerMatcher(Value, MVT::i32));
|
|
|
|
ResultOps.push_back(NextRecordedOperandNo++);
|
|
|
|
return;
|
|
|
|
}
|
2010-02-18 23:03:03 +01:00
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-18 07:47:49 +01:00
|
|
|
errs() << "unhandled leaf node: \n";
|
|
|
|
N->dump();
|
|
|
|
}
|
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
/// GetInstPatternNode - Get the pattern for an instruction.
|
2010-12-21 17:16:00 +01:00
|
|
|
///
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
const TreePatternNode *MatcherGen::
|
|
|
|
GetInstPatternNode(const DAGInstruction &Inst, const TreePatternNode *N) {
|
|
|
|
const TreePattern *InstPat = Inst.getPattern();
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// FIXME2?: Assume actual pattern comes before "implicit".
|
|
|
|
TreePatternNode *InstPatNode;
|
|
|
|
if (InstPat)
|
|
|
|
InstPatNode = InstPat->getTree(0);
|
|
|
|
else if (/*isRoot*/ N == Pattern.getDstPattern())
|
|
|
|
InstPatNode = Pattern.getSrcPattern();
|
|
|
|
else
|
2014-04-15 09:20:03 +02:00
|
|
|
return nullptr;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
if (InstPatNode && !InstPatNode->isLeaf() &&
|
|
|
|
InstPatNode->getOperator()->getName() == "set")
|
|
|
|
InstPatNode = InstPatNode->getChild(InstPatNode->getNumChildren()-1);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
return InstPatNode;
|
|
|
|
}
|
|
|
|
|
2011-05-19 23:13:30 +02:00
|
|
|
static bool
|
|
|
|
mayInstNodeLoadOrStore(const TreePatternNode *N,
|
|
|
|
const CodeGenDAGPatterns &CGP) {
|
|
|
|
Record *Op = N->getOperator();
|
|
|
|
const CodeGenTarget &CGT = CGP.getTargetInfo();
|
|
|
|
CodeGenInstruction &II = CGT.getInstruction(Op);
|
|
|
|
return II.mayLoad || II.mayStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
|
|
|
numNodesThatMayLoadOrStore(const TreePatternNode *N,
|
|
|
|
const CodeGenDAGPatterns &CGP) {
|
|
|
|
if (N->isLeaf())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
Record *OpRec = N->getOperator();
|
|
|
|
if (!OpRec->isSubClassOf("Instruction"))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unsigned Count = 0;
|
|
|
|
if (mayInstNodeLoadOrStore(N, CGP))
|
|
|
|
++Count;
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
|
|
|
|
Count += numNodesThatMayLoadOrStore(N->getChild(i), CGP);
|
|
|
|
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
void MatcherGen::
|
|
|
|
EmitResultInstructionAsOperand(const TreePatternNode *N,
|
|
|
|
SmallVectorImpl<unsigned> &OutputOps) {
|
2010-02-18 07:47:49 +01:00
|
|
|
Record *Op = N->getOperator();
|
|
|
|
const CodeGenTarget &CGT = CGP.getTargetInfo();
|
2010-03-19 01:07:20 +01:00
|
|
|
CodeGenInstruction &II = CGT.getInstruction(Op);
|
2010-02-18 07:47:49 +01:00
|
|
|
const DAGInstruction &Inst = CGP.getInstruction(Op);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2014-11-03 00:46:47 +01:00
|
|
|
// If we can, get the pattern for the instruction we're generating. We derive
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// a variety of information from this pattern, such as whether it has a chain.
|
|
|
|
//
|
|
|
|
// FIXME2: This is extremely dubious for several reasons, not the least of
|
|
|
|
// which it gives special status to instructions with patterns that Pat<>
|
|
|
|
// nodes can't duplicate.
|
|
|
|
const TreePatternNode *InstPatNode = GetInstPatternNode(Inst, N);
|
|
|
|
|
2010-12-21 17:16:00 +01:00
|
|
|
// NodeHasChain - Whether the instruction node we're creating takes chains.
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
bool NodeHasChain = InstPatNode &&
|
|
|
|
InstPatNode->TreeHasProperty(SDNPHasChain, CGP);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2012-06-26 20:46:28 +02:00
|
|
|
// Instructions which load and store from memory should have a chain,
|
|
|
|
// regardless of whether they happen to have an internal pattern saying so.
|
|
|
|
if (Pattern.getSrcPattern()->TreeHasProperty(SDNPHasChain, CGP)
|
|
|
|
&& (II.hasCtrlDep || II.mayLoad || II.mayStore || II.canFoldAsLoad ||
|
|
|
|
II.hasSideEffects))
|
|
|
|
NodeHasChain = true;
|
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
bool isRoot = N == Pattern.getDstPattern();
|
|
|
|
|
2010-12-23 18:03:20 +01:00
|
|
|
// TreeHasOutGlue - True if this tree has glue.
|
|
|
|
bool TreeHasInGlue = false, TreeHasOutGlue = false;
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
if (isRoot) {
|
|
|
|
const TreePatternNode *SrcPat = Pattern.getSrcPattern();
|
2010-12-23 19:28:41 +01:00
|
|
|
TreeHasInGlue = SrcPat->TreeHasProperty(SDNPOptInGlue, CGP) ||
|
|
|
|
SrcPat->TreeHasProperty(SDNPInGlue, CGP);
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// FIXME2: this is checking the entire pattern, not just the node in
|
|
|
|
// question, doing this just for the root seems like a total hack.
|
2010-12-23 19:28:41 +01:00
|
|
|
TreeHasOutGlue = SrcPat->TreeHasProperty(SDNPOutGlue, CGP);
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NumResults - This is the number of results produced by the instruction in
|
|
|
|
// the "outs" list.
|
2010-12-21 17:16:00 +01:00
|
|
|
unsigned NumResults = Inst.getNumResults();
|
2010-02-18 07:47:49 +01:00
|
|
|
|
2014-11-03 00:46:51 +01:00
|
|
|
// Number of operands we know the output instruction must have. If it is
|
|
|
|
// variadic, we could have more operands.
|
|
|
|
unsigned NumFixedOperands = II.Operands.size();
|
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
SmallVector<unsigned, 8> InstOps;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2014-11-03 00:46:51 +01:00
|
|
|
// Loop over all of the fixed operands of the instruction pattern, emitting
|
|
|
|
// code to fill them all in. The node 'N' usually has number children equal to
|
|
|
|
// the number of input operands of the instruction. However, in cases where
|
|
|
|
// there are predicate operands for an instruction, we need to fill in the
|
|
|
|
// 'execute always' values. Match up the node operands to the instruction
|
|
|
|
// operands to do this.
|
|
|
|
unsigned ChildNo = 0;
|
|
|
|
for (unsigned InstOpNo = NumResults, e = NumFixedOperands;
|
|
|
|
InstOpNo != e; ++InstOpNo) {
|
2010-02-18 07:47:49 +01:00
|
|
|
// Determine what to emit for this operand.
|
2010-11-01 05:03:32 +01:00
|
|
|
Record *OperandNode = II.Operands[InstOpNo].Rec;
|
2012-09-06 16:15:52 +02:00
|
|
|
if (OperandNode->isSubClassOf("OperandWithDefaultOps") &&
|
2010-02-18 07:47:49 +01:00
|
|
|
!CGP.getDefaultOperand(OperandNode).DefaultOps.empty()) {
|
|
|
|
// This is a predicate or optional def operand; emit the
|
|
|
|
// 'default ops' operands.
|
2010-08-11 01:46:20 +02:00
|
|
|
const DAGDefaultOperand &DefaultOp
|
2010-12-21 17:16:00 +01:00
|
|
|
= CGP.getDefaultOperand(OperandNode);
|
2010-02-18 07:47:49 +01:00
|
|
|
for (unsigned i = 0, e = DefaultOp.DefaultOps.size(); i != e; ++i)
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
EmitResultOperand(DefaultOp.DefaultOps[i], InstOps);
|
2010-02-18 07:47:49 +01:00
|
|
|
continue;
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-18 07:47:49 +01:00
|
|
|
// Otherwise this is a normal operand or a predicate operand without
|
|
|
|
// 'execute always'; emit it.
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Extend TableGen instruction selection matcher to improve handling
of complex instruction operands (e.g. address modes).
Currently, if a Pat pattern creates an instruction that has a complex
operand (i.e. one that consists of multiple sub-operands at the MI
level), this operand must match a ComplexPattern DAG pattern with the
correct number of output operands.
This commit extends TableGen to alternatively allow match a complex
operands against multiple separate operands at the DAG level.
This allows using Pat patterns to match pre-increment nodes like
pre_store (which must have separate operands at the DAG level) onto
an instruction pattern that uses a multi-operand memory operand,
like the following example on PowerPC (will be committed as a
follow-on patch):
def STWU : DForm_1<37, (outs ptr_rc:$ea_res), (ins GPRC:$rS, memri:$dst),
"stwu $rS, $dst", LdStStoreUpd, []>,
RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
def : Pat<(pre_store GPRC:$rS, ptr_rc:$ptrreg, iaddroff:$ptroff),
(STWU GPRC:$rS, iaddroff:$ptroff, ptr_rc:$ptrreg)>;
Here, the pair of "ptroff" and "ptrreg" operands is matched onto the
complex operand "dst" of class "memri" in the "STWU" instruction.
Approved by Jakob Stoklund Olesen.
llvm-svn: 177428
2013-03-19 20:51:09 +01:00
|
|
|
// For operands with multiple sub-operands we may need to emit
|
|
|
|
// multiple child patterns to cover them all. However, ComplexPattern
|
|
|
|
// children may themselves emit multiple MI operands.
|
|
|
|
unsigned NumSubOps = 1;
|
|
|
|
if (OperandNode->isSubClassOf("Operand")) {
|
|
|
|
DagInit *MIOpInfo = OperandNode->getValueAsDag("MIOperandInfo");
|
|
|
|
if (unsigned NumArgs = MIOpInfo->getNumArgs())
|
|
|
|
NumSubOps = NumArgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned FinalNumOps = InstOps.size() + NumSubOps;
|
|
|
|
while (InstOps.size() < FinalNumOps) {
|
|
|
|
const TreePatternNode *Child = N->getChild(ChildNo);
|
|
|
|
unsigned BeforeAddingNumOps = InstOps.size();
|
|
|
|
EmitResultOperand(Child, InstOps);
|
|
|
|
assert(InstOps.size() > BeforeAddingNumOps && "Didn't add any operands");
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Extend TableGen instruction selection matcher to improve handling
of complex instruction operands (e.g. address modes).
Currently, if a Pat pattern creates an instruction that has a complex
operand (i.e. one that consists of multiple sub-operands at the MI
level), this operand must match a ComplexPattern DAG pattern with the
correct number of output operands.
This commit extends TableGen to alternatively allow match a complex
operands against multiple separate operands at the DAG level.
This allows using Pat patterns to match pre-increment nodes like
pre_store (which must have separate operands at the DAG level) onto
an instruction pattern that uses a multi-operand memory operand,
like the following example on PowerPC (will be committed as a
follow-on patch):
def STWU : DForm_1<37, (outs ptr_rc:$ea_res), (ins GPRC:$rS, memri:$dst),
"stwu $rS, $dst", LdStStoreUpd, []>,
RegConstraint<"$dst.reg = $ea_res">, NoEncode<"$ea_res">;
def : Pat<(pre_store GPRC:$rS, ptr_rc:$ptrreg, iaddroff:$ptroff),
(STWU GPRC:$rS, iaddroff:$ptroff, ptr_rc:$ptrreg)>;
Here, the pair of "ptroff" and "ptrreg" operands is matched onto the
complex operand "dst" of class "memri" in the "STWU" instruction.
Approved by Jakob Stoklund Olesen.
llvm-svn: 177428
2013-03-19 20:51:09 +01:00
|
|
|
// If the operand is an instruction and it produced multiple results, just
|
|
|
|
// take the first one.
|
|
|
|
if (!Child->isLeaf() && Child->getOperator()->isSubClassOf("Instruction"))
|
|
|
|
InstOps.resize(BeforeAddingNumOps+1);
|
|
|
|
|
|
|
|
++ChildNo;
|
|
|
|
}
|
2010-02-18 07:47:49 +01:00
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2014-11-03 00:46:51 +01:00
|
|
|
// If this is a variadic output instruction (i.e. REG_SEQUENCE), we can't
|
|
|
|
// expand suboperands, use default operands, or other features determined from
|
|
|
|
// the CodeGenInstruction after the fixed operands, which were handled
|
|
|
|
// above. Emit the remaining instructions implicitly added by the use for
|
|
|
|
// variable_ops.
|
|
|
|
if (II.Operands.isVariadic) {
|
|
|
|
for (unsigned I = ChildNo, E = N->getNumChildren(); I < E; ++I)
|
|
|
|
EmitResultOperand(N->getChild(I), InstOps);
|
|
|
|
}
|
|
|
|
|
2010-12-23 18:03:20 +01:00
|
|
|
// If this node has input glue or explicitly specified input physregs, we
|
|
|
|
// need to add chained and glued copyfromreg nodes and materialize the glue
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// input.
|
|
|
|
if (isRoot && !PhysRegInputs.empty()) {
|
|
|
|
// Emit all of the CopyToReg nodes for the input physical registers. These
|
|
|
|
// occur in patterns like (mul:i8 AL:i8, GR8:i8:$src).
|
|
|
|
for (unsigned i = 0, e = PhysRegInputs.size(); i != e; ++i)
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new EmitCopyToRegMatcher(PhysRegInputs[i].second,
|
2010-03-19 00:57:40 +01:00
|
|
|
PhysRegInputs[i].first));
|
2010-12-23 18:03:20 +01:00
|
|
|
// Even if the node has no other glue inputs, the resultant node must be
|
|
|
|
// glued to the CopyFromReg nodes we just generated.
|
|
|
|
TreeHasInGlue = true;
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-12-23 18:03:20 +01:00
|
|
|
// Result order: node results, chain, glue
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// Determine the result types.
|
|
|
|
SmallVector<MVT::SimpleValueType, 4> ResultVTs;
|
2010-03-27 20:15:02 +01:00
|
|
|
for (unsigned i = 0, e = N->getNumTypes(); i != e; ++i)
|
|
|
|
ResultVTs.push_back(N->getType(i));
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// If this is the root instruction of a pattern that has physical registers in
|
|
|
|
// its result pattern, add output VTs for them. For example, X86 has:
|
|
|
|
// (set AL, (mul ...))
|
|
|
|
// This also handles implicit results like:
|
|
|
|
// (implicit EFLAGS)
|
2010-03-27 21:45:15 +01:00
|
|
|
if (isRoot && !Pattern.getDstRegs().empty()) {
|
2010-03-19 00:57:40 +01:00
|
|
|
// If the root came from an implicit def in the instruction handling stuff,
|
|
|
|
// don't re-add it.
|
2014-04-15 09:20:03 +02:00
|
|
|
Record *HandledReg = nullptr;
|
2010-03-27 21:09:24 +01:00
|
|
|
if (II.HasOneImplicitDefWithKnownVT(CGT) != MVT::Other)
|
2010-03-19 00:57:40 +01:00
|
|
|
HandledReg = II.ImplicitDefs[0];
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-19 00:57:40 +01:00
|
|
|
for (unsigned i = 0; i != Pattern.getDstRegs().size(); ++i) {
|
|
|
|
Record *Reg = Pattern.getDstRegs()[i];
|
|
|
|
if (!Reg->isSubClassOf("Register") || Reg == HandledReg) continue;
|
|
|
|
ResultVTs.push_back(getRegisterValueType(Reg, CGT));
|
|
|
|
}
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
}
|
|
|
|
|
2010-03-19 06:34:15 +01:00
|
|
|
// If this is the root of the pattern and the pattern we're matching includes
|
|
|
|
// a node that is variadic, mark the generated node as variadic so that it
|
|
|
|
// gets the excess operands from the input DAG.
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
int NumFixedArityOperands = -1;
|
2010-03-19 06:34:15 +01:00
|
|
|
if (isRoot &&
|
2014-11-03 00:46:51 +01:00
|
|
|
Pattern.getSrcPattern()->NodeHasProperty(SDNPVariadic, CGP))
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
NumFixedArityOperands = Pattern.getSrcPattern()->getNumChildren();
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2011-05-19 23:13:30 +02:00
|
|
|
// If this is the root node and multiple matched nodes in the input pattern
|
|
|
|
// have MemRefs in them, have the interpreter collect them and plop them onto
|
|
|
|
// this node. If there is just one node with MemRefs, leave them on that node
|
|
|
|
// even if it is not the root.
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
//
|
2011-05-19 23:13:30 +02:00
|
|
|
// FIXME3: This is actively incorrect for result patterns with multiple
|
|
|
|
// memory-referencing instructions.
|
|
|
|
bool PatternHasMemOperands =
|
|
|
|
Pattern.getSrcPattern()->TreeHasProperty(SDNPMemOperand, CGP);
|
|
|
|
|
|
|
|
bool NodeHasMemRefs = false;
|
|
|
|
if (PatternHasMemOperands) {
|
|
|
|
unsigned NumNodesThatLoadOrStore =
|
|
|
|
numNodesThatMayLoadOrStore(Pattern.getDstPattern(), CGP);
|
|
|
|
bool NodeIsUniqueLoadOrStore = mayInstNodeLoadOrStore(N, CGP) &&
|
|
|
|
NumNodesThatLoadOrStore == 1;
|
|
|
|
NodeHasMemRefs =
|
|
|
|
NodeIsUniqueLoadOrStore || (isRoot && (mayInstNodeLoadOrStore(N, CGP) ||
|
|
|
|
NumNodesThatLoadOrStore != 1));
|
|
|
|
}
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
|
2010-12-23 18:03:20 +01:00
|
|
|
assert((!ResultVTs.empty() || TreeHasOutGlue || NodeHasChain) &&
|
2010-03-27 20:15:02 +01:00
|
|
|
"Node has no result");
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new EmitNodeMatcher(II.Namespace+"::"+II.TheDef->getName(),
|
2014-01-21 08:20:05 +01:00
|
|
|
ResultVTs, InstOps,
|
2010-12-23 18:03:20 +01:00
|
|
|
NodeHasChain, TreeHasInGlue, TreeHasOutGlue,
|
2010-02-28 03:41:25 +01:00
|
|
|
NodeHasMemRefs, NumFixedArityOperands,
|
|
|
|
NextRecordedOperandNo));
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-12-23 18:03:20 +01:00
|
|
|
// The non-chain and non-glue results of the newly emitted node get recorded.
|
2010-02-22 00:54:05 +01:00
|
|
|
for (unsigned i = 0, e = ResultVTs.size(); i != e; ++i) {
|
2010-12-21 03:38:05 +01:00
|
|
|
if (ResultVTs[i] == MVT::Other || ResultVTs[i] == MVT::Glue) break;
|
2010-02-21 07:03:07 +01:00
|
|
|
OutputOps.push_back(NextRecordedOperandNo++);
|
2010-02-22 00:54:05 +01:00
|
|
|
}
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MatcherGen::
|
|
|
|
EmitResultSDNodeXFormAsOperand(const TreePatternNode *N,
|
|
|
|
SmallVectorImpl<unsigned> &ResultOps) {
|
|
|
|
assert(N->getOperator()->isSubClassOf("SDNodeXForm") && "Not SDNodeXForm?");
|
|
|
|
|
|
|
|
// Emit the operand.
|
|
|
|
SmallVector<unsigned, 8> InputOps;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// FIXME2: Could easily generalize this to support multiple inputs and outputs
|
|
|
|
// to the SDNodeXForm. For now we just support one input and one output like
|
|
|
|
// the old instruction selector.
|
|
|
|
assert(N->getNumChildren() == 1);
|
|
|
|
EmitResultOperand(N->getChild(0), InputOps);
|
|
|
|
|
|
|
|
// The input currently must have produced exactly one result.
|
|
|
|
assert(InputOps.size() == 1 && "Unexpected input to SDNodeXForm");
|
|
|
|
|
2010-02-25 03:04:40 +01:00
|
|
|
AddMatcher(new EmitNodeXFormMatcher(InputOps[0], N->getOperator()));
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
ResultOps.push_back(NextRecordedOperandNo++);
|
2010-02-18 07:47:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MatcherGen::EmitResultOperand(const TreePatternNode *N,
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
SmallVectorImpl<unsigned> &ResultOps) {
|
2010-02-18 07:47:49 +01:00
|
|
|
// This is something selected from the pattern we matched.
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
if (!N->getName().empty())
|
|
|
|
return EmitResultOfNamedOperand(N, ResultOps);
|
2010-02-18 07:47:49 +01:00
|
|
|
|
|
|
|
if (N->isLeaf())
|
|
|
|
return EmitResultLeafAsOperand(N, ResultOps);
|
|
|
|
|
|
|
|
Record *OpRec = N->getOperator();
|
|
|
|
if (OpRec->isSubClassOf("Instruction"))
|
|
|
|
return EmitResultInstructionAsOperand(N, ResultOps);
|
|
|
|
if (OpRec->isSubClassOf("SDNodeXForm"))
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
return EmitResultSDNodeXFormAsOperand(N, ResultOps);
|
2010-02-18 07:47:49 +01:00
|
|
|
errs() << "Unknown result node to emit code for: " << *N << '\n';
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError("Unknown node in result pattern!");
|
2010-02-18 07:47:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MatcherGen::EmitResultCode() {
|
2010-03-01 23:46:42 +01:00
|
|
|
// Patterns that match nodes with (potentially multiple) chain inputs have to
|
|
|
|
// merge them together into a token factor. This informs the generated code
|
|
|
|
// what all the chained nodes are.
|
|
|
|
if (!MatchedChainNodes.empty())
|
2014-01-21 08:20:05 +01:00
|
|
|
AddMatcher(new EmitMergeInputChainsMatcher(MatchedChainNodes));
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-22 00:54:05 +01:00
|
|
|
// Codegen the root of the result pattern, capturing the resulting values.
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
SmallVector<unsigned, 8> Ops;
|
2010-02-18 07:47:49 +01:00
|
|
|
EmitResultOperand(Pattern.getDstPattern(), Ops);
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
|
2010-02-22 00:54:05 +01:00
|
|
|
// At this point, we have however many values the result pattern produces.
|
|
|
|
// However, the input pattern might not need all of these. If there are
|
2010-03-27 21:45:15 +01:00
|
|
|
// excess values at the end (such as implicit defs of condition codes etc)
|
2010-12-23 18:03:20 +01:00
|
|
|
// just lop them off. This doesn't need to worry about glue or chains, just
|
2010-03-27 21:45:15 +01:00
|
|
|
// explicit results.
|
2010-02-22 00:54:05 +01:00
|
|
|
//
|
2010-03-27 21:45:15 +01:00
|
|
|
unsigned NumSrcResults = Pattern.getSrcPattern()->getNumTypes();
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-27 21:45:15 +01:00
|
|
|
// If the pattern also has (implicit) results, count them as well.
|
|
|
|
if (!Pattern.getDstRegs().empty()) {
|
|
|
|
// If the root came from an implicit def in the instruction handling stuff,
|
|
|
|
// don't re-add it.
|
2014-04-15 09:20:03 +02:00
|
|
|
Record *HandledReg = nullptr;
|
2010-03-27 21:45:15 +01:00
|
|
|
const TreePatternNode *DstPat = Pattern.getDstPattern();
|
|
|
|
if (!DstPat->isLeaf() &&DstPat->getOperator()->isSubClassOf("Instruction")){
|
|
|
|
const CodeGenTarget &CGT = CGP.getTargetInfo();
|
|
|
|
CodeGenInstruction &II = CGT.getInstruction(DstPat->getOperator());
|
|
|
|
|
|
|
|
if (II.HasOneImplicitDefWithKnownVT(CGT) != MVT::Other)
|
|
|
|
HandledReg = II.ImplicitDefs[0];
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-03-27 21:45:15 +01:00
|
|
|
for (unsigned i = 0; i != Pattern.getDstRegs().size(); ++i) {
|
|
|
|
Record *Reg = Pattern.getDstRegs()[i];
|
|
|
|
if (!Reg->isSubClassOf("Register") || Reg == HandledReg) continue;
|
|
|
|
++NumSrcResults;
|
|
|
|
}
|
2010-12-21 17:16:00 +01:00
|
|
|
}
|
|
|
|
|
2010-02-22 00:54:05 +01:00
|
|
|
assert(Ops.size() >= NumSrcResults && "Didn't provide enough results");
|
|
|
|
Ops.resize(NumSrcResults);
|
2010-02-24 06:33:42 +01:00
|
|
|
|
2010-12-23 18:03:20 +01:00
|
|
|
// If the matched pattern covers nodes which define a glue result, emit a node
|
2010-02-24 06:33:42 +01:00
|
|
|
// that tells the matcher about them so that it can update their results.
|
2010-12-23 18:03:20 +01:00
|
|
|
if (!MatchedGlueResultNodes.empty())
|
2014-01-21 08:20:05 +01:00
|
|
|
AddMatcher(new MarkGlueResultsMatcher(MatchedGlueResultNodes));
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2014-01-21 08:20:05 +01:00
|
|
|
AddMatcher(new CompleteMatchMatcher(Ops, Pattern));
|
2010-02-18 07:47:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-01 08:17:40 +01:00
|
|
|
/// ConvertPatternToMatcher - Create the matcher for the specified pattern with
|
|
|
|
/// the specified variant. If the variant number is invalid, this returns null.
|
2010-02-25 03:04:40 +01:00
|
|
|
Matcher *llvm::ConvertPatternToMatcher(const PatternToMatch &Pattern,
|
2010-03-01 08:17:40 +01:00
|
|
|
unsigned Variant,
|
2010-02-28 21:49:53 +01:00
|
|
|
const CodeGenDAGPatterns &CGP) {
|
2010-02-15 09:04:42 +01:00
|
|
|
MatcherGen Gen(Pattern, CGP);
|
|
|
|
|
|
|
|
// Generate the code for the matcher.
|
2010-03-01 08:17:40 +01:00
|
|
|
if (Gen.EmitMatcherCode(Variant))
|
2014-04-15 09:20:03 +02:00
|
|
|
return nullptr;
|
2010-12-21 17:16:00 +01:00
|
|
|
|
Lots of improvements to the new dagisel emitter. This gets it to
the point where it is to the 95% feature complete mark, it just
needs result updating to be done (then testing, optimization
etc).
More specificallly, this adds support for chain and flag handling
on the result nodes, support for sdnodexforms, support for variadic
nodes, memrefs, pinned physreg inputs, and probably lots of other
stuff.
In the old DAGISelEmitter, this deletes the dead code related to
OperatorMap, cleans up a variety of dead stuff handling "implicit
remapping" from things like globaladdr -> targetglobaladdr (which
is no longer used because globaladdr always needs to be legalized),
and some minor formatting fixes.
llvm-svn: 96716
2010-02-21 04:22:59 +01:00
|
|
|
// FIXME2: Kill extra MoveParent commands at the end of the matcher sequence.
|
|
|
|
// FIXME2: Split result code out to another table, and make the matcher end
|
|
|
|
// with an "Emit <index>" command. This allows result generation stuff to be
|
|
|
|
// shared and factored?
|
2010-12-21 17:16:00 +01:00
|
|
|
|
2010-02-15 09:04:42 +01:00
|
|
|
// If the match succeeds, then we generate Pattern.
|
2010-02-18 07:47:49 +01:00
|
|
|
Gen.EmitResultCode();
|
2010-02-15 09:04:42 +01:00
|
|
|
|
|
|
|
// Unconditional match.
|
2010-02-18 07:47:49 +01:00
|
|
|
return Gen.GetMatcher();
|
2010-02-15 09:04:42 +01:00
|
|
|
}
|