2012-04-10 12:01:50 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2012 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Authors:
|
|
|
|
|
* Eric Anholt <eric@anholt.net>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2014-02-19 14:47:57 -08:00
|
|
|
#pragma once
|
|
|
|
|
#ifndef BRW_CFG_H
|
|
|
|
|
#define BRW_CFG_H
|
|
|
|
|
|
2013-11-30 16:39:43 -08:00
|
|
|
#include "brw_shader.h"
|
|
|
|
|
|
2014-05-12 09:54:15 -07:00
|
|
|
struct bblock_t;
|
|
|
|
|
|
2014-05-12 14:40:40 -07:00
|
|
|
struct bblock_link {
|
2014-05-12 09:54:15 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
DECLARE_RALLOC_CXX_OPERATORS(bblock_link)
|
2012-04-10 12:01:50 -07:00
|
|
|
|
2012-10-03 13:16:09 -07:00
|
|
|
bblock_link(bblock_t *block)
|
2012-04-10 12:01:50 -07:00
|
|
|
: block(block)
|
|
|
|
|
{
|
|
|
|
|
}
|
2014-05-12 09:54:15 -07:00
|
|
|
#endif
|
2012-04-10 12:01:50 -07:00
|
|
|
|
2014-05-12 14:40:40 -07:00
|
|
|
struct exec_node link;
|
2014-05-12 09:54:15 -07:00
|
|
|
struct bblock_t *block;
|
2012-04-10 12:01:50 -07:00
|
|
|
};
|
|
|
|
|
|
2014-05-12 09:54:15 -07:00
|
|
|
#ifndef __cplusplus
|
|
|
|
|
struct backend_instruction;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct bblock_t {
|
|
|
|
|
#ifdef __cplusplus
|
2013-09-20 16:27:42 -07:00
|
|
|
DECLARE_RALLOC_CXX_OPERATORS(bblock_t)
|
2012-04-10 12:01:50 -07:00
|
|
|
|
2014-07-13 22:17:50 -07:00
|
|
|
explicit bblock_t(cfg_t *cfg);
|
2012-04-10 12:01:50 -07:00
|
|
|
|
2012-10-03 13:16:09 -07:00
|
|
|
void add_successor(void *mem_ctx, bblock_t *successor);
|
2014-07-16 12:14:41 -07:00
|
|
|
bool is_predecessor_of(const bblock_t *block) const;
|
|
|
|
|
bool is_successor_of(const bblock_t *block) const;
|
2014-07-15 14:51:43 -07:00
|
|
|
bool can_combine_with(const bblock_t *that) const;
|
|
|
|
|
void combine_with(bblock_t *that);
|
2014-09-03 23:29:04 -07:00
|
|
|
void dump(backend_visitor *v) const;
|
2014-05-12 09:54:15 -07:00
|
|
|
#endif
|
2012-04-10 12:01:50 -07:00
|
|
|
|
2014-07-11 16:17:47 -07:00
|
|
|
struct exec_node link;
|
2014-07-13 22:17:50 -07:00
|
|
|
struct cfg_t *cfg;
|
2014-07-11 16:17:47 -07:00
|
|
|
|
2014-05-12 09:54:15 -07:00
|
|
|
struct backend_instruction *start;
|
|
|
|
|
struct backend_instruction *end;
|
2012-04-10 12:01:50 -07:00
|
|
|
|
|
|
|
|
int start_ip;
|
|
|
|
|
int end_ip;
|
|
|
|
|
|
2014-05-12 09:54:15 -07:00
|
|
|
struct exec_list parents;
|
|
|
|
|
struct exec_list children;
|
2014-07-11 22:31:39 -07:00
|
|
|
int num;
|
2013-10-30 16:51:32 -07:00
|
|
|
|
2014-07-16 15:20:15 -07:00
|
|
|
/* If the current basic block ends in an IF or ELSE instruction, these will
|
|
|
|
|
* point to the basic blocks containing the other associated instruction.
|
2013-10-30 16:51:32 -07:00
|
|
|
*
|
|
|
|
|
* Otherwise they are NULL.
|
|
|
|
|
*/
|
2014-07-16 15:20:15 -07:00
|
|
|
struct bblock_t *if_block;
|
|
|
|
|
struct bblock_t *else_block;
|
2012-04-10 12:01:50 -07:00
|
|
|
};
|
|
|
|
|
|
2014-06-29 18:18:53 -07:00
|
|
|
struct cfg_t {
|
2014-05-12 09:54:15 -07:00
|
|
|
#ifdef __cplusplus
|
2013-09-20 16:29:48 -07:00
|
|
|
DECLARE_RALLOC_CXX_OPERATORS(cfg_t)
|
2012-04-10 12:01:50 -07:00
|
|
|
|
2013-11-28 23:24:44 -08:00
|
|
|
cfg_t(exec_list *instructions);
|
2012-10-03 13:16:09 -07:00
|
|
|
~cfg_t();
|
2012-11-20 17:30:46 -08:00
|
|
|
|
2014-07-13 22:17:50 -07:00
|
|
|
void remove_block(bblock_t *block);
|
|
|
|
|
|
2012-10-03 13:16:09 -07:00
|
|
|
bblock_t *new_block();
|
2013-11-30 20:38:48 -08:00
|
|
|
void set_next_block(bblock_t **cur, bblock_t *block, int ip);
|
2012-04-10 12:01:50 -07:00
|
|
|
void make_block_array();
|
|
|
|
|
|
2014-09-03 23:29:04 -07:00
|
|
|
void dump(backend_visitor *v) const;
|
2014-06-29 18:18:53 -07:00
|
|
|
#endif
|
2012-04-10 12:01:50 -07:00
|
|
|
void *mem_ctx;
|
|
|
|
|
|
|
|
|
|
/** Ordered list (by ip) of basic blocks */
|
2014-06-29 18:18:53 -07:00
|
|
|
struct exec_list block_list;
|
|
|
|
|
struct bblock_t **blocks;
|
2012-04-10 12:01:50 -07:00
|
|
|
int num_blocks;
|
|
|
|
|
};
|
2014-02-19 14:47:57 -08:00
|
|
|
|
2014-09-02 17:30:29 -07:00
|
|
|
/* Note that this is implemented with a double for loop -- break will
|
|
|
|
|
* break from the inner loop only!
|
|
|
|
|
*/
|
2014-07-11 21:17:01 -07:00
|
|
|
#define foreach_block_and_inst(__block, __type, __inst, __cfg) \
|
|
|
|
|
foreach_block (__block, __cfg) \
|
|
|
|
|
foreach_inst_in_block (__type, __inst, __block)
|
|
|
|
|
|
2014-09-02 17:30:29 -07:00
|
|
|
/* Note that this is implemented with a double for loop -- break will
|
|
|
|
|
* break from the inner loop only!
|
|
|
|
|
*/
|
2014-07-14 19:48:15 -07:00
|
|
|
#define foreach_block_and_inst_safe(__block, __type, __inst, __cfg) \
|
|
|
|
|
foreach_block_safe (__block, __cfg) \
|
|
|
|
|
foreach_inst_in_block_safe (__type, __inst, __block)
|
|
|
|
|
|
2014-07-11 22:31:39 -07:00
|
|
|
#define foreach_block(__block, __cfg) \
|
|
|
|
|
foreach_list_typed (bblock_t, __block, link, &(__cfg)->block_list)
|
|
|
|
|
|
2014-07-14 11:15:51 -07:00
|
|
|
#define foreach_block_safe(__block, __cfg) \
|
|
|
|
|
foreach_list_typed_safe (bblock_t, __block, link, &(__cfg)->block_list)
|
|
|
|
|
|
2014-06-24 12:42:00 -07:00
|
|
|
#define foreach_inst_in_block(__type, __inst, __block) \
|
|
|
|
|
for (__type *__inst = (__type *)__block->start; \
|
|
|
|
|
__inst != __block->end->next; \
|
|
|
|
|
__inst = (__type *)__inst->next)
|
|
|
|
|
|
2014-07-10 17:30:40 -07:00
|
|
|
#define foreach_inst_in_block_safe(__type, __inst, __block) \
|
|
|
|
|
for (__type *__inst = (__type *)__block->start, \
|
|
|
|
|
*__next = (__type *)__inst->next, \
|
|
|
|
|
*__end = (__type *)__block->end->next->next; \
|
|
|
|
|
__next != __end; \
|
|
|
|
|
__inst = __next, \
|
|
|
|
|
__next = (__type *)__next->next)
|
|
|
|
|
|
2014-06-24 12:42:00 -07:00
|
|
|
#define foreach_inst_in_block_reverse(__type, __inst, __block) \
|
|
|
|
|
for (__type *__inst = (__type *)__block->end; \
|
|
|
|
|
__inst != __block->start->prev; \
|
|
|
|
|
__inst = (__type *)__inst->prev)
|
|
|
|
|
|
2014-09-01 20:01:50 -07:00
|
|
|
#define foreach_inst_in_block_starting_from(__type, __scan_inst, __inst, __block) \
|
|
|
|
|
for (__type *__scan_inst = (__type *)__inst->next; \
|
|
|
|
|
__scan_inst != __block->end->next; \
|
|
|
|
|
__scan_inst = (__type *)__scan_inst->next)
|
|
|
|
|
|
|
|
|
|
#define foreach_inst_in_block_reverse_starting_from(__type, __scan_inst, __inst, __block) \
|
|
|
|
|
for (__type *__scan_inst = (__type *)__inst->prev; \
|
|
|
|
|
__scan_inst != __block->start->prev; \
|
|
|
|
|
__scan_inst = (__type *)__scan_inst->prev)
|
|
|
|
|
|
2014-02-19 14:47:57 -08:00
|
|
|
#endif /* BRW_CFG_H */
|