2008-01-06 09:10:31 +08:00
|
|
|
//===- CodeGenDAGPatterns.h - Read DAG patterns from .td file ---*- C++ -*-===//
|
2008-01-06 06:25:12 +08: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 09:10:31 +08:00
|
|
|
// This file declares the CodeGenDAGPatterns class, which is used to read and
|
2008-01-06 06:25:12 +08:00
|
|
|
// represent the patterns present in a .td file for instructions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H
|
|
|
|
#define LLVM_UTILS_TABLEGEN_CODEGENDAGPATTERNS_H
|
2008-01-06 06:25:12 +08:00
|
|
|
|
|
|
|
#include "CodeGenIntrinsics.h"
|
2012-12-04 18:37:14 +08:00
|
|
|
#include "CodeGenTarget.h"
|
2010-03-15 14:00:16 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
2012-02-05 15:21:30 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-03-19 09:07:44 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
2012-12-04 18:37:14 +08:00
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
2008-01-06 06:25:12 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Record;
|
2011-07-14 06:25:51 +08:00
|
|
|
class Init;
|
2008-01-06 06:25:12 +08:00
|
|
|
class ListInit;
|
|
|
|
class DagInit;
|
|
|
|
class SDNodeInfo;
|
|
|
|
class TreePattern;
|
|
|
|
class TreePatternNode;
|
2008-01-06 09:10:31 +08:00
|
|
|
class CodeGenDAGPatterns;
|
2008-01-06 06:25:12 +08:00
|
|
|
class ComplexPattern;
|
|
|
|
|
2009-08-11 06:56:29 +08:00
|
|
|
/// EEVT::DAGISelGenValueType - These are some extended forms of
|
2009-08-12 04:47:22 +08:00
|
|
|
/// MVT::SimpleValueType that we use as lattice values during type inference.
|
2009-08-29 13:53:25 +08: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-11 06:56:29 +08:00
|
|
|
namespace EEVT {
|
2010-03-15 14:00:16 +08:00
|
|
|
/// TypeSet - This is either empty if it's completely unknown, or holds a set
|
|
|
|
/// of types. It is used during type inference because register classes can
|
|
|
|
/// have multiple possible types and we don't know which one they get until
|
|
|
|
/// type inference is complete.
|
|
|
|
///
|
|
|
|
/// TypeSet can have three states:
|
|
|
|
/// Vector is empty: The type is completely unknown, it can be any valid
|
|
|
|
/// target type.
|
|
|
|
/// Vector has multiple constrained types: (e.g. v4i32 + v4f32) it is one
|
|
|
|
/// of those types only.
|
|
|
|
/// Vector has one concrete type: The type is completely known.
|
|
|
|
///
|
|
|
|
class TypeSet {
|
2010-03-20 01:41:26 +08:00
|
|
|
SmallVector<MVT::SimpleValueType, 4> TypeVec;
|
2010-03-15 14:00:16 +08:00
|
|
|
public:
|
|
|
|
TypeSet() {}
|
|
|
|
TypeSet(MVT::SimpleValueType VT, TreePattern &TP);
|
2013-03-18 01:26:09 +08:00
|
|
|
TypeSet(ArrayRef<MVT::SimpleValueType> VTList);
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
bool isCompletelyUnknown() const { return TypeVec.empty(); }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
bool isConcrete() const {
|
|
|
|
if (TypeVec.size() != 1) return false;
|
|
|
|
unsigned char T = TypeVec[0]; (void)T;
|
|
|
|
assert(T < MVT::LAST_VALUETYPE || T == MVT::iPTR || T == MVT::iPTRAny);
|
|
|
|
return true;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
MVT::SimpleValueType getConcrete() const {
|
|
|
|
assert(isConcrete() && "Type isn't concrete yet");
|
|
|
|
return (MVT::SimpleValueType)TypeVec[0];
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
bool isDynamicallyResolved() const {
|
|
|
|
return getConcrete() == MVT::iPTR || getConcrete() == MVT::iPTRAny;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
const SmallVectorImpl<MVT::SimpleValueType> &getTypeList() const {
|
|
|
|
assert(!TypeVec.empty() && "Not a type list!");
|
|
|
|
return TypeVec;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-19 07:15:10 +08:00
|
|
|
bool isVoid() const {
|
|
|
|
return TypeVec.size() == 1 && TypeVec[0] == MVT::isVoid;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
/// hasIntegerTypes - Return true if this TypeSet contains any integer value
|
|
|
|
/// types.
|
|
|
|
bool hasIntegerTypes() const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
/// hasFloatingPointTypes - Return true if this TypeSet contains an fAny or
|
|
|
|
/// a floating point value type.
|
|
|
|
bool hasFloatingPointTypes() const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2014-01-28 12:49:01 +08:00
|
|
|
/// hasScalarTypes - Return true if this TypeSet contains a scalar value
|
|
|
|
/// type.
|
|
|
|
bool hasScalarTypes() const;
|
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
/// hasVectorTypes - Return true if this TypeSet contains a vector value
|
|
|
|
/// type.
|
|
|
|
bool hasVectorTypes() const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
/// getName() - Return this TypeSet as a string.
|
|
|
|
std::string getName() const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
/// MergeInTypeInfo - This merges in type information from the specified
|
|
|
|
/// argument. If 'this' changes, it returns true. If the two types are
|
2012-10-26 04:33:17 +08:00
|
|
|
/// contradictory (e.g. merge f32 into i32) then this flags an error.
|
2010-03-15 14:00:16 +08:00
|
|
|
bool MergeInTypeInfo(const EEVT::TypeSet &InVT, TreePattern &TP);
|
|
|
|
|
|
|
|
bool MergeInTypeInfo(MVT::SimpleValueType InVT, TreePattern &TP) {
|
|
|
|
return MergeInTypeInfo(EEVT::TypeSet(InVT, TP), TP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Force this type list to only contain integer types.
|
|
|
|
bool EnforceInteger(TreePattern &TP);
|
|
|
|
|
|
|
|
/// Force this type list to only contain floating point types.
|
|
|
|
bool EnforceFloatingPoint(TreePattern &TP);
|
2008-06-06 20:08:01 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
/// EnforceScalar - Remove all vector types from this type list.
|
|
|
|
bool EnforceScalar(TreePattern &TP);
|
2008-01-06 06:25:12 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
/// EnforceVector - Remove all non-vector types from this type list.
|
|
|
|
bool EnforceVector(TreePattern &TP);
|
2009-08-13 06:30:59 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
/// EnforceSmallerThan - 'this' must be a smaller VT than Other. Update
|
|
|
|
/// this an other based on this information.
|
|
|
|
bool EnforceSmallerThan(EEVT::TypeSet &Other, TreePattern &TP);
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
/// EnforceVectorEltTypeIs - 'this' is now constrainted to be a vector type
|
|
|
|
/// whose element is VT.
|
2010-03-24 08:01:16 +08:00
|
|
|
bool EnforceVectorEltTypeIs(EEVT::TypeSet &VT, TreePattern &TP);
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2015-03-05 15:11:34 +08:00
|
|
|
/// EnforceVectorEltTypeIs - 'this' is now constrainted to be a vector type
|
|
|
|
/// whose element is VT.
|
|
|
|
bool EnforceVectorEltTypeIs(MVT::SimpleValueType VT, TreePattern &TP);
|
|
|
|
|
2011-01-25 04:53:18 +08:00
|
|
|
/// EnforceVectorSubVectorTypeIs - 'this' is now constrainted to
|
|
|
|
/// be a vector type VT.
|
|
|
|
bool EnforceVectorSubVectorTypeIs(EEVT::TypeSet &VT, TreePattern &TP);
|
|
|
|
|
2015-03-05 15:11:34 +08:00
|
|
|
/// EnforceVectorSameNumElts - 'this' is now constrainted to
|
|
|
|
/// be a vector with same num elements as VT.
|
|
|
|
bool EnforceVectorSameNumElts(EEVT::TypeSet &VT, TreePattern &TP);
|
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
bool operator!=(const TypeSet &RHS) const { return TypeVec != RHS.TypeVec; }
|
|
|
|
bool operator==(const TypeSet &RHS) const { return TypeVec == RHS.TypeVec; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-19 12:54:36 +08:00
|
|
|
private:
|
|
|
|
/// FillWithPossibleTypes - Set to all legal types and return true, only
|
2010-03-20 01:41:26 +08:00
|
|
|
/// valid on completely unknown type sets. If Pred is non-null, only MVTs
|
|
|
|
/// that pass the predicate are added.
|
|
|
|
bool FillWithPossibleTypes(TreePattern &TP,
|
2014-04-16 12:21:27 +08:00
|
|
|
bool (*Pred)(MVT::SimpleValueType) = nullptr,
|
|
|
|
const char *PredicateName = nullptr);
|
2010-03-15 14:00:16 +08:00
|
|
|
};
|
2008-01-06 06:25:12 +08:00
|
|
|
}
|
|
|
|
|
2008-03-06 01:49:05 +08:00
|
|
|
/// Set type used to track multiply used variables in patterns
|
|
|
|
typedef std::set<std::string> MultipleUseVarSet;
|
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// SDTypeConstraint - This is a discriminated union of constraints,
|
|
|
|
/// corresponding to the SDTypeConstraint tablegen class in Target.td.
|
|
|
|
struct SDTypeConstraint {
|
|
|
|
SDTypeConstraint(Record *R);
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
unsigned OperandNo; // The operand # this constraint applies to.
|
2010-12-24 13:06:32 +08:00
|
|
|
enum {
|
|
|
|
SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisVec, SDTCisSameAs,
|
2011-01-25 04:53:18 +08:00
|
|
|
SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisEltOfVec,
|
2015-03-05 15:11:34 +08:00
|
|
|
SDTCisSubVecOfVec, SDTCVecEltisVT, SDTCisSameNumEltsAs
|
2008-01-06 06:25:12 +08:00
|
|
|
} ConstraintType;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
union { // The discriminated union.
|
|
|
|
struct {
|
2010-03-15 14:00:16 +08:00
|
|
|
MVT::SimpleValueType VT;
|
2008-01-06 06:25:12 +08:00
|
|
|
} SDTCisVT_Info;
|
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisSameAs_Info;
|
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisVTSmallerThanOp_Info;
|
|
|
|
struct {
|
|
|
|
unsigned BigOperandNum;
|
|
|
|
} SDTCisOpSmallerThanOp_Info;
|
2008-02-09 09:37:05 +08:00
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisEltOfVec_Info;
|
2011-01-25 04:53:18 +08:00
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisSubVecOfVec_Info;
|
2015-03-05 15:11:34 +08:00
|
|
|
struct {
|
|
|
|
MVT::SimpleValueType VT;
|
|
|
|
} SDTCVecEltisVT_Info;
|
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisSameNumEltsAs_Info;
|
2008-01-06 06:25:12 +08:00
|
|
|
} x;
|
|
|
|
|
|
|
|
/// ApplyTypeConstraint - Given a node in a pattern, apply this type
|
|
|
|
/// constraint to the nodes operands. This returns true if it makes a
|
2012-10-26 04:33:17 +08:00
|
|
|
/// change, false otherwise. If a type contradiction is found, an error
|
|
|
|
/// is flagged.
|
2008-01-06 06:25:12 +08:00
|
|
|
bool ApplyTypeConstraint(TreePatternNode *N, const SDNodeInfo &NodeInfo,
|
|
|
|
TreePattern &TP) 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.
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
unsigned getNumResults() const { return NumResults; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-28 16:48:47 +08:00
|
|
|
/// getNumOperands - This is the number of operands required or -1 if
|
|
|
|
/// variadic.
|
2008-01-06 06:25:12 +08:00
|
|
|
int getNumOperands() const { return NumOperands; }
|
|
|
|
Record *getRecord() const { return Def; }
|
|
|
|
const std::string &getEnumName() const { return EnumName; }
|
|
|
|
const std::string &getSDClassName() const { return SDClassName; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
const std::vector<SDTypeConstraint> &getTypeConstraints() const {
|
|
|
|
return TypeConstraints;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-02-28 08:22:30 +08:00
|
|
|
/// getKnownType - If the type constraints on this node imply a fixed type
|
|
|
|
/// (e.g. all stores return void, etc), then return it as an
|
2010-03-19 09:14:27 +08:00
|
|
|
/// MVT::SimpleValueType. Otherwise, return MVT::Other.
|
2010-03-24 08:41:19 +08:00
|
|
|
MVT::SimpleValueType getKnownType(unsigned ResNo) const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// 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
|
2012-10-26 04:33:17 +08:00
|
|
|
/// found, an error is flagged.
|
2008-01-06 06:25:12 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
2011-04-18 05:38:24 +08:00
|
|
|
|
|
|
|
/// TreePredicateFn - This is an abstraction that represents the predicates on
|
|
|
|
/// a PatFrag node. This is a simple one-word wrapper around a pointer to
|
|
|
|
/// provide nice accessors.
|
|
|
|
class TreePredicateFn {
|
|
|
|
/// PatFragRec - This is the TreePattern for the PatFrag that we
|
|
|
|
/// originally came from.
|
|
|
|
TreePattern *PatFragRec;
|
|
|
|
public:
|
|
|
|
/// TreePredicateFn constructor. Here 'N' is a subclass of PatFrag.
|
2011-04-18 06:05:17 +08:00
|
|
|
TreePredicateFn(TreePattern *N);
|
2011-04-18 05:38:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
TreePattern *getOrigPatFragRecord() const { return PatFragRec; }
|
|
|
|
|
|
|
|
/// isAlwaysTrue - Return true if this is a noop predicate.
|
|
|
|
bool isAlwaysTrue() const;
|
|
|
|
|
2011-04-18 14:22:33 +08:00
|
|
|
bool isImmediatePattern() const { return !getImmCode().empty(); }
|
|
|
|
|
|
|
|
/// getImmediatePredicateCode - Return the code that evaluates this pattern if
|
|
|
|
/// this is an immediate predicate. It is an error to call this on a
|
|
|
|
/// non-immediate pattern.
|
|
|
|
std::string getImmediatePredicateCode() const {
|
|
|
|
std::string Result = getImmCode();
|
|
|
|
assert(!Result.empty() && "Isn't an immediate pattern!");
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2011-04-18 05:38:24 +08:00
|
|
|
|
|
|
|
bool operator==(const TreePredicateFn &RHS) const {
|
|
|
|
return PatFragRec == RHS.PatFragRec;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const TreePredicateFn &RHS) const { return !(*this == RHS); }
|
|
|
|
|
|
|
|
/// Return the name to use in the generated code to reference this, this is
|
|
|
|
/// "Predicate_foo" if from a pattern fragment "foo".
|
|
|
|
std::string getFnName() const;
|
|
|
|
|
|
|
|
/// getCodeToRunOnSDNode - Return the code for the function body that
|
|
|
|
/// evaluates this predicate. The argument is expected to be in "Node",
|
|
|
|
/// not N. This handles casting and conversion to a concrete node type as
|
|
|
|
/// appropriate.
|
|
|
|
std::string getCodeToRunOnSDNode() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string getPredCode() const;
|
2011-04-18 06:05:17 +08:00
|
|
|
std::string getImmCode() const;
|
2011-04-18 05:38:24 +08:00
|
|
|
};
|
2014-11-18 06:55:41 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
|
|
|
|
/// 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 {
|
2010-03-20 05:37:09 +08:00
|
|
|
/// The type of each node result. Before and during type inference, each
|
|
|
|
/// result may be a set of possible types. After (successful) type inference,
|
|
|
|
/// each is a single concrete type.
|
|
|
|
SmallVector<EEVT::TypeSet, 1> Types;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// Operator - The Record for the operator if this is an interior node (not
|
|
|
|
/// a leaf).
|
|
|
|
Record *Operator;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf.
|
|
|
|
///
|
2011-07-30 06:43:06 +08:00
|
|
|
Init *Val;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// Name - The name given to this node with the :$foo notation.
|
|
|
|
///
|
|
|
|
std::string Name;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-10-15 14:17:21 +08:00
|
|
|
/// PredicateFns - The predicate functions to execute on this node to check
|
|
|
|
/// for a match. If this list is empty, no predicate is involved.
|
2011-04-18 05:38:24 +08:00
|
|
|
std::vector<TreePredicateFn> PredicateFns;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08: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;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
std::vector<TreePatternNode*> Children;
|
|
|
|
public:
|
2010-03-20 05:37:09 +08:00
|
|
|
TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch,
|
2010-12-24 13:06:32 +08:00
|
|
|
unsigned NumResults)
|
2014-04-16 12:21:27 +08:00
|
|
|
: Operator(Op), Val(nullptr), TransformFn(nullptr), Children(Ch) {
|
2010-03-20 05:37:09 +08:00
|
|
|
Types.resize(NumResults);
|
|
|
|
}
|
2011-07-30 06:43:06 +08:00
|
|
|
TreePatternNode(Init *val, unsigned NumResults) // leaf ctor
|
2014-04-16 12:21:27 +08:00
|
|
|
: Operator(nullptr), Val(val), TransformFn(nullptr) {
|
2010-03-20 05:37:09 +08:00
|
|
|
Types.resize(NumResults);
|
2008-01-06 06:25:12 +08:00
|
|
|
}
|
|
|
|
~TreePatternNode();
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2013-03-24 02:08:44 +08:00
|
|
|
bool hasName() const { return !Name.empty(); }
|
2008-01-06 06:25:12 +08:00
|
|
|
const std::string &getName() const { return Name; }
|
2010-03-28 14:50:34 +08:00
|
|
|
void setName(StringRef N) { Name.assign(N.begin(), N.end()); }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2014-04-16 12:21:27 +08:00
|
|
|
bool isLeaf() const { return Val != nullptr; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
// Type accessors.
|
2010-03-20 05:37:09 +08:00
|
|
|
unsigned getNumTypes() const { return Types.size(); }
|
|
|
|
MVT::SimpleValueType getType(unsigned ResNo) const {
|
|
|
|
return Types[ResNo].getConcrete();
|
|
|
|
}
|
|
|
|
const SmallVectorImpl<EEVT::TypeSet> &getExtTypes() const { return Types; }
|
|
|
|
const EEVT::TypeSet &getExtType(unsigned ResNo) const { return Types[ResNo]; }
|
|
|
|
EEVT::TypeSet &getExtType(unsigned ResNo) { return Types[ResNo]; }
|
|
|
|
void setType(unsigned ResNo, const EEVT::TypeSet &T) { Types[ResNo] = T; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-20 05:37:09 +08:00
|
|
|
bool hasTypeSet(unsigned ResNo) const {
|
|
|
|
return Types[ResNo].isConcrete();
|
|
|
|
}
|
|
|
|
bool isTypeCompletelyUnknown(unsigned ResNo) const {
|
|
|
|
return Types[ResNo].isCompletelyUnknown();
|
|
|
|
}
|
|
|
|
bool isTypeDynamicallyResolved(unsigned ResNo) const {
|
|
|
|
return Types[ResNo].isDynamicallyResolved();
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2011-07-30 06:43:06 +08:00
|
|
|
Init *getLeafValue() const { assert(isLeaf()); return Val; }
|
2008-01-06 06:25:12 +08:00
|
|
|
Record *getOperator() const { assert(!isLeaf()); return Operator; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
unsigned getNumChildren() const { return Children.size(); }
|
|
|
|
TreePatternNode *getChild(unsigned N) const { return Children[N]; }
|
|
|
|
void setChild(unsigned i, TreePatternNode *N) {
|
|
|
|
Children[i] = N;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-02-16 14:10:58 +08:00
|
|
|
/// hasChild - Return true if N is any of our children.
|
|
|
|
bool hasChild(const TreePatternNode *N) const {
|
|
|
|
for (unsigned i = 0, e = Children.size(); i != e; ++i)
|
|
|
|
if (Children[i] == N) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-06 13:36:50 +08:00
|
|
|
|
2011-04-18 05:38:24 +08:00
|
|
|
bool hasAnyPredicate() const { return !PredicateFns.empty(); }
|
|
|
|
|
|
|
|
const std::vector<TreePredicateFn> &getPredicateFns() const {
|
|
|
|
return PredicateFns;
|
|
|
|
}
|
2008-10-15 14:17:21 +08:00
|
|
|
void clearPredicateFns() { PredicateFns.clear(); }
|
2011-04-18 05:38:24 +08:00
|
|
|
void setPredicateFns(const std::vector<TreePredicateFn> &Fns) {
|
2008-10-15 14:17:21 +08:00
|
|
|
assert(PredicateFns.empty() && "Overwriting non-empty predicate list!");
|
|
|
|
PredicateFns = Fns;
|
|
|
|
}
|
2011-04-18 05:38:24 +08:00
|
|
|
void addPredicateFn(const TreePredicateFn &Fn) {
|
|
|
|
assert(!Fn.isAlwaysTrue() && "Empty predicate string!");
|
2008-10-15 14:17:21 +08:00
|
|
|
if (std::find(PredicateFns.begin(), PredicateFns.end(), Fn) ==
|
|
|
|
PredicateFns.end())
|
|
|
|
PredicateFns.push_back(Fn);
|
|
|
|
}
|
2008-01-06 06:25:12 +08:00
|
|
|
|
|
|
|
Record *getTransformFn() const { return TransformFn; }
|
|
|
|
void setTransformFn(Record *Fn) { TransformFn = Fn; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 13:36:50 +08: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-17 04:29:38 +08:00
|
|
|
|
2010-02-15 06:22:58 +08:00
|
|
|
/// getComplexPatternInfo - If this node corresponds to a ComplexPattern,
|
|
|
|
/// return the ComplexPattern information, otherwise return null.
|
|
|
|
const ComplexPattern *
|
|
|
|
getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const;
|
|
|
|
|
2014-05-20 19:52:46 +08:00
|
|
|
/// Returns the number of MachineInstr operands that would be produced by this
|
|
|
|
/// node if it mapped directly to an output Instruction's
|
|
|
|
/// operand. ComplexPattern specifies this explicitly; MIOperandInfo gives it
|
|
|
|
/// for Operands; otherwise 1.
|
|
|
|
unsigned getNumMIResults(const CodeGenDAGPatterns &CGP) const;
|
|
|
|
|
2010-02-15 06:22:58 +08:00
|
|
|
/// NodeHasProperty - Return true if this node has the specified property.
|
2010-02-15 06:33:49 +08:00
|
|
|
bool NodeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-02-15 06:22:58 +08:00
|
|
|
/// TreeHasProperty - Return true if any node in this tree has the specified
|
|
|
|
/// property.
|
2010-02-15 06:33:49 +08:00
|
|
|
bool TreeHasProperty(SDNP Property, const CodeGenDAGPatterns &CGP) const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-06-17 04:29:38 +08:00
|
|
|
/// isCommutativeIntrinsic - Return true if the node is an intrinsic which is
|
|
|
|
/// marked isCommutative.
|
|
|
|
bool isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2009-07-03 08:10:29 +08:00
|
|
|
void print(raw_ostream &OS) const;
|
2008-01-06 06:25:12 +08:00
|
|
|
void dump() const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
public: // Higher level manipulation routines.
|
|
|
|
|
|
|
|
/// clone - Return a new copy of this tree.
|
|
|
|
///
|
|
|
|
TreePatternNode *clone() const;
|
2010-02-15 06:22:58 +08:00
|
|
|
|
|
|
|
/// RemoveAllTypes - Recursively strip all the types of this tree.
|
|
|
|
void RemoveAllTypes();
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// 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-06 01:49:05 +08:00
|
|
|
bool isIsomorphicTo(const TreePatternNode *N,
|
|
|
|
const MultipleUseVarSet &DepVars) const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08: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);
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2009-01-06 01:23:09 +08:00
|
|
|
/// ApplyTypeConstraints - Apply all of the type constraints relevant to
|
2008-01-06 06:25:12 +08:00
|
|
|
/// this node and its children in the tree. This returns true if it makes a
|
2012-10-26 04:33:17 +08:00
|
|
|
/// change, false otherwise. If a type contradiction is found, flag an error.
|
2008-01-06 06:25:12 +08:00
|
|
|
bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters);
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// UpdateNodeType - Set the node type of N to VT if VT contains
|
2012-10-26 04:33:17 +08:00
|
|
|
/// information. If N already contains a conflicting type, then flag an
|
|
|
|
/// error. This returns true if any information was updated.
|
2008-01-06 06:25:12 +08:00
|
|
|
///
|
2010-03-20 05:37:09 +08:00
|
|
|
bool UpdateNodeType(unsigned ResNo, const EEVT::TypeSet &InTy,
|
|
|
|
TreePattern &TP) {
|
|
|
|
return Types[ResNo].MergeInTypeInfo(InTy, TP);
|
2010-03-15 14:00:16 +08:00
|
|
|
}
|
|
|
|
|
2010-03-20 05:37:09 +08:00
|
|
|
bool UpdateNodeType(unsigned ResNo, MVT::SimpleValueType InTy,
|
|
|
|
TreePattern &TP) {
|
|
|
|
return Types[ResNo].MergeInTypeInfo(EEVT::TypeSet(InTy, TP), TP);
|
2008-01-06 06:25:12 +08:00
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2013-03-18 12:08:07 +08:00
|
|
|
// Update node type with types inferred from an instruction operand or result
|
|
|
|
// def from the ins/outs lists.
|
|
|
|
// Return true if the type changed.
|
|
|
|
bool UpdateNodeTypeFromInst(unsigned ResNo, Record *Operand, TreePattern &TP);
|
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// ContainsUnresolvedType - Return true if this tree contains any
|
|
|
|
/// unresolved types.
|
|
|
|
bool ContainsUnresolvedType() const {
|
2010-03-20 05:37:09 +08:00
|
|
|
for (unsigned i = 0, e = Types.size(); i != e; ++i)
|
|
|
|
if (!Types[i].isConcrete()) return true;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
|
|
|
|
if (getChild(i)->ContainsUnresolvedType()) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// 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 08:02:49 +08:00
|
|
|
bool canPatternMatch(std::string &Reason, const CodeGenDAGPatterns &CDP);
|
2008-01-06 06:25:12 +08:00
|
|
|
};
|
|
|
|
|
2010-02-15 05:10:33 +08:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const TreePatternNode &TPN) {
|
|
|
|
TPN.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08: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.
|
|
|
|
///
|
2014-11-18 06:55:41 +08:00
|
|
|
std::vector<TreePatternNode*> Trees;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
/// NamedNodes - This is all of the nodes that have names in the trees in this
|
|
|
|
/// pattern.
|
|
|
|
StringMap<SmallVector<TreePatternNode*,1> > NamedNodes;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// TheRecord - The actual TableGen record corresponding to this pattern.
|
|
|
|
///
|
|
|
|
Record *TheRecord;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// 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;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// CDP - the top-level object coordinating this madness.
|
|
|
|
///
|
2008-01-06 09:10:31 +08:00
|
|
|
CodeGenDAGPatterns &CDP;
|
2008-01-06 06:25:12 +08:00
|
|
|
|
|
|
|
/// isInputPattern - True if this is an input pattern, something to match.
|
|
|
|
/// False if this is an output pattern, something to emit.
|
|
|
|
bool isInputPattern;
|
2012-10-26 04:33:17 +08:00
|
|
|
|
|
|
|
/// hasError - True if the currently processed nodes have unresolvable types
|
|
|
|
/// or other non-fatal errors
|
|
|
|
bool HasError;
|
2014-05-20 19:52:46 +08:00
|
|
|
|
|
|
|
/// It's important that the usage of operands in ComplexPatterns is
|
|
|
|
/// consistent: each named operand can be defined by at most one
|
|
|
|
/// ComplexPattern. This records the ComplexPattern instance and the operand
|
|
|
|
/// number for each operand encountered in a ComplexPattern to aid in that
|
|
|
|
/// check.
|
|
|
|
StringMap<std::pair<Record *, unsigned>> ComplexPatternOperands;
|
2008-01-06 06:25:12 +08:00
|
|
|
public:
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// TreePattern constructor - Parse the specified DagInits into the
|
|
|
|
/// current record.
|
2011-07-30 06:43:06 +08:00
|
|
|
TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
|
2008-01-06 09:10:31 +08:00
|
|
|
CodeGenDAGPatterns &ise);
|
2011-07-30 06:43:06 +08:00
|
|
|
TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
|
2008-01-06 09:10:31 +08:00
|
|
|
CodeGenDAGPatterns &ise);
|
2014-11-18 06:55:41 +08:00
|
|
|
TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
|
|
|
|
CodeGenDAGPatterns &ise);
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// getTrees - Return the tree patterns which corresponds to this pattern.
|
|
|
|
///
|
2014-11-18 06:55:41 +08:00
|
|
|
const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
|
2008-01-06 06:25:12 +08:00
|
|
|
unsigned getNumTrees() const { return Trees.size(); }
|
2014-11-18 06:55:41 +08:00
|
|
|
TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
|
|
|
|
TreePatternNode *getOnlyTree() const {
|
2008-01-06 06:25:12 +08:00
|
|
|
assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
|
|
|
|
return Trees[0];
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-15 14:00:16 +08:00
|
|
|
const StringMap<SmallVector<TreePatternNode*,1> > &getNamedNodesMap() {
|
|
|
|
if (NamedNodes.empty())
|
|
|
|
ComputeNamedNodes();
|
|
|
|
return NamedNodes;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// getRecord - Return the actual TableGen record corresponding to this
|
|
|
|
/// pattern.
|
|
|
|
///
|
|
|
|
Record *getRecord() const { return TheRecord; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
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; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 09:10:31 +08:00
|
|
|
CodeGenDAGPatterns &getDAGPatterns() const { return CDP; }
|
2008-01-06 06:25:12 +08: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)
|
2014-11-18 06:55:41 +08:00
|
|
|
Trees[i] = Trees[i]->InlinePatternFragments(*this);
|
2008-01-06 06:25:12 +08:00
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// InferAllTypes - Infer/propagate as many types throughout the expression
|
2009-03-27 00:17:51 +08:00
|
|
|
/// patterns as possible. Return true if all types are inferred, false
|
2012-10-26 04:33:17 +08:00
|
|
|
/// otherwise. Bail out if a type contradiction is found.
|
2010-03-15 14:00:16 +08:00
|
|
|
bool InferAllTypes(const StringMap<SmallVector<TreePatternNode*,1> >
|
2014-04-16 12:21:27 +08:00
|
|
|
*NamedTypes=nullptr);
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2012-10-26 04:33:17 +08:00
|
|
|
/// error - If this is the first error in the current resolution step,
|
|
|
|
/// print it and set the error flag. Otherwise, continue silently.
|
2014-11-12 07:48:11 +08:00
|
|
|
void error(const Twine &Msg);
|
2012-10-26 04:33:17 +08:00
|
|
|
bool hasError() const {
|
|
|
|
return HasError;
|
|
|
|
}
|
|
|
|
void resetError() {
|
|
|
|
HasError = false;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2009-07-03 08:10:29 +08:00
|
|
|
void print(raw_ostream &OS) const;
|
2008-01-06 06:25:12 +08:00
|
|
|
void dump() const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
private:
|
2014-11-18 06:55:41 +08:00
|
|
|
TreePatternNode *ParseTreePattern(Init *DI, StringRef OpName);
|
2010-03-15 14:00:16 +08:00
|
|
|
void ComputeNamedNodes();
|
|
|
|
void ComputeNamedNodes(TreePatternNode *N);
|
2008-01-06 06:25:12 +08:00
|
|
|
};
|
|
|
|
|
2012-09-06 22:15:52 +08:00
|
|
|
/// DAGDefaultOperand - One of these is created for each OperandWithDefaultOps
|
|
|
|
/// that has a set ExecuteAlways / DefaultOps field.
|
2008-01-06 06:25:12 +08:00
|
|
|
struct DAGDefaultOperand {
|
|
|
|
std::vector<TreePatternNode*> DefaultOps;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DAGInstruction {
|
|
|
|
TreePattern *Pattern;
|
|
|
|
std::vector<Record*> Results;
|
|
|
|
std::vector<Record*> Operands;
|
|
|
|
std::vector<Record*> ImpResults;
|
2014-11-18 06:55:41 +08:00
|
|
|
TreePatternNode *ResultPattern;
|
2008-01-06 06:25:12 +08:00
|
|
|
public:
|
|
|
|
DAGInstruction(TreePattern *TP,
|
|
|
|
const std::vector<Record*> &results,
|
|
|
|
const std::vector<Record*> &operands,
|
2010-04-20 14:28:43 +08:00
|
|
|
const std::vector<Record*> &impresults)
|
2010-12-24 13:06:32 +08:00
|
|
|
: Pattern(TP), Results(results), Operands(operands),
|
2014-11-18 06:55:41 +08:00
|
|
|
ImpResults(impresults), ResultPattern(nullptr) {}
|
2008-01-06 06:25:12 +08:00
|
|
|
|
2012-10-26 04:33:17 +08:00
|
|
|
TreePattern *getPattern() const { return Pattern; }
|
2008-01-06 06:25:12 +08:00
|
|
|
unsigned getNumResults() const { return Results.size(); }
|
|
|
|
unsigned getNumOperands() const { return Operands.size(); }
|
|
|
|
unsigned getNumImpResults() const { return ImpResults.size(); }
|
|
|
|
const std::vector<Record*>& getImpResults() const { return ImpResults; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2014-11-18 06:55:41 +08:00
|
|
|
void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
Record *getResult(unsigned RN) const {
|
|
|
|
assert(RN < Results.size());
|
|
|
|
return Results[RN];
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
Record *getOperand(unsigned ON) const {
|
|
|
|
assert(ON < Operands.size());
|
|
|
|
return Operands[ON];
|
|
|
|
}
|
|
|
|
|
|
|
|
Record *getImpResult(unsigned RN) const {
|
|
|
|
assert(RN < ImpResults.size());
|
|
|
|
return ImpResults[RN];
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2014-11-18 06:55:41 +08:00
|
|
|
TreePatternNode *getResultPattern() const { return ResultPattern; }
|
2008-01-06 06:25:12 +08:00
|
|
|
};
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 09:10:31 +08:00
|
|
|
/// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns
|
2008-01-06 06:25:12 +08:00
|
|
|
/// processed to produce isel.
|
2010-02-18 14:47:49 +08:00
|
|
|
class PatternToMatch {
|
|
|
|
public:
|
2011-07-30 06:43:06 +08:00
|
|
|
PatternToMatch(Record *srcrecord, ListInit *preds,
|
2008-01-06 06:25:12 +08:00
|
|
|
TreePatternNode *src, TreePatternNode *dst,
|
|
|
|
const std::vector<Record*> &dstregs,
|
2014-08-01 08:32:36 +08:00
|
|
|
int complexity, unsigned uid)
|
2010-12-08 07:05:49 +08:00
|
|
|
: SrcRecord(srcrecord), Predicates(preds), SrcPattern(src), DstPattern(dst),
|
2010-03-02 06:09:11 +08:00
|
|
|
Dstregs(dstregs), AddedComplexity(complexity), ID(uid) {}
|
2008-01-06 06:25:12 +08:00
|
|
|
|
2010-12-08 07:05:49 +08:00
|
|
|
Record *SrcRecord; // Originating Record for the pattern.
|
2011-07-30 06:43:06 +08:00
|
|
|
ListInit *Predicates; // Top level predicate conditions to match.
|
2008-01-06 06:25:12 +08:00
|
|
|
TreePatternNode *SrcPattern; // Source pattern to match.
|
|
|
|
TreePatternNode *DstPattern; // Resulting pattern.
|
|
|
|
std::vector<Record*> Dstregs; // Physical register defs being matched.
|
2014-08-01 08:32:36 +08:00
|
|
|
int AddedComplexity; // Add to matching pattern complexity.
|
2010-03-02 06:09:11 +08:00
|
|
|
unsigned ID; // Unique ID for the record.
|
2008-01-06 06:25:12 +08:00
|
|
|
|
2010-12-08 07:05:49 +08:00
|
|
|
Record *getSrcRecord() const { return SrcRecord; }
|
2011-07-30 06:43:06 +08:00
|
|
|
ListInit *getPredicates() const { return Predicates; }
|
2008-01-06 06:25:12 +08:00
|
|
|
TreePatternNode *getSrcPattern() const { return SrcPattern; }
|
|
|
|
TreePatternNode *getDstPattern() const { return DstPattern; }
|
|
|
|
const std::vector<Record*> &getDstRegs() const { return Dstregs; }
|
2014-08-01 08:32:36 +08:00
|
|
|
int getAddedComplexity() const { return AddedComplexity; }
|
2008-08-22 08:20:26 +08:00
|
|
|
|
|
|
|
std::string getPredicateCheck() const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-03-29 09:40:38 +08:00
|
|
|
/// Compute the complexity metric for the input pattern. This roughly
|
|
|
|
/// corresponds to the number of nodes that are covered.
|
2014-08-01 08:32:36 +08:00
|
|
|
int getPatternComplexity(const CodeGenDAGPatterns &CGP) const;
|
2008-01-06 06:25:12 +08:00
|
|
|
};
|
|
|
|
|
2008-01-06 09:10:31 +08:00
|
|
|
class CodeGenDAGPatterns {
|
2008-01-06 06:25:12 +08:00
|
|
|
RecordKeeper &Records;
|
|
|
|
CodeGenTarget Target;
|
|
|
|
std::vector<CodeGenIntrinsic> Intrinsics;
|
2009-02-05 09:49:45 +08:00
|
|
|
std::vector<CodeGenIntrinsic> TgtIntrinsics;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2012-09-19 09:47:00 +08:00
|
|
|
std::map<Record*, SDNodeInfo, LessRecordByID> SDNodes;
|
|
|
|
std::map<Record*, std::pair<Record*, std::string>, LessRecordByID> SDNodeXForms;
|
|
|
|
std::map<Record*, ComplexPattern, LessRecordByID> ComplexPatterns;
|
2014-11-14 05:40:02 +08:00
|
|
|
std::map<Record *, std::unique_ptr<TreePattern>, LessRecordByID>
|
|
|
|
PatternFragments;
|
2012-09-19 09:47:00 +08:00
|
|
|
std::map<Record*, DAGDefaultOperand, LessRecordByID> DefaultOperands;
|
|
|
|
std::map<Record*, DAGInstruction, LessRecordByID> Instructions;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
// Specific SDNode definitions:
|
|
|
|
Record *intrinsic_void_sdnode;
|
|
|
|
Record *intrinsic_w_chain_sdnode, *intrinsic_wo_chain_sdnode;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
/// 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:
|
2010-12-24 13:06:32 +08:00
|
|
|
CodeGenDAGPatterns(RecordKeeper &R);
|
|
|
|
|
2008-04-03 08:02:49 +08:00
|
|
|
CodeGenTarget &getTargetInfo() { return Target; }
|
2008-01-06 06:25:12 +08:00
|
|
|
const CodeGenTarget &getTargetInfo() const { return Target; }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
Record *getSDNodeNamed(const std::string &Name) const;
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
const SDNodeInfo &getSDNodeInfo(Record *R) const {
|
|
|
|
assert(SDNodes.count(R) && "Unknown node!");
|
|
|
|
return SDNodes.find(R)->second;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:54:53 +08:00
|
|
|
// Node transformation lookups.
|
|
|
|
typedef std::pair<Record*, std::string> NodeXForm;
|
|
|
|
const NodeXForm &getSDNodeTransform(Record *R) const {
|
2008-01-06 06:25:12 +08:00
|
|
|
assert(SDNodeXForms.count(R) && "Invalid transform!");
|
|
|
|
return SDNodeXForms.find(R)->second;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2012-09-19 09:47:00 +08:00
|
|
|
typedef std::map<Record*, NodeXForm, LessRecordByID>::const_iterator
|
2009-08-23 18:39:21 +08:00
|
|
|
nx_iterator;
|
2008-01-06 06:54:53 +08:00
|
|
|
nx_iterator nx_begin() const { return SDNodeXForms.begin(); }
|
|
|
|
nx_iterator nx_end() const { return SDNodeXForms.end(); }
|
|
|
|
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
const ComplexPattern &getComplexPattern(Record *R) const {
|
|
|
|
assert(ComplexPatterns.count(R) && "Unknown addressing mode!");
|
|
|
|
return ComplexPatterns.find(R)->second;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
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 09:49:45 +08:00
|
|
|
for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
|
|
|
|
if (TgtIntrinsics[i].TheDef == R) return TgtIntrinsics[i];
|
2012-02-05 15:21:30 +08:00
|
|
|
llvm_unreachable("Unknown intrinsic!");
|
2008-01-06 06:25:12 +08:00
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
const CodeGenIntrinsic &getIntrinsicInfo(unsigned IID) const {
|
2009-02-05 09:49:45 +08:00
|
|
|
if (IID-1 < Intrinsics.size())
|
|
|
|
return Intrinsics[IID-1];
|
|
|
|
if (IID-Intrinsics.size()-1 < TgtIntrinsics.size())
|
|
|
|
return TgtIntrinsics[IID-Intrinsics.size()-1];
|
2012-02-05 15:21:30 +08:00
|
|
|
llvm_unreachable("Bad intrinsic ID!");
|
2008-01-06 06:25:12 +08:00
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08: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 09:49:45 +08:00
|
|
|
for (unsigned i = 0, e = TgtIntrinsics.size(); i != e; ++i)
|
|
|
|
if (TgtIntrinsics[i].TheDef == R) return i + Intrinsics.size();
|
2012-02-05 15:21:30 +08:00
|
|
|
llvm_unreachable("Unknown intrinsic!");
|
2008-01-06 06:25:12 +08:00
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2010-02-18 14:47:49 +08:00
|
|
|
const DAGDefaultOperand &getDefaultOperand(Record *R) const {
|
2008-01-06 06:25:12 +08:00
|
|
|
assert(DefaultOperands.count(R) &&"Isn't an analyzed default operand!");
|
|
|
|
return DefaultOperands.find(R)->second;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
// Pattern Fragment information.
|
|
|
|
TreePattern *getPatternFragment(Record *R) const {
|
|
|
|
assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
|
2014-11-14 05:40:02 +08:00
|
|
|
return PatternFragments.find(R)->second.get();
|
2008-01-06 06:25:12 +08:00
|
|
|
}
|
2010-03-20 05:37:09 +08:00
|
|
|
TreePattern *getPatternFragmentIfRead(Record *R) const {
|
2014-11-14 05:40:02 +08:00
|
|
|
if (!PatternFragments.count(R))
|
|
|
|
return nullptr;
|
|
|
|
return PatternFragments.find(R)->second.get();
|
2010-03-20 05:37:09 +08:00
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2014-11-14 05:56:57 +08:00
|
|
|
typedef std::map<Record *, std::unique_ptr<TreePattern>,
|
|
|
|
LessRecordByID>::const_iterator pf_iterator;
|
2008-01-06 06:25:12 +08:00
|
|
|
pf_iterator pf_begin() const { return PatternFragments.begin(); }
|
|
|
|
pf_iterator pf_end() const { return PatternFragments.end(); }
|
|
|
|
|
|
|
|
// Patterns to match information.
|
2008-01-06 06:30:17 +08: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(); }
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2013-10-29 02:07:21 +08:00
|
|
|
/// Parse the Pattern for an instruction, and insert the result in DAGInsts.
|
|
|
|
typedef std::map<Record*, DAGInstruction, LessRecordByID> DAGInstMap;
|
|
|
|
const DAGInstruction &parseInstructionPattern(
|
|
|
|
CodeGenInstruction &CGI, ListInit *Pattern,
|
|
|
|
DAGInstMap &DAGInsts);
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
const DAGInstruction &getInstruction(Record *R) const {
|
|
|
|
assert(Instructions.count(R) && "Unknown instruction!");
|
|
|
|
return Instructions.find(R)->second;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
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;
|
|
|
|
}
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2009-10-16 02:50:03 +08:00
|
|
|
bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); }
|
|
|
|
|
2008-01-06 06:25:12 +08:00
|
|
|
private:
|
|
|
|
void ParseNodeInfo();
|
2008-01-06 06:54:53 +08:00
|
|
|
void ParseNodeTransforms();
|
2008-01-06 06:25:12 +08:00
|
|
|
void ParseComplexPatterns();
|
2014-02-28 08:26:56 +08:00
|
|
|
void ParsePatternFragments(bool OutFrags = false);
|
2008-01-06 06:25:12 +08:00
|
|
|
void ParseDefaultOperands();
|
|
|
|
void ParseInstructions();
|
|
|
|
void ParsePatterns();
|
2008-04-03 08:02:49 +08:00
|
|
|
void InferInstructionFlags();
|
2008-01-06 06:25:12 +08:00
|
|
|
void GenerateVariants();
|
2012-08-28 11:26:49 +08:00
|
|
|
void VerifyInstructionFlags();
|
2010-12-24 13:06:32 +08:00
|
|
|
|
2012-10-26 04:33:17 +08:00
|
|
|
void AddPatternToMatch(TreePattern *Pattern, const PatternToMatch &PTM);
|
2008-01-06 06:25:12 +08:00
|
|
|
void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
|
|
|
|
std::map<std::string,
|
|
|
|
TreePatternNode*> &InstInputs,
|
|
|
|
std::map<std::string,
|
|
|
|
TreePatternNode*> &InstResults,
|
|
|
|
std::vector<Record*> &InstImpResults);
|
|
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|