mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
Revert r73790, and replace it with a significantly less ugly solution. Rather than trying to make the global reader-writer lock work,
create separate recursive mutexes for each value map. The recursive-ness fixes the double-acquiring issue, which having one per ValueMap lets us continue to maintain some concurrency. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73801 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d5fb790613
commit
04fb7c36a9
@ -61,7 +61,7 @@ protected:
|
||||
public:
|
||||
/// Static constructor to get a '0' constant of arbitrary type...
|
||||
///
|
||||
static Constant *getNullValue(const Type *Ty, bool locked = true);
|
||||
static Constant *getNullValue(const Type *Ty);
|
||||
|
||||
/// Static constructor to get a '-1' constant. This supports integers and
|
||||
/// vectors.
|
||||
@ -107,9 +107,7 @@ public:
|
||||
/// available cached constants. Implementations should call
|
||||
/// destroyConstantImpl as the last thing they do, to destroy all users and
|
||||
/// delete this.
|
||||
virtual void destroyConstant(bool locked = true) {
|
||||
assert(0 && "Not reached!");
|
||||
}
|
||||
virtual void destroyConstant() { assert(0 && "Not reached!"); }
|
||||
|
||||
//// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
static inline bool classof(const Constant *) { return true; }
|
||||
|
@ -109,13 +109,11 @@ public:
|
||||
/// the type.
|
||||
/// @brief Get a ConstantInt for a specific value.
|
||||
static ConstantInt *get(const IntegerType *Ty,
|
||||
uint64_t V, bool isSigned = false,
|
||||
bool locked = true);
|
||||
uint64_t V, bool isSigned = false);
|
||||
|
||||
/// If Ty is a vector type, return a Constant with a splat of the given
|
||||
/// value. Otherwise return a ConstantInt for the given value.
|
||||
static Constant *get(const Type *Ty, uint64_t V,
|
||||
bool isSigned = false, bool locked = true);
|
||||
static Constant *get(const Type *Ty, uint64_t V, bool isSigned = false);
|
||||
|
||||
/// Return a ConstantInt with the specified value for the specified type. The
|
||||
/// value V will be canonicalized to a an unsigned APInt. Accessing it with
|
||||
@ -131,11 +129,11 @@ public:
|
||||
|
||||
/// Return a ConstantInt with the specified value and an implied Type. The
|
||||
/// type is the integer type that corresponds to the bit width of the value.
|
||||
static ConstantInt *get(const APInt &V, bool locked = true);
|
||||
static ConstantInt *get(const APInt &V);
|
||||
|
||||
/// If Ty is a vector type, return a Constant with a splat of the given
|
||||
/// value. Otherwise return a ConstantInt for the given value.
|
||||
static Constant *get(const Type *Ty, const APInt &V, bool locked = true);
|
||||
static Constant *get(const Type *Ty, const APInt &V);
|
||||
|
||||
/// getType - Specialize the getType() method to always return an IntegerType,
|
||||
/// which reduces the amount of casting needed in parts of the compiler.
|
||||
@ -232,7 +230,7 @@ public:
|
||||
/// @returns the value for an integer constant of the given type that has all
|
||||
/// its bits set to true.
|
||||
/// @brief Get the all ones value
|
||||
static ConstantInt *getAllOnesValue(const Type *Ty, bool locked = true);
|
||||
static ConstantInt *getAllOnesValue(const Type *Ty);
|
||||
|
||||
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
|
||||
static inline bool classof(const ConstantInt *) { return true; }
|
||||
@ -261,13 +259,13 @@ protected:
|
||||
}
|
||||
public:
|
||||
/// get() - Static factory methods - Return objects of the specified value
|
||||
static ConstantFP *get(const APFloat &V, bool locked = true);
|
||||
static ConstantFP *get(const APFloat &V);
|
||||
|
||||
/// get() - This returns a ConstantFP, or a vector containing a splat of a
|
||||
/// ConstantFP, for the specified value in the specified type. This should
|
||||
/// only be used for simple constant values like 2.0/1.0 etc, that are
|
||||
/// known-valid both as host double and as the target format.
|
||||
static Constant *get(const Type *Ty, double V, bool locked = true);
|
||||
static Constant *get(const Type *Ty, double V);
|
||||
|
||||
/// isValueValidForType - return true if Ty is big enough to represent V.
|
||||
static bool isValueValidForType(const Type *Ty, const APFloat& V);
|
||||
@ -323,13 +321,13 @@ protected:
|
||||
public:
|
||||
/// get() - static factory method for creating a null aggregate. It is
|
||||
/// illegal to call this method with a non-aggregate type.
|
||||
static ConstantAggregateZero *get(const Type *Ty, bool locked = true);
|
||||
static ConstantAggregateZero *get(const Type *Ty);
|
||||
|
||||
/// isNullValue - Return true if this is the value that would be returned by
|
||||
/// getNullValue.
|
||||
virtual bool isNullValue() const { return true; }
|
||||
|
||||
virtual void destroyConstant(bool locked = true);
|
||||
virtual void destroyConstant();
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
///
|
||||
@ -351,11 +349,9 @@ protected:
|
||||
ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
|
||||
public:
|
||||
/// get() - Static factory methods - Return objects of the specified value
|
||||
static Constant *get(const ArrayType *T, const std::vector<Constant*> &,
|
||||
bool locked = true);
|
||||
static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
|
||||
static Constant *get(const ArrayType *T,
|
||||
Constant*const*Vals, unsigned NumVals,
|
||||
bool locked = true) {
|
||||
Constant*const*Vals, unsigned NumVals) {
|
||||
// FIXME: make this the primary ctor method.
|
||||
return get(T, std::vector<Constant*>(Vals, Vals+NumVals));
|
||||
}
|
||||
@ -366,8 +362,7 @@ public:
|
||||
/// of the array by one (you've been warned). However, in some situations
|
||||
/// this is not desired so if AddNull==false then the string is copied without
|
||||
/// null termination.
|
||||
static Constant *get(const std::string &Initializer,
|
||||
bool AddNull = true, bool locked = true);
|
||||
static Constant *get(const std::string &Initializer, bool AddNull = true);
|
||||
|
||||
/// Transparently provide more efficient getOperand methods.
|
||||
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
|
||||
@ -400,7 +395,7 @@ public:
|
||||
/// created as ConstantAggregateZero objects.
|
||||
virtual bool isNullValue() const { return false; }
|
||||
|
||||
virtual void destroyConstant(bool locked = true);
|
||||
virtual void destroyConstant();
|
||||
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
@ -428,14 +423,12 @@ protected:
|
||||
public:
|
||||
/// get() - Static factory methods - Return objects of the specified value
|
||||
///
|
||||
static Constant *get(const StructType *T, const std::vector<Constant*> &V,
|
||||
bool locked = true);
|
||||
static Constant *get(const std::vector<Constant*> &V, bool Packed = false,
|
||||
bool locked = true);
|
||||
static Constant *get(const StructType *T, const std::vector<Constant*> &V);
|
||||
static Constant *get(const std::vector<Constant*> &V, bool Packed = false);
|
||||
static Constant *get(Constant*const* Vals, unsigned NumVals,
|
||||
bool Packed = false, bool locked = true) {
|
||||
bool Packed = false) {
|
||||
// FIXME: make this the primary ctor method.
|
||||
return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed, locked);
|
||||
return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
|
||||
}
|
||||
|
||||
/// Transparently provide more efficient getOperand methods.
|
||||
@ -454,7 +447,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void destroyConstant(bool locked = true);
|
||||
virtual void destroyConstant();
|
||||
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
@ -481,13 +474,11 @@ protected:
|
||||
ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
|
||||
public:
|
||||
/// get() - Static factory methods - Return objects of the specified value
|
||||
static Constant *get(const VectorType *T, const std::vector<Constant*> &,
|
||||
bool locked = true);
|
||||
static Constant *get(const std::vector<Constant*> &V, bool locked = true);
|
||||
static Constant *get(Constant*const* Vals, unsigned NumVals,
|
||||
bool locked = true) {
|
||||
static Constant *get(const VectorType *T, const std::vector<Constant*> &);
|
||||
static Constant *get(const std::vector<Constant*> &V);
|
||||
static Constant *get(Constant*const* Vals, unsigned NumVals) {
|
||||
// FIXME: make this the primary ctor method.
|
||||
return get(std::vector<Constant*>(Vals, Vals+NumVals), locked);
|
||||
return get(std::vector<Constant*>(Vals, Vals+NumVals));
|
||||
}
|
||||
|
||||
/// Transparently provide more efficient getOperand methods.
|
||||
@ -503,8 +494,7 @@ public:
|
||||
/// @returns the value for a vector integer constant of the given type that
|
||||
/// has all its bits set to true.
|
||||
/// @brief Get the all ones value
|
||||
static ConstantVector *getAllOnesValue(const VectorType *Ty,
|
||||
bool locked = true);
|
||||
static ConstantVector *getAllOnesValue(const VectorType *Ty);
|
||||
|
||||
/// isNullValue - Return true if this is the value that would be returned by
|
||||
/// getNullValue. This always returns false because zero vectors are always
|
||||
@ -521,7 +511,7 @@ public:
|
||||
/// elements have the same value, return that value. Otherwise return NULL.
|
||||
Constant *getSplatValue();
|
||||
|
||||
virtual void destroyConstant(bool locked = true);
|
||||
virtual void destroyConstant();
|
||||
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
@ -556,13 +546,13 @@ protected:
|
||||
}
|
||||
public:
|
||||
/// get() - Static factory methods - Return objects of the specified value
|
||||
static ConstantPointerNull *get(const PointerType *T, bool locked = true);
|
||||
static ConstantPointerNull *get(const PointerType *T);
|
||||
|
||||
/// isNullValue - Return true if this is the value that would be returned by
|
||||
/// getNullValue.
|
||||
virtual bool isNullValue() const { return true; }
|
||||
|
||||
virtual void destroyConstant(bool locked = true);
|
||||
virtual void destroyConstant();
|
||||
|
||||
/// getType - Specialize the getType() method to always return an PointerType,
|
||||
/// which reduces the amount of casting needed in parts of the compiler.
|
||||
@ -600,14 +590,13 @@ protected:
|
||||
// These private methods are used by the type resolution code to create
|
||||
// ConstantExprs in intermediate forms.
|
||||
static Constant *getTy(const Type *Ty, unsigned Opcode,
|
||||
Constant *C1, Constant *C2, bool locked = true);
|
||||
Constant *C1, Constant *C2);
|
||||
static Constant *getCompareTy(unsigned short pred, Constant *C1,
|
||||
Constant *C2);
|
||||
static Constant *getSelectTy(const Type *Ty, Constant *C1, Constant *C2,
|
||||
Constant *C3, bool locked = true);
|
||||
static Constant *getSelectTy(const Type *Ty,
|
||||
Constant *C1, Constant *C2, Constant *C3);
|
||||
static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
|
||||
Value* const *Idxs, unsigned NumIdxs,
|
||||
bool locked = true);
|
||||
Value* const *Idxs, unsigned NumIdxs);
|
||||
static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
|
||||
Constant *Idx);
|
||||
static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
|
||||
@ -628,18 +617,18 @@ public:
|
||||
|
||||
/// Cast constant expr
|
||||
///
|
||||
static Constant *getTrunc (Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getSExt (Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getZExt (Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getFPTrunc (Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getFPExtend(Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getUIToFP (Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getSIToFP (Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getFPToUI (Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getFPToSI (Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getPtrToInt(Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getIntToPtr(Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getBitCast (Constant *C, const Type *Ty, bool locked = true);
|
||||
static Constant *getTrunc (Constant *C, const Type *Ty);
|
||||
static Constant *getSExt (Constant *C, const Type *Ty);
|
||||
static Constant *getZExt (Constant *C, const Type *Ty);
|
||||
static Constant *getFPTrunc (Constant *C, const Type *Ty);
|
||||
static Constant *getFPExtend(Constant *C, const Type *Ty);
|
||||
static Constant *getUIToFP (Constant *C, const Type *Ty);
|
||||
static Constant *getSIToFP (Constant *C, const Type *Ty);
|
||||
static Constant *getFPToUI (Constant *C, const Type *Ty);
|
||||
static Constant *getFPToSI (Constant *C, const Type *Ty);
|
||||
static Constant *getPtrToInt(Constant *C, const Type *Ty);
|
||||
static Constant *getIntToPtr(Constant *C, const Type *Ty);
|
||||
static Constant *getBitCast (Constant *C, const Type *Ty);
|
||||
|
||||
/// Transparently provide more efficient getOperand methods.
|
||||
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
|
||||
@ -649,8 +638,7 @@ public:
|
||||
static Constant *getCast(
|
||||
unsigned ops, ///< The opcode for the conversion
|
||||
Constant *C, ///< The constant to be converted
|
||||
const Type *Ty, ///< The type to which the constant is converted
|
||||
bool locked = true
|
||||
const Type *Ty ///< The type to which the constant is converted
|
||||
);
|
||||
|
||||
// @brief Create a ZExt or BitCast cast constant expression
|
||||
@ -662,8 +650,7 @@ public:
|
||||
// @brief Create a SExt or BitCast cast constant expression
|
||||
static Constant *getSExtOrBitCast(
|
||||
Constant *C, ///< The constant to sext or bitcast
|
||||
const Type *Ty, ///< The type to sext or bitcast C to
|
||||
bool locked = true
|
||||
const Type *Ty ///< The type to sext or bitcast C to
|
||||
);
|
||||
|
||||
// @brief Create a Trunc or BitCast cast constant expression
|
||||
@ -675,8 +662,7 @@ public:
|
||||
/// @brief Create a BitCast or a PtrToInt cast constant expression
|
||||
static Constant *getPointerCast(
|
||||
Constant *C, ///< The pointer value to be casted (operand 0)
|
||||
const Type *Ty, ///< The type to which cast should be made
|
||||
bool locked = true
|
||||
const Type *Ty ///< The type to which cast should be made
|
||||
);
|
||||
|
||||
/// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
|
||||
@ -722,8 +708,7 @@ public:
|
||||
/// ConstantExpr::get - Return a binary or shift operator constant expression,
|
||||
/// folding if possible.
|
||||
///
|
||||
static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
|
||||
bool locked = true);
|
||||
static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
|
||||
|
||||
/// @brief Return an ICmp, FCmp, VICmp, or VFCmp comparison operator constant
|
||||
/// expression.
|
||||
@ -735,38 +720,36 @@ public:
|
||||
static Constant *getNeg(Constant *C);
|
||||
static Constant *getFNeg(Constant *C);
|
||||
static Constant *getNot(Constant *C);
|
||||
static Constant *getAdd(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getFAdd(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getSub(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getFSub(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getMul(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getFMul(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getUDiv(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getSDiv(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getFDiv(Constant *C1, Constant *C2, bool locked = true);
|
||||
// unsigned rem
|
||||
static Constant *getURem(Constant *C1, Constant *C2, bool locked = true);
|
||||
// signed rem
|
||||
static Constant *getSRem(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getFRem(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getAnd(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getOr(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getXor(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getAdd(Constant *C1, Constant *C2);
|
||||
static Constant *getFAdd(Constant *C1, Constant *C2);
|
||||
static Constant *getSub(Constant *C1, Constant *C2);
|
||||
static Constant *getFSub(Constant *C1, Constant *C2);
|
||||
static Constant *getMul(Constant *C1, Constant *C2);
|
||||
static Constant *getFMul(Constant *C1, Constant *C2);
|
||||
static Constant *getUDiv(Constant *C1, Constant *C2);
|
||||
static Constant *getSDiv(Constant *C1, Constant *C2);
|
||||
static Constant *getFDiv(Constant *C1, Constant *C2);
|
||||
static Constant *getURem(Constant *C1, Constant *C2); // unsigned rem
|
||||
static Constant *getSRem(Constant *C1, Constant *C2); // signed rem
|
||||
static Constant *getFRem(Constant *C1, Constant *C2);
|
||||
static Constant *getAnd(Constant *C1, Constant *C2);
|
||||
static Constant *getOr(Constant *C1, Constant *C2);
|
||||
static Constant *getXor(Constant *C1, Constant *C2);
|
||||
static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS);
|
||||
static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
|
||||
static Constant *getVICmp(unsigned short pred, Constant *LHS, Constant *RHS);
|
||||
static Constant *getVFCmp(unsigned short pred, Constant *LHS, Constant *RHS);
|
||||
static Constant *getShl(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getLShr(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getAShr(Constant *C1, Constant *C2, bool locked = true);
|
||||
static Constant *getShl(Constant *C1, Constant *C2);
|
||||
static Constant *getLShr(Constant *C1, Constant *C2);
|
||||
static Constant *getAShr(Constant *C1, Constant *C2);
|
||||
|
||||
/// Getelementptr form. std::vector<Value*> is only accepted for convenience:
|
||||
/// all elements must be Constant's.
|
||||
///
|
||||
static Constant *getGetElementPtr(Constant *C, Constant* const *IdxList,
|
||||
unsigned NumIdx, bool locked = true);
|
||||
static Constant *getGetElementPtr(Constant *C, Value* const *IdxList,
|
||||
unsigned NumIdx, bool locked = true);
|
||||
static Constant *getGetElementPtr(Constant *C,
|
||||
Constant* const *IdxList, unsigned NumIdx);
|
||||
static Constant *getGetElementPtr(Constant *C,
|
||||
Value* const *IdxList, unsigned NumIdx);
|
||||
|
||||
static Constant *getExtractElement(Constant *Vec, Constant *Idx);
|
||||
static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
|
||||
@ -811,7 +794,7 @@ public:
|
||||
}
|
||||
Constant *getWithOperands(Constant* const *Ops, unsigned NumOps) const;
|
||||
|
||||
virtual void destroyConstant(bool locked = true);
|
||||
virtual void destroyConstant();
|
||||
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
@ -848,13 +831,13 @@ public:
|
||||
/// get() - Static factory methods - Return an 'undef' object of the specified
|
||||
/// type.
|
||||
///
|
||||
static UndefValue *get(const Type *T, bool locked = true);
|
||||
static UndefValue *get(const Type *T);
|
||||
|
||||
/// isNullValue - Return true if this is the value that would be returned by
|
||||
/// getNullValue.
|
||||
virtual bool isNullValue() const { return false; }
|
||||
|
||||
virtual void destroyConstant(bool locked = true);
|
||||
virtual void destroyConstant();
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
static inline bool classof(const UndefValue *) { return true; }
|
||||
@ -881,8 +864,7 @@ protected:
|
||||
public:
|
||||
/// get() - Static factory methods - Return objects of the specified value.
|
||||
///
|
||||
static MDString *get(const char *StrBegin, const char *StrEnd,
|
||||
bool locked = true);
|
||||
static MDString *get(const char *StrBegin, const char *StrEnd);
|
||||
|
||||
/// size() - The length of this string.
|
||||
///
|
||||
@ -909,7 +891,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void destroyConstant(bool locked = true);
|
||||
virtual void destroyConstant();
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
static inline bool classof(const MDString *) { return true; }
|
||||
|
@ -172,7 +172,7 @@ public:
|
||||
virtual bool isNullValue() const { return false; }
|
||||
|
||||
/// Override from Constant class.
|
||||
virtual void destroyConstant(bool locked = true);
|
||||
virtual void destroyConstant();
|
||||
|
||||
/// isDeclaration - Return true if the primary definition of this global
|
||||
/// value is outside of the current translation unit...
|
||||
|
@ -78,7 +78,7 @@ public:
|
||||
|
||||
/// get() - Static factory methods - Return objects of the specified value.
|
||||
///
|
||||
static MDNode *get(Value*const* Vals, unsigned NumVals, bool locked = true);
|
||||
static MDNode *get(Value*const* Vals, unsigned NumVals);
|
||||
|
||||
Value *getElement(unsigned i) const {
|
||||
return Node[i];
|
||||
@ -117,7 +117,7 @@ public:
|
||||
/// duplicates
|
||||
void Profile(FoldingSetNodeID &ID) const;
|
||||
|
||||
virtual void destroyConstant(bool locked = true);
|
||||
virtual void destroyConstant();
|
||||
virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) {
|
||||
assert(0 && "This should never be called because MDNodes have no ops");
|
||||
abort();
|
||||
|
@ -40,8 +40,7 @@ using namespace llvm;
|
||||
/// specified vector type. At this point, we know that the elements of the
|
||||
/// input vector constant are all simple integer or FP values.
|
||||
static Constant *BitCastConstantVector(ConstantVector *CV,
|
||||
const VectorType *DstTy,
|
||||
bool locked) {
|
||||
const VectorType *DstTy) {
|
||||
// If this cast changes element count then we can't handle it here:
|
||||
// doing so requires endianness information. This should be handled by
|
||||
// Analysis/ConstantFolding.cpp
|
||||
@ -61,7 +60,7 @@ static Constant *BitCastConstantVector(ConstantVector *CV,
|
||||
const Type *DstEltTy = DstTy->getElementType();
|
||||
for (unsigned i = 0; i != NumElts; ++i)
|
||||
Result.push_back(ConstantExpr::getBitCast(CV->getOperand(i), DstEltTy));
|
||||
return ConstantVector::get(Result, locked);
|
||||
return ConstantVector::get(Result);
|
||||
}
|
||||
|
||||
/// This function determines which opcode to use to fold two constant cast
|
||||
@ -89,8 +88,7 @@ foldConstantCastPair(
|
||||
Type::Int64Ty);
|
||||
}
|
||||
|
||||
static Constant *FoldBitCast(Constant *V, const Type *DestTy,
|
||||
bool locked = true) {
|
||||
static Constant *FoldBitCast(Constant *V, const Type *DestTy) {
|
||||
const Type *SrcTy = V->getType();
|
||||
if (SrcTy == DestTy)
|
||||
return V; // no-op cast
|
||||
@ -101,7 +99,7 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy,
|
||||
if (const PointerType *DPTy = dyn_cast<PointerType>(DestTy))
|
||||
if (PTy->getAddressSpace() == DPTy->getAddressSpace()) {
|
||||
SmallVector<Value*, 8> IdxList;
|
||||
IdxList.push_back(Constant::getNullValue(Type::Int32Ty, locked));
|
||||
IdxList.push_back(Constant::getNullValue(Type::Int32Ty));
|
||||
const Type *ElTy = PTy->getElementType();
|
||||
while (ElTy != DPTy->getElementType()) {
|
||||
if (const StructType *STy = dyn_cast<StructType>(ElTy)) {
|
||||
@ -119,8 +117,7 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy,
|
||||
}
|
||||
|
||||
if (ElTy == DPTy->getElementType())
|
||||
return ConstantExpr::getGetElementPtr(V, &IdxList[0],
|
||||
IdxList.size(), locked);
|
||||
return ConstantExpr::getGetElementPtr(V, &IdxList[0], IdxList.size());
|
||||
}
|
||||
|
||||
// Handle casts from one vector constant to another. We know that the src
|
||||
@ -132,24 +129,23 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy,
|
||||
SrcTy = NULL;
|
||||
// First, check for null. Undef is already handled.
|
||||
if (isa<ConstantAggregateZero>(V))
|
||||
return Constant::getNullValue(DestTy, locked);
|
||||
return Constant::getNullValue(DestTy);
|
||||
|
||||
if (ConstantVector *CV = dyn_cast<ConstantVector>(V))
|
||||
return BitCastConstantVector(CV, DestPTy, locked);
|
||||
return BitCastConstantVector(CV, DestPTy);
|
||||
}
|
||||
|
||||
// Canonicalize scalar-to-vector bitcasts into vector-to-vector bitcasts
|
||||
// This allows for other simplifications (although some of them
|
||||
// can only be handled by Analysis/ConstantFolding.cpp).
|
||||
if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
|
||||
return ConstantExpr::getBitCast(ConstantVector::get(&V, 1, locked),
|
||||
DestPTy, locked);
|
||||
return ConstantExpr::getBitCast(ConstantVector::get(&V, 1), DestPTy);
|
||||
}
|
||||
|
||||
// Finally, implement bitcast folding now. The code below doesn't handle
|
||||
// bitcast right.
|
||||
if (isa<ConstantPointerNull>(V)) // ptr->ptr cast.
|
||||
return ConstantPointerNull::get(cast<PointerType>(DestTy), locked);
|
||||
return ConstantPointerNull::get(cast<PointerType>(DestTy));
|
||||
|
||||
// Handle integral constant input.
|
||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
|
||||
@ -160,7 +156,7 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy,
|
||||
|
||||
if (DestTy->isFloatingPoint())
|
||||
return ConstantFP::get(APFloat(CI->getValue(),
|
||||
DestTy != Type::PPC_FP128Ty), locked);
|
||||
DestTy != Type::PPC_FP128Ty));
|
||||
|
||||
// Otherwise, can't fold this (vector?)
|
||||
return 0;
|
||||
@ -169,22 +165,22 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy,
|
||||
// Handle ConstantFP input.
|
||||
if (const ConstantFP *FP = dyn_cast<ConstantFP>(V))
|
||||
// FP -> Integral.
|
||||
return ConstantInt::get(FP->getValueAPF().bitcastToAPInt(), locked);
|
||||
return ConstantInt::get(FP->getValueAPF().bitcastToAPInt());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
const Type *DestTy, bool locked) {
|
||||
const Type *DestTy) {
|
||||
if (isa<UndefValue>(V)) {
|
||||
// zext(undef) = 0, because the top bits will be zero.
|
||||
// sext(undef) = 0, because the top bits will all be the same.
|
||||
// [us]itofp(undef) = 0, because the result value is bounded.
|
||||
if (opc == Instruction::ZExt || opc == Instruction::SExt ||
|
||||
opc == Instruction::UIToFP || opc == Instruction::SIToFP)
|
||||
return Constant::getNullValue(DestTy, locked);
|
||||
return UndefValue::get(DestTy, locked);
|
||||
return Constant::getNullValue(DestTy);
|
||||
return UndefValue::get(DestTy);
|
||||
}
|
||||
// No compile-time operations on this type yet.
|
||||
if (V->getType() == Type::PPC_FP128Ty || DestTy == Type::PPC_FP128Ty)
|
||||
@ -196,7 +192,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
if (CE->isCast()) {
|
||||
// Try hard to fold cast of cast because they are often eliminable.
|
||||
if (unsigned newOpc = foldConstantCastPair(opc, CE, DestTy))
|
||||
return ConstantExpr::getCast(newOpc, CE->getOperand(0), DestTy, locked);
|
||||
return ConstantExpr::getCast(newOpc, CE->getOperand(0), DestTy);
|
||||
} else if (CE->getOpcode() == Instruction::GetElementPtr) {
|
||||
// If all of the indexes in the GEP are null values, there is no pointer
|
||||
// adjustment going on. We might as well cast the source pointer.
|
||||
@ -208,7 +204,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
}
|
||||
if (isAllNull)
|
||||
// This is casting one pointer type to another, always BitCast
|
||||
return ConstantExpr::getPointerCast(CE->getOperand(0), DestTy, locked);
|
||||
return ConstantExpr::getPointerCast(CE->getOperand(0), DestTy);
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,8 +220,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
const Type *DstEltTy = DestVecTy->getElementType();
|
||||
for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i)
|
||||
res.push_back(ConstantExpr::getCast(opc,
|
||||
CV->getOperand(i), DstEltTy, locked));
|
||||
return ConstantVector::get(DestVecTy, res, locked);
|
||||
CV->getOperand(i), DstEltTy));
|
||||
return ConstantVector::get(DestVecTy, res);
|
||||
}
|
||||
|
||||
// We actually have to do a cast now. Perform the cast according to the
|
||||
@ -242,7 +238,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
DestTy == Type::FP128Ty ? APFloat::IEEEquad :
|
||||
APFloat::Bogus,
|
||||
APFloat::rmNearestTiesToEven, &ignored);
|
||||
return ConstantFP::get(Val, locked);
|
||||
return ConstantFP::get(Val);
|
||||
}
|
||||
return 0; // Can't fold.
|
||||
case Instruction::FPToUI:
|
||||
@ -255,16 +251,16 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
(void) V.convertToInteger(x, DestBitWidth, opc==Instruction::FPToSI,
|
||||
APFloat::rmTowardZero, &ignored);
|
||||
APInt Val(DestBitWidth, 2, x);
|
||||
return ConstantInt::get(Val, locked);
|
||||
return ConstantInt::get(Val);
|
||||
}
|
||||
return 0; // Can't fold.
|
||||
case Instruction::IntToPtr: //always treated as unsigned
|
||||
if (V->isNullValue()) // Is it an integral null value?
|
||||
return ConstantPointerNull::get(cast<PointerType>(DestTy), locked);
|
||||
return ConstantPointerNull::get(cast<PointerType>(DestTy));
|
||||
return 0; // Other pointer types cannot be casted
|
||||
case Instruction::PtrToInt: // always treated as unsigned
|
||||
if (V->isNullValue()) // is it a null pointer value?
|
||||
return ConstantInt::get(DestTy, 0, locked);
|
||||
return ConstantInt::get(DestTy, 0);
|
||||
return 0; // Other pointer types cannot be casted
|
||||
case Instruction::UIToFP:
|
||||
case Instruction::SIToFP:
|
||||
@ -276,7 +272,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
(void)apf.convertFromAPInt(api,
|
||||
opc==Instruction::SIToFP,
|
||||
APFloat::rmNearestTiesToEven);
|
||||
return ConstantFP::get(apf, locked);
|
||||
return ConstantFP::get(apf);
|
||||
}
|
||||
return 0;
|
||||
case Instruction::ZExt:
|
||||
@ -284,7 +280,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||
APInt Result(CI->getValue());
|
||||
Result.zext(BitWidth);
|
||||
return ConstantInt::get(Result, locked);
|
||||
return ConstantInt::get(Result);
|
||||
}
|
||||
return 0;
|
||||
case Instruction::SExt:
|
||||
@ -292,7 +288,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||
APInt Result(CI->getValue());
|
||||
Result.sext(BitWidth);
|
||||
return ConstantInt::get(Result, locked);
|
||||
return ConstantInt::get(Result);
|
||||
}
|
||||
return 0;
|
||||
case Instruction::Trunc:
|
||||
@ -300,11 +296,11 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||
APInt Result(CI->getValue());
|
||||
Result.trunc(BitWidth);
|
||||
return ConstantInt::get(Result, locked);
|
||||
return ConstantInt::get(Result);
|
||||
}
|
||||
return 0;
|
||||
case Instruction::BitCast:
|
||||
return FoldBitCast(const_cast<Constant*>(V), DestTy, locked);
|
||||
return FoldBitCast(const_cast<Constant*>(V), DestTy);
|
||||
default:
|
||||
assert(!"Invalid CE CastInst opcode");
|
||||
break;
|
||||
@ -316,7 +312,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
||||
|
||||
Constant *llvm::ConstantFoldSelectInstruction(const Constant *Cond,
|
||||
const Constant *V1,
|
||||
const Constant *V2, bool locked) {
|
||||
const Constant *V2) {
|
||||
if (const ConstantInt *CB = dyn_cast<ConstantInt>(Cond))
|
||||
return const_cast<Constant*>(CB->getZExtValue() ? V1 : V2);
|
||||
|
||||
@ -570,22 +566,21 @@ Constant *llvm::ConstantFoldInsertValueInstruction(const Constant *Agg,
|
||||
static Constant *EvalVectorOp(const ConstantVector *V1,
|
||||
const ConstantVector *V2,
|
||||
const VectorType *VTy,
|
||||
Constant *(*FP)(Constant*, Constant*, bool)) {
|
||||
Constant *(*FP)(Constant*, Constant*)) {
|
||||
std::vector<Constant*> Res;
|
||||
const Type *EltTy = VTy->getElementType();
|
||||
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
|
||||
const Constant *C1 = V1 ? V1->getOperand(i) : Constant::getNullValue(EltTy);
|
||||
const Constant *C2 = V2 ? V2->getOperand(i) : Constant::getNullValue(EltTy);
|
||||
Res.push_back(FP(const_cast<Constant*>(C1),
|
||||
const_cast<Constant*>(C2), true));
|
||||
const_cast<Constant*>(C2)));
|
||||
}
|
||||
return ConstantVector::get(Res);
|
||||
}
|
||||
|
||||
Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
|
||||
const Constant *C1,
|
||||
const Constant *C2,
|
||||
bool locked) {
|
||||
const Constant *C2) {
|
||||
// No compile-time operations on this type yet.
|
||||
if (C1->getType() == Type::PPC_FP128Ty)
|
||||
return 0;
|
||||
@ -597,29 +592,29 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
|
||||
if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
|
||||
// Handle undef ^ undef -> 0 special case. This is a common
|
||||
// idiom (misuse).
|
||||
return Constant::getNullValue(C1->getType(), locked);
|
||||
return Constant::getNullValue(C1->getType());
|
||||
// Fallthrough
|
||||
case Instruction::Add:
|
||||
case Instruction::Sub:
|
||||
return UndefValue::get(C1->getType(), locked);
|
||||
return UndefValue::get(C1->getType());
|
||||
case Instruction::Mul:
|
||||
case Instruction::And:
|
||||
return Constant::getNullValue(C1->getType(), locked);
|
||||
return Constant::getNullValue(C1->getType());
|
||||
case Instruction::UDiv:
|
||||
case Instruction::SDiv:
|
||||
case Instruction::URem:
|
||||
case Instruction::SRem:
|
||||
if (!isa<UndefValue>(C2)) // undef / X -> 0
|
||||
return Constant::getNullValue(C1->getType(), locked);
|
||||
return Constant::getNullValue(C1->getType());
|
||||
return const_cast<Constant*>(C2); // X / undef -> undef
|
||||
case Instruction::Or: // X | undef -> -1
|
||||
if (const VectorType *PTy = dyn_cast<VectorType>(C1->getType()))
|
||||
return ConstantVector::getAllOnesValue(PTy, locked);
|
||||
return ConstantInt::getAllOnesValue(C1->getType(), locked);
|
||||
return ConstantVector::getAllOnesValue(PTy);
|
||||
return ConstantInt::getAllOnesValue(C1->getType());
|
||||
case Instruction::LShr:
|
||||
if (isa<UndefValue>(C2) && isa<UndefValue>(C1))
|
||||
return const_cast<Constant*>(C1); // undef lshr undef -> undef
|
||||
return Constant::getNullValue(C1->getType(), locked); // X lshr undef -> 0
|
||||
return Constant::getNullValue(C1->getType()); // X lshr undef -> 0
|
||||
// undef lshr X -> 0
|
||||
case Instruction::AShr:
|
||||
if (!isa<UndefValue>(C2))
|
||||
@ -630,7 +625,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
|
||||
return const_cast<Constant*>(C1); // X ashr undef --> X
|
||||
case Instruction::Shl:
|
||||
// undef << X -> 0 or X << undef -> 0
|
||||
return Constant::getNullValue(C1->getType(), locked);
|
||||
return Constant::getNullValue(C1->getType());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1577,7 +1572,7 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
|
||||
|
||||
Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
||||
Constant* const *Idxs,
|
||||
unsigned NumIdx, bool locked) {
|
||||
unsigned NumIdx) {
|
||||
if (NumIdx == 0 ||
|
||||
(NumIdx == 1 && Idxs[0]->isNullValue()))
|
||||
return const_cast<Constant*>(C);
|
||||
@ -1588,8 +1583,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
||||
(Value **)Idxs,
|
||||
(Value **)Idxs+NumIdx);
|
||||
assert(Ty != 0 && "Invalid indices for GEP!");
|
||||
return UndefValue::get(PointerType::get(Ty, Ptr->getAddressSpace()),
|
||||
locked);
|
||||
return UndefValue::get(PointerType::get(Ty, Ptr->getAddressSpace()));
|
||||
}
|
||||
|
||||
Constant *Idx0 = Idxs[0];
|
||||
@ -1607,8 +1601,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
||||
(Value**)Idxs+NumIdx);
|
||||
assert(Ty != 0 && "Invalid indices for GEP!");
|
||||
return
|
||||
ConstantPointerNull::get(PointerType::get(Ty,Ptr->getAddressSpace()),
|
||||
locked);
|
||||
ConstantPointerNull::get(PointerType::get(Ty,Ptr->getAddressSpace()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1636,22 +1629,20 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
||||
if (!Idx0->isNullValue()) {
|
||||
const Type *IdxTy = Combined->getType();
|
||||
if (IdxTy != Idx0->getType()) {
|
||||
Constant *C1 = ConstantExpr::getSExtOrBitCast(Idx0, Type::Int64Ty,
|
||||
locked);
|
||||
Constant *C1 = ConstantExpr::getSExtOrBitCast(Idx0, Type::Int64Ty);
|
||||
Constant *C2 = ConstantExpr::getSExtOrBitCast(Combined,
|
||||
Type::Int64Ty,
|
||||
locked);
|
||||
Combined = ConstantExpr::get(Instruction::Add, C1, C2, locked);
|
||||
Type::Int64Ty);
|
||||
Combined = ConstantExpr::get(Instruction::Add, C1, C2);
|
||||
} else {
|
||||
Combined =
|
||||
ConstantExpr::get(Instruction::Add, Idx0, Combined, locked);
|
||||
ConstantExpr::get(Instruction::Add, Idx0, Combined);
|
||||
}
|
||||
}
|
||||
|
||||
NewIndices.push_back(Combined);
|
||||
NewIndices.insert(NewIndices.end(), Idxs+1, Idxs+NumIdx);
|
||||
return ConstantExpr::getGetElementPtr(CE->getOperand(0), &NewIndices[0],
|
||||
NewIndices.size(), locked);
|
||||
NewIndices.size());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1668,7 +1659,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
||||
dyn_cast<ArrayType>(cast<PointerType>(C->getType())->getElementType()))
|
||||
if (CAT->getElementType() == SAT->getElementType())
|
||||
return ConstantExpr::getGetElementPtr(
|
||||
(Constant*)CE->getOperand(0), Idxs, NumIdx, locked);
|
||||
(Constant*)CE->getOperand(0), Idxs, NumIdx);
|
||||
}
|
||||
|
||||
// Fold: getelementptr (i8* inttoptr (i64 1 to i8*), i32 -1)
|
||||
@ -1686,10 +1677,10 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
||||
Offset = ConstantExpr::getSExt(Offset, Base->getType());
|
||||
else if (Base->getType()->getPrimitiveSizeInBits() <
|
||||
Offset->getType()->getPrimitiveSizeInBits())
|
||||
Base = ConstantExpr::getZExt(Base, Offset->getType(), locked);
|
||||
Base = ConstantExpr::getZExt(Base, Offset->getType());
|
||||
|
||||
Base = ConstantExpr::getAdd(Base, Offset, locked);
|
||||
return ConstantExpr::getIntToPtr(Base, CE->getType(), locked);
|
||||
Base = ConstantExpr::getAdd(Base, Offset);
|
||||
return ConstantExpr::getIntToPtr(Base, CE->getType());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -75,7 +75,7 @@ void GlobalValue::removeDeadConstantUsers() const {
|
||||
|
||||
/// Override destroyConstant to make sure it doesn't get called on
|
||||
/// GlobalValue's because they shouldn't be treated like other constants.
|
||||
void GlobalValue::destroyConstant(bool locked) {
|
||||
void GlobalValue::destroyConstant() {
|
||||
assert(0 && "You can't GV->destroyConstant()!");
|
||||
abort();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user