brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.1 KiB · 031606f Raw
195 lines · plain
1// RUN: llvm-tblgen %s | FileCheck %s2// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s3// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s4// RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s5// RUN: not llvm-tblgen -DERROR4 %s 2>&1 | FileCheck --check-prefix=ERROR4 %s6// RUN: not llvm-tblgen -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s7// RUN: not llvm-tblgen -DERROR6 %s 2>&1 | FileCheck --check-prefix=ERROR6 %s8// RUN: not llvm-tblgen -DERROR7 %s 2>&1 | FileCheck --check-prefix=ERROR7 %s9// RUN: not llvm-tblgen -DERROR8 %s 2>&1 | FileCheck --check-prefix=ERROR8 %s10// RUN: not llvm-tblgen -DERROR9 %s 2>&1 | FileCheck --check-prefix=ERROR9 %s11// RUN: not llvm-tblgen -DERROR10 %s 2>&1 | FileCheck --check-prefix=ERROR10 %s12 13// !setop and !getop are deprecated in favor of !setdagop and !getdagop.14// Two tests retain the old names just to be sure they are still supported.15 16class Base;17class OtherBase;18 19class Super : Base;20 21def foo: Base;22def bar: Base;23def qux: OtherBase;24 25def alice : Super;26def bob : Super;27 28def test {29  dag orig = (foo 1, 2:$a, $b);30  dag another = (qux "hello", $world);31  dag named = (foo:$root 1, 2:$a, $b);32 33  // CHECK: dag replaceWithBar = (bar 1, 2:$a, ?:$b);34  dag replaceWithBar = !setop(orig, bar);35 36  // CHECK: dag replaceWithBaz = (qux 1, 2:$a, ?:$b);37  dag replaceWithBaz = !setdagop(orig, qux);38 39  // CHECK: Base getopWithCast = foo;40  Base getopWithCast = !getop<Base>(orig);41 42  // CHECK: dag getopToSetop = (foo "hello", ?:$world);43  dag getopToSetop = !setdagop(another, !getdagop(orig));44 45  // CHECK: dag setOpName = (foo:$baz 1, 2:$a, ?:$b);46  dag setOpName = !setdagopname(orig, "baz");47 48  // CHECK: dag getopNameToSetOpName = (foo:$root 1, 2:$a, ?:$b);49  dag getopNameToSetOpName = !setdagopname(orig, !getdagopname(named));50 51  // CHECK: dag setOpNameExpl = (foo:$baz 1, 2:$a, ?:$b);52  dag setOpNameExpl = !setdagopname((foo 1, 2:$a, $b), "baz");53 54  // CHECK: dag getopNameToSetOpNameExpl = (foo:$root 1, 2:$a, ?:$b);55  dag getopNameToSetOpNameExpl =56    !setdagopname(orig, !getdagopname((foo:$root 1, 2:$a, $b)));57 58  // CHECK: dag getopToBangDag = (foo 1:$a, 2:$b, 3:$c);59  dag getopToBangDag = !dag(!getdagop(orig), [1, 2, 3], ["a", "b", "c"]);60 61  // CHECK: dag getopToDagInit = (foo "it worked");62  dag getopToDagInit = (!getdagop(orig) "it worked");63 64#ifdef ERROR165  // !getdagop(...) has a static type of 'any record at all, with no66  // required superclasses'. That's too general to use in an67  // assignment whose LHS demands an instance of Base, so we expect a68  // static (parse-time) type-checking error.69 70  // ERROR1: error: Field 'noCast' of type 'Base' is incompatible with value '!getdagop(orig)' of type '{}'71  Base noCast = !getdagop(orig);72#endif73 74#ifdef ERROR275  // Here, we expect a _dynamic_ type error, when it turns out at76  // evaluation time that the operator of 'another' is a record that77  // isn't an instance of the specified base class.78 79  // ERROR2: error: Expected type 'Base', got 'OtherBase' in: !getdagop((qux "hello", ?:$world))80  Base badCast = !getdagop<Base>(another);81#endif82 83#ifdef ERROR384  // Obviously, you shouldn't be able to give any type to !getdagop that85  // isn't a class type.86 87  // ERROR3: error: type for !getdagop must be a record type88  int ridiculousCast = !getdagop<int>(orig);89#endif90 91  dag in1 = (foo 1:$a, 2:$b, 3:$c);92  // CHECK: list<string> in1Names = ["a", "b", "c"];93  list<string> in1Names = !foreach(i, !range(!size(in1)), !getdagname(in1, i));94  // CHECK: list<int> in1Args = [1, 2, 3];95  list<int> in1Args = !foreach(i, !range(!size(in1)), !getdagarg<int>(in1, i));96 97  dag in2 = (foo 1:$a, (bar "x":$x, (qux foo:$s1, bar:$s2):$y, 7:$z):$b, 3:$c);98  // CHECK: dag in2NestedDag = (qux foo:$s1, bar:$s2);99  dag in2NestedDag = !getdagarg<dag>(!getdagarg<dag>(in2, 1), "y");100  // CHECK: Base in2NestedArg = foo;101  Base in2NestedArg = !getdagarg<Base>(!getdagarg<dag>(!getdagarg<dag>(in2, 1), "y"), "s1");102 103  dag in3 = (foo 1:$a, ?:$b, 3);104  // CHECK: list<string> in3Names = ["a", "b", ?];105  list<string> in3Names = !foreach(i, !range(!size(in3)), !getdagname(in3, i));106  // CHECK: list<int> in3Args = [1, ?, 3];107  list<int> in3Args = !foreach(i, !range(!size(in3)), !getdagarg<int>(in3, i));108 109#ifdef ERROR4110  // ERROR4: error: !getdagarg index -1 is negative111  int outOfRange = !getdagarg<int>(in1, -1);112#endif113 114#ifdef ERROR5115  // ERROR5: error: !getdagarg index 3 is out of range (dag has 3 arguments)116  int outOfRange = !getdagarg<int>(in1, 3);117#endif118 119#ifdef ERROR6120  // ERROR6: error: !getdagarg key 'x' is not found121  int notFound = !getdagarg<int>(in1, "x");122#endif123 124  dag in4 = (foo "arg1":$a, "arg2":$b, "arg3":$c);125  // CHECK: int misMatchType1 = ?;126  int misMatchType1 = !getdagarg<int>(in4, 0);127 128  dag in5 = (foo foo:$a, bar:$b, foo:$c);129  // CHECK: OtherBase misMatchType2 = ?;130  OtherBase misMatchType2 = !getdagarg<OtherBase>(in5, 1);131 132  dag in6 = (foo alice:$a, bob:$b);133  // CHECK: Base base = bob;134  Base base = !getdagarg<Base>(in6, 1);135 136  // CHECK: dag orig_set_val = (foo 1, 2:$a, "val":$b);137  dag orig_set_val = !setdagarg(orig, 2, "val");138  // CHECK: dag orig_set_val_by_name = (foo 1, 2:$a, "aval":$b);139  dag orig_set_val_by_name = !setdagarg(orig, "b", "aval");140  // CHECK: dag orig_set_dag_val = (foo 1, 2:$a, (bar foo:$p, qux:$q):$b);141  dag orig_set_dag_val = !setdagarg(orig, "b", (bar foo:$p, qux:$q));142  // CHECK: dag orig_clr_val = (foo 1, ?:$a, ?:$b);143  dag orig_clr_val = !setdagarg(orig, "a", ?);144  // CHECK: dag orig_set_name = (foo 1:$c, 2:$a, ?:$b);145  dag orig_set_name = !setdagname(orig, 0, "c");146  // CHECK: dag orig_clr_name = (foo 1, 2, ?:$b);147  dag orig_clr_name = !setdagname(orig, 1, ?);148  // CHECK: dag orig_rename = (foo 1, 2:$x, ?:$y);149  dag orig_rename = !setdagname(!setdagname(orig, "a", "x"), "b", "y");150 151#ifdef ERROR7152  // ERROR7: error: !setdagarg index -1 is negative153  dag orig_negative = !setdagarg(orig, -1, "val");154#endif155 156#ifdef ERROR8157  // ERROR8: error: !setdagarg index 3 is out of range (dag has 3 arguments)158  dag orig_out_of_range = !setdagarg(orig, 3, "val");159#endif160 161#ifdef ERROR9162  // ERROR9: error: expected integer index or string name, got type 'Base'163  dag orig_out_of_range = !setdagarg(orig, foo, (foo qux:$a));164#endif165}166 167// Copy a list (Predicates) that is a field in a dag operator168// (TestInstruction), which is defined in the same multiclass169// (TestInstructionAndPattern) as the destination of the copy170// (TestPattern::Predicates).171class TestInstruction<list<int> _Predicates> {172  list<int> Predicates = _Predicates;173}174#ifdef ERROR10175class OtherTestInstruction<list<int> _Predicates> {176  list<int> Predicates = _Predicates;177}178// ERROR10: error: Expected type 'OtherTestInstruction', got 'TestInstruction'179class TestPattern<dag D> {180  list<int> Predicates = !getdagop<OtherTestInstruction>(D).Predicates;181}182#else183class TestPattern<dag D> {184  list<int> Predicates = !getdagop<TestInstruction>(D).Predicates;185}186#endif187 188multiclass TestInstructionAndPattern<list<int> Predicates> {189  def NAME : TestInstruction<Predicates>;190  def : TestPattern<(!cast<TestInstruction>(NAME) foo)>;191}192// CHECK: def testInst0 { // TestInstruction193// CHECK-NEXT: list<int> Predicates = [7];194defm testInst0 : TestInstructionAndPattern<[7]>;195