#include "TableGenBackend.h"
#include "CodeGenTarget.h"
+#include "CodeGenIntrinsics.h"
+#include <set>
namespace llvm {
class Record;
unsigned OperandNo; // The operand # this constraint applies to.
enum {
SDTCisVT, SDTCisPtrTy, SDTCisInt, SDTCisFP, SDTCisSameAs,
- SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp
+ SDTCisVTSmallerThanOp, SDTCisOpSmallerThanOp, SDTCisIntVectorOfSameSize
} ConstraintType;
union { // The discriminated union.
struct {
unsigned BigOperandNum;
} SDTCisOpSmallerThanOp_Info;
+ struct {
+ unsigned OtherOperandNum;
+ } SDTCisIntVectorOfSameSize_Info;
} x;
/// ApplyTypeConstraint - Given a node in a pattern, apply this type
void setName(const std::string &N) { Name = N; }
bool isLeaf() const { return Val != 0; }
- bool hasTypeSet() const { return Types[0] < MVT::LAST_VALUETYPE; }
+ bool hasTypeSet() const {
+ return (Types[0] < MVT::LAST_VALUETYPE) || (Types[0] == MVT::iPTR);
+ }
bool isTypeCompletelyUnknown() const {
return Types[0] == MVT::isUnknown;
}
+ bool isTypeDynamicallyResolved() const {
+ return Types[0] == MVT::iPTR;
+ }
MVT::ValueType getTypeNum(unsigned Num) const {
assert(hasTypeSet() && "Doesn't have a type yet!");
assert(Types.size() > Num && "Type num out of range!");
/// ContainsUnresolvedType - Return true if this tree contains any
/// unresolved types.
bool ContainsUnresolvedType() const {
- if (!hasTypeSet()) return true;
+ if (!hasTypeSet() && !isTypeDynamicallyResolved()) return true;
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
if (getChild(i)->ContainsUnresolvedType()) return true;
return false;
/// PatternToMatch - Used by DAGISelEmitter to keep tab of patterns processed
/// to produce isel.
struct PatternToMatch {
- PatternToMatch(ListInit *preds, TreePatternNode *src, TreePatternNode *dst):
- Predicates(preds), SrcPattern(src), DstPattern(dst) {};
+ PatternToMatch(ListInit *preds,
+ TreePatternNode *src, TreePatternNode *dst,
+ unsigned complexity):
+ Predicates(preds), SrcPattern(src), DstPattern(dst),
+ AddedComplexity(complexity) {};
ListInit *Predicates; // Top level predicate conditions to match.
TreePatternNode *SrcPattern; // Source pattern to match.
TreePatternNode *DstPattern; // Resulting pattern.
+ unsigned AddedComplexity; // Add to matching pattern complexity.
ListInit *getPredicates() const { return Predicates; }
TreePatternNode *getSrcPattern() const { return SrcPattern; }
TreePatternNode *getDstPattern() const { return DstPattern; }
+ unsigned getAddedComplexity() const { return AddedComplexity; }
};
/// DAGISelEmitter - The top-level class which coordinates construction
/// and emission of the instruction selector.
///
class DAGISelEmitter : public TableGenBackend {
-public:
- //typedef std::pair<TreePatternNode*, TreePatternNode*> PatternToMatch;
private:
RecordKeeper &Records;
CodeGenTarget Target;
-
+ std::vector<CodeGenIntrinsic> Intrinsics;
+
std::map<Record*, SDNodeInfo> SDNodes;
std::map<Record*, std::pair<Record*, std::string> > SDNodeXForms;
std::map<Record*, ComplexPattern> ComplexPatterns;
std::map<Record*, TreePattern*> PatternFragments;
std::map<Record*, DAGInstruction> Instructions;
+ // 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.
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];
+ assert(0 && "Unknown intrinsic!");
+ abort();
+ }
+
+ 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();
+ }
+
TreePattern *getPatternFragment(Record *R) const {
assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
return PatternFragments.find(R)->second;
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;
+ }
+
+
private:
void ParseNodeInfo();
void ParseNodeTransforms(std::ostream &OS);
void FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat,
std::map<std::string,
TreePatternNode*> &InstInputs,
- std::map<std::string, Record*> &InstResults,
+ std::map<std::string,
+ TreePatternNode*> &InstResults,
std::vector<Record*> &InstImpInputs,
std::vector<Record*> &InstImpResults);
void GenerateCodeForPattern(PatternToMatch &Pattern,
- std::vector<std::pair<bool, std::string> > &GeneratedCode);
+ std::vector<std::pair<bool, std::string> > &GeneratedCode,
+ std::set<std::pair<bool, std::string> > &GeneratedDecl,
+ bool UseGoto);
void EmitPatterns(std::vector<std::pair<PatternToMatch*,
std::vector<std::pair<bool, std::string> > > > &Patterns,
unsigned Indent, std::ostream &OS);