llvm.org GIT mirror llvm / 7ed1391
now that predicates have a decent abstraction layer on them, introduce a new kind of predicate: one that is specific to imm nodes. The predicate function specified here just checks an int64_t directly instead of messing around with SDNode's. The virtue of this is that it means that fastisel and other things can reason about these predicates. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129675 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
5 changed file(s) with 49 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
519519 dag Operands = ops;
520520 dag Fragment = frag;
521521 code PredicateCode = pred;
522 code ImmediateCode = [{}];
522523 SDNodeXForm OperandTransform = xform;
523524 }
524525
526527 // to define immediates and other common things concisely.
527528 class PatLeaf
528529 : PatFrag<(ops), frag, pred, xform>;
530
531
532 // ImmLeaf is a pattern fragment with a constraint on the immediate. The
533 // constraint is a function that is run on the immediate (always with the value
534 // sign extended out to an int64_t) as Imm. The value type being matched is
535 // available as VT. For example:
536 //
537 // def immSExt8 : ImmLeaf;
538 //
539 // this is a more convenient form to match 'imm' nodes in than PatLeaf and also
540 // is preferred over using PatLeaf because it allows the code generator to
541 // reason more about the constraint.
542 class ImmLeaf : PatFrag<(ops), (vt imm)> {
543 let ImmediateCode = pred;
544 }
545
529546
530547 // Leaf fragments.
531548
485485 def i16immSExt8 : PatLeaf<(i16 immSext8)>;
486486 def i32immSExt8 : PatLeaf<(i32 immSext8)>;
487487 def i64immSExt8 : PatLeaf<(i64 immSext8)>;
488 def i64immSExt32 : PatLeaf<(i64 imm), [{ return i64immSExt32(N); }]>;
488
489
490 def i64immSExt32 : ImmLeaf;
491
492
493
489494 def i64immZExt32 : PatLeaf<(i64 imm), [{
490495 // i64immZExt32 predicate - True if the 64-bit immediate fits in a 32-bit
491496 // unsignedsign extended field.
620620 // TreePredicateFn Implementation
621621 //===----------------------------------------------------------------------===//
622622
623 /// TreePredicateFn constructor. Here 'N' is a subclass of PatFrag.
624 TreePredicateFn::TreePredicateFn(TreePattern *N) : PatFragRec(N) {
625 assert((getPredCode().empty() || getImmCode().empty()) &&
626 ".td file corrupt: can't have a node predicate *and* an imm predicate");
627 }
628
623629 std::string TreePredicateFn::getPredCode() const {
624630 return PatFragRec->getRecord()->getValueAsCode("PredicateCode");
625631 }
626632
633 std::string TreePredicateFn::getImmCode() const {
634 return PatFragRec->getRecord()->getValueAsCode("ImmediateCode");
635 }
636
627637
628638 /// isAlwaysTrue - Return true if this is a noop predicate.
629639 bool TreePredicateFn::isAlwaysTrue() const {
630 return getPredCode().empty();
640 return getPredCode().empty() && getImmCode().empty();
631641 }
632642
633643 /// Return the name to use in the generated code to reference this, this is
641651 /// not N. This handles casting and conversion to a concrete node type as
642652 /// appropriate.
643653 std::string TreePredicateFn::getCodeToRunOnSDNode() const {
654 // Handle immediate predicates first.
655 std::string ImmCode = getImmCode();
656 if (!ImmCode.empty()) {
657 std::string Result =
658 " int64_t Imm = cast(Node)->getSExtValue();\n";
659 if (ImmCode.find("VT") != std::string::npos)
660 Result += " MVT VT = Node->getValueType(0).getSimpleVT();\n";
661 return Result + ImmCode;
662 }
663
664 // Handle arbitrary node predicates.
665 assert(!getPredCode().empty() && "Don't have any predicate code!");
644666 std::string ClassName;
645667 if (PatFragRec->getOnlyTree()->isLeaf())
646668 ClassName = "SDNode";
248248 TreePattern *PatFragRec;
249249 public:
250250 /// TreePredicateFn constructor. Here 'N' is a subclass of PatFrag.
251 TreePredicateFn(TreePattern *N) : PatFragRec(N) {}
251 TreePredicateFn(TreePattern *N);
252252
253253
254254 TreePattern *getOrigPatFragRecord() const { return PatFragRec; }
275275
276276 private:
277277 std::string getPredCode() const;
278 std::string getImmCode() const;
278279 };
279280
280281
706706 public:
707707 explicit CodeInit(const std::string &V) : Value(V) {}
708708
709 const std::string getValue() const { return Value; }
709 const std::string &getValue() const { return Value; }
710710
711711 virtual Init *convertInitializerTo(RecTy *Ty) {
712712 return Ty->convertValue(this);