[llvm-commits] CVS: llvm/lib/VMCore/ConstantHandling.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Nov 17 14:20:02 PST 2003
Changes in directory llvm/lib/VMCore:
ConstantHandling.cpp updated: 1.40 -> 1.41
---
Log message:
Implement == and != correctly. Before they would incorrectly return !=
for some constant exprs when they could really be the same value
---
Diffs of the changes: (+24 -0)
Index: llvm/lib/VMCore/ConstantHandling.cpp
diff -u llvm/lib/VMCore/ConstantHandling.cpp:1.40 llvm/lib/VMCore/ConstantHandling.cpp:1.41
--- llvm/lib/VMCore/ConstantHandling.cpp:1.40 Mon Nov 17 13:21:04 2003
+++ llvm/lib/VMCore/ConstantHandling.cpp Mon Nov 17 14:19:35 2003
@@ -256,6 +256,10 @@
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 @@
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 @@
// 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 @@
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 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;
}
@@ -474,6 +492,12 @@
bool R = (BuiltinType)V1->getValue() < (BuiltinType)V2->getValue();
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) {
More information about the llvm-commits
mailing list