2008-01-06 01:10:31 +00:00
|
|
|
//===- CodeGenDAGPatterns.h - Read DAG patterns from .td file ---*- C++ -*-===//
|
2008-01-05 22:25:12 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-01-06 01:10:31 +00:00
|
|
|
// This file declares the CodeGenDAGPatterns class, which is used to read and
|
2008-01-05 22:25:12 +00:00
|
|
|
// represent the patterns present in a .td file for instructions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CODEGEN_DAGPATTERNS_H
|
|
|
|
#define CODEGEN_DAGPATTERNS_H
|
|
|
|
|
2008-03-05 17:49:05 +00:00
|
|
|
#include <set>
|
2008-10-15 06:17:21 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2008-03-05 17:49:05 +00:00
|
|
|
|
2008-01-05 22:25:12 +00:00
|
|
|
#include "CodeGenTarget.h"
|
|
|
|
#include "CodeGenIntrinsics.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Record;
|
|
|
|
struct Init;
|
|
|
|
class ListInit;
|
|
|
|
class DagInit;
|
|
|
|
class SDNodeInfo;
|
|
|
|
class TreePattern;
|
|
|
|
class TreePatternNode;
|
2008-01-06 01:10:31 +00:00
|
|
|
class CodeGenDAGPatterns;
|
2008-01-05 22:25:12 +00:00
|
|
|
class ComplexPattern;
|
|
|
|
|
2009-08-10 22:56:29 +00:00
|
|
|
/// EEVT::DAGISelGenValueType - These are some extended forms of
|
2009-08-11 20:47:22 +00:00
|
|
|
/// MVT::SimpleValueType that we use as lattice values during type inference.
|
2009-08-29 05:53:25 +00:00
|
|
|
/// The existing MVT iAny, fAny and vAny types suffice to represent
|
|
|
|
/// arbitrary integer, floating-point, and vector types, so only an unknown
|
|
|
|
/// value is needed.
|
2009-08-10 22:56:29 +00:00
|
|
|
namespace EEVT {
|
2008-01-05 22:25:12 +00:00
|
|
|
enum DAGISelGenValueType {
|
2009-08-29 05:53:25 +00:00
|
|
|
isUnknown = MVT::LAST_VALUETYPE
|
2008-01-05 22:25:12 +00:00
|
|
|
};
|
2008-06-06 12:08:01 +00:00
|
|
|
|
2009-08-12 22:30:59 +00:00
|
|
|
/// isExtIntegerInVTs - Return true if the specified extended value type
|
2009-08-29 05:53:25 +00:00
|
|
|
/// vector contains iAny or an integer value type.
|
2008-01-05 22:25:12 +00:00
|
|
|
bool isExtIntegerInVTs(const std::vector<unsigned char> &EVTs);
|
|
|
|
|
2009-08-12 22:30:59 +00:00
|
|
|
/// isExtFloatingPointInVTs - Return true if the specified extended value
|
2009-08-29 05:53:25 +00:00
|
|
|
/// type vector contains fAny or a FP value type.
|
2008-01-05 22:25:12 +00:00
|
|
|
bool isExtFloatingPointInVTs(const std::vector<unsigned char> &EVTs);
|
2009-08-12 22:30:59 +00:00
|
|
|
|
|
|
|
/// isExtVectorinVTs - Return true if the specified extended value type
|
2009-08-29 05:53:25 +00:00
|
|
|
/// vector contains vAny or a vector value type.
|
2009-08-12 22:30:59 +00:00
|
|
|
bool isExtVectorInVTs(const std::vector<unsigned char> &EVTs);
|
2008-01-05 22:25:12 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 17:49:05 +00:00
|
|
|
/// Set type used to track multiply used variables in patterns
|
|
|
|
typedef std::set<std::string> MultipleUseVarSet;
|
|
|
|
|
2008-01-05 22:25:12 +00:00
|
|
|
/// SDTypeConstraint - This is a discriminated union of constraints,
|
|
|
|
/// corresponding to the SDTypeConstraint tablegen class in Target.td.
|
|
|
|
struct SDTypeConstraint {
|
|
|
|
SDTypeConstraint(Record *R);
|
|
|
|
|
|
|
|
unsigned OperandNo; // The operand # this constraint applies to.
|
|
|
|
enum {
|
2009-08-12 22:30:59 +00:00
|
|
|
SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisVec, SDTCisSameAs,
|
2009-04-27 18:41:29 +00:00
|
|
|
SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisEltOfVec
|
2008-01-05 22:25:12 +00:00
|
|
|
} ConstraintType;
|
|
|
|
|
|
|
|
union { // The discriminated union.
|
|
|
|
struct {
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned char VT;
|
2008-01-05 22:25:12 +00:00
|
|
|
} SDTCisVT_Info;
|
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisSameAs_Info;
|
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisVTSmallerThanOp_Info;
|
|
|
|
struct {
|
|
|
|
unsigned BigOperandNum;
|
|
|
|
} SDTCisOpSmallerThanOp_Info;
|
2008-02-09 01:37:05 +00:00
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisEltOfVec_Info;
|
2008-01-05 22:25:12 +00:00
|
|
|
} x;
|
|
|
|
|
|
|
|
/// ApplyTypeConstraint - Given a node in a pattern, apply this type
|
|
|
|
/// constraint to the nodes operands. This returns true if it makes a
|
|
|
|
/// change, false otherwise. If a type contradiction is found, throw an
|
|
|
|
/// exception.
|
|
|
|
bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
|
|
|
|
TreePattern &TP) const;
|
|
|
|
|
|
|
|
/// getOperandNum - Return the node corresponding to operand #OpNo in tree
|
|
|
|
/// N, which has NumResults results.
|
|
|
|
TreePatternNode *getOperandNum(unsigned OpNo, TreePatternNode *N,
|
|
|
|
unsigned NumResults) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// SDNodeInfo - One of these records is created for each SDNode instance in
|
|
|
|
/// the target .td file. This represents the various dag nodes we will be
|
|
|
|
/// processing.
|
|
|
|
class SDNodeInfo {
|
|
|
|
Record *Def;
|
|
|
|
std::string EnumName;
|
|
|
|
std::string SDClassName;
|
|
|
|
unsigned Properties;
|
|
|
|
unsigned NumResults;
|
|
|
|
int NumOperands;
|
|
|
|
std::vector<SDTypeConstraint> TypeConstraints;
|
|
|
|
public:
|
|
|
|
SDNodeInfo(Record *R); // Parse the specified record.
|
|
|
|
|
|
|
|
unsigned getNumResults() const { return NumResults; }
|
|
|
|
int getNumOperands() const { return NumOperands; }
|
|
|
|
Record *getRecord() const { return Def; }
|
|
|
|
const std::string &getEnumName() const { return EnumName; }
|
|
|
|
const std::string &getSDClassName() const { return SDClassName; }
|
|
|
|
|
|
|
|
const std::vector<SDTypeConstraint> &getTypeConstraints() const {
|
|
|
|
return TypeConstraints;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// hasProperty - Return true if this node has the specified property.
|
|
|
|
///
|
|
|
|
bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
|
|
|
|
|
|
|
|
/// ApplyTypeConstraints - Given a node in a pattern, apply the type
|
|
|
|
/// constraints for this node to the operands of the node. This returns
|
|
|
|
/// true if it makes a change, false otherwise. If a type contradiction is
|
|
|
|
/// found, throw an exception.
|
|
|
|
bool ApplyTypeConstraints(TreePatternNode *N, TreePattern &TP) const {
|
|
|
|
bool MadeChange = false;
|
|
|
|
for (unsigned i = 0, e = TypeConstraints.size(); i != e; ++i)
|
|
|
|
MadeChange |= TypeConstraints[i].ApplyTypeConstraint(N, *this, TP);
|
|
|
|
return MadeChange;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped
|
|
|
|
/// patterns), and as such should be ref counted. We currently just leak all
|
|
|
|
/// TreePatternNode objects!
|
|
|
|
class TreePatternNode {
|
2009-08-10 22:56:29 +00:00
|
|
|
/// The inferred type for this node, or EEVT::isUnknown if it hasn't
|
2009-03-31 16:46:45 +00:00
|
|
|
/// been determined yet. This is a std::vector because during inference
|
|
|
|
/// there may be multiple possible types.
|
2008-01-05 22:25:12 +00:00
|
|
|
std::vector<unsigned char> Types;
|
|
|
|
|
|
|
|
/// Operator - The Record for the operator if this is an interior node (not
|
|
|
|
/// a leaf).
|
|
|
|
Record *Operator;
|
|
|
|
|
|
|
|
/// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf.
|
|
|
|
///
|
|
|
|
Init *Val;
|
|
|
|
|
|
|
|
/// Name - The name given to this node with the :$foo notation.
|
|
|
|
///
|
|
|
|
std::string Name;
|
|
|
|
|
2008-10-15 06:17:21 +00:00
|
|
|
/// PredicateFns - The predicate functions to execute on this node to check
|
|
|
|
/// for a match. If this list is empty, no predicate is involved.
|
|
|
|
std::vector<std::string> PredicateFns;
|
2008-01-05 22:25:12 +00:00
|
|
|
|
|
|
|
/// TransformFn - The transformation function to execute on this node before
|
|
|
|
/// it can be substituted into the resulting instruction on a pattern match.
|
|
|
|
Record *TransformFn;
|
|
|
|
|
|
|
|
std::vector<TreePatternNode*> Children;
|
|
|
|
public:
|
|
|
|
TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch)
|
|
|
|
: Types(), Operator(Op), Val(0), TransformFn(0),
|
2009-08-10 22:56:29 +00:00
|
|
|
Children(Ch) { Types.push_back(EEVT::isUnknown); }
|
2008-01-05 22:25:12 +00:00
|
|
|
TreePatternNode(Init *val) // leaf ctor
|
|
|
|
: Types(), Operator(0), Val(val), TransformFn(0) {
|
2009-08-10 22:56:29 +00:00
|
|
|
Types.push_back(EEVT::isUnknown);
|
2008-01-05 22:25:12 +00:00
|
|
|
}
|
|
|
|
~TreePatternNode();
|
|
|
|
|
|
|
|
const std::string &getName() const { return Name; }
|
|
|
|
void setName(const std::string &N) { Name = N; }
|
|
|
|
|
|
|
|
bool isLeaf() const { return Val != 0; }
|
|
|
|
bool hasTypeSet() const {
|
2009-08-11 20:47:22 +00:00
|
|
|
return (Types[0] < MVT::LAST_VALUETYPE) || (Types[0] == MVT::iPTR) ||
|
|
|
|
(Types[0] == MVT::iPTRAny);
|
2008-01-05 22:25:12 +00:00
|
|
|
}
|
|
|
|
bool isTypeCompletelyUnknown() const {
|
2009-08-10 22:56:29 +00:00
|
|
|
return Types[0] == EEVT::isUnknown;
|
2008-01-05 22:25:12 +00:00
|
|
|
}
|
|
|
|
bool isTypeDynamicallyResolved() const {
|
2009-08-11 20:47:22 +00:00
|
|
|
return (Types[0] == MVT::iPTR) || (Types[0] == MVT::iPTRAny);
|
2008-01-05 22:25:12 +00:00
|
|
|
}
|
2009-08-11 20:47:22 +00:00
|
|
|
MVT::SimpleValueType getTypeNum(unsigned Num) const {
|
2008-01-05 22:25:12 +00:00
|
|
|
assert(hasTypeSet() && "Doesn't have a type yet!");
|
|
|
|
assert(Types.size() > Num && "Type num out of range!");
|
2009-08-11 20:47:22 +00:00
|
|
|
return (MVT::SimpleValueType)Types[Num];
|
2008-01-05 22:25:12 +00:00
|
|
|
}
|
|
|
|
unsigned char getExtTypeNum(unsigned Num) const {
|
|
|
|
assert(Types.size() > Num && "Extended type num out of range!");
|
|
|
|
return Types[Num];
|
|
|
|
}
|
|
|
|
const std::vector<unsigned char> &getExtTypes() const { return Types; }
|
|
|
|
void setTypes(const std::vector<unsigned char> &T) { Types = T; }
|
2009-08-10 22:56:29 +00:00
|
|
|
void removeTypes() { Types = std::vector<unsigned char>(1, EEVT::isUnknown); }
|
2008-01-05 22:25:12 +00:00
|
|
|
|
|
|
|
Init *getLeafValue() const { assert(isLeaf()); return Val; }
|
|
|
|
Record *getOperator() const { assert(!isLeaf()); return Operator; }
|
|
|
|
|
|
|
|
unsigned getNumChildren() const { return Children.size(); }
|
|
|
|
TreePatternNode *getChild(unsigned N) const { return Children[N]; }
|
|
|
|
void setChild(unsigned i, TreePatternNode *N) {
|
|
|
|
Children[i] = N;
|
|
|
|
}
|
2008-01-06 05:36:50 +00:00
|
|
|
|
2008-10-15 06:17:21 +00:00
|
|
|
const std::vector<std::string> &getPredicateFns() const { return PredicateFns; }
|
|
|
|
void clearPredicateFns() { PredicateFns.clear(); }
|
|
|
|
void setPredicateFns(const std::vector<std::string> &Fns) {
|
|
|
|
assert(PredicateFns.empty() && "Overwriting non-empty predicate list!");
|
|
|
|
PredicateFns = Fns;
|
|
|
|
}
|
|
|
|
void addPredicateFn(const std::string &Fn) {
|
|
|
|
assert(!Fn.empty() && "Empty predicate string!");
|
|
|
|
if (std::find(PredicateFns.begin(), PredicateFns.end(), Fn) ==
|
|
|
|
PredicateFns.end())
|
|
|
|
PredicateFns.push_back(Fn);
|
|
|
|
}
|
2008-01-05 22:25:12 +00:00
|
|
|
|
|
|
|
Record *getTransformFn() const { return TransformFn; }
|
|
|
|
void setTransformFn(Record *Fn) { TransformFn = Fn; }
|
|
|
|
|
2008-01-06 05:36:50 +00:00
|
|
|
/// getIntrinsicInfo - If this node corresponds to an intrinsic, return the
|
|
|
|
/// CodeGenIntrinsic information for it, otherwise return a null pointer.
|
|
|
|
const CodeGenIntrinsic *getIntrinsicInfo(const CodeGenDAGPatterns &CDP) const;
|
2008-06-16 20:29:38 +00:00
|
|
|
|
|
|
|
/// isCommutativeIntrinsic - Return true if the node is an intrinsic which is
|
|
|
|
/// marked isCommutative.
|
|
|
|
bool isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const;
|
2008-01-06 05:36:50 +00:00
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
void print(raw_ostream &OS) const;
|
2008-01-05 22:25:12 +00:00
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
public: // Higher level manipulation routines.
|
|
|
|
|
|
|
|
/// clone - Return a new copy of this tree.
|
|
|
|
///
|
|
|
|
TreePatternNode *clone() const;
|
|
|
|
|
|
|
|
/// isIsomorphicTo - Return true if this node is recursively isomorphic to
|
|
|
|
/// the specified node. For this comparison, all of the state of the node
|
|
|
|
/// is considered, except for the assigned name. Nodes with differing names
|
|
|
|
/// that are otherwise identical are considered isomorphic.
|
2008-03-05 17:49:05 +00:00
|
|
|
bool isIsomorphicTo(const TreePatternNode *N,
|
|
|
|
const MultipleUseVarSet &DepVars) const;
|
2008-01-05 22:25:12 +00:00
|
|
|
|
|
|
|
/// SubstituteFormalArguments - Replace the formal arguments in this tree
|
|
|
|
/// with actual values specified by ArgMap.
|
|
|
|
void SubstituteFormalArguments(std::map<std::string,
|
|
|
|
TreePatternNode*> &ArgMap);
|
|
|
|
|
|
|
|
/// InlinePatternFragments - If this pattern refers to any pattern
|
|
|
|
/// fragments, inline them into place, giving us a pattern without any
|
|
|
|
/// PatFrag references.
|
|
|
|
TreePatternNode *InlinePatternFragments(TreePattern &TP);
|
|
|
|
|
2009-01-05 17:23:09 +00:00
|
|
|
/// ApplyTypeConstraints - Apply all of the type constraints relevant to
|
2008-01-05 22:25:12 +00:00
|
|
|
/// this node and its children in the tree. This returns true if it makes a
|
|
|
|
/// change, false otherwise. If a type contradiction is found, throw an
|
|
|
|
/// exception.
|
|
|
|
bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters);
|
|
|
|
|
|
|
|
/// UpdateNodeType - Set the node type of N to VT if VT contains
|
|
|
|
/// information. If N already contains a conflicting type, then throw an
|
|
|
|
/// exception. This returns true if any information was updated.
|
|
|
|
///
|
|
|
|
bool UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
|
|
|
|
TreePattern &TP);
|
|
|
|
bool UpdateNodeType(unsigned char ExtVT, TreePattern &TP) {
|
|
|
|
std::vector<unsigned char> ExtVTs(1, ExtVT);
|
|
|
|
return UpdateNodeType(ExtVTs, TP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ContainsUnresolvedType - Return true if this tree contains any
|
|
|
|
/// unresolved types.
|
|
|
|
bool ContainsUnresolvedType() const {
|
|
|
|
if (!hasTypeSet() && !isTypeDynamicallyResolved()) return true;
|
|
|
|
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
|
|
|
|
if (getChild(i)->ContainsUnresolvedType()) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// canPatternMatch - If it is impossible for this pattern to match on this
|
|
|
|
/// target, fill in Reason and return false. Otherwise, return true.
|
2008-04-03 00:02:49 +00:00
|
|
|
bool canPatternMatch(std::string &Reason, const CodeGenDAGPatterns &CDP);
|
2008-01-05 22:25:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// TreePattern - Represent a pattern, used for instructions, pattern
|
|
|
|
/// fragments, etc.
|
|
|
|
///
|
|
|
|
class TreePattern {
|
|
|
|
/// Trees - The list of pattern trees which corresponds to this pattern.
|
|
|
|
/// Note that PatFrag's only have a single tree.
|
|
|
|
///
|
|
|
|
std::vector<TreePatternNode*> Trees;
|
|
|
|
|
|
|
|
/// TheRecord - The actual TableGen record corresponding to this pattern.
|
|
|
|
///
|
|
|
|
Record *TheRecord;
|
|
|
|
|
|
|
|
/// Args - This is a list of all of the arguments to this pattern (for
|
|
|
|
/// PatFrag patterns), which are the 'node' markers in this pattern.
|
|
|
|
std::vector<std::string> Args;
|
|
|
|
|
|
|
|
/// CDP - the top-level object coordinating this madness.
|
|
|
|
///
|
2008-01-06 01:10:31 +00:00
|
|
|
CodeGenDAGPatterns &CDP;
|
2008-01-05 22:25:12 +00:00
|
|
|
|
|
|
|
/// isInputPattern - True if this is an input pattern, something to match.
|
|
|
|
/// False if this is an output pattern, something to emit.
|
|
|
|
bool isInputPattern;
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// TreePattern constructor - Parse the specified DagInits into the
|
|
|
|
/// current record.
|
|
|
|
TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
|
2008-01-06 01:10:31 +00:00
|
|
|
CodeGenDAGPatterns &ise);
|
2008-01-05 22:25:12 +00:00
|
|
|
TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
|
2008-01-06 01:10:31 +00:00
|
|
|
CodeGenDAGPatterns &ise);
|
2008-01-05 22:25:12 +00:00
|
|
|
TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
|
2008-01-06 01:10:31 +00:00
|
|
|
CodeGenDAGPatterns &ise);
|
2008-01-05 22:25:12 +00:00
|
|
|
|
|
|
|
/// getTrees - Return the tree patterns which corresponds to this pattern.
|
|
|
|
///
|
|
|
|
const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
|
|
|
|
unsigned getNumTrees() const { return Trees.size(); }
|
|
|
|
TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
|
|
|
|
TreePatternNode *getOnlyTree() const {
|
|
|
|
assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
|
|
|
|
return Trees[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getRecord - Return the actual TableGen record corresponding to this
|
|
|
|
/// pattern.
|
|
|
|
///
|
|
|
|
Record *getRecord() const { return TheRecord; }
|
|
|
|
|
|
|
|
unsigned getNumArgs() const { return Args.size(); }
|
|
|
|
const std::string &getArgName(unsigned i) const {
|
|
|
|
assert(i < Args.size() && "Argument reference out of range!");
|
|
|
|
return Args[i];
|
|
|
|
}
|
|
|
|
std::vector<std::string> &getArgList() { return Args; }
|
|
|
|
|
2008-01-06 01:10:31 +00:00
|
|
|
CodeGenDAGPatterns &getDAGPatterns() const { return CDP; }
|
2008-01-05 22:25:12 +00:00
|
|
|
|
|
|
|
/// InlinePatternFragments - If this pattern refers to any pattern
|
|
|
|
/// fragments, inline them into place, giving us a pattern without any
|
|
|
|
/// PatFrag references.
|
|
|
|
void InlinePatternFragments() {
|
|
|
|
for (unsigned i = 0, e = Trees.size(); i != e; ++i)
|
|
|
|
Trees[i] = Trees[i]->InlinePatternFragments(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// InferAllTypes - Infer/propagate as many types throughout the expression
|
2009-03-26 16:17:51 +00:00
|
|
|
/// patterns as possible. Return true if all types are inferred, false
|
2008-01-05 22:25:12 +00:00
|
|
|
/// otherwise. Throw an exception if a type contradiction is found.
|
|
|
|
bool InferAllTypes();
|
|
|
|
|
|
|
|
/// error - Throw an exception, prefixing it with information about this
|
|
|
|
/// pattern.
|
|
|
|
void error(const std::string &Msg) const;
|
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
void print(raw_ostream &OS) const;
|
2008-01-05 22:25:12 +00:00
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
TreePatternNode *ParseTreePattern(DagInit *DI);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// DAGDefaultOperand - One of these is created for each PredicateOperand
|
|
|
|
/// or OptionalDefOperand that has a set ExecuteAlways / DefaultOps field.
|
|
|
|
struct DAGDefaultOperand {
|
|
|
|
std::vector<TreePatternNode*> DefaultOps;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DAGInstruction {
|
|
|
|
TreePattern *Pattern;
|
|
|
|
std::vector<Record*> Results;
|
|
|
|
std::vector<Record*> Operands;
|
|
|
|
std::vector<Record*> ImpResults;
|
|
|
|
std::vector<Record*> ImpOperands;
|
|
|
|
TreePatternNode *ResultPattern;
|
|
|
|
public:
|
|
|
|
DAGInstruction(TreePattern *TP,
|
|
|
|
const std::vector<Record*> &results,
|
|
|
|
const std::vector<Record*> &operands,
|
|
|
|
const std::vector<Record*> &impresults,
|
|
|
|
const std::vector<Record*> &impoperands)
|
|
|
|
: Pattern(TP), Results(results), Operands(operands),
|
|
|
|
ImpResults(impresults), ImpOperands(impoperands),
|
|
|
|
ResultPattern(0) {}
|
|
|
|
|
2008-01-06 01:52:22 +00:00
|
|
|
const TreePattern *getPattern() const { return Pattern; }
|
2008-01-05 22:25:12 +00:00
|
|
|
unsigned getNumResults() const { return Results.size(); }
|
|
|
|
unsigned getNumOperands() const { return Operands.size(); }
|
|
|
|
unsigned getNumImpResults() const { return ImpResults.size(); }
|
|
|
|
unsigned getNumImpOperands() const { return ImpOperands.size(); }
|
|
|
|
const std::vector<Record*>& getImpResults() const { return ImpResults; }
|
|
|
|
|
|
|
|
void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
|
|
|
|
|
|
|
|
Record *getResult(unsigned RN) const {
|
|
|
|
assert(RN < Results.size());
|
|
|
|
return Results[RN];
|
|
|
|
}
|
|
|
|
|
|
|
|
Record *getOperand(unsigned ON) const {
|
|
|
|
assert(ON < Operands.size());
|
|
|
|
return Operands[ON];
|
|
|
|
}
|
|
|
|
|
|
|
|
Record *getImpResult(unsigned RN) const {
|
|
|
|
assert(RN < ImpResults.size());
|
|
|
|
return ImpResults[RN];
|
|
|
|
}
|
|
|
|
|
|
|
|
Record *getImpOperand(unsigned ON) const {
|
|
|
|
assert(ON < ImpOperands.size());
|
|
|
|
return ImpOperands[ON];
|
|
|
|
}
|
|
|
|
|
|
|
|
TreePatternNode *getResultPattern() const { return ResultPattern; }
|
|
|
|
};
|
|
|
|
|
2008-01-06 01:10:31 +00:00
|
|
|
/// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns
|
2008-01-05 22:25:12 +00:00
|
|
|
/// processed to produce isel.
|
|
|
|
struct PatternToMatch {
|
|
|
|
PatternToMatch(ListInit *preds,
|
|
|
|
TreePatternNode *src, TreePatternNode *dst,
|
|
|
|
const std::vector<Record*> &dstregs,
|
|
|
|
unsigned complexity):
|
|
|
|
Predicates(preds), SrcPattern(src), DstPattern(dst), Dstregs(dstregs),
|
|
|
|
AddedComplexity(complexity) {};
|
|
|
|
|
|
|
|
ListInit *Predicates; // Top level predicate conditions to match.
|
|
|
|
TreePatternNode *SrcPattern; // Source pattern to match.
|
|
|
|
TreePatternNode *DstPattern; // Resulting pattern.
|
|
|
|
std::vector<Record*> Dstregs; // Physical register defs being matched.
|
|
|
|
unsigned AddedComplexity; // Add to matching pattern complexity.
|
|
|
|
|
|
|
|
ListInit *getPredicates() const { return Predicates; }
|
|
|
|
TreePatternNode *getSrcPattern() const { return SrcPattern; }
|
|
|
|
TreePatternNode *getDstPattern() const { return DstPattern; }
|
|
|
|
const std::vector<Record*> &getDstRegs() const { return Dstregs; }
|
|
|
|
unsigned getAddedComplexity() const { return AddedComplexity; }
|
2008-08-22 00:20:26 +00:00
|
|
|
|
|
|
|
std::string getPredicateCheck() const;
|
2008-01-05 22:25:12 +00:00
|
|
|
};
|
|
|
|
|
2009-08-23 09:47:37 +00:00
|
|
|
// Deterministic comparison of Record*.
|
|
|
|
struct RecordPtrCmp {
|
|
|
|
bool operator()(const Record *LHS, const Record *RHS) const;
|
|
|
|
};
|
2008-01-05 22:25:12 +00:00
|
|
|
|
2008-01-06 01:10:31 +00:00
|
|
|
class CodeGenDAGPatterns {
|
2008-01-05 22:25:12 +00:00
|
|
|
RecordKeeper &Records;
|
|
|
|
CodeGenTarget Target;
|
|
|
|
std::vector<CodeGenIntrinsic> Intrinsics;
|
2009-02-05 01:49:45 +00:00
|
|
|
std::vector<CodeGenIntrinsic> TgtIntrinsics;
|
2008-01-05 22:25:12 +00:00
|
|
|
|
2009-08-23 09:47:37 +00:00
|
|
|
std::map<Record*, SDNodeInfo, RecordPtrCmp> SDNodes;
|
|
|
|
std::map<Record*, std::pair<Record*, std::string>, RecordPtrCmp> SDNodeXForms;
|
|
|
|
std::map<Record*, ComplexPattern, RecordPtrCmp> ComplexPatterns;
|
|
|
|
std::map<Record*, TreePattern*, RecordPtrCmp> PatternFragments;
|
|
|
|
std::map<Record*, DAGDefaultOperand, RecordPtrCmp> DefaultOperands;
|
|
|
|
std::map<Record*, DAGInstruction, RecordPtrCmp> Instructions;
|
2008-01-05 22:25:12 +00:00
|
|
|
|
|
|
|
// Specific SDNode definitions:
|
|
|
|
Record *intrinsic_void_sdnode;
|
|
|
|
Record *intrinsic_w_chain_sdnode, *intrinsic_wo_chain_sdnode;
|
|
|
|
|
|
|
|
/// PatternsToMatch - All of the things we are matching on the DAG. The first
|
|
|
|
/// value is the pattern to match, the second pattern is the result to
|
|
|
|
/// emit.
|
|
|
|
std::vector<PatternToMatch> PatternsToMatch;
|
|
|
|
public:
|
2008-01-06 01:10:31 +00:00
|
|
|
CodeGenDAGPatterns(RecordKeeper &R);
|
|
|
|
~CodeGenDAGPatterns();
|
2008-01-05 22:25:12 +00:00
|
|
|
|
2008-04-03 00:02:49 +00:00
|
|
|
CodeGenTarget &getTargetInfo() { return Target; }
|
2008-01-05 22:25:12 +00:00
|
|
|
const CodeGenTarget &getTargetInfo() const { return Target; }
|
|
|
|
|
|
|
|
Record *getSDNodeNamed(const std::string &Name) const;
|
|
|
|
|
|
|
|
const SDNodeInfo &getSDNodeInfo(Record *R) const {
|
|
|
|
assert(SDNodes.count(R) && "Unknown node!");
|
|
|
|
return SDNodes.find(R)->second;
|
|
|
|
}
|
|
|
|
|
2008-01-05 22:54:53 +00:00
|
|
|
// Node transformation lookups.
|
|
|
|
typedef std::pair<Record*, std::string> NodeXForm;
|
|
|
|
const NodeXForm &getSDNodeTransform(Record *R) const {
|
2008-01-05 22:25:12 +00:00
|
|
|
assert(SDNodeXForms.count(R) && "Invalid transform!");
|
|
|
|
return SDNodeXForms.find(R)->second;
|
|
|
|
}
|
|
|
|
|
2009-08-23 10:39:21 +00:00
|
|
|
typedef std::map<Record*, NodeXForm, RecordPtrCmp>::const_iterator
|
|
|
|
nx_iterator;
|
2008-01-05 22:54:53 +00:00
|
|
|
nx_iterator nx_begin() const { return SDNodeXForms.begin(); }
|
|
|
|
nx_iterator nx_end() const { return SDNodeXForms.end(); }
|
|
|
|
|
|
|
|
|
2008-01-05 22:25:12 +00:00
|
|
|
const ComplexPattern &getComplexPattern(Record *R) const {
|
|
|
|
assert(ComplexPatterns.count(R) && "Unknown addressing mode!");
|
|
|
|
return ComplexPatterns.find(R)->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CodeGenIntrinsic &getIntrinsic(Record *R) const {
|
|
|
|
for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
|
|
|
|
if (Intrinsics[i].TheDef == R) return Intrinsics[i];
|
2009-02-05 01:49:45 +00:00
|
|
|
for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
|
|
|
|
if (TgtIntrinsics[i].TheDef == R) return TgtIntrinsics[i];
|
2008-01-05 22:25:12 +00:00
|
|
|
assert(0 && "Unknown intrinsic!");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
const CodeGenIntrinsic &getIntrinsicInfo(unsigned IID) const {
|
2009-02-05 01:49:45 +00:00
|
|
|
if (IID-1 < Intrinsics.size())
|
|
|
|
return Intrinsics[IID-1];
|
|
|
|
if (IID-Intrinsics.size()-1 < TgtIntrinsics.size())
|
|
|
|
return TgtIntrinsics[IID-Intrinsics.size()-1];
|
|
|
|
assert(0 && "Bad intrinsic ID!");
|
2009-02-09 03:07:24 +00:00
|
|
|
abort();
|
2008-01-05 22:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getIntrinsicID(Record *R) const {
|
|
|
|
for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
|
|
|
|
if (Intrinsics[i].TheDef == R) return i;
|
2009-02-05 01:49:45 +00:00
|
|
|
for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
|
|
|
|
if (TgtIntrinsics[i].TheDef == R) return i + Intrinsics.size();
|
2008-01-05 22:25:12 +00:00
|
|
|
assert(0 && "Unknown intrinsic!");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
const DAGDefaultOperand &getDefaultOperand(Record *R) {
|
|
|
|
assert(DefaultOperands.count(R) &&"Isn't an analyzed default operand!");
|
|
|
|
return DefaultOperands.find(R)->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pattern Fragment information.
|
|
|
|
TreePattern *getPatternFragment(Record *R) const {
|
|
|
|
assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
|
|
|
|
return PatternFragments.find(R)->second;
|
|
|
|
}
|
2009-08-23 10:39:21 +00:00
|
|
|
typedef std::map<Record*, TreePattern*, RecordPtrCmp>::const_iterator
|
|
|
|
pf_iterator;
|
2008-01-05 22:25:12 +00:00
|
|
|
pf_iterator pf_begin() const { return PatternFragments.begin(); }
|
|
|
|
pf_iterator pf_end() const { return PatternFragments.end(); }
|
|
|
|
|
|
|
|
// Patterns to match information.
|
2008-01-05 22:30:17 +00:00
|
|
|
typedef std::vector<PatternToMatch>::const_iterator ptm_iterator;
|
|
|
|
ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); }
|
|
|
|
ptm_iterator ptm_end() const { return PatternsToMatch.end(); }
|
2008-01-05 22:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const DAGInstruction &getInstruction(Record *R) const {
|
|
|
|
assert(Instructions.count(R) && "Unknown instruction!");
|
|
|
|
return Instructions.find(R)->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
Record *get_intrinsic_void_sdnode() const {
|
|
|
|
return intrinsic_void_sdnode;
|
|
|
|
}
|
|
|
|
Record *get_intrinsic_w_chain_sdnode() const {
|
|
|
|
return intrinsic_w_chain_sdnode;
|
|
|
|
}
|
|
|
|
Record *get_intrinsic_wo_chain_sdnode() const {
|
|
|
|
return intrinsic_wo_chain_sdnode;
|
|
|
|
}
|
|
|
|
|
2009-10-15 18:50:03 +00:00
|
|
|
bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); }
|
|
|
|
|
2008-01-05 22:25:12 +00:00
|
|
|
private:
|
|
|
|
void ParseNodeInfo();
|
2008-01-05 22:54:53 +00:00
|
|
|
void ParseNodeTransforms();
|
2008-01-05 22:25:12 +00:00
|
|
|
void ParseComplexPatterns();
|
2008-01-05 22:43:57 +00:00
|
|
|
void ParsePatternFragments();
|
2008-01-05 22:25:12 +00:00
|
|
|
void ParseDefaultOperands();
|
|
|
|
void ParseInstructions();
|
|
|
|
void ParsePatterns();
|
2008-04-03 00:02:49 +00:00
|
|
|
void InferInstructionFlags();
|
2008-01-05 22:25:12 +00:00
|
|
|
void GenerateVariants();
|
|
|
|
|
|
|
|
void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
|
|
|
|
std::map<std::string,
|
|
|
|
TreePatternNode*> &InstInputs,
|
|
|
|
std::map<std::string,
|
|
|
|
TreePatternNode*> &InstResults,
|
|
|
|
std::vector<Record*> &InstImpInputs,
|
|
|
|
std::vector<Record*> &InstImpResults);
|
|
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|