C-sparse
view release on metacpan or search on metacpan
src/sparse-0.4.4/storage.c view on Meta::CPAN
/*
* Storage - associate pseudos with "storage" that keeps them alive
* between basic blocks. The aim is to be able to turn as much of
* the global storage allocation problem as possible into a local
* per-basic-block one.
*
* Copyright (C) 2004 Linus Torvalds
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "symbol.h"
#include "expression.h"
#include "linearize.h"
#include "storage.h"
ALLOCATOR(storage, "storages", 0);
ALLOCATOR(storage_hash, "storage hash", 0);
/*#define MAX_STORAGE_HASH 64*/
#ifndef DO_CTX
static struct storage_hash_list *storage_hash_table[MAX_STORAGE_HASH];
#endif
static inline unsigned int storage_hash(struct basic_block *bb, pseudo_t pseudo, enum inout_enum inout)
{
unsigned hash = hashval(bb) + hashval(pseudo) + hashval(inout);
hash += hash / MAX_STORAGE_HASH;
return hash & (MAX_STORAGE_HASH-1);
}
static int hash_list_cmp(SCTX_ const void *_a, const void *_b)
{
const struct storage_hash *a = _a;
const struct storage_hash *b = _b;
if (a->pseudo != b->pseudo)
return a->pseudo < b->pseudo ? -1 : 1;
return 0;
}
static void sort_hash_list(SCTX_ struct storage_hash_list **listp)
{
sort_list(sctx_ (struct ptr_list **)listp, hash_list_cmp);
}
struct storage_hash_list *gather_storage(SCTX_ struct basic_block *bb, enum inout_enum inout)
{
int i;
struct storage_hash *entry, *prev;
struct storage_hash_list *list = NULL;
for (i = 0; i < MAX_STORAGE_HASH; i++) {
struct storage_hash *hash;
FOR_EACH_PTR(sctxp storage_hash_table[i], hash) {
if (hash->bb == bb && hash->inout == inout)
add_ptr_list(&list, hash);
} END_FOR_EACH_PTR(hash);
}
sort_hash_list(sctx_ &list);
prev = NULL;
( run in 0.950 second using v1.01-cache-2.11-cpan-39bf76dae61 )