[llvm-commits] CVS: llvm-gcc/gcc/tree.c tree.h
Chris Lattner
lattner at cs.uiuc.edu
Mon Feb 14 13:24:37 PST 2005
Changes in directory llvm-gcc/gcc:
tree.c updated: 1.5 -> 1.6
tree.h updated: 1.3 -> 1.4
---
Log message:
Modify staticp to return the static decl if true instead of just a flag.
Be more generous about what is a constant, including p[x], where p is a
pointer (this is an llvm extension to the GCC IR).
---
Diffs of the changes: (+47 -27)
tree.c | 70 +++++++++++++++++++++++++++++++++++++++++------------------------
tree.h | 4 +--
2 files changed, 47 insertions(+), 27 deletions(-)
Index: llvm-gcc/gcc/tree.c
diff -u llvm-gcc/gcc/tree.c:1.5 llvm-gcc/gcc/tree.c:1.6
--- llvm-gcc/gcc/tree.c:1.5 Sun Feb 13 21:20:33 2005
+++ llvm-gcc/gcc/tree.c Mon Feb 14 15:23:54 2005
@@ -1270,10 +1270,11 @@
: fold (build (MINUS_EXPR, TREE_TYPE (max), max, min)));
}
-/* Return nonzero if arg is static -- a reference to an object in
- static storage. This is not the same as the C meaning of `static'. */
+/* If arg is static -- a reference to an object in static storage -- then
+ return the object. This is not the same as the C meaning of `static'.
+ If arg isn't static, return NULL. */
-int
+tree
staticp (tree arg)
{
switch (TREE_CODE (arg))
@@ -1281,56 +1282,75 @@
case FUNCTION_DECL:
/* Nested functions aren't static, since taking their address
involves a trampoline. */
- return ((decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg))
- && ! DECL_NON_ADDR_CONST_P (arg));
+ if ((decl_function_context (arg) == 0 || DECL_NO_STATIC_CHAIN (arg))
+ && ! DECL_NON_ADDR_CONST_P (arg))
+ return arg;
+ return NULL;
case VAR_DECL:
return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
&& ! DECL_THREAD_LOCAL (arg)
- && ! DECL_NON_ADDR_CONST_P (arg));
+ && ! DECL_NON_ADDR_CONST_P (arg))
+ ? arg : NULL;
+
+ case CONST_DECL:
+ return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
+ ? arg : NULL);
case CONSTRUCTOR:
- return TREE_STATIC (arg);
+ return TREE_STATIC (arg) ? arg : NULL;
case LABEL_DECL:
case STRING_CST:
- return 1;
+ return arg;
- /* If we are referencing a bitfield, we can't evaluate an
- ADDR_EXPR at compile time and so it isn't a constant. */
case COMPONENT_REF:
- return (! DECL_BIT_FIELD (TREE_OPERAND (arg, 1))
- && staticp (TREE_OPERAND (arg, 0)));
+ /* If the thing being referenced is not a field, then it is
+ something language specific. */
+ if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
+ return (*lang_hooks.staticp) (arg);
- case BIT_FIELD_REF:
- return 0;
+ /* If we are referencing a bitfield, we can't evaluate an
+ ADDR_EXPR at compile time and so it isn't a constant. */
+ if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
+ return NULL;
+ return staticp (TREE_OPERAND (arg, 0));
- case INDIRECT_REF:
- return TREE_CONSTANT (TREE_OPERAND (arg, 0));
+ case BIT_FIELD_REF:
+ return NULL;
-#if 0
- /* This case is technically correct, but results in setting
- TREE_CONSTANT on ADDR_EXPRs that cannot be evaluated at
- compile time. */
case INDIRECT_REF:
- return TREE_CONSTANT (TREE_OPERAND (arg, 0));
-#endif
+ return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
case ARRAY_REF:
case ARRAY_RANGE_REF:
if (TYPE_SIZE (TREE_TYPE (arg))
&& TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
- && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
- return staticp (TREE_OPERAND (arg, 0));
+ && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST) {
+
+ /* As an LLVM extension, we support ARRAY_REF where the first operand is
+ * a pointer type (and ADDR_EXPR). Strip it off the addr_expr if it
+ * exists.
+ */
+ if (TREE_CODE(TREE_OPERAND(arg, 0)) == ADDR_EXPR)
+ return staticp (TREE_OPERAND (TREE_OPERAND(arg, 0), 0));
+ else if (TREE_CODE(TREE_OPERAND(arg, 0)) == NOP_EXPR &&
+ TREE_CODE(TREE_OPERAND(TREE_OPERAND(arg, 0), 0)) == ADDR_EXPR)
+ return staticp (TREE_OPERAND (TREE_OPERAND(TREE_OPERAND(arg,
+ 0), 0),0));
+ else
+ return staticp (TREE_OPERAND (arg, 0));
+ }
+ return NULL;
default:
if ((unsigned int) TREE_CODE (arg)
>= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
return (*lang_hooks.staticp) (arg);
else
- return 0;
+ return NULL;
}
}
Index: llvm-gcc/gcc/tree.h
diff -u llvm-gcc/gcc/tree.h:1.3 llvm-gcc/gcc/tree.h:1.4
--- llvm-gcc/gcc/tree.h:1.3 Thu Feb 5 10:05:45 2004
+++ llvm-gcc/gcc/tree.h Mon Feb 14 15:23:54 2005
@@ -2547,9 +2547,9 @@
extern int integer_nonzerop (tree);
/* staticp (tree x) is nonzero if X is a reference to data allocated
- at a fixed address in memory. */
+ at a fixed address in memory. Returns the outermost data. */
-extern int staticp (tree);
+extern tree staticp (tree);
/* Gets an error if argument X is not an lvalue.
Also returns 1 if X is an lvalue, 0 if not. */
More information about the llvm-commits
mailing list