[llvm-commits] [llvm] r49630 - in /llvm/branches/ggreif/use-diet: include/llvm/Constants.h lib/VMCore/Constants.cpp
Gabor Greif
ggreif at gmail.com
Sun Apr 13 17:14:34 PDT 2008
Author: ggreif
Date: Sun Apr 13 19:14:34 2008
New Revision: 49630
URL: http://llvm.org/viewvc/llvm-project?rev=49630&view=rev
Log:
convert Constant{Array|Struct|Vector} to prefix allocation. does not compile yet
Modified:
llvm/branches/ggreif/use-diet/include/llvm/Constants.h
llvm/branches/ggreif/use-diet/lib/VMCore/Constants.cpp
Modified: llvm/branches/ggreif/use-diet/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Constants.h?rev=49630&r1=49629&r2=49630&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/Constants.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/Constants.h Sun Apr 13 19:14:34 2008
@@ -331,6 +331,9 @@
/// null termination.
static Constant *get(const std::string &Initializer, bool AddNull = true);
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
/// getType - Specialize the getType() method to always return an ArrayType,
/// which reduces the amount of casting needed in parts of the compiler.
///
@@ -369,6 +372,11 @@
}
};
+template <>
+struct OperandTraits<ConstantArray> : VariadicOperandTraits<> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Value)
//===----------------------------------------------------------------------===//
// ConstantStruct - Constant Struct Declarations
@@ -391,6 +399,9 @@
return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
}
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
/// getType() specialization - Reduce amount of casting...
///
inline const StructType *getType() const {
@@ -414,6 +425,12 @@
}
};
+template <>
+struct OperandTraits<ConstantStruct> : VariadicOperandTraits<> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Value)
+
//===----------------------------------------------------------------------===//
/// ConstantVector - Constant Vector Declarations
///
@@ -433,6 +450,9 @@
return get(std::vector<Constant*>(Vals, Vals+NumVals));
}
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
/// getType - Specialize the getType() method to always return a VectorType,
/// which reduces the amount of casting needed in parts of the compiler.
///
@@ -470,6 +490,12 @@
}
};
+template <>
+struct OperandTraits<ConstantVector> : VariadicOperandTraits<> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Value)
+
//===----------------------------------------------------------------------===//
/// ConstantPointerNull - a constant pointer value that points to null
///
@@ -568,6 +594,9 @@
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);
+
// @brief Convenience function for getting one of the casting operations
// using a CastOps opcode.
static Constant *getCast(
@@ -720,6 +749,11 @@
}
};
+template <>
+struct OperandTraits<ConstantExpr> : VariadicOperandTraits<1> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant)
//===----------------------------------------------------------------------===//
/// UndefValue - 'undef' values are things that do not have specified contents.
Modified: llvm/branches/ggreif/use-diet/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/VMCore/Constants.cpp?rev=49630&r1=49629&r2=49630&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/lib/VMCore/Constants.cpp (original)
+++ llvm/branches/ggreif/use-diet/lib/VMCore/Constants.cpp Sun Apr 13 19:14:34 2008
@@ -341,7 +341,9 @@
ConstantArray::ConstantArray(const ArrayType *T,
const std::vector<Constant*> &V)
- : Constant(T, ConstantArrayVal, allocHangoffUses(V.size()), V.size()) {
+ : Constant(T, ConstantArrayVal,
+ OperandTraits<ConstantArray>::op_end(this) - V.size(),
+ V.size()) {
assert(V.size() == T->getNumElements() &&
"Invalid initializer vector for constant array");
Use *OL = OperandList;
@@ -356,13 +358,12 @@
}
}
-ConstantArray::~ConstantArray() {
-// delete [] OperandList;
-}
ConstantStruct::ConstantStruct(const StructType *T,
const std::vector<Constant*> &V)
- : Constant(T, ConstantStructVal, allocHangoffUses(V.size()), V.size()) {
+ : Constant(T, ConstantStructVal,
+ OperandTraits<ConstantStruct>::op_end(this) - V.size(),
+ V.size()) {
assert(V.size() == T->getNumElements() &&
"Invalid initializer vector for constant structure");
Use *OL = OperandList;
@@ -379,14 +380,12 @@
}
}
-ConstantStruct::~ConstantStruct() {
- delete [] OperandList;
-}
-
ConstantVector::ConstantVector(const VectorType *T,
const std::vector<Constant*> &V)
- : Constant(T, ConstantVectorVal, allocHangoffUses(V.size()), V.size()) {
+ : Constant(T, ConstantVectorVal,
+ OperandTraits<ConstantVector>::op_end(this) - V.size(),
+ V.size()) {
Use *OL = OperandList;
for (std::vector<Constant*>::const_iterator I = V.begin(), E = V.end();
I != E; ++I, ++OL) {
@@ -399,9 +398,6 @@
}
}
-ConstantVector::~ConstantVector() {
-// delete [] OperandList;
-}
namespace llvm {
// We declare several classes private to this file, so use an anonymous
@@ -864,17 +860,29 @@
//===----------------------------------------------------------------------===//
// Factory Function Implementation
+
+// The number of operands for each ConstantCreator::create method is
+// determined by the ConstantTraits template.
// ConstantCreator - A class that is used to create constants by
// ValueMap*. This class should be partially specialized if there is
// something strange that needs to be done to interface to the ctor for the
// constant.
//
namespace llvm {
+ template<class ValType>
+ struct ConstantTraits;
+
+ template<typename T, typename Alloc>
+ struct VISIBILITY_HIDDEN ConstantTraits< std::vector<T, Alloc> > {
+ static unsigned uses(const std::vector<T, Alloc>& v) {
+ return v.size();
+ }
+ };
+
template<class ConstantClass, class TypeClass, class ValType>
struct VISIBILITY_HIDDEN ConstantCreator {
static ConstantClass *create(const TypeClass *Ty, const ValType &V) {
- unsigned FIXME = 0; // = traits<ValType>::uses(V)
- return new(FIXME) ConstantClass(Ty, V);
+ return new(ConstantTraits<ValType>::uses(V)) ConstantClass(Ty, V);
}
};
More information about the llvm-commits
mailing list