mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-20 14:29:27 +00:00
Implement constant propogation of null pointer values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1078 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d558426b0e
commit
76ac1a45b4
@ -36,6 +36,7 @@
|
|||||||
#include "llvm/ConstPoolVals.h"
|
#include "llvm/ConstPoolVals.h"
|
||||||
#include "llvm/Instruction.h"
|
#include "llvm/Instruction.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
|
class PointerType;
|
||||||
|
|
||||||
namespace opt {
|
namespace opt {
|
||||||
|
|
||||||
@ -90,6 +91,8 @@ public:
|
|||||||
virtual ConstPoolUInt *castToULong (const ConstPoolVal *V) const = 0;
|
virtual ConstPoolUInt *castToULong (const ConstPoolVal *V) const = 0;
|
||||||
virtual ConstPoolFP *castToFloat (const ConstPoolVal *V) const = 0;
|
virtual ConstPoolFP *castToFloat (const ConstPoolVal *V) const = 0;
|
||||||
virtual ConstPoolFP *castToDouble(const ConstPoolVal *V) const = 0;
|
virtual ConstPoolFP *castToDouble(const ConstPoolVal *V) const = 0;
|
||||||
|
virtual ConstPoolPointer *castToPointer(const ConstPoolVal *V,
|
||||||
|
const PointerType *Ty) const = 0;
|
||||||
|
|
||||||
inline ConstPoolVal *castTo(const ConstPoolVal *V, const Type *Ty) const {
|
inline ConstPoolVal *castTo(const ConstPoolVal *V, const Type *Ty) const {
|
||||||
switch (Ty->getPrimitiveID()) {
|
switch (Ty->getPrimitiveID()) {
|
||||||
@ -104,6 +107,7 @@ public:
|
|||||||
case Type::LongTyID: return castToLong(V);
|
case Type::LongTyID: return castToLong(V);
|
||||||
case Type::FloatTyID: return castToFloat(V);
|
case Type::FloatTyID: return castToFloat(V);
|
||||||
case Type::DoubleTyID: return castToDouble(V);
|
case Type::DoubleTyID: return castToDouble(V);
|
||||||
|
case Type::PointerTyID:return castToPointer(V, (PointerType*)Ty);
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,10 @@ class TemplateRules : public ConstRules {
|
|||||||
virtual ConstPoolFP *castToDouble(const ConstPoolVal *V) const {
|
virtual ConstPoolFP *castToDouble(const ConstPoolVal *V) const {
|
||||||
return SubClassName::CastToDouble((const ArgType*)V);
|
return SubClassName::CastToDouble((const ArgType*)V);
|
||||||
}
|
}
|
||||||
|
virtual ConstPoolPointer *castToPointer(const ConstPoolVal *V,
|
||||||
|
const PointerType *Ty) const {
|
||||||
|
return SubClassName::CastToPointer((const ArgType*)V, Ty);
|
||||||
|
}
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Default "noop" implementations
|
// Default "noop" implementations
|
||||||
@ -121,6 +125,8 @@ class TemplateRules : public ConstRules {
|
|||||||
inline static ConstPoolUInt *CastToULong (const ConstPoolVal *V) { return 0; }
|
inline static ConstPoolUInt *CastToULong (const ConstPoolVal *V) { return 0; }
|
||||||
inline static ConstPoolFP *CastToFloat (const ConstPoolVal *V) { return 0; }
|
inline static ConstPoolFP *CastToFloat (const ConstPoolVal *V) { return 0; }
|
||||||
inline static ConstPoolFP *CastToDouble(const ConstPoolVal *V) { return 0; }
|
inline static ConstPoolFP *CastToDouble(const ConstPoolVal *V) { return 0; }
|
||||||
|
inline static ConstPoolPointer *CastToPointer(const ConstPoolVal *,
|
||||||
|
const PointerType *) {return 0;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -160,6 +166,67 @@ struct BoolRules : public TemplateRules<ConstPoolBool, BoolRules> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// PointerRules Class
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// PointerRules provides a concrete base class of ConstRules for pointer types
|
||||||
|
//
|
||||||
|
struct PointerRules : public TemplateRules<ConstPoolPointer, PointerRules> {
|
||||||
|
inline static ConstPoolBool *CastToBool (const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolBool::False;
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
inline static ConstPoolSInt *CastToSByte (const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolSInt::get(Type::SByteTy, 0);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
inline static ConstPoolUInt *CastToUByte (const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolUInt::get(Type::UByteTy, 0);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
inline static ConstPoolSInt *CastToShort (const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolSInt::get(Type::ShortTy, 0);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
inline static ConstPoolUInt *CastToUShort(const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolUInt::get(Type::UShortTy, 0);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
inline static ConstPoolSInt *CastToInt (const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolSInt::get(Type::IntTy, 0);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
inline static ConstPoolUInt *CastToUInt (const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolUInt::get(Type::UIntTy, 0);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
inline static ConstPoolSInt *CastToLong (const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolSInt::get(Type::LongTy, 0);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
inline static ConstPoolUInt *CastToULong (const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolUInt::get(Type::ULongTy, 0);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
inline static ConstPoolFP *CastToFloat (const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolFP::get(Type::FloatTy, 0);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
inline static ConstPoolFP *CastToDouble(const ConstPoolVal *V) {
|
||||||
|
if (V->isNullValue()) return ConstPoolFP::get(Type::DoubleTy, 0);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static ConstPoolPointer *CastToPointer(const ConstPoolPointer *V,
|
||||||
|
const PointerType *PTy) {
|
||||||
|
if (V->isNullValue())
|
||||||
|
return ConstPoolPointerNull::get(PTy);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// DirectRules Class
|
// DirectRules Class
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -204,6 +271,13 @@ struct DirectRules
|
|||||||
return ConstPoolBool::get(Result);
|
return ConstPoolBool::get(Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static ConstPoolPointer *CastToPointer(const ConstPoolClass *V,
|
||||||
|
const PointerType *PTy) {
|
||||||
|
if (V->isNullValue()) // Is it a FP or Integral null value?
|
||||||
|
return ConstPoolPointerNull::get(PTy);
|
||||||
|
return 0; // Can't const prop other types of pointers
|
||||||
|
}
|
||||||
|
|
||||||
// Casting operators. ick
|
// Casting operators. ick
|
||||||
#define DEF_CAST(TYPE, CLASS, CTYPE) \
|
#define DEF_CAST(TYPE, CLASS, CTYPE) \
|
||||||
inline static CLASS *CastTo##TYPE (const ConstPoolClass *V) { \
|
inline static CLASS *CastTo##TYPE (const ConstPoolClass *V) { \
|
||||||
@ -241,7 +315,8 @@ Annotation *ConstRules::find(AnnotationID AID, const Annotable *TyA, void *) {
|
|||||||
const Type *Ty = cast<Type>((const Value*)TyA);
|
const Type *Ty = cast<Type>((const Value*)TyA);
|
||||||
|
|
||||||
switch (Ty->getPrimitiveID()) {
|
switch (Ty->getPrimitiveID()) {
|
||||||
case Type::BoolTyID: return new BoolRules();
|
case Type::BoolTyID: return new BoolRules();
|
||||||
|
case Type::PointerTyID: return new PointerRules();
|
||||||
case Type::SByteTyID:
|
case Type::SByteTyID:
|
||||||
return new DirectRules<ConstPoolSInt, signed char , &Type::SByteTy>();
|
return new DirectRules<ConstPoolSInt, signed char , &Type::SByteTy>();
|
||||||
case Type::UByteTyID:
|
case Type::UByteTyID:
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "llvm/ConstPoolVals.h"
|
#include "llvm/ConstPoolVals.h"
|
||||||
#include "llvm/Instruction.h"
|
#include "llvm/Instruction.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
|
class PointerType;
|
||||||
|
|
||||||
namespace opt {
|
namespace opt {
|
||||||
|
|
||||||
@ -90,6 +91,8 @@ public:
|
|||||||
virtual ConstPoolUInt *castToULong (const ConstPoolVal *V) const = 0;
|
virtual ConstPoolUInt *castToULong (const ConstPoolVal *V) const = 0;
|
||||||
virtual ConstPoolFP *castToFloat (const ConstPoolVal *V) const = 0;
|
virtual ConstPoolFP *castToFloat (const ConstPoolVal *V) const = 0;
|
||||||
virtual ConstPoolFP *castToDouble(const ConstPoolVal *V) const = 0;
|
virtual ConstPoolFP *castToDouble(const ConstPoolVal *V) const = 0;
|
||||||
|
virtual ConstPoolPointer *castToPointer(const ConstPoolVal *V,
|
||||||
|
const PointerType *Ty) const = 0;
|
||||||
|
|
||||||
inline ConstPoolVal *castTo(const ConstPoolVal *V, const Type *Ty) const {
|
inline ConstPoolVal *castTo(const ConstPoolVal *V, const Type *Ty) const {
|
||||||
switch (Ty->getPrimitiveID()) {
|
switch (Ty->getPrimitiveID()) {
|
||||||
@ -104,6 +107,7 @@ public:
|
|||||||
case Type::LongTyID: return castToLong(V);
|
case Type::LongTyID: return castToLong(V);
|
||||||
case Type::FloatTyID: return castToFloat(V);
|
case Type::FloatTyID: return castToFloat(V);
|
||||||
case Type::DoubleTyID: return castToDouble(V);
|
case Type::DoubleTyID: return castToDouble(V);
|
||||||
|
case Type::PointerTyID:return castToPointer(V, (PointerType*)Ty);
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "llvm/ConstPoolVals.h"
|
#include "llvm/ConstPoolVals.h"
|
||||||
#include "llvm/Instruction.h"
|
#include "llvm/Instruction.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
|
class PointerType;
|
||||||
|
|
||||||
namespace opt {
|
namespace opt {
|
||||||
|
|
||||||
@ -90,6 +91,8 @@ public:
|
|||||||
virtual ConstPoolUInt *castToULong (const ConstPoolVal *V) const = 0;
|
virtual ConstPoolUInt *castToULong (const ConstPoolVal *V) const = 0;
|
||||||
virtual ConstPoolFP *castToFloat (const ConstPoolVal *V) const = 0;
|
virtual ConstPoolFP *castToFloat (const ConstPoolVal *V) const = 0;
|
||||||
virtual ConstPoolFP *castToDouble(const ConstPoolVal *V) const = 0;
|
virtual ConstPoolFP *castToDouble(const ConstPoolVal *V) const = 0;
|
||||||
|
virtual ConstPoolPointer *castToPointer(const ConstPoolVal *V,
|
||||||
|
const PointerType *Ty) const = 0;
|
||||||
|
|
||||||
inline ConstPoolVal *castTo(const ConstPoolVal *V, const Type *Ty) const {
|
inline ConstPoolVal *castTo(const ConstPoolVal *V, const Type *Ty) const {
|
||||||
switch (Ty->getPrimitiveID()) {
|
switch (Ty->getPrimitiveID()) {
|
||||||
@ -104,6 +107,7 @@ public:
|
|||||||
case Type::LongTyID: return castToLong(V);
|
case Type::LongTyID: return castToLong(V);
|
||||||
case Type::FloatTyID: return castToFloat(V);
|
case Type::FloatTyID: return castToFloat(V);
|
||||||
case Type::DoubleTyID: return castToDouble(V);
|
case Type::DoubleTyID: return castToDouble(V);
|
||||||
|
case Type::PointerTyID:return castToPointer(V, (PointerType*)Ty);
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user