[llvm-commits] [dragonegg] r133908 - in /dragonegg/trunk: include/dragonegg/Internals.h include/dragonegg/Trees.h src/Backend.cpp src/Convert.cpp src/Debug.cpp src/Trees.cpp
Duncan Sands
baldrick at free.fr
Mon Jun 27 06:52:25 PDT 2011
Author: baldrick
Date: Mon Jun 27 08:52:25 2011
New Revision: 133908
URL: http://llvm.org/viewvc/llvm-project?rev=133908&view=rev
Log:
Remove getINTEGER_CSTVal, which was not used much, in favour of getInt64.
This required some changes to the debug info logic, which are hopefully
correct... Move getIntegerValue and friends into Trees.cpp.
Modified:
dragonegg/trunk/include/dragonegg/Internals.h
dragonegg/trunk/include/dragonegg/Trees.h
dragonegg/trunk/src/Backend.cpp
dragonegg/trunk/src/Convert.cpp
dragonegg/trunk/src/Debug.cpp
dragonegg/trunk/src/Trees.cpp
Modified: dragonegg/trunk/include/dragonegg/Internals.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/dragonegg/Internals.h?rev=133908&r1=133907&r2=133908&view=diff
==============================================================================
--- dragonegg/trunk/include/dragonegg/Internals.h (original)
+++ dragonegg/trunk/include/dragonegg/Internals.h Mon Jun 27 08:52:25 2011
@@ -268,25 +268,6 @@
/// INT_MAX if there is no such LLVM field.
int GetFieldIndex(tree_node *decl, const Type *Ty);
-/// getIntegerValue - Return the specified INTEGER_CST as an APInt.
-APInt getIntegerValue(tree_node *exp);
-
-/// getINTEGER_CSTVal - Return the specified INTEGER_CST value as a uint64_t.
-/// TODO: Remove this and use getIntegerValue instead.
-uint64_t getINTEGER_CSTVal(tree_node *exp);
-
-/// isInt64 - Return true if t is an INTEGER_CST that fits in a 64 bit integer.
-/// If Unsigned is false, returns whether it fits in a int64_t. If Unsigned is
-/// true, returns whether the value is non-negative and fits in a uint64_t.
-/// Always returns false for overflowed constants or if t is NULL.
-bool isInt64(tree_node *t, bool Unsigned);
-
-/// getInt64 - Extract the value of an INTEGER_CST as a 64 bit integer. If
-/// Unsigned is false, the value must fit in a int64_t. If Unsigned is true,
-/// the value must be non-negative and fit in a uint64_t. Must not be used on
-/// overflowed constants. These conditions can be checked by calling isInt64.
-uint64_t getInt64(tree_node *t, bool Unsigned);
-
/// isPassedByInvisibleReference - Return true if the specified type should be
/// passed by 'invisible reference'. In other words, instead of passing the
/// thing by value, pass the address of a temporary.
Modified: dragonegg/trunk/include/dragonegg/Trees.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/dragonegg/Trees.h?rev=133908&r1=133907&r2=133908&view=diff
==============================================================================
--- dragonegg/trunk/include/dragonegg/Trees.h (original)
+++ dragonegg/trunk/include/dragonegg/Trees.h Mon Jun 27 08:52:25 2011
@@ -23,6 +23,9 @@
#ifndef DRAGONEGG_TREES_H
#define DRAGONEGG_TREES_H
+// LLVM headers
+#include "llvm/ADT/APInt.h"
+
// System headers
#include <string>
@@ -41,4 +44,19 @@
/// in undefined behaviour.
bool hasNSW(tree_node *type);
+/// getIntegerValue - Return the specified INTEGER_CST as an APInt.
+llvm::APInt getIntegerValue(tree_node *exp);
+
+/// isInt64 - Return true if t is an INTEGER_CST that fits in a 64 bit integer.
+/// If Unsigned is false, returns whether it fits in a int64_t. If Unsigned is
+/// true, returns whether the value is non-negative and fits in a uint64_t.
+/// Always returns false for overflowed constants or if t is NULL.
+bool isInt64(tree_node *t, bool Unsigned);
+
+/// getInt64 - Extract the value of an INTEGER_CST as a 64 bit integer. If
+/// Unsigned is false, the value must fit in a int64_t. If Unsigned is true,
+/// the value must be non-negative and fit in a uint64_t. Must not be used on
+/// overflowed constants. These conditions can be checked by calling isInt64.
+uint64_t getInt64(tree_node *t, bool Unsigned);
+
#endif /* DRAGONEGG_TREES_H */
Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=133908&r1=133907&r2=133908&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Mon Jun 27 08:52:25 2011
@@ -29,6 +29,7 @@
#include "dragonegg/Debug.h"
#include "dragonegg/OS.h"
#include "dragonegg/Target.h"
+#include "dragonegg/Trees.h"
// LLVM headers
#define DEBUG_TYPE "plugin"
Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=133908&r1=133907&r2=133908&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Mon Jun 27 08:52:25 2011
@@ -80,64 +80,6 @@
STATISTIC(NumBasicBlocks, "Number of basic blocks converted");
STATISTIC(NumStatements, "Number of gimple statements converted");
-/// getIntegerValue - Return the specified INTEGER_CST as an APInt.
-APInt getIntegerValue(tree exp) {
- double_int val = tree_to_double_int(exp);
- unsigned NumBits = TYPE_PRECISION(TREE_TYPE(exp));
-
- if (integerPartWidth == HOST_BITS_PER_WIDE_INT)
- return APInt(NumBits, /*numWords*/2, (integerPart*)&val);
- assert(integerPartWidth == 2 * HOST_BITS_PER_WIDE_INT &&
- "Unsupported host integer width!");
- unsigned ShiftAmt = HOST_BITS_PER_WIDE_INT;
- integerPart Part = integerPart(val.low) + (integerPart(val.high) << ShiftAmt);
- return APInt(NumBits, Part);
-}
-
-/// getINTEGER_CSTVal - Return the specified INTEGER_CST value as a uint64_t.
-///
-uint64_t getINTEGER_CSTVal(tree exp) {
- unsigned HOST_WIDE_INT LO = (unsigned HOST_WIDE_INT)TREE_INT_CST_LOW(exp);
- if (HOST_BITS_PER_WIDE_INT == 64) {
- return (uint64_t)LO;
- } else {
- assert(HOST_BITS_PER_WIDE_INT == 32 &&
- "Only 32- and 64-bit hosts supported!");
- unsigned HOST_WIDE_INT HI = (unsigned HOST_WIDE_INT)TREE_INT_CST_HIGH(exp);
- return ((uint64_t)HI << 32) | (uint64_t)LO;
- }
-}
-
-/// isInt64 - Return true if t is an INTEGER_CST that fits in a 64 bit integer.
-/// If Unsigned is false, returns whether it fits in a int64_t. If Unsigned is
-/// true, returns whether the value is non-negative and fits in a uint64_t.
-/// Always returns false for overflowed constants.
-bool isInt64(tree t, bool Unsigned) {
- if (!t)
- return false;
- if (HOST_BITS_PER_WIDE_INT == 64)
- return host_integerp(t, Unsigned) && !TREE_OVERFLOW (t);
- assert(HOST_BITS_PER_WIDE_INT == 32 &&
- "Only 32- and 64-bit hosts supported!");
- return
- (TREE_CODE (t) == INTEGER_CST && !TREE_OVERFLOW (t))
- && ((TYPE_UNSIGNED(TREE_TYPE(t)) == Unsigned) ||
- // If the constant is signed and we want an unsigned result, check
- // that the value is non-negative. If the constant is unsigned and
- // we want a signed result, check it fits in 63 bits.
- (HOST_WIDE_INT)TREE_INT_CST_HIGH(t) >= 0);
-}
-
-/// getInt64 - Extract the value of an INTEGER_CST as a 64 bit integer. If
-/// Unsigned is false, the value must fit in a int64_t. If Unsigned is true,
-/// the value must be non-negative and fit in a uint64_t. Must not be used on
-/// overflowed constants. These conditions can be checked by calling isInt64.
-uint64_t getInt64(tree t, bool Unsigned) {
- assert(isInt64(t, Unsigned) && "invalid constant!");
- (void)Unsigned; // Otherwise unused if asserts off - avoid compiler warning.
- return getINTEGER_CSTVal(t);
-}
-
/// getPointerAlignment - Return the alignment in bytes of exp, a pointer valued
/// expression, or 1 if the alignment is not known.
static unsigned int getPointerAlignment(tree exp) {
Modified: dragonegg/trunk/src/Debug.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Debug.cpp?rev=133908&r1=133907&r2=133908&view=diff
==============================================================================
--- dragonegg/trunk/src/Debug.cpp (original)
+++ dragonegg/trunk/src/Debug.cpp Mon Jun 27 08:52:25 2011
@@ -23,6 +23,7 @@
// Plugin headers
#include "dragonegg/Debug.h"
+#include "dragonegg/Trees.h"
// LLVM headers
#include "llvm/Module.h"
@@ -89,15 +90,15 @@
} else if (TYPE_P(Node)) {
if (TYPE_SIZE(Node) == NULL_TREE)
return 0;
- else if (isInt64(TYPE_SIZE(Node), 1))
- return getINTEGER_CSTVal(TYPE_SIZE(Node));
+ else if (isInt64(TYPE_SIZE(Node), true))
+ return getInt64(TYPE_SIZE(Node), true);
else
return TYPE_ALIGN(Node);
} else if (DECL_P(Node)) {
if (DECL_SIZE(Node) == NULL_TREE)
return 0;
else if (isInt64(DECL_SIZE(Node), 1))
- return getINTEGER_CSTVal(DECL_SIZE(Node));
+ return getInt64(DECL_SIZE(Node), 1);
else
return DECL_ALIGN(Node);
}
@@ -635,12 +636,12 @@
// FIXME - handle dynamic ranges
tree MinValue = TYPE_MIN_VALUE(Domain);
tree MaxValue = TYPE_MAX_VALUE(Domain);
- uint64_t Low = 0;
- uint64_t Hi = 0;
+ int64_t Low = 0;
+ int64_t Hi = 0;
if (isInt64(MinValue, false))
- Low = getINTEGER_CSTVal(MinValue);
+ Low = getInt64(MinValue, false);
if (isInt64(MaxValue, false))
- Hi = getINTEGER_CSTVal(MaxValue);
+ Hi = getInt64(MaxValue, false);
Subscripts.push_back(DebugFactory.GetOrCreateSubrange(Low, Hi));
}
EltTy = TREE_TYPE(atype);
@@ -674,7 +675,7 @@
tree EnumValue = TREE_VALUE(Link);
if (TREE_CODE(EnumValue) == CONST_DECL)
EnumValue = DECL_INITIAL(EnumValue);
- int64_t Value = getINTEGER_CSTVal(EnumValue);
+ int64_t Value = getInt64(EnumValue, false);
const char *EnumName = IDENTIFIER_POINTER(TREE_PURPOSE(Link));
Elements.push_back(DebugFactory.CreateEnumerator(EnumName, Value));
}
@@ -793,10 +794,10 @@
// Check for zero BINFO_OFFSET.
// FIXME : Is this correct ?
unsigned Offset = BINFO_OFFSET(BInfo) ?
- getINTEGER_CSTVal(BINFO_OFFSET(BInfo))*8 : 0;
+ getInt64(BINFO_OFFSET(BInfo), true)*8 : 0;
if (BINFO_VIRTUAL_P (BInfo))
- Offset = 0 - getINTEGER_CSTVal(BINFO_VPTR_FIELD (BInfo));
+ Offset = 0 - getInt64(BINFO_VPTR_FIELD (BInfo), false);
// FIXME : name, size, align etc...
DIType DTy =
DebugFactory.CreateDerivedType(DW_TAG_inheritance,
Modified: dragonegg/trunk/src/Trees.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Trees.cpp?rev=133908&r1=133907&r2=133908&view=diff
==============================================================================
--- dragonegg/trunk/src/Trees.cpp (original)
+++ dragonegg/trunk/src/Trees.cpp Mon Jun 27 08:52:25 2011
@@ -141,3 +141,55 @@
bool hasNSW(tree type) {
return !TYPE_UNSIGNED(type) && !TYPE_OVERFLOW_WRAPS(type);
}
+
+/// getIntegerValue - Return the specified INTEGER_CST as an APInt.
+APInt getIntegerValue(tree exp) {
+ double_int val = tree_to_double_int(exp);
+ unsigned NumBits = TYPE_PRECISION(TREE_TYPE(exp));
+
+ if (integerPartWidth == HOST_BITS_PER_WIDE_INT)
+ return APInt(NumBits, /*numWords*/2, (integerPart*)&val);
+ assert(integerPartWidth == 2 * HOST_BITS_PER_WIDE_INT &&
+ "Unsupported host integer width!");
+ unsigned ShiftAmt = HOST_BITS_PER_WIDE_INT;
+ integerPart Part = integerPart(val.low) + (integerPart(val.high) << ShiftAmt);
+ return APInt(NumBits, Part);
+}
+
+/// isInt64 - Return true if t is an INTEGER_CST that fits in a 64 bit integer.
+/// If Unsigned is false, returns whether it fits in a int64_t. If Unsigned is
+/// true, returns whether the value is non-negative and fits in a uint64_t.
+/// Always returns false for overflowed constants.
+bool isInt64(tree t, bool Unsigned) {
+ if (!t)
+ return false;
+ if (HOST_BITS_PER_WIDE_INT == 64)
+ return host_integerp(t, Unsigned) && !TREE_OVERFLOW (t);
+ assert(HOST_BITS_PER_WIDE_INT == 32 &&
+ "Only 32- and 64-bit hosts supported!");
+ return
+ (TREE_CODE (t) == INTEGER_CST && !TREE_OVERFLOW (t))
+ && ((TYPE_UNSIGNED(TREE_TYPE(t)) == Unsigned) ||
+ // If the constant is signed and we want an unsigned result, check
+ // that the value is non-negative. If the constant is unsigned and
+ // we want a signed result, check it fits in 63 bits.
+ (HOST_WIDE_INT)TREE_INT_CST_HIGH(t) >= 0);
+}
+
+/// getInt64 - Extract the value of an INTEGER_CST as a 64 bit integer. If
+/// Unsigned is false, the value must fit in a int64_t. If Unsigned is true,
+/// the value must be non-negative and fit in a uint64_t. Must not be used on
+/// overflowed constants. These conditions can be checked by calling isInt64.
+uint64_t getInt64(tree t, bool Unsigned) {
+ assert(isInt64(t, Unsigned) && "invalid constant!");
+ (void)Unsigned; // Otherwise unused if asserts off - avoid compiler warning.
+ unsigned HOST_WIDE_INT LO = (unsigned HOST_WIDE_INT)TREE_INT_CST_LOW(t);
+ if (HOST_BITS_PER_WIDE_INT == 64) {
+ return (uint64_t)LO;
+ } else {
+ assert(HOST_BITS_PER_WIDE_INT == 32 &&
+ "Only 32- and 64-bit hosts supported!");
+ unsigned HOST_WIDE_INT HI = (unsigned HOST_WIDE_INT)TREE_INT_CST_HIGH(t);
+ return ((uint64_t)HI << 32) | (uint64_t)LO;
+ }
+}
More information about the llvm-commits
mailing list