summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-11-17 20:19:35 +0000
committerChris Lattner <sabre@nondot.org>2003-11-17 20:19:35 +0000
commitdc2e39191ad08648540b93f962828764b2dcdcf5 (patch)
tree8581ba385647a3d8afaa6298ebc78aa2b6953764 /llvm/lib
parente120a7316655f838c0f57615297f646b34268de6 (diff)
downloadbcm5719-llvm-dc2e39191ad08648540b93f962828764b2dcdcf5.tar.gz
bcm5719-llvm-dc2e39191ad08648540b93f962828764b2dcdcf5.zip
Implement == and != correctly. Before they would incorrectly return !=
for some constant exprs when they could really be the same value llvm-svn: 10058
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/VMCore/ConstantHandling.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/ConstantHandling.cpp b/llvm/lib/VMCore/ConstantHandling.cpp
index 5e7bd029659..d86ef11ecf5 100644
--- a/llvm/lib/VMCore/ConstantHandling.cpp
+++ b/llvm/lib/VMCore/ConstantHandling.cpp
@@ -256,6 +256,10 @@ class TemplateRules : public ConstRules {
const Constant *V2) const {
return SubClassName::LessThan((const ArgType *)V1, (const ArgType *)V2);
}
+ virtual ConstantBool *equalto(const Constant *V1,
+ const Constant *V2) const {
+ return SubClassName::EqualTo((const ArgType *)V1, (const ArgType *)V2);
+ }
// Casting operators. ick
virtual ConstantBool *castToBool(const Constant *V) const {
@@ -313,6 +317,9 @@ class TemplateRules : public ConstRules {
static ConstantBool *LessThan(const ArgType *V1, const ArgType *V2) {
return 0;
}
+ static ConstantBool *EqualTo(const ArgType *V1, const ArgType *V2) {
+ return 0;
+ }
// Casting operators. ick
static ConstantBool *CastToBool (const Constant *V) { return 0; }
@@ -339,6 +346,10 @@ class TemplateRules : public ConstRules {
// EmptyRules provides a concrete base class of ConstRules that does nothing
//
struct EmptyRules : public TemplateRules<Constant, EmptyRules> {
+ static ConstantBool *EqualTo(const Constant *V1, const Constant *V2) {
+ if (V1 == V2) return ConstantBool::True;
+ return 0;
+ }
};
@@ -355,6 +366,10 @@ struct BoolRules : public TemplateRules<ConstantBool, BoolRules> {
return ConstantBool::get(V1->getValue() < V2->getValue());
}
+ static ConstantBool *EqualTo(const Constant *V1, const Constant *V2) {
+ return ConstantBool::get(V1 == V2);
+ }
+
static Constant *And(const ConstantBool *V1, const ConstantBool *V2) {
return ConstantBool::get(V1->getValue() & V2->getValue());
}
@@ -397,6 +412,9 @@ struct BoolRules : public TemplateRules<ConstantBool, BoolRules> {
//
struct NullPointerRules : public TemplateRules<ConstantPointerNull,
NullPointerRules> {
+ static ConstantBool *EqualTo(const Constant *V1, const Constant *V2) {
+ return ConstantBool::True; // Null pointers are always equal
+ }
static ConstantBool *CastToBool (const Constant *V) {
return ConstantBool::False;
}
@@ -475,6 +493,12 @@ struct DirectRules : public TemplateRules<ConstantClass, SuperClass> {
return ConstantBool::get(R);
}
+ static ConstantBool *EqualTo(const ConstantClass *V1,
+ const ConstantClass *V2) {
+ bool R = (BuiltinType)V1->getValue() == (BuiltinType)V2->getValue();
+ return ConstantBool::get(R);
+ }
+
static Constant *CastToPointer(const ConstantClass *V,
const PointerType *PTy) {
if (V->isNullValue()) // Is it a FP or Integral null value?
OpenPOWER on IntegriCloud