Update BitRecTy::convertValue to allow if expressions with bit values on both sides of the if

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215087 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pete Cooper 2014-08-07 05:47:10 +00:00
parent 64a334da36
commit ecdbbbefea
2 changed files with 12 additions and 0 deletions

View File

@ -119,6 +119,16 @@ Init *BitRecTy::convertValue(TypedInit *VI) {
if (auto *BitsTy = dyn_cast<BitsRecTy>(Ty))
// Accept only bits<1> expression.
return BitsTy->getNumBits() == 1 ? VI : nullptr;
// Ternary !if can be converted to bit, but only if both sides are
// convertible to a bit.
if (TernOpInit *TOI = dyn_cast<TernOpInit>(VI)) {
if (TOI->getOpcode() != TernOpInit::TernaryOp::IF)
return nullptr;
if (!TOI->getMHS()->convertInitializerTo(BitRecTy::get()) ||
!TOI->getRHS()->convertInitializerTo(BitRecTy::get()))
return nullptr;
return TOI;
}
return nullptr;
}

View File

@ -5,6 +5,8 @@
class A<bit b = 1> {
int a = !if(b, 5, 6);
bit c = !if(b, 0, 1);
bits<1> d = !if(b, 0, 1);
}
def X : A<0>;