llvm.org GIT mirror llvm / e87de41
let the '!eq' expression support 'int' and 'bit' types git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106171 91177308-0d34-0410-b5e6-96231b3b80d8 Bruno Cardoso Lopes 10 years ago
3 changed file(s) with 25 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
424424
'b' if the result of integer operator 'a' is nonzero, 'c' otherwise.
425425
!eq(a,b)
426426
Integer one if string a is equal to string b, zero otherwise. This
427 only operates on string objects. Use !cast to compare other
428 types of objects.
427 only operates on string, int and bit objects. Use !cast to
428 compare other types of objects.
429429
430430
431431

Note that all of the values have rules specifying how they convert to values

0 // RUN: tblgen %s | FileCheck %s
1 // XFAIL: vg_leak
2 // CHECK: a = 6
3 // CHECK: a = 5
4
5 class A {
6 int a = !if(!eq(b, 1), 5, 6);
7 }
8
9 def X : A<0>;
10 def Y : A;
720720 break;
721721 }
722722 case EQ: {
723 // Make sure we've resolved
723 // try to fold eq comparison for 'bit' and 'int', otherwise fallback
724 // to string objects.
725 IntInit* L =
726 dynamic_cast(LHS->convertInitializerTo(new IntRecTy()));
727 IntInit* R =
728 dynamic_cast(RHS->convertInitializerTo(new IntRecTy()));
729
730 if (L && R)
731 return new IntInit(L->getValue() == R->getValue());
732
724733 StringInit *LHSs = dynamic_cast(LHS);
725734 StringInit *RHSs = dynamic_cast(RHS);
735
736 // Make sure we've resolved
726737 if (LHSs && RHSs)
727738 return new IntInit(LHSs->getValue() == RHSs->getValue());
728739