[llvm-commits] [llvm] r49487 - in /llvm/branches/ggreif/use-diet: include/llvm/GlobalVariable.h include/llvm/Instructions.h include/llvm/OperandTraits.h lib/VMCore/Globals.cpp
Gabor Greif
ggreif at gmail.com
Thu Apr 10 09:15:39 PDT 2008
Author: ggreif
Date: Thu Apr 10 11:15:39 2008
New Revision: 49487
URL: http://llvm.org/viewvc/llvm-project?rev=49487&view=rev
Log:
factor out VariadicOperandTraits to a header, use traits for GlobalVariable
Added:
llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h
Modified:
llvm/branches/ggreif/use-diet/include/llvm/GlobalVariable.h
llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
llvm/branches/ggreif/use-diet/lib/VMCore/Globals.cpp
Modified: llvm/branches/ggreif/use-diet/include/llvm/GlobalVariable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/GlobalVariable.h?rev=49487&r1=49486&r2=49487&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/GlobalVariable.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/GlobalVariable.h Thu Apr 10 11:15:39 2008
@@ -21,6 +21,7 @@
#define LLVM_GLOBAL_VARIABLE_H
#include "llvm/GlobalValue.h"
+#include "llvm/OperandTraits.h"
namespace llvm {
@@ -78,6 +79,9 @@
ThreadLocal, AddressSpace);
}
+ /// Provide fast operand accessors
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
/// isDeclaration - Is this global variable lacking an initializer? If so,
/// the global variable is defined in some other translation unit, and is thus
/// only a declaration here.
@@ -155,6 +159,12 @@
const GlobalVariable *getPrev() const { return Prev; }
};
+template <>
+struct OperandTraits<GlobalVariable> : VariadicOperandTraits<> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalVariable, Value)
+
} // End llvm namespace
#endif
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=49487&r1=49486&r2=49487&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/Instructions.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/Instructions.h Thu Apr 10 11:15:39 2008
@@ -21,6 +21,7 @@
#include "llvm/InstrTypes.h"
#include "llvm/DerivedTypes.h"
#include "llvm/ParameterAttributes.h"
+#include "llvm/OperandTraits.h"
namespace llvm {
@@ -364,24 +365,6 @@
//===----------------------------------------------------------------------===//
-// VariadicOperand Trait Class
-//===----------------------------------------------------------------------===//
-
-template <unsigned MINARITY = 0>
-struct VariadicOperandTraits {
- static Use *op_begin(User* U) {
- return reinterpret_cast<Use*>(U) - U->getNumOperands();
- }
- static Use *op_end(User* U) {
- return reinterpret_cast<Use*>(U);
- }
- static unsigned operands(const User*U) {
- return U->getNumOperands();
- }
- static inline void *allocate(unsigned); // FIXME
-};
-
-//===----------------------------------------------------------------------===//
// GetElementPtrInst Class
//===----------------------------------------------------------------------===//
Added: 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=49487&view=auto
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h (added)
+++ llvm/branches/ggreif/use-diet/include/llvm/OperandTraits.h Thu Apr 10 11:15:39 2008
@@ -0,0 +1,67 @@
+//===-- llvm/OperandTraits.h - OperandTraits class definition ---------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the FIXME.
+//
+
+#ifndef LLVM_OPERAND_TRAITS_H
+#define LLVM_OPERAND_TRAITS_H
+
+#include "llvm/User.h"
+
+namespace llvm {
+
+//===----------------------------------------------------------------------===//
+// VariadicOperand Trait Class
+//===----------------------------------------------------------------------===//
+
+template <unsigned MINARITY = 0>
+struct VariadicOperandTraits {
+ static Use *op_begin(User* U) {
+ return reinterpret_cast<Use*>(U) - U->getNumOperands();
+ }
+ static Use *op_end(User* U) {
+ return reinterpret_cast<Use*>(U);
+ }
+ static unsigned operands(const User *U) {
+ return U->getNumOperands();
+ }
+ static inline void *allocate(unsigned); // FIXME
+};
+
+/// Macro for generating in-class operand accessor declarations
+#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS) \
+ inline VALUECLASS *getOperand(unsigned) const; \
+ inline void setOperand(unsigned, VALUECLASS*); \
+ inline unsigned getNumOperands() const; \
+ template <unsigned Idx> inline Use &Op(); \
+ template <unsigned Idx> inline const Use &Op() const
+
+/// Macro for generating out-of-class operand accessor definitions
+#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS) \
+VALUECLASS *CLASS::getOperand(unsigned i) const { \
+ assert(i < OperandTraits<CLASS>::operands(this) && "getOperand() out of range!"); \
+ return OperandTraits<CLASS>::op_begin(const_cast<CLASS*>(this))[i]; \
+} \
+void CLASS::setOperand(unsigned i, VALUECLASS *Val) { \
+ assert(i < OperandTraits<CLASS>::operands(this) && "setOperand() out of range!"); \
+ OperandTraits<CLASS>::op_begin(this)[i] = Val; \
+} \
+unsigned CLASS::getNumOperands() const { return OperandTraits<CLASS>::operands(this); } \
+template <unsigned Idx> Use &CLASS::Op() { \
+ return OperandTraits<CLASS>::op_begin(this)[Idx]; \
+} \
+template <unsigned Idx> const Use &CLASS::Op() const { \
+ return OperandTraits<CLASS>::op_begin(const_cast<CLASS*>(this))[Idx]; \
+}
+
+
+} // End llvm namespace
+
+#endif
Modified: llvm/branches/ggreif/use-diet/lib/VMCore/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/VMCore/Globals.cpp?rev=49487&r1=49486&r2=49487&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/lib/VMCore/Globals.cpp (original)
+++ llvm/branches/ggreif/use-diet/lib/VMCore/Globals.cpp Thu Apr 10 11:15:39 2008
@@ -89,14 +89,13 @@
Module *ParentModule, bool ThreadLocal,
unsigned AddressSpace)
: GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
- &Op<0>(), InitVal != 0, Link, Name),
+ OperandTraits<GlobalVariable>::op_end(this) - (InitVal != 0),
+ InitVal != 0, Link, Name),
isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
if (InitVal) {
assert(InitVal->getType() == Ty &&
"Initializer should be the same type as the GlobalVariable!");
Op<0>().init(InitVal, this);
- } else {
- Op<0>().init(0, this); // FIXME: if no InitVal, then none!
}
LeakDetector::addGarbageObject(this);
@@ -110,14 +109,13 @@
GlobalVariable *Before, bool ThreadLocal,
unsigned AddressSpace)
: GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
- &Op<0>(), InitVal != 0, Link, Name),
+ OperandTraits<GlobalVariable>::op_end(this) - (InitVal != 0),
+ InitVal != 0, Link, Name),
isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
if (InitVal) {
assert(InitVal->getType() == Ty &&
"Initializer should be the same type as the GlobalVariable!");
Op<0>().init(InitVal, this);
- } else {
- Op<0>().init(0, this); // FIXME: if no InitVal, then none!
}
LeakDetector::addGarbageObject(this);
More information about the llvm-commits
mailing list