exec_list &actual_ir_parameters,
exec_list &actual_ast_parameters)
{
- exec_node *actual_ir_node = actual_ir_parameters.head;
- exec_node *actual_ast_node = actual_ast_parameters.head;
+ exec_node *actual_ir_node = actual_ir_parameters.get_head_raw();
+ exec_node *actual_ast_node = actual_ast_parameters.get_head_raw();
foreach_in_list(const ir_variable, formal, &sig->parameters) {
/* The lists must be the same length. */
const char *func_name = sig->function_name();
bool is_atomic = is_atomic_function(func_name);
if (is_atomic) {
- const ir_rvalue *const actual = (ir_rvalue *) actual_ir_parameters.head;
+ const ir_rvalue *const actual =
+ (ir_rvalue *) actual_ir_parameters.get_head_raw();
const ast_expression *const actual_ast =
- exec_node_data(ast_expression, actual_ast_parameters.head, link);
+ exec_node_data(ast_expression,
+ actual_ast_parameters.get_head_raw(), link);
YYLTYPE loc = actual_ast->get_location();
if (!verify_first_atomic_parameter(&loc, state,
bool
single_scalar_parameter(exec_list *parameters)
{
- const ir_rvalue *const p = (ir_rvalue *) parameters->head;
+ const ir_rvalue *const p = (ir_rvalue *) parameters->get_head_raw();
assert(((ir_rvalue *)p)->as_rvalue() != NULL);
return (p->type->is_scalar() && p->next->is_tail_sentinel());
*/
const unsigned lhs_components = type->components();
if (single_scalar_parameter(parameters)) {
- ir_rvalue *first_param = (ir_rvalue *)parameters->head;
+ ir_rvalue *first_param = (ir_rvalue *)parameters->get_head_raw();
ir_rvalue *rhs = new(ctx) ir_swizzle(first_param, 0, 0, 0, 0,
lhs_components);
ir_dereference_variable *lhs = new(ctx) ir_dereference_variable(var);
* to the upper left portion of the constructed matrix, and the remaining
* elements take values from the identity matrix.
*/
- ir_rvalue *const first_param = (ir_rvalue *) parameters->head;
+ ir_rvalue *const first_param = (ir_rvalue *) parameters->get_head_raw();
if (single_scalar_parameter(parameters)) {
/* Assign the scalar to the X component of a vec4, and fill the remaining
* components with zero.
instructions->push_tail(var);
- exec_node *node = parameters->head;
+ exec_node *node = parameters->get_head_raw();
for (unsigned i = 0; i < type->length; i++) {
assert(!node->is_tail_sentinel());
process_parameters(instructions, &actual_parameters,
parameters, state);
- exec_node *node = actual_parameters.head;
+ exec_node *node = actual_parameters.get_head_raw();
for (unsigned i = 0; i < constructor_type->length; i++) {
ir_rvalue *ir = (ir_rvalue *) node;
if (all_parameters_are_constant) {
return new(ctx) ir_constant(constructor_type, &actual_parameters);
} else if (constructor_type->is_scalar()) {
- return dereference_component((ir_rvalue *) actual_parameters.head,
+ return dereference_component((ir_rvalue *) actual_parameters.get_head_raw(),
0);
} else if (constructor_type->is_vector()) {
return emit_inline_vector_constructor(constructor_type,
*
* A list is empty if either the head sentinel's \c next pointer points to the
* tail sentinel or the tail sentinel's \c prev poiner points to the head
- * sentinel.
- *
- * Instead of tracking two separate \c node structures and a \c list structure
- * that points to them, the sentinel nodes are in a single structure. Noting
- * that each sentinel node always has one \c NULL pointer, the \c NULL
- * pointers occupy the same memory location. In the \c list structure
- * contains a the following:
- *
- * - A \c head pointer that represents the \c next pointer of the
- * head sentinel node.
- * - A \c tail pointer that represents the \c prev pointer of the head
- * sentinel node and the \c next pointer of the tail sentinel node. This
- * pointer is \b always \c NULL.
- * - A \c tail_prev pointer that represents the \c prev pointer of the
- * tail sentinel node.
- *
- * Therefore, if \c head->next is \c NULL or \c tail_prev->prev is \c NULL,
- * the list is empty.
+ * sentinel. The head sentinel and tail sentinel nodes are allocated within the
+ * list structure.
*
* Do note that this means that the list nodes will contain pointers into the
* list structure itself and as a result you may not \c realloc() an \c
* exec_list or any structure in which an \c exec_list is embedded.
- *
- * To anyone familiar with "exec lists" on the Amiga, this structure should
- * be immediately recognizable. See the following link for the original Amiga
- * operating system documentation on the subject.
- *
- * http://www.natami.net/dev/Libraries_Manual_guide/node02D7.html
- *
- * \author Ian Romanick <ian.d.romanick@intel.com>
*/
#pragma once
#endif
struct exec_list {
- struct exec_node *head;
- struct exec_node *tail;
- struct exec_node *tail_pred;
+ struct exec_node head_sentinel;
+ struct exec_node tail_sentinel;
#ifdef __cplusplus
DECLARE_RALLOC_CXX_OPERATORS(exec_list)
const exec_node *get_head() const;
exec_node *get_head();
+ const exec_node *get_head_raw() const;
+ exec_node *get_head_raw();
const exec_node *get_tail() const;
exec_node *get_tail();
+ const exec_node *get_tail_raw() const;
+ exec_node *get_tail_raw();
unsigned length() const;
static inline void
exec_list_make_empty(struct exec_list *list)
{
- list->head = (struct exec_node *) & list->tail;
- list->tail = NULL;
- list->tail_pred = (struct exec_node *) & list->head;
+ list->head_sentinel.next = &list->tail_sentinel;
+ list->head_sentinel.prev = NULL;
+ list->tail_sentinel.next = NULL;
+ list->tail_sentinel.prev = &list->head_sentinel;
}
static inline bool
{
/* There are three ways to test whether a list is empty or not.
*
- * - Check to see if the \c head points to the \c tail.
- * - Check to see if the \c tail_pred points to the \c head.
- * - Check to see if the \c head is the sentinel node by test whether its
+ * - Check to see if the head sentinel's \c next is the tail sentinel.
+ * - Check to see if the tail sentinel's \c prev is the head sentinel.
+ * - Check to see if the head is the sentinel node by test whether its
* \c next pointer is \c NULL.
*
* The first two methods tend to generate better code on modern systems
* because they save a pointer dereference.
*/
- return list->head == (struct exec_node *) &list->tail;
+ return list->head_sentinel.next == &list->tail_sentinel;
}
static inline const struct exec_node *
exec_list_get_head_const(const struct exec_list *list)
{
- return !exec_list_is_empty(list) ? list->head : NULL;
+ return !exec_list_is_empty(list) ? list->head_sentinel.next : NULL;
}
static inline struct exec_node *
exec_list_get_head(struct exec_list *list)
{
- return !exec_list_is_empty(list) ? list->head : NULL;
+ return !exec_list_is_empty(list) ? list->head_sentinel.next : NULL;
+}
+
+static inline const struct exec_node *
+exec_list_get_head_raw_const(const struct exec_list *list)
+{
+ return list->head_sentinel.next;
+}
+
+static inline struct exec_node *
+exec_list_get_head_raw(struct exec_list *list)
+{
+ return list->head_sentinel.next;
}
static inline const struct exec_node *
exec_list_get_tail_const(const struct exec_list *list)
{
- return !exec_list_is_empty(list) ? list->tail_pred : NULL;
+ return !exec_list_is_empty(list) ? list->tail_sentinel.prev : NULL;
}
static inline struct exec_node *
exec_list_get_tail(struct exec_list *list)
{
- return !exec_list_is_empty(list) ? list->tail_pred : NULL;
+ return !exec_list_is_empty(list) ? list->tail_sentinel.prev : NULL;
+}
+
+static inline const struct exec_node *
+exec_list_get_tail_raw_const(const struct exec_list *list)
+{
+ return list->tail_sentinel.prev;
+}
+
+static inline struct exec_node *
+exec_list_get_tail_raw(struct exec_list *list)
+{
+ return list->tail_sentinel.prev;
}
static inline unsigned
unsigned size = 0;
struct exec_node *node;
- for (node = list->head; node->next != NULL; node = node->next) {
+ for (node = list->head_sentinel.next; node->next != NULL; node = node->next) {
size++;
}
static inline void
exec_list_push_head(struct exec_list *list, struct exec_node *n)
{
- n->next = list->head;
- n->prev = (struct exec_node *) &list->head;
+ n->next = list->head_sentinel.next;
+ n->prev = &list->head_sentinel;
n->next->prev = n;
- list->head = n;
+ list->head_sentinel.next = n;
}
static inline void
exec_list_push_tail(struct exec_list *list, struct exec_node *n)
{
- n->next = (struct exec_node *) &list->tail;
- n->prev = list->tail_pred;
+ n->next = &list->tail_sentinel;
+ n->prev = list->tail_sentinel.prev;
n->prev->next = n;
- list->tail_pred = n;
+ list->tail_sentinel.prev = n;
}
static inline void
{
assert(n->prev->next == n);
- n->prev->next = list->head;
- list->head->prev = n->prev;
- n->prev = (struct exec_node *) &list->head;
- list->head = n;
+ n->prev->next = list->head_sentinel.next;
+ list->head_sentinel.next->prev = n->prev;
+ n->prev = &list->head_sentinel;
+ list->head_sentinel.next = n;
}
static inline struct exec_node *
if (exec_list_is_empty(list)) {
exec_list_make_empty(target);
} else {
- target->head = list->head;
- target->tail = NULL;
- target->tail_pred = list->tail_pred;
+ target->head_sentinel.next = list->head_sentinel.next;
+ target->head_sentinel.prev = NULL;
+ target->tail_sentinel.next = NULL;
+ target->tail_sentinel.prev = list->tail_sentinel.prev;
- target->head->prev = (struct exec_node *) &target->head;
- target->tail_pred->next = (struct exec_node *) &target->tail;
+ target->head_sentinel.next->prev = &target->head_sentinel;
+ target->tail_sentinel.prev->next = &target->tail_sentinel;
exec_list_make_empty(list);
}
/* Link the first node of the source with the last node of the target list.
*/
- list->tail_pred->next = source->head;
- source->head->prev = list->tail_pred;
+ list->tail_sentinel.prev->next = source->head_sentinel.next;
+ source->head_sentinel.next->prev = list->tail_sentinel.prev;
/* Make the tail of the source list be the tail of the target list.
*/
- list->tail_pred = source->tail_pred;
- list->tail_pred->next = (struct exec_node *) &list->tail;
+ list->tail_sentinel.prev = source->tail_sentinel.prev;
+ list->tail_sentinel.prev->next = &list->tail_sentinel;
/* Make the source list empty for good measure.
*/
if (exec_list_is_empty(before))
return;
- before->tail_pred->next = n;
- before->head->prev = n->prev;
+ before->tail_sentinel.prev->next = n;
+ before->head_sentinel.next->prev = n->prev;
- n->prev->next = before->head;
- n->prev = before->tail_pred;
+ n->prev->next = before->head_sentinel.next;
+ n->prev = before->tail_sentinel.prev;
exec_list_make_empty(before);
}
{
const struct exec_node *node;
- assert(list->head->prev == (const struct exec_node *) &list->head);
- assert(list->tail == NULL);
- assert(list->tail_pred->next == (const struct exec_node *) &list->tail);
+ assert(list->head_sentinel.next->prev == &list->head_sentinel);
+ assert(list->head_sentinel.prev == NULL);
+ assert(list->tail_sentinel.next == NULL);
+ assert(list->tail_sentinel.prev->next == &list->tail_sentinel);
/* We could try to use one of the interators below for this but they all
* either require C++ or assume the exec_node is embedded in a structure
* which is not the case for this function.
*/
- for (node = list->head; node->next != NULL; node = node->next) {
+ for (node = list->head_sentinel.next; node->next != NULL; node = node->next) {
assert(node->next->prev == node);
assert(node->prev->next == node);
}
return exec_list_get_head(this);
}
+inline const exec_node *exec_list::get_head_raw() const
+{
+ return exec_list_get_head_raw_const(this);
+}
+
+inline exec_node *exec_list::get_head_raw()
+{
+ return exec_list_get_head_raw(this);
+}
+
inline const exec_node *exec_list::get_tail() const
{
return exec_list_get_tail_const(this);
return exec_list_get_tail(this);
}
+inline const exec_node *exec_list::get_tail_raw() const
+{
+ return exec_list_get_tail_raw_const(this);
+}
+
+inline exec_node *exec_list::get_tail_raw()
+{
+ return exec_list_get_tail_raw(this);
+}
+
inline unsigned exec_list::length() const
{
return exec_list_length(this);
#endif
#define foreach_in_list(__type, __inst, __list) \
- for (__type *(__inst) = (__type *)(__list)->head; \
+ for (__type *(__inst) = (__type *)(__list)->head_sentinel.next; \
!(__inst)->is_tail_sentinel(); \
(__inst) = (__type *)(__inst)->next)
#define foreach_in_list_reverse(__type, __inst, __list) \
- for (__type *(__inst) = (__type *)(__list)->tail_pred; \
+ for (__type *(__inst) = (__type *)(__list)->tail_sentinel.prev; \
!(__inst)->is_head_sentinel(); \
(__inst) = (__type *)(__inst)->prev)
* This version is safe even if the current node is removed.
*/
#define foreach_in_list_safe(__type, __node, __list) \
- for (__type *__node = (__type *)(__list)->head, \
+ for (__type *__node = (__type *)(__list)->head_sentinel.next, \
*__next = (__type *)__node->next; \
__next != NULL; \
__node = __next, __next = (__type *)__next->next)
#define foreach_in_list_reverse_safe(__type, __node, __list) \
- for (__type *__node = (__type *)(__list)->tail_pred, \
+ for (__type *__node = (__type *)(__list)->tail_sentinel.prev, \
*__prev = (__type *)__node->prev; \
__prev != NULL; \
__node = __prev, __prev = (__type *)__prev->prev)
#define foreach_in_list_use_after(__type, __inst, __list) \
__type *(__inst); \
- for ((__inst) = (__type *)(__list)->head; \
+ for ((__inst) = (__type *)(__list)->head_sentinel.next; \
!(__inst)->is_tail_sentinel(); \
(__inst) = (__type *)(__inst)->next)
/**
* This is safe against either current node being removed or replaced.
*/
#define foreach_two_lists(__node1, __list1, __node2, __list2) \
- for (struct exec_node * __node1 = (__list1)->head, \
- * __node2 = (__list2)->head, \
+ for (struct exec_node * __node1 = (__list1)->head_sentinel.next, \
+ * __node2 = (__list2)->head_sentinel.next, \
* __next1 = __node1->next, \
* __next2 = __node2->next \
; __next1 != NULL && __next2 != NULL \
#define foreach_list_typed(__type, __node, __field, __list) \
for (__type * __node = \
- exec_node_data(__type, (__list)->head, __field); \
+ exec_node_data(__type, (__list)->head_sentinel.next, __field); \
(__node)->__field.next != NULL; \
(__node) = exec_node_data(__type, (__node)->__field.next, __field))
#define foreach_list_typed_reverse(__type, __node, __field, __list) \
for (__type * __node = \
- exec_node_data(__type, (__list)->tail_pred, __field); \
+ exec_node_data(__type, (__list)->tail_sentinel.prev, __field); \
(__node)->__field.prev != NULL; \
(__node) = exec_node_data(__type, (__node)->__field.prev, __field))
#define foreach_list_typed_safe(__type, __node, __field, __list) \
for (__type * __node = \
- exec_node_data(__type, (__list)->head, __field), \
+ exec_node_data(__type, (__list)->head_sentinel.next, __field), \
* __next = \
exec_node_data(__type, (__node)->__field.next, __field); \
(__node)->__field.next != NULL; \
#define foreach_list_typed_reverse_safe(__type, __node, __field, __list) \
for (__type * __node = \
- exec_node_data(__type, (__list)->tail_pred, __field), \
+ exec_node_data(__type, (__list)->tail_sentinel.prev, __field), \
* __prev = \
exec_node_data(__type, (__node)->__field.prev, __field); \
(__node)->__field.prev != NULL; \