aboutsummaryrefslogtreecommitdiffstats
path: root/utils/TableGen/DAGISelEmitter.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-09-08 23:22:48 +0000
committerChris Lattner <sabre@nondot.org>2005-09-08 23:22:48 +0000
commit327076005d608361c9f3b036e9401f14c235a8e3 (patch)
tree3b0b1b472bf45e7ef2bd37bec418382b0e17e944 /utils/TableGen/DAGISelEmitter.h
parentb85c64c4d882d24fe727f28126f83fce993ed8c8 (diff)
downloadexternal_llvm-327076005d608361c9f3b036e9401f14c235a8e3.zip
external_llvm-327076005d608361c9f3b036e9401f14c235a8e3.tar.gz
external_llvm-327076005d608361c9f3b036e9401f14c235a8e3.tar.bz2
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))) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23284 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/DAGISelEmitter.h')
-rw-r--r--utils/TableGen/DAGISelEmitter.h62
1 files changed, 58 insertions, 4 deletions
diff --git a/utils/TableGen/DAGISelEmitter.h b/utils/TableGen/DAGISelEmitter.h
index e2fade9..20d24fb 100644
--- a/utils/TableGen/DAGISelEmitter.h
+++ b/utils/TableGen/DAGISelEmitter.h
@@ -21,7 +21,9 @@ namespace llvm {
class Record;
class Init;
class DagInit;
+ class SDNodeInfo;
class TreePattern;
+ class TreePatternNode;
class DAGISelEmitter;
/// SDTypeConstraint - This is a discriminated union of constraints,
@@ -45,6 +47,18 @@ namespace llvm {
unsigned OtherOperandNum;
} SDTCisVTSmallerThanOp_Info;
} 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
@@ -54,20 +68,32 @@ namespace llvm {
Record *Def;
std::string EnumName;
std::string SDClassName;
- int NumResults, NumOperands;
+ unsigned NumResults;
+ int NumOperands;
std::vector<SDTypeConstraint> TypeConstraints;
public:
SDNodeInfo(Record *R); // Parse the specified record.
- int getNumResults() const { return NumResults; }
+ 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 std::vector<SDTypeConstraint> &getTypeConstraints() const {
return TypeConstraints;
}
+
+ /// 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
@@ -106,6 +132,7 @@ namespace llvm {
void setName(const std::string &N) { Name = N; }
bool isLeaf() const { return Val != 0; }
+ bool hasTypeSet() const { return Ty != MVT::LAST_VALUETYPE; }
MVT::ValueType getType() const { return Ty; }
void setType(MVT::ValueType VT) { Ty = VT; }
@@ -130,6 +157,8 @@ namespace llvm {
///
TreePatternNode *clone() const;
+ /// SubstituteFormalArguments - Replace the formal arguments in this tree
+ /// with actual values specified by ArgMap.
void SubstituteFormalArguments(std::map<std::string,
TreePatternNode*> &ArgMap);
@@ -137,7 +166,27 @@ namespace llvm {
/// fragments, inline them into place, giving us a pattern without any
/// PatFrag references.
TreePatternNode *InlinePatternFragments(TreePattern &TP);
-
+
+ /// 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.
+ bool ApplyTypeConstraints(TreePattern &TP);
+
+ /// 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(MVT::ValueType VT, TreePattern &TP);
+
+ /// ContainsUnresolvedType - Return true if this tree contains any
+ /// unresolved types.
+ bool ContainsUnresolvedType() const {
+ if (Ty == MVT::LAST_VALUETYPE) return true;
+ for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
+ if (getChild(i)->ContainsUnresolvedType()) return true;
+ return false;
+ }
};
@@ -206,6 +255,11 @@ namespace llvm {
Trees[i] = Trees[i]->InlinePatternFragments(*this);
}
+ /// 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();
+
/// error - Throw an exception, prefixing it with information about this
/// pattern.
void error(const std::string &Msg) const;