diff options
author | Chris Lattner <sabre@nondot.org> | 2004-10-16 18:07:16 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-10-16 18:07:16 +0000 |
commit | b9f18592a62b5f60d20ee6d498df0086b1813b21 (patch) | |
tree | 75f1428bba2eaef90298eaa4b51dd7acede7d44f | |
parent | c8717b1624bfdbca3183de1317be2f92a65106e5 (diff) |
Implement UndefValue class
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17040 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/VMCore/Constants.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 8d964bcb24..77aa23135e 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1098,6 +1098,51 @@ void ConstantPointerNull::destroyConstant() { } +//---- UndefValue::get() implementation... +// + +namespace llvm { + // UndefValue does not take extra "value" argument... + template<class ValType> + struct ConstantCreator<UndefValue, Type, ValType> { + static UndefValue *create(const Type *Ty, const ValType &V) { + return new UndefValue(Ty); + } + }; + + template<> + struct ConvertConstantType<UndefValue, Type> { + static void convert(UndefValue *OldC, const Type *NewTy) { + // Make everyone now use a constant of the new type. + Constant *New = UndefValue::get(NewTy); + assert(New != OldC && "Didn't replace constant??"); + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. + } + }; +} + +static ValueMap<char, Type, UndefValue> UndefValueConstants; + +static char getValType(UndefValue *) { + return 0; +} + + +UndefValue *UndefValue::get(const Type *Ty) { + return UndefValueConstants.getOrCreate(Ty, 0); +} + +// destroyConstant - Remove the constant from the constant table. +// +void UndefValue::destroyConstant() { + UndefValueConstants.remove(this); + destroyConstantImpl(); +} + + + + //---- ConstantExpr::get() implementations... // typedef std::pair<unsigned, std::vector<Constant*> > ExprMapKeyType; |