[llvm-commits] [llvm] r51679 - in /llvm/branches/ggreif/use-diet: include/llvm/Instructions.h include/llvm/OperandTraits.h include/llvm/User.h lib/VMCore/Instructions.cpp
Gabor Greif
ggreif at gmail.com
Thu May 29 07:04:53 PDT 2008
Author: ggreif
Date: Thu May 29 09:04:53 2008
New Revision: 51679
URL: http://llvm.org/viewvc/llvm-project?rev=51679&view=rev
Log:
start of experiment to use a more centralized allocation strategy which delegates work to the OperandTraits
Modified:
llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h
llvm/branches/ggreif/use-diet/include/llvm/User.h
llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp
Modified: llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Instructions.h?rev=51679&r1=51678&r2=51679&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/Instructions.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/Instructions.h Thu May 29 09:04:53 2008
@@ -1229,15 +1229,18 @@
setName(Name);
}
public:
- static SelectInst *Create(Value *C, Value *S1, Value *S2,
- const std::string &Name = "",
- Instruction *InsertBefore = 0) {
- return new(3) SelectInst(C, S1, S2, Name, InsertBefore);
- }
- static SelectInst *Create(Value *C, Value *S1, Value *S2,
- const std::string &Name, BasicBlock *InsertAtEnd) {
- return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd);
- }
+ /// Create - allocate and construct a SelectInst
+ /// given condition and value alternatives
+ /// before another Instruction
+ static inline SelectInst *Create(Value *C, Value *S1, Value *S2,
+ const std::string &Name = "",
+ Instruction *InsertBefore = 0);
+ /// Create - allocate and construct a SelectInst
+ /// given condition and value alternatives
+ /// at end of block
+ static inline SelectInst *Create(Value *C, Value *S1, Value *S2,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd);
Value *getCondition() const { return Op<0>(); }
Value *getTrueValue() const { return Op<1>(); }
@@ -1268,6 +1271,19 @@
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
+SelectInst *SelectInst::Create(Value *C, Value *S1, Value *S2,
+ const std::string &Name,
+ Instruction *InsertBefore) {
+ return new('A', OperandTraits<SelectInst>::alloc<SelectInst>())
+ SelectInst(C, S1, S2, Name, InsertBefore);
+}
+SelectInst *SelectInst::Create(Value *C, Value *S1, Value *S2,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd) {
+ return new('A', OperandTraits<SelectInst>::alloc<SelectInst>())
+ SelectInst(C, S1, S2, Name, InsertAtEnd);
+}
+
//===----------------------------------------------------------------------===//
// VAArgInst Class
//===----------------------------------------------------------------------===//
Modified: llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h?rev=51679&r1=51678&r2=51679&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h Thu May 29 09:04:53 2008
@@ -34,17 +34,22 @@
static unsigned operands(const User*) {
return ARITY;
}
- struct prefix {
- Use Ops[ARITY];
- prefix(); // DO NOT IMPLEMENT
- };
template <class U>
struct Layout {
- struct overlay : prefix, U {
- overlay(); // DO NOT IMPLEMENT
- };
+ Use Ops[ARITY];
+ U It;
+ Layout(); // DO NOT IMPLEMENT
};
- static inline void *allocate(unsigned); // FIXME
+ template <class U>
+ static inline void *alloc() {
+ void *Storage = ::operator new(sizeof(Layout<U>));
+ Layout<U> *Obj = static_cast<Layout<U>*>(Storage);
+ Use *Start = Obj->Ops;
+// Obj->OperandList = Start;
+// Obj->NumOperands = ARITY;
+ Use::initTags(Start, Start + ARITY);
+ return &Obj->It;
+ }
};
//===----------------------------------------------------------------------===//
Modified: llvm/branches/ggreif/use-diet/include/llvm/User.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/User.h?rev=51679&r1=51678&r2=51679&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/User.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/User.h Thu May 29 09:04:53 2008
@@ -227,6 +227,9 @@
///
unsigned NumOperands;
+ void* operator new(size_t, char dummy, void* __p) throw() {
+ return __p;
+ }
void *operator new(size_t s, unsigned Us) {
void *Storage = ::operator new(s + sizeof(Use) * Us);
Use *Start = static_cast<Use*>(Storage);
Modified: llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp?rev=51679&r1=51678&r2=51679&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp (original)
+++ llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp Thu May 29 09:04:53 2008
@@ -2813,7 +2813,8 @@
return new(getNumOperands()) CallInst(*this);
}
SelectInst *SelectInst::clone() const {
- return new(getNumOperands()) SelectInst(*this);
+ return new('A', OperandTraits<SelectInst>::alloc<SelectInst>())
+ SelectInst(*this);
}
VAArgInst *VAArgInst::clone() const { return new VAArgInst(*this); }
More information about the llvm-commits
mailing list