X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firnodeset.h;h=09b99a871ea25db3f40c416bcc956a8892eaf997;hb=e5c8ad12dba958fd212704917d7a433e6716462b;hp=0d779647a724978b867b209fd1cc5de4633f16c7;hpb=92869d69702fc0fd8e77832b9b68c60cb0d3e82a;p=libfirm diff --git a/ir/ir/irnodeset.h b/ir/ir/irnodeset.h index 0d779647a..09b99a871 100644 --- a/ir/ir/irnodeset.h +++ b/ir/ir/irnodeset.h @@ -1,20 +1,6 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. + * Copyright (C) 2012 University of Karlsruhe. */ /** @@ -23,38 +9,22 @@ * @date 30.03.2007 * @brief A nodeset. This should be prefered over a simple pset, because it * tries to guarantee deterministic behavior. (and is faster) - * @version $Id$ * @note Actually the bits to make the behaviour deterministic are not * implemented yet... */ #ifndef _FIRM_IRNODESET_H_ #define _FIRM_IRNODESET_H_ -#include "firm_config.h" - +#include #include "firm_types.h" #include "xmalloc.h" -/* - * sebastian experimental: - * use ordered arrays as node sets. - * the guys here have made good experiences with that. - * Internally we use normal Firm arrays and binary - * search for locating the elements. Using arrays should - * give the sets a small footprint. - */ -#undef IR_NODESET_USE_ORDERED_SETS - #define HashSet ir_nodeset_t #define HashSetIterator ir_nodeset_iterator_t #define ValueType ir_node* #define DO_REHASH -#ifdef IR_NODESET_USE_ORDERED_SETS -#include "arrayset.h" -#else #include "hashset.h" -#endif #undef DO_REHASH #undef ValueType @@ -93,8 +63,8 @@ void ir_nodeset_destroy(ir_nodeset_t *nodeset); * @param expected_elements Number of elements expected in the nodeset (roughly) * @return The initialized nodeset */ -static INLINE ir_nodeset_t *ir_nodeset_new(size_t expected_elements) { - ir_nodeset_t *res = xmalloc(sizeof(*res)); +static inline ir_nodeset_t *ir_nodeset_new(size_t expected_elements) { + ir_nodeset_t *res = XMALLOC(ir_nodeset_t); ir_nodeset_init_size(res, expected_elements); return res; } @@ -102,7 +72,7 @@ static INLINE ir_nodeset_t *ir_nodeset_new(size_t expected_elements) { /** * Destroys a nodeset and frees the memory of the nodeset itself. */ -static INLINE void ir_nodeset_del(ir_nodeset_t *nodeset) { +static inline void ir_nodeset_del(ir_nodeset_t *nodeset) { ir_nodeset_destroy(nodeset); xfree(nodeset); } @@ -112,10 +82,10 @@ static INLINE void ir_nodeset_del(ir_nodeset_t *nodeset) { * * @param nodeset Pointer to the nodeset * @param node node to insert into the nodeset - * @returns 1 if the element has been inserted, - * 0 if it was already there + * @returns true if the element has been inserted, + * false if it was already there */ -int ir_nodeset_insert(ir_nodeset_t *nodeset, ir_node *node); +bool ir_nodeset_insert(ir_nodeset_t *nodeset, ir_node *node); /** @@ -132,9 +102,8 @@ void ir_nodeset_remove(ir_nodeset_t *nodeset, const ir_node *node); * * @param nodeset Pointer to the nodeset * @param node The pointer to find - * @returns 1 if nodeset contains the node, 0 else */ -int ir_nodeset_contains(const ir_nodeset_t *nodeset, const ir_node *node); +bool ir_nodeset_contains(const ir_nodeset_t *nodeset, const ir_node *node); /** * Returns the number of pointers contained in the nodeset @@ -174,51 +143,17 @@ ir_node *ir_nodeset_iterator_next(ir_nodeset_iterator_t *iterator); void ir_nodeset_remove_iterator(ir_nodeset_t *nodeset, const ir_nodeset_iterator_t *iterator); -#define foreach_ir_nodeset(nodeset, irn, iter) \ - for(ir_nodeset_iterator_init(&iter, nodeset), \ - irn = ir_nodeset_iterator_next(&iter); \ - irn != NULL; irn = ir_nodeset_iterator_next(&iter)) - - -#ifdef IR_NODESET_USE_ORDERED_SETS - -/** - * Insert an element quickly into from the set. - * This method may destroy internal invariats of the set (think of sorted arrays). - * All calls to other routines but - * - iteration - * - get the number of elements in the set - * will not work until ir_nodeset_fixup() was called. - * @param nodeset The nodeset. - * @param node The node to insert. - */ -void ir_nodeset_insert_quick(ir_nodeset_t *nodeset, ir_node *node); - -/** - * Remove an element quickly from the set. - * This method may destroy internal invariats of the set (think of sorted arrays). - * All calls to other routines but - * - iteration - * - get the number of elements in the set - * will not work until ir_nodeset_fixup() was called. - * @param nodeset The nodeset. - * @param node The node to delete. - */ -void ir_nodeset_remove_quick(ir_nodeset_t *nodeset, const ir_node *node); - -/** - * Fixes up internal state of the set. - * Is needed when one of the _quick functions was called. - * @param nodeset The nodeset. - */ -void ir_nodeset_fixup(ir_nodeset_t *nodeset); - -#else - -#define ir_nodeset_remove_quick ir_nodeset_remove -#define ir_nodeset_insert_quick ir_nodeset_insert -#define ir_nodeset_fixup(set) +static inline ir_node *ir_nodeset_first(ir_nodeset_t const *const nodeset) +{ + ir_nodeset_iterator_t iter; + ir_nodeset_iterator_init(&iter, nodeset); + return ir_nodeset_iterator_next(&iter); +} -#endif /* IR_NODESET_USE_ORDERED_SETS */ +#define foreach_ir_nodeset(nodeset, irn, iter) \ + for (bool irn##__once = true; irn##__once;) \ + for (ir_nodeset_iterator_t iter; irn##__once;) \ + for (ir_node *irn; irn##__once; irn##__once = false) \ + for (ir_nodeset_iterator_init(&iter, nodeset); (irn = ir_nodeset_iterator_next(&iter));) #endif