Constant folding shalt not be built on annotations

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10052 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2003-11-17 19:05:17 +00:00
parent 02071d08c1
commit 0dc396909e
4 changed files with 102 additions and 148 deletions

View File

@ -64,11 +64,8 @@ inline ConstantBool *operator!=(const Constant &V1, const Constant &V2) {
// Implement all other operators indirectly through TypeRules system // Implement all other operators indirectly through TypeRules system
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
class ConstRules : public Annotation { struct ConstRules {
protected: ConstRules() {}
inline ConstRules() : Annotation(AID) {} // Can only be subclassed...
public:
static AnnotationID AID; // AnnotationID for this class
// Binary Operators... // Binary Operators...
virtual Constant *add(const Constant *V1, const Constant *V2) const = 0; virtual Constant *add(const Constant *V1, const Constant *V2) const = 0;
@ -119,19 +116,11 @@ public:
} }
} }
// ConstRules::get - A type will cache its own type rules if one is needed... // ConstRules::get - Return an instance of ConstRules for the specified
// we just want to make sure to hit the cache instead of doing it indirectly, // constant operands.
// if possible...
// //
static inline ConstRules *get(const Constant &V1, const Constant &V2) { static ConstRules &get(const Constant &V1, const Constant &V2);
if (isa<ConstantExpr>(V1) || isa<ConstantExpr>(V2))
return getConstantExprRules();
return static_cast<ConstRules*>(V1.getType()->getOrCreateAnnotation(AID));
}
private: private:
static ConstRules *getConstantExprRules();
static Annotation *find(AnnotationID AID, const Annotable *Ty, void *);
ConstRules(const ConstRules &); // Do not implement ConstRules(const ConstRules &); // Do not implement
ConstRules &operator=(const ConstRules &); // Do not implement ConstRules &operator=(const ConstRules &); // Do not implement
}; };
@ -139,71 +128,71 @@ private:
// Unary operators... // Unary operators...
inline Constant *operator~(const Constant &V) { inline Constant *operator~(const Constant &V) {
assert(V.getType()->isIntegral() && "Cannot invert non-integral constant!"); assert(V.getType()->isIntegral() && "Cannot invert non-integral constant!");
return ConstRules::get(V, V)->op_xor(&V, return ConstRules::get(V, V).op_xor(&V,
ConstantInt::getAllOnesValue(V.getType())); ConstantInt::getAllOnesValue(V.getType()));
} }
inline Constant *operator-(const Constant &V) { inline Constant *operator-(const Constant &V) {
return ConstRules::get(V, V)->sub(Constant::getNullValue(V.getType()), &V); return ConstRules::get(V, V).sub(Constant::getNullValue(V.getType()), &V);
} }
// Standard binary operators... // Standard binary operators...
inline Constant *operator+(const Constant &V1, const Constant &V2) { inline Constant *operator+(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->add(&V1, &V2); return ConstRules::get(V1, V2).add(&V1, &V2);
} }
inline Constant *operator-(const Constant &V1, const Constant &V2) { inline Constant *operator-(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->sub(&V1, &V2); return ConstRules::get(V1, V2).sub(&V1, &V2);
} }
inline Constant *operator*(const Constant &V1, const Constant &V2) { inline Constant *operator*(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->mul(&V1, &V2); return ConstRules::get(V1, V2).mul(&V1, &V2);
} }
inline Constant *operator/(const Constant &V1, const Constant &V2) { inline Constant *operator/(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->div(&V1, &V2); return ConstRules::get(V1, V2).div(&V1, &V2);
} }
inline Constant *operator%(const Constant &V1, const Constant &V2) { inline Constant *operator%(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->rem(&V1, &V2); return ConstRules::get(V1, V2).rem(&V1, &V2);
} }
// Logical Operators... // Logical Operators...
inline Constant *operator&(const Constant &V1, const Constant &V2) { inline Constant *operator&(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->op_and(&V1, &V2); return ConstRules::get(V1, V2).op_and(&V1, &V2);
} }
inline Constant *operator|(const Constant &V1, const Constant &V2) { inline Constant *operator|(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->op_or(&V1, &V2); return ConstRules::get(V1, V2).op_or(&V1, &V2);
} }
inline Constant *operator^(const Constant &V1, const Constant &V2) { inline Constant *operator^(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->op_xor(&V1, &V2); return ConstRules::get(V1, V2).op_xor(&V1, &V2);
} }
// Shift Instructions... // Shift Instructions...
inline Constant *operator<<(const Constant &V1, const Constant &V2) { inline Constant *operator<<(const Constant &V1, const Constant &V2) {
assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy); assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy);
return ConstRules::get(V1, V2)->shl(&V1, &V2); return ConstRules::get(V1, V2).shl(&V1, &V2);
} }
inline Constant *operator>>(const Constant &V1, const Constant &V2) { inline Constant *operator>>(const Constant &V1, const Constant &V2) {
assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy); assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy);
return ConstRules::get(V1, V2)->shr(&V1, &V2); return ConstRules::get(V1, V2).shr(&V1, &V2);
} }
inline ConstantBool *operator<(const Constant &V1, inline ConstantBool *operator<(const Constant &V1,
const Constant &V2) { const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->lessthan(&V1, &V2); return ConstRules::get(V1, V2).lessthan(&V1, &V2);
} }

View File

@ -16,16 +16,12 @@
#include "llvm/InstrTypes.h" #include "llvm/InstrTypes.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
#include <cmath> #include <cmath>
using namespace llvm;
namespace llvm {
AnnotationID ConstRules::AID(AnnotationManager::getID("opt::ConstRules",
&ConstRules::find));
// ConstantFoldInstruction - Attempt to constant fold the specified instruction. // ConstantFoldInstruction - Attempt to constant fold the specified instruction.
// If successful, the constant result is returned, if not, null is returned. // If successful, the constant result is returned, if not, null is returned.
// //
Constant *ConstantFoldInstruction(Instruction *I) { Constant *llvm::ConstantFoldInstruction(Instruction *I) {
if (PHINode *PN = dyn_cast<PHINode>(I)) { if (PHINode *PN = dyn_cast<PHINode>(I)) {
if (PN->getNumIncomingValues() == 0) if (PN->getNumIncomingValues() == 0)
return Constant::getNullValue(PN->getType()); return Constant::getNullValue(PN->getType());
@ -85,7 +81,8 @@ static unsigned getSize(const Type *Ty) {
return S ? S : 8; // Treat pointers at 8 bytes return S ? S : 8; // Treat pointers at 8 bytes
} }
Constant *ConstantFoldCastInstruction(const Constant *V, const Type *DestTy) { Constant *llvm::ConstantFoldCastInstruction(const Constant *V,
const Type *DestTy) {
if (V->getType() == DestTy) return (Constant*)V; if (V->getType() == DestTy) return (Constant*)V;
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
@ -117,11 +114,12 @@ Constant *ConstantFoldCastInstruction(const Constant *V, const Type *DestTy) {
return ConstantExpr::getCast(CE->getOperand(0), DestTy); return ConstantExpr::getCast(CE->getOperand(0), DestTy);
} }
return ConstRules::get(*V, *V)->castTo(V, DestTy); return ConstRules::get(*V, *V).castTo(V, DestTy);
} }
Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1, Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
const Constant *V2) { const Constant *V1,
const Constant *V2) {
switch (Opcode) { switch (Opcode) {
case Instruction::Add: return *V1 + *V2; case Instruction::Add: return *V1 + *V2;
case Instruction::Sub: return *V1 - *V2; case Instruction::Sub: return *V1 - *V2;
@ -142,8 +140,9 @@ Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
return 0; return 0;
} }
Constant *ConstantFoldShiftInstruction(unsigned Opcode, const Constant *V1, Constant *llvm::ConstantFoldShiftInstruction(unsigned Opcode,
const Constant *V2) { const Constant *V1,
const Constant *V2) {
switch (Opcode) { switch (Opcode) {
case Instruction::Shl: return *V1 << *V2; case Instruction::Shl: return *V1 << *V2;
case Instruction::Shr: return *V1 >> *V2; case Instruction::Shr: return *V1 >> *V2;
@ -151,8 +150,8 @@ Constant *ConstantFoldShiftInstruction(unsigned Opcode, const Constant *V1,
} }
} }
Constant *ConstantFoldGetElementPtr(const Constant *C, Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
const std::vector<Constant*> &IdxList) { const std::vector<Constant*> &IdxList) {
if (IdxList.size() == 0 || if (IdxList.size() == 0 ||
(IdxList.size() == 1 && IdxList[0]->isNullValue())) (IdxList.size() == 1 && IdxList[0]->isNullValue()))
return const_cast<Constant*>(C); return const_cast<Constant*>(C);
@ -592,53 +591,41 @@ struct DirectFPRules
} }
}; };
//===----------------------------------------------------------------------===// ConstRules &ConstRules::get(const Constant &V1, const Constant &V2) {
// DirectRules Subclasses static EmptyRules EmptyR;
//===----------------------------------------------------------------------===// static BoolRules BoolR;
// static PointerRules PointerR;
// Given the DirectRules class we can now implement lots of types with little static DirectIntRules<ConstantSInt, signed char , &Type::SByteTy> SByteR;
// code. Thank goodness C++ compilers are great at stomping out layers of static DirectIntRules<ConstantUInt, unsigned char , &Type::UByteTy> UByteR;
// templates... can you imagine having to do this all by hand? (/me is lazy :) static DirectIntRules<ConstantSInt, signed short, &Type::ShortTy> ShortR;
// static DirectIntRules<ConstantUInt, unsigned short, &Type::UShortTy> UShortR;
static DirectIntRules<ConstantSInt, signed int , &Type::IntTy> IntR;
static DirectIntRules<ConstantUInt, unsigned int , &Type::UIntTy> UIntR;
static DirectIntRules<ConstantSInt, int64_t , &Type::LongTy> LongR;
static DirectIntRules<ConstantUInt, uint64_t , &Type::ULongTy> ULongR;
static DirectFPRules <ConstantFP , float , &Type::FloatTy> FloatR;
static DirectFPRules <ConstantFP , double , &Type::DoubleTy> DoubleR;
// ConstRules::find - Return the constant rules that take care of the specified if (isa<ConstantExpr>(V1) || isa<ConstantExpr>(V2))
// type. return EmptyR;
//
Annotation *ConstRules::find(AnnotationID AID, const Annotable *TyA, void *) { // FIXME: This assert doesn't work because shifts pass both operands in to
assert(AID == ConstRules::AID && "Bad annotation for factory!"); // check for constant exprs. :(
const Type *Ty = cast<Type>((const Value*)TyA); //assert(V1.getType() == V2.getType() &&"Nonequal types to constant folder?");
switch (Ty->getPrimitiveID()) { switch (V1.getType()->getPrimitiveID()) {
case Type::BoolTyID: return new BoolRules(); default: assert(0 && "Unknown value type for constant folding!");
case Type::PointerTyID: return new PointerRules(); case Type::BoolTyID: return BoolR;
case Type::SByteTyID: case Type::PointerTyID: return PointerR;
return new DirectIntRules<ConstantSInt, signed char , &Type::SByteTy>(); case Type::SByteTyID: return SByteR;
case Type::UByteTyID: case Type::UByteTyID: return UByteR;
return new DirectIntRules<ConstantUInt, unsigned char , &Type::UByteTy>(); case Type::ShortTyID: return ShortR;
case Type::ShortTyID: case Type::UShortTyID: return UShortR;
return new DirectIntRules<ConstantSInt, signed short, &Type::ShortTy>(); case Type::IntTyID: return IntR;
case Type::UShortTyID: case Type::UIntTyID: return UIntR;
return new DirectIntRules<ConstantUInt, unsigned short, &Type::UShortTy>(); case Type::LongTyID: return LongR;
case Type::IntTyID: case Type::ULongTyID: return ULongR;
return new DirectIntRules<ConstantSInt, signed int , &Type::IntTy>(); case Type::FloatTyID: return FloatR;
case Type::UIntTyID: case Type::DoubleTyID: return DoubleR;
return new DirectIntRules<ConstantUInt, unsigned int , &Type::UIntTy>();
case Type::LongTyID:
return new DirectIntRules<ConstantSInt, int64_t , &Type::LongTy>();
case Type::ULongTyID:
return new DirectIntRules<ConstantUInt, uint64_t , &Type::ULongTy>();
case Type::FloatTyID:
return new DirectFPRules<ConstantFP , float , &Type::FloatTy>();
case Type::DoubleTyID:
return new DirectFPRules<ConstantFP , double , &Type::DoubleTy>();
default:
return new EmptyRules();
} }
} }
ConstRules *ConstRules::getConstantExprRules() {
static EmptyRules CERules;
return &CERules;
}
} // End llvm namespace

View File

@ -64,11 +64,8 @@ inline ConstantBool *operator!=(const Constant &V1, const Constant &V2) {
// Implement all other operators indirectly through TypeRules system // Implement all other operators indirectly through TypeRules system
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
class ConstRules : public Annotation { struct ConstRules {
protected: ConstRules() {}
inline ConstRules() : Annotation(AID) {} // Can only be subclassed...
public:
static AnnotationID AID; // AnnotationID for this class
// Binary Operators... // Binary Operators...
virtual Constant *add(const Constant *V1, const Constant *V2) const = 0; virtual Constant *add(const Constant *V1, const Constant *V2) const = 0;
@ -119,19 +116,11 @@ public:
} }
} }
// ConstRules::get - A type will cache its own type rules if one is needed... // ConstRules::get - Return an instance of ConstRules for the specified
// we just want to make sure to hit the cache instead of doing it indirectly, // constant operands.
// if possible...
// //
static inline ConstRules *get(const Constant &V1, const Constant &V2) { static ConstRules &get(const Constant &V1, const Constant &V2);
if (isa<ConstantExpr>(V1) || isa<ConstantExpr>(V2))
return getConstantExprRules();
return static_cast<ConstRules*>(V1.getType()->getOrCreateAnnotation(AID));
}
private: private:
static ConstRules *getConstantExprRules();
static Annotation *find(AnnotationID AID, const Annotable *Ty, void *);
ConstRules(const ConstRules &); // Do not implement ConstRules(const ConstRules &); // Do not implement
ConstRules &operator=(const ConstRules &); // Do not implement ConstRules &operator=(const ConstRules &); // Do not implement
}; };
@ -139,71 +128,71 @@ private:
// Unary operators... // Unary operators...
inline Constant *operator~(const Constant &V) { inline Constant *operator~(const Constant &V) {
assert(V.getType()->isIntegral() && "Cannot invert non-integral constant!"); assert(V.getType()->isIntegral() && "Cannot invert non-integral constant!");
return ConstRules::get(V, V)->op_xor(&V, return ConstRules::get(V, V).op_xor(&V,
ConstantInt::getAllOnesValue(V.getType())); ConstantInt::getAllOnesValue(V.getType()));
} }
inline Constant *operator-(const Constant &V) { inline Constant *operator-(const Constant &V) {
return ConstRules::get(V, V)->sub(Constant::getNullValue(V.getType()), &V); return ConstRules::get(V, V).sub(Constant::getNullValue(V.getType()), &V);
} }
// Standard binary operators... // Standard binary operators...
inline Constant *operator+(const Constant &V1, const Constant &V2) { inline Constant *operator+(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->add(&V1, &V2); return ConstRules::get(V1, V2).add(&V1, &V2);
} }
inline Constant *operator-(const Constant &V1, const Constant &V2) { inline Constant *operator-(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->sub(&V1, &V2); return ConstRules::get(V1, V2).sub(&V1, &V2);
} }
inline Constant *operator*(const Constant &V1, const Constant &V2) { inline Constant *operator*(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->mul(&V1, &V2); return ConstRules::get(V1, V2).mul(&V1, &V2);
} }
inline Constant *operator/(const Constant &V1, const Constant &V2) { inline Constant *operator/(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->div(&V1, &V2); return ConstRules::get(V1, V2).div(&V1, &V2);
} }
inline Constant *operator%(const Constant &V1, const Constant &V2) { inline Constant *operator%(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->rem(&V1, &V2); return ConstRules::get(V1, V2).rem(&V1, &V2);
} }
// Logical Operators... // Logical Operators...
inline Constant *operator&(const Constant &V1, const Constant &V2) { inline Constant *operator&(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->op_and(&V1, &V2); return ConstRules::get(V1, V2).op_and(&V1, &V2);
} }
inline Constant *operator|(const Constant &V1, const Constant &V2) { inline Constant *operator|(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->op_or(&V1, &V2); return ConstRules::get(V1, V2).op_or(&V1, &V2);
} }
inline Constant *operator^(const Constant &V1, const Constant &V2) { inline Constant *operator^(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->op_xor(&V1, &V2); return ConstRules::get(V1, V2).op_xor(&V1, &V2);
} }
// Shift Instructions... // Shift Instructions...
inline Constant *operator<<(const Constant &V1, const Constant &V2) { inline Constant *operator<<(const Constant &V1, const Constant &V2) {
assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy); assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy);
return ConstRules::get(V1, V2)->shl(&V1, &V2); return ConstRules::get(V1, V2).shl(&V1, &V2);
} }
inline Constant *operator>>(const Constant &V1, const Constant &V2) { inline Constant *operator>>(const Constant &V1, const Constant &V2) {
assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy); assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy);
return ConstRules::get(V1, V2)->shr(&V1, &V2); return ConstRules::get(V1, V2).shr(&V1, &V2);
} }
inline ConstantBool *operator<(const Constant &V1, inline ConstantBool *operator<(const Constant &V1,
const Constant &V2) { const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->lessthan(&V1, &V2); return ConstRules::get(V1, V2).lessthan(&V1, &V2);
} }

View File

@ -64,11 +64,8 @@ inline ConstantBool *operator!=(const Constant &V1, const Constant &V2) {
// Implement all other operators indirectly through TypeRules system // Implement all other operators indirectly through TypeRules system
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
class ConstRules : public Annotation { struct ConstRules {
protected: ConstRules() {}
inline ConstRules() : Annotation(AID) {} // Can only be subclassed...
public:
static AnnotationID AID; // AnnotationID for this class
// Binary Operators... // Binary Operators...
virtual Constant *add(const Constant *V1, const Constant *V2) const = 0; virtual Constant *add(const Constant *V1, const Constant *V2) const = 0;
@ -119,19 +116,11 @@ public:
} }
} }
// ConstRules::get - A type will cache its own type rules if one is needed... // ConstRules::get - Return an instance of ConstRules for the specified
// we just want to make sure to hit the cache instead of doing it indirectly, // constant operands.
// if possible...
// //
static inline ConstRules *get(const Constant &V1, const Constant &V2) { static ConstRules &get(const Constant &V1, const Constant &V2);
if (isa<ConstantExpr>(V1) || isa<ConstantExpr>(V2))
return getConstantExprRules();
return static_cast<ConstRules*>(V1.getType()->getOrCreateAnnotation(AID));
}
private: private:
static ConstRules *getConstantExprRules();
static Annotation *find(AnnotationID AID, const Annotable *Ty, void *);
ConstRules(const ConstRules &); // Do not implement ConstRules(const ConstRules &); // Do not implement
ConstRules &operator=(const ConstRules &); // Do not implement ConstRules &operator=(const ConstRules &); // Do not implement
}; };
@ -139,71 +128,71 @@ private:
// Unary operators... // Unary operators...
inline Constant *operator~(const Constant &V) { inline Constant *operator~(const Constant &V) {
assert(V.getType()->isIntegral() && "Cannot invert non-integral constant!"); assert(V.getType()->isIntegral() && "Cannot invert non-integral constant!");
return ConstRules::get(V, V)->op_xor(&V, return ConstRules::get(V, V).op_xor(&V,
ConstantInt::getAllOnesValue(V.getType())); ConstantInt::getAllOnesValue(V.getType()));
} }
inline Constant *operator-(const Constant &V) { inline Constant *operator-(const Constant &V) {
return ConstRules::get(V, V)->sub(Constant::getNullValue(V.getType()), &V); return ConstRules::get(V, V).sub(Constant::getNullValue(V.getType()), &V);
} }
// Standard binary operators... // Standard binary operators...
inline Constant *operator+(const Constant &V1, const Constant &V2) { inline Constant *operator+(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->add(&V1, &V2); return ConstRules::get(V1, V2).add(&V1, &V2);
} }
inline Constant *operator-(const Constant &V1, const Constant &V2) { inline Constant *operator-(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->sub(&V1, &V2); return ConstRules::get(V1, V2).sub(&V1, &V2);
} }
inline Constant *operator*(const Constant &V1, const Constant &V2) { inline Constant *operator*(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->mul(&V1, &V2); return ConstRules::get(V1, V2).mul(&V1, &V2);
} }
inline Constant *operator/(const Constant &V1, const Constant &V2) { inline Constant *operator/(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->div(&V1, &V2); return ConstRules::get(V1, V2).div(&V1, &V2);
} }
inline Constant *operator%(const Constant &V1, const Constant &V2) { inline Constant *operator%(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->rem(&V1, &V2); return ConstRules::get(V1, V2).rem(&V1, &V2);
} }
// Logical Operators... // Logical Operators...
inline Constant *operator&(const Constant &V1, const Constant &V2) { inline Constant *operator&(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->op_and(&V1, &V2); return ConstRules::get(V1, V2).op_and(&V1, &V2);
} }
inline Constant *operator|(const Constant &V1, const Constant &V2) { inline Constant *operator|(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->op_or(&V1, &V2); return ConstRules::get(V1, V2).op_or(&V1, &V2);
} }
inline Constant *operator^(const Constant &V1, const Constant &V2) { inline Constant *operator^(const Constant &V1, const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->op_xor(&V1, &V2); return ConstRules::get(V1, V2).op_xor(&V1, &V2);
} }
// Shift Instructions... // Shift Instructions...
inline Constant *operator<<(const Constant &V1, const Constant &V2) { inline Constant *operator<<(const Constant &V1, const Constant &V2) {
assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy); assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy);
return ConstRules::get(V1, V2)->shl(&V1, &V2); return ConstRules::get(V1, V2).shl(&V1, &V2);
} }
inline Constant *operator>>(const Constant &V1, const Constant &V2) { inline Constant *operator>>(const Constant &V1, const Constant &V2) {
assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy); assert(V1.getType()->isInteger() && V2.getType() == Type::UByteTy);
return ConstRules::get(V1, V2)->shr(&V1, &V2); return ConstRules::get(V1, V2).shr(&V1, &V2);
} }
inline ConstantBool *operator<(const Constant &V1, inline ConstantBool *operator<(const Constant &V1,
const Constant &V2) { const Constant &V2) {
assert(V1.getType() == V2.getType() && "Constant types must be identical!"); assert(V1.getType() == V2.getType() && "Constant types must be identical!");
return ConstRules::get(V1, V2)->lessthan(&V1, &V2); return ConstRules::get(V1, V2).lessthan(&V1, &V2);
} }