[silgen] Add RValue::isPlus{One,Zero} to distinguish +0 from +1 rvalues.

I already in a previous commit forced all rvalues to have consistent cleanups
and consistent value ownership kinds. Now that we know all constructed RValues
are consistent, we can safely query that information.

rdar://33358110
This commit is contained in:
Michael Gottesman
2017-07-26 11:02:10 -07:00
parent d018ecccf5
commit 4557d925ad
2 changed files with 43 additions and 0 deletions

View File

@@ -21,6 +21,7 @@
#include "Initialization.h"
#include "SILGenFunction.h"
#include "swift/AST/CanTypeVisitor.h"
#include "swift/Basic/STLExtras.h"
#include "swift/SIL/AbstractionPattern.h"
#include "swift/SIL/SILArgument.h"
@@ -784,3 +785,21 @@ void RValue::verifyConsistentOwnership() const {
}
#endif
}
bool RValue::isPlusOne(SILGenFunction &SGF) const & {
return llvm::none_of(values, [&SGF](ManagedValue mv) -> bool {
if (mv.getType().isTrivial(SGF.F.getModule()) ||
mv.getOwnershipKind() == ValueOwnershipKind::Trivial)
return false;
return !mv.hasCleanup();
});
}
bool RValue::isPlusZero(SILGenFunction &SGF) const & {
return llvm::none_of(values, [&SGF](ManagedValue mv) -> bool {
if (mv.getType().isTrivial(SGF.F.getModule()) ||
mv.getOwnershipKind() == ValueOwnershipKind::Trivial)
return false;
return mv.hasCleanup();
});
}