2005-09-03 09:14:03 +08:00
|
|
|
//===- DAGISelEmitter.h - Generate an instruction selector ------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:37:13 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-09-03 09:14:03 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tablegen backend emits a DAG instruction selector.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef DAGISEL_EMITTER_H
|
|
|
|
#define DAGISEL_EMITTER_H
|
|
|
|
|
|
|
|
#include "TableGenBackend.h"
|
|
|
|
#include "CodeGenTarget.h"
|
2006-03-25 05:48:51 +08:00
|
|
|
#include "CodeGenIntrinsics.h"
|
2006-02-07 08:37:41 +08:00
|
|
|
#include <set>
|
2005-09-03 09:14:03 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2005-09-08 07:44:43 +08:00
|
|
|
class Record;
|
2005-09-10 10:00:02 +08:00
|
|
|
struct Init;
|
2005-09-16 06:23:50 +08:00
|
|
|
class ListInit;
|
2005-09-08 07:44:43 +08:00
|
|
|
class DagInit;
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
class SDNodeInfo;
|
2005-09-08 07:44:43 +08:00
|
|
|
class TreePattern;
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
class TreePatternNode;
|
2005-09-08 07:44:43 +08:00
|
|
|
class DAGISelEmitter;
|
2005-12-08 10:00:36 +08:00
|
|
|
class ComplexPattern;
|
2005-09-09 05:03:01 +08:00
|
|
|
|
2005-10-14 14:12:03 +08:00
|
|
|
/// MVT::DAGISelGenValueType - These are some extended forms of MVT::ValueType
|
|
|
|
/// that we use as lattice values during type inferrence.
|
|
|
|
namespace MVT {
|
|
|
|
enum DAGISelGenValueType {
|
|
|
|
isFP = MVT::LAST_VALUETYPE,
|
|
|
|
isInt,
|
|
|
|
isUnknown
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-09-09 05:27:15 +08: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 {
|
2005-12-10 06:57:42 +08:00
|
|
|
SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisSameAs,
|
2006-03-20 13:39:48 +08:00
|
|
|
SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisIntVectorOfSameSize
|
2005-09-09 05:27:15 +08:00
|
|
|
} ConstraintType;
|
|
|
|
|
|
|
|
union { // The discriminated union.
|
|
|
|
struct {
|
|
|
|
MVT::ValueType VT;
|
|
|
|
} SDTCisVT_Info;
|
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisSameAs_Info;
|
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisVTSmallerThanOp_Info;
|
2005-10-14 12:53:53 +08:00
|
|
|
struct {
|
|
|
|
unsigned BigOperandNum;
|
|
|
|
} SDTCisOpSmallerThanOp_Info;
|
2006-03-20 13:39:48 +08:00
|
|
|
struct {
|
|
|
|
unsigned OtherOperandNum;
|
|
|
|
} SDTCisIntVectorOfSameSize_Info;
|
2005-09-09 05:27:15 +08:00
|
|
|
} x;
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
|
|
|
|
/// 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;
|
2005-09-09 05:27:15 +08:00
|
|
|
};
|
|
|
|
|
2005-09-09 05:03:01 +08:00
|
|
|
/// 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;
|
2005-09-29 02:28:29 +08:00
|
|
|
unsigned Properties;
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
unsigned NumResults;
|
|
|
|
int NumOperands;
|
2005-09-09 05:27:15 +08:00
|
|
|
std::vector<SDTypeConstraint> TypeConstraints;
|
2005-09-09 05:03:01 +08:00
|
|
|
public:
|
|
|
|
SDNodeInfo(Record *R); // Parse the specified record.
|
|
|
|
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
unsigned getNumResults() const { return NumResults; }
|
2005-09-09 05:27:15 +08:00
|
|
|
int getNumOperands() const { return NumOperands; }
|
2005-09-09 05:03:01 +08:00
|
|
|
Record *getRecord() const { return Def; }
|
|
|
|
const std::string &getEnumName() const { return EnumName; }
|
|
|
|
const std::string &getSDClassName() const { return SDClassName; }
|
2005-09-09 05:27:15 +08:00
|
|
|
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
const std::vector<SDTypeConstraint> &getTypeConstraints() const {
|
2005-09-09 05:27:15 +08:00
|
|
|
return TypeConstraints;
|
|
|
|
}
|
2005-09-29 02:28:29 +08:00
|
|
|
|
|
|
|
/// hasProperty - Return true if this node has the specified property.
|
|
|
|
///
|
|
|
|
bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
|
|
|
|
/// 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;
|
|
|
|
}
|
2005-09-09 05:03:01 +08:00
|
|
|
};
|
2005-09-03 09:14:03 +08:00
|
|
|
|
2005-09-08 07:44:43 +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 {
|
2005-12-30 08:12:56 +08:00
|
|
|
/// The inferred type for this node, or MVT::isUnknown if it hasn't
|
2005-09-08 07:44:43 +08:00
|
|
|
/// been determined yet.
|
2005-12-30 08:12:56 +08:00
|
|
|
std::vector<unsigned char> Types;
|
2005-10-14 14:12:03 +08:00
|
|
|
|
2005-09-08 07:44:43 +08:00
|
|
|
/// 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;
|
|
|
|
|
|
|
|
/// PredicateFn - The predicate function to execute on this node to check
|
|
|
|
/// for a match. If this string is empty, no predicate is involved.
|
|
|
|
std::string PredicateFn;
|
|
|
|
|
2005-09-14 05:51:00 +08:00
|
|
|
/// TransformFn - The transformation function to execute on this node before
|
|
|
|
/// it can be substituted into the resulting instruction on a pattern match.
|
2005-09-15 06:55:26 +08:00
|
|
|
Record *TransformFn;
|
2005-09-14 05:51:00 +08:00
|
|
|
|
2005-09-08 07:44:43 +08:00
|
|
|
std::vector<TreePatternNode*> Children;
|
|
|
|
public:
|
|
|
|
TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch)
|
2005-12-30 08:12:56 +08:00
|
|
|
: Types(), Operator(Op), Val(0), TransformFn(0),
|
|
|
|
Children(Ch) { Types.push_back(MVT::isUnknown); }
|
2005-09-08 07:44:43 +08:00
|
|
|
TreePatternNode(Init *val) // leaf ctor
|
2006-01-29 10:43:35 +08:00
|
|
|
: Types(), Operator(0), Val(val), TransformFn(0) {
|
|
|
|
Types.push_back(MVT::isUnknown);
|
|
|
|
}
|
2005-09-08 07:44:43 +08:00
|
|
|
~TreePatternNode();
|
|
|
|
|
|
|
|
const std::string &getName() const { return Name; }
|
|
|
|
void setName(const std::string &N) { Name = N; }
|
|
|
|
|
|
|
|
bool isLeaf() const { return Val != 0; }
|
2006-05-18 04:37:59 +08:00
|
|
|
bool hasTypeSet() const {
|
|
|
|
return (Types[0] < MVT::LAST_VALUETYPE) || (Types[0] == MVT::iPTR);
|
|
|
|
}
|
2005-10-14 14:12:03 +08:00
|
|
|
bool isTypeCompletelyUnknown() const {
|
2005-12-30 08:12:56 +08:00
|
|
|
return Types[0] == MVT::isUnknown;
|
2005-10-14 14:12:03 +08:00
|
|
|
}
|
2006-05-18 04:37:59 +08:00
|
|
|
bool isTypeDynamicallyResolved() const {
|
|
|
|
return Types[0] == MVT::iPTR;
|
|
|
|
}
|
2005-12-30 08:12:56 +08:00
|
|
|
MVT::ValueType getTypeNum(unsigned Num) const {
|
2005-10-14 14:12:03 +08:00
|
|
|
assert(hasTypeSet() && "Doesn't have a type yet!");
|
2005-12-30 08:12:56 +08:00
|
|
|
assert(Types.size() > Num && "Type num out of range!");
|
|
|
|
return (MVT::ValueType)Types[Num];
|
2005-10-14 14:12:03 +08:00
|
|
|
}
|
2005-12-30 08:12:56 +08: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; }
|
|
|
|
void removeTypes() { Types = std::vector<unsigned char>(1,MVT::isUnknown); }
|
2005-09-08 07:44:43 +08: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;
|
|
|
|
}
|
|
|
|
|
2005-12-30 08:12:56 +08:00
|
|
|
|
2005-09-08 07:44:43 +08:00
|
|
|
const std::string &getPredicateFn() const { return PredicateFn; }
|
|
|
|
void setPredicateFn(const std::string &Fn) { PredicateFn = Fn; }
|
2005-09-14 05:51:00 +08:00
|
|
|
|
2005-09-15 06:55:26 +08:00
|
|
|
Record *getTransformFn() const { return TransformFn; }
|
|
|
|
void setTransformFn(Record *Fn) { TransformFn = Fn; }
|
2005-09-08 07:44:43 +08:00
|
|
|
|
|
|
|
void print(std::ostream &OS) const;
|
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
public: // Higher level manipulation routines.
|
|
|
|
|
|
|
|
/// clone - Return a new copy of this tree.
|
|
|
|
///
|
|
|
|
TreePatternNode *clone() const;
|
|
|
|
|
2005-09-30 03:28:10 +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.
|
|
|
|
bool isIsomorphicTo(const TreePatternNode *N) const;
|
|
|
|
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
/// SubstituteFormalArguments - Replace the formal arguments in this tree
|
|
|
|
/// with actual values specified by ArgMap.
|
2005-09-08 07:44:43 +08:00
|
|
|
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);
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
|
|
|
|
/// ApplyTypeConstraints - Apply all of the type constraints relevent to
|
|
|
|
/// 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.
|
2005-10-14 12:11:13 +08:00
|
|
|
bool ApplyTypeConstraints(TreePattern &TP, bool NotRegisters);
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
|
|
|
|
/// 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.
|
|
|
|
///
|
2005-12-30 08:12:56 +08:00
|
|
|
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);
|
|
|
|
}
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
|
|
|
|
/// ContainsUnresolvedType - Return true if this tree contains any
|
|
|
|
/// unresolved types.
|
|
|
|
bool ContainsUnresolvedType() const {
|
2006-05-18 04:37:59 +08:00
|
|
|
if (!hasTypeSet() && !isTypeDynamicallyResolved()) return true;
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
|
|
|
|
if (getChild(i)->ContainsUnresolvedType()) return true;
|
|
|
|
return false;
|
|
|
|
}
|
Emit an error if instructions or patterns are defined but can never match.
Currently we check that immediate values live on the RHS of commutative
operators. Defining ORI like this, for example:
def ORI : DForm_4<24, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
"ori $dst, $src1, $src2",
[(set GPRC:$dst, (or immZExt16:$src2, GPRC:$src1))]>;
results in:
tblgen: In ORI: Instruction can never match: Immediate values must be on the RHS of commutative operators!
llvm-svn: 23501
2005-09-29 03:27:25 +08:00
|
|
|
|
2005-09-29 04:58:06 +08:00
|
|
|
/// canPatternMatch - If it is impossible for this pattern to match on this
|
|
|
|
/// target, fill in Reason and return false. Otherwise, return true.
|
Emit an error if instructions or patterns are defined but can never match.
Currently we check that immediate values live on the RHS of commutative
operators. Defining ORI like this, for example:
def ORI : DForm_4<24, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
"ori $dst, $src1, $src2",
[(set GPRC:$dst, (or immZExt16:$src2, GPRC:$src1))]>;
results in:
tblgen: In ORI: Instruction can never match: Immediate values must be on the RHS of commutative operators!
llvm-svn: 23501
2005-09-29 03:27:25 +08:00
|
|
|
bool canPatternMatch(std::string &Reason, DAGISelEmitter &ISE);
|
2005-09-08 07:44:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-09-14 05:20:49 +08:00
|
|
|
/// TreePattern - Represent a pattern, used for instructions, pattern
|
|
|
|
/// fragments, etc.
|
2005-09-08 07:44:43 +08:00
|
|
|
///
|
|
|
|
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;
|
|
|
|
|
|
|
|
/// ISE - the DAG isel emitter coordinating this madness.
|
|
|
|
///
|
|
|
|
DAGISelEmitter &ISE;
|
2005-10-21 09:19:59 +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;
|
2005-09-08 07:44:43 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
/// TreePattern constructor - Parse the specified DagInits into the
|
|
|
|
/// current record.
|
2005-10-21 09:19:59 +08:00
|
|
|
TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
|
|
|
|
DAGISelEmitter &ise);
|
|
|
|
TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
|
|
|
|
DAGISelEmitter &ise);
|
|
|
|
TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
|
|
|
|
DAGISelEmitter &ise);
|
2005-09-08 07:44:43 +08:00
|
|
|
|
|
|
|
/// getTrees - Return the tree patterns which corresponds to this pattern.
|
|
|
|
///
|
|
|
|
const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
|
2005-09-09 09:11:17 +08:00
|
|
|
unsigned getNumTrees() const { return Trees.size(); }
|
|
|
|
TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
|
2005-09-09 09:15:01 +08:00
|
|
|
TreePatternNode *getOnlyTree() const {
|
|
|
|
assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
|
|
|
|
return Trees[0];
|
|
|
|
}
|
2005-09-08 07:44:43 +08:00
|
|
|
|
|
|
|
/// 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];
|
|
|
|
}
|
2005-09-14 05:20:49 +08:00
|
|
|
std::vector<std::string> &getArgList() { return Args; }
|
2005-09-08 07:44:43 +08:00
|
|
|
|
|
|
|
DAGISelEmitter &getDAGISelEmitter() const { return ISE; }
|
|
|
|
|
|
|
|
/// 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);
|
|
|
|
}
|
|
|
|
|
Implement a complete type inference system for dag patterns, based on the
constraints defined in the DAG node definitions in the .td files. This
allows us to infer (and check!) the types for all nodes in the current
ppc .td file. For example, instead of:
Inst pattern EQV: (set GPRC:i32:$rT, (xor (xor GPRC:i32:$rA, GPRC:i32:$rB), (imm)<<Predicate_immAllOnes>>))
we now fully infer:
Inst pattern EQV: (set:void GPRC:i32:$rT, (xor:i32 (xor:i32 GPRC:i32:$rA, GPRC:i32:$rB), (imm:i32)<<Predicate_immAllOnes>>))
from: (set GPRC:$rT, (not (xor GPRC:$rA, GPRC:$rB)))
llvm-svn: 23284
2005-09-09 07:22:48 +08:00
|
|
|
/// InferAllTypes - Infer/propagate as many types throughout the expression
|
|
|
|
/// patterns as possible. Return true if all types are infered, false
|
|
|
|
/// otherwise. Throw an exception if a type contradiction is found.
|
|
|
|
bool InferAllTypes();
|
|
|
|
|
2005-09-08 07:44:43 +08:00
|
|
|
/// error - Throw an exception, prefixing it with information about this
|
|
|
|
/// pattern.
|
|
|
|
void error(const std::string &Msg) const;
|
|
|
|
|
|
|
|
void print(std::ostream &OS) const;
|
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
TreePatternNode *ParseTreePattern(DagInit *DI);
|
|
|
|
};
|
2005-09-14 12:03:16 +08:00
|
|
|
|
2007-07-06 09:05:26 +08:00
|
|
|
/// DAGDefaultOperand - One of these is created for each PredicateOperand
|
|
|
|
/// or OptionalDefOperand that has a set ExecuteAlways / DefaultOps field.
|
|
|
|
struct DAGDefaultOperand {
|
|
|
|
std::vector<TreePatternNode*> DefaultOps;
|
2006-11-04 13:12:02 +08:00
|
|
|
};
|
2005-09-14 12:03:16 +08:00
|
|
|
|
|
|
|
class DAGInstruction {
|
|
|
|
TreePattern *Pattern;
|
2005-12-01 08:06:14 +08:00
|
|
|
std::vector<Record*> Results;
|
|
|
|
std::vector<Record*> Operands;
|
2005-12-17 09:19:28 +08:00
|
|
|
std::vector<Record*> ImpResults;
|
2005-12-24 06:11:47 +08:00
|
|
|
std::vector<Record*> ImpOperands;
|
2005-09-15 06:55:26 +08:00
|
|
|
TreePatternNode *ResultPattern;
|
2005-09-14 12:03:16 +08:00
|
|
|
public:
|
2005-09-16 05:51:12 +08:00
|
|
|
DAGInstruction(TreePattern *TP,
|
2005-12-01 08:06:14 +08:00
|
|
|
const std::vector<Record*> &results,
|
2005-12-17 09:19:28 +08:00
|
|
|
const std::vector<Record*> &operands,
|
2005-12-24 06:11:47 +08:00
|
|
|
const std::vector<Record*> &impresults,
|
|
|
|
const std::vector<Record*> &impoperands)
|
2005-12-01 08:06:14 +08:00
|
|
|
: Pattern(TP), Results(results), Operands(operands),
|
2005-12-24 06:11:47 +08:00
|
|
|
ImpResults(impresults), ImpOperands(impoperands),
|
|
|
|
ResultPattern(0) {}
|
2005-09-14 12:03:16 +08:00
|
|
|
|
|
|
|
TreePattern *getPattern() const { return Pattern; }
|
2005-12-01 08:06:14 +08:00
|
|
|
unsigned getNumResults() const { return Results.size(); }
|
|
|
|
unsigned getNumOperands() const { return Operands.size(); }
|
2005-12-17 09:19:28 +08:00
|
|
|
unsigned getNumImpResults() const { return ImpResults.size(); }
|
2005-12-24 06:11:47 +08:00
|
|
|
unsigned getNumImpOperands() const { return ImpOperands.size(); }
|
2007-09-13 07:30:14 +08:00
|
|
|
const std::vector<Record*>& getImpResults() const { return ImpResults; }
|
2005-09-16 05:51:12 +08:00
|
|
|
|
2005-09-16 06:23:50 +08:00
|
|
|
void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
|
|
|
|
|
2005-12-01 08:06:14 +08:00
|
|
|
Record *getResult(unsigned RN) const {
|
|
|
|
assert(RN < Results.size());
|
|
|
|
return Results[RN];
|
2005-09-16 05:51:12 +08:00
|
|
|
}
|
|
|
|
|
2005-12-01 08:06:14 +08:00
|
|
|
Record *getOperand(unsigned ON) const {
|
|
|
|
assert(ON < Operands.size());
|
|
|
|
return Operands[ON];
|
2005-09-16 05:51:12 +08:00
|
|
|
}
|
2005-12-17 09:19:28 +08:00
|
|
|
|
|
|
|
Record *getImpResult(unsigned RN) const {
|
|
|
|
assert(RN < ImpResults.size());
|
|
|
|
return ImpResults[RN];
|
|
|
|
}
|
|
|
|
|
2005-12-24 06:11:47 +08:00
|
|
|
Record *getImpOperand(unsigned ON) const {
|
|
|
|
assert(ON < ImpOperands.size());
|
|
|
|
return ImpOperands[ON];
|
|
|
|
}
|
|
|
|
|
2005-09-15 06:55:26 +08:00
|
|
|
TreePatternNode *getResultPattern() const { return ResultPattern; }
|
2005-09-14 12:03:16 +08:00
|
|
|
};
|
2005-09-08 07:44:43 +08:00
|
|
|
|
2005-12-15 06:02:59 +08:00
|
|
|
/// PatternToMatch - Used by DAGISelEmitter to keep tab of patterns processed
|
|
|
|
/// to produce isel.
|
|
|
|
struct PatternToMatch {
|
2006-04-20 02:07:24 +08:00
|
|
|
PatternToMatch(ListInit *preds,
|
2006-04-20 04:36:09 +08:00
|
|
|
TreePatternNode *src, TreePatternNode *dst,
|
2007-09-13 07:30:14 +08:00
|
|
|
const std::vector<Record*> &dstregs,
|
2006-04-20 04:36:09 +08:00
|
|
|
unsigned complexity):
|
2007-09-13 07:30:14 +08:00
|
|
|
Predicates(preds), SrcPattern(src), DstPattern(dst), Dstregs(dstregs),
|
2006-04-20 04:36:09 +08:00
|
|
|
AddedComplexity(complexity) {};
|
2005-12-15 06:02:59 +08:00
|
|
|
|
|
|
|
ListInit *Predicates; // Top level predicate conditions to match.
|
|
|
|
TreePatternNode *SrcPattern; // Source pattern to match.
|
|
|
|
TreePatternNode *DstPattern; // Resulting pattern.
|
2007-09-13 07:30:14 +08:00
|
|
|
std::vector<Record*> Dstregs; // Physical register defs being matched.
|
2006-04-20 04:36:09 +08:00
|
|
|
unsigned AddedComplexity; // Add to matching pattern complexity.
|
2005-12-15 06:02:59 +08:00
|
|
|
|
|
|
|
ListInit *getPredicates() const { return Predicates; }
|
|
|
|
TreePatternNode *getSrcPattern() const { return SrcPattern; }
|
|
|
|
TreePatternNode *getDstPattern() const { return DstPattern; }
|
2007-09-13 07:30:14 +08:00
|
|
|
const std::vector<Record*> &getDstRegs() const { return Dstregs; }
|
2006-04-20 04:36:09 +08:00
|
|
|
unsigned getAddedComplexity() const { return AddedComplexity; }
|
2005-12-15 06:02:59 +08:00
|
|
|
};
|
|
|
|
|
2006-01-18 05:31:18 +08:00
|
|
|
/// DAGISelEmitter - The top-level class which coordinates construction
|
2005-09-03 09:14:03 +08:00
|
|
|
/// and emission of the instruction selector.
|
|
|
|
///
|
|
|
|
class DAGISelEmitter : public TableGenBackend {
|
2005-09-24 04:52:47 +08:00
|
|
|
private:
|
2005-09-03 09:14:03 +08:00
|
|
|
RecordKeeper &Records;
|
|
|
|
CodeGenTarget Target;
|
2006-03-25 05:48:51 +08:00
|
|
|
std::vector<CodeGenIntrinsic> Intrinsics;
|
2006-02-07 08:37:41 +08:00
|
|
|
|
2005-09-09 05:03:01 +08:00
|
|
|
std::map<Record*, SDNodeInfo> SDNodes;
|
2005-09-14 05:51:00 +08:00
|
|
|
std::map<Record*, std::pair<Record*, std::string> > SDNodeXForms;
|
2005-12-08 10:00:36 +08:00
|
|
|
std::map<Record*, ComplexPattern> ComplexPatterns;
|
2005-09-08 07:44:43 +08:00
|
|
|
std::map<Record*, TreePattern*> PatternFragments;
|
2007-07-06 09:05:26 +08:00
|
|
|
std::map<Record*, DAGDefaultOperand> DefaultOperands;
|
2005-09-16 05:57:35 +08:00
|
|
|
std::map<Record*, DAGInstruction> Instructions;
|
2005-09-14 08:09:24 +08:00
|
|
|
|
2006-03-25 07:10:39 +08:00
|
|
|
// Specific SDNode definitions:
|
|
|
|
Record *intrinsic_void_sdnode;
|
|
|
|
Record *intrinsic_w_chain_sdnode, *intrinsic_wo_chain_sdnode;
|
|
|
|
|
2005-09-14 08:09:24 +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.
|
2005-09-24 03:36:15 +08:00
|
|
|
std::vector<PatternToMatch> PatternsToMatch;
|
2005-09-03 09:14:03 +08:00
|
|
|
public:
|
|
|
|
DAGISelEmitter(RecordKeeper &R) : Records(R) {}
|
|
|
|
|
|
|
|
// run - Output the isel, returning true on failure.
|
2005-09-08 07:44:43 +08:00
|
|
|
void run(std::ostream &OS);
|
2005-09-09 05:03:01 +08:00
|
|
|
|
2005-10-14 12:11:13 +08:00
|
|
|
const CodeGenTarget &getTargetInfo() const { return Target; }
|
|
|
|
|
2005-11-02 14:49:14 +08:00
|
|
|
Record *getSDNodeNamed(const std::string &Name) const;
|
|
|
|
|
2005-09-09 05:03:01 +08:00
|
|
|
const SDNodeInfo &getSDNodeInfo(Record *R) const {
|
|
|
|
assert(SDNodes.count(R) && "Unknown node!");
|
|
|
|
return SDNodes.find(R)->second;
|
|
|
|
}
|
2005-09-08 07:44:43 +08:00
|
|
|
|
2005-09-14 05:59:15 +08:00
|
|
|
const std::pair<Record*, std::string> &getSDNodeTransform(Record *R) const {
|
|
|
|
assert(SDNodeXForms.count(R) && "Invalid transform!");
|
|
|
|
return SDNodeXForms.find(R)->second;
|
|
|
|
}
|
2005-12-08 10:00:36 +08:00
|
|
|
|
|
|
|
const ComplexPattern &getComplexPattern(Record *R) const {
|
|
|
|
assert(ComplexPatterns.count(R) && "Unknown addressing mode!");
|
|
|
|
return ComplexPatterns.find(R)->second;
|
|
|
|
}
|
|
|
|
|
2006-03-25 05:48:51 +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];
|
|
|
|
assert(0 && "Unknown intrinsic!");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2006-03-25 07:10:39 +08:00
|
|
|
const CodeGenIntrinsic &getIntrinsicInfo(unsigned IID) const {
|
|
|
|
assert(IID-1 < Intrinsics.size() && "Bad intrinsic ID!");
|
|
|
|
return Intrinsics[IID-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getIntrinsicID(Record *R) const {
|
|
|
|
for (unsigned i = 0, e = Intrinsics.size(); i != e; ++i)
|
|
|
|
if (Intrinsics[i].TheDef == R) return i;
|
|
|
|
assert(0 && "Unknown intrinsic!");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2007-07-06 09:05:26 +08:00
|
|
|
const DAGDefaultOperand &getDefaultOperand(Record *R) {
|
|
|
|
assert(DefaultOperands.count(R) &&"Isn't an analyzed default operand!");
|
|
|
|
return DefaultOperands.find(R)->second;
|
2006-11-04 13:12:02 +08:00
|
|
|
}
|
|
|
|
|
2005-12-08 10:00:36 +08:00
|
|
|
TreePattern *getPatternFragment(Record *R) const {
|
|
|
|
assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
|
|
|
|
return PatternFragments.find(R)->second;
|
|
|
|
}
|
2005-09-14 05:59:15 +08:00
|
|
|
|
2005-09-16 05:57:35 +08:00
|
|
|
const DAGInstruction &getInstruction(Record *R) const {
|
|
|
|
assert(Instructions.count(R) && "Unknown instruction!");
|
|
|
|
return Instructions.find(R)->second;
|
|
|
|
}
|
|
|
|
|
2006-03-25 07:10:39 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 07:44:43 +08:00
|
|
|
private:
|
2005-09-09 05:03:01 +08:00
|
|
|
void ParseNodeInfo();
|
2005-09-14 05:51:00 +08:00
|
|
|
void ParseNodeTransforms(std::ostream &OS);
|
2005-12-08 10:00:36 +08:00
|
|
|
void ParseComplexPatterns();
|
2005-09-15 10:38:02 +08:00
|
|
|
void ParsePatternFragments(std::ostream &OS);
|
2007-07-06 09:05:26 +08:00
|
|
|
void ParseDefaultOperands();
|
2005-09-15 10:38:02 +08:00
|
|
|
void ParseInstructions();
|
|
|
|
void ParsePatterns();
|
Emit an error if instructions or patterns are defined but can never match.
Currently we check that immediate values live on the RHS of commutative
operators. Defining ORI like this, for example:
def ORI : DForm_4<24, (ops GPRC:$dst, GPRC:$src1, u16imm:$src2),
"ori $dst, $src1, $src2",
[(set GPRC:$dst, (or immZExt16:$src2, GPRC:$src1))]>;
results in:
tblgen: In ORI: Instruction can never match: Immediate values must be on the RHS of commutative operators!
llvm-svn: 23501
2005-09-29 03:27:25 +08:00
|
|
|
void GenerateVariants();
|
2005-09-15 04:53:42 +08:00
|
|
|
void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
|
|
|
|
std::map<std::string,
|
|
|
|
TreePatternNode*> &InstInputs,
|
2006-03-20 14:04:09 +08:00
|
|
|
std::map<std::string,
|
|
|
|
TreePatternNode*> &InstResults,
|
2005-12-24 06:11:47 +08:00
|
|
|
std::vector<Record*> &InstImpInputs,
|
2005-12-17 09:19:28 +08:00
|
|
|
std::vector<Record*> &InstImpResults);
|
2006-01-29 12:25:26 +08:00
|
|
|
void GenerateCodeForPattern(PatternToMatch &Pattern,
|
2006-08-26 08:59:04 +08:00
|
|
|
std::vector<std::pair<unsigned, std::string> > &GeneratedCode,
|
2006-08-26 09:02:19 +08:00
|
|
|
std::set<std::string> &GeneratedDecl,
|
2006-07-15 16:45:20 +08:00
|
|
|
std::vector<std::string> &TargetOpcodes,
|
2006-08-08 06:17:58 +08:00
|
|
|
std::vector<std::string> &TargetVTs);
|
2006-01-29 12:25:26 +08:00
|
|
|
void EmitPatterns(std::vector<std::pair<PatternToMatch*,
|
2006-08-26 08:59:04 +08:00
|
|
|
std::vector<std::pair<unsigned, std::string> > > > &Patterns,
|
2006-01-29 12:25:26 +08:00
|
|
|
unsigned Indent, std::ostream &OS);
|
2005-09-08 07:44:43 +08:00
|
|
|
void EmitInstructionSelector(std::ostream &OS);
|
2005-09-03 09:14:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|