diff options
author | Chris Lattner <sabre@nondot.org> | 2011-07-15 06:14:08 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-07-15 06:14:08 +0000 |
commit | 032c6eb1c4d36a9e906f5efc0ada76c952225a4f (patch) | |
tree | 20671f91b63c05bd9d2ea600cbab2ace61927cfb /lib/VMCore/Constants.cpp | |
parent | c73b24db5f6226ed44ebc44ce1c25bb357206623 (diff) |
devirtualize Constant::isNullValue:
4 files changed, 15 insertions(+), 60 deletions(-)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135252 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r-- | lib/VMCore/Constants.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 019a590f41..681e7269c9 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -49,6 +49,19 @@ bool Constant::isNegativeZeroValue() const { return isNullValue(); } +bool Constant::isNullValue() const { + // 0 is null. + if (const ConstantInt *CI = dyn_cast<ConstantInt>(this)) + return CI->isZero(); + + // +0.0 is null. + if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this)) + return CFP->isZero() && !CFP->isNegative(); + + // constant zero is zero for aggregates and cpnull is null for pointers. + return isa<ConstantAggregateZero>(this) || isa<ConstantPointerNull>(this); +} + // Constructor to create a '0' constant of arbitrary type... Constant *Constant::getNullValue(const Type *Ty) { switch (Ty->getTypeID()) { @@ -551,11 +564,7 @@ ConstantFP::ConstantFP(const Type *Ty, const APFloat& V) "FP type Mismatch"); } -bool ConstantFP::isNullValue() const { - return Val.isZero() && !Val.isNegative(); -} - -bool ConstantFP::isExactlyValue(const APFloat& V) const { +bool ConstantFP::isExactlyValue(const APFloat &V) const { return Val.bitwiseIsEqual(V); } |