69 if (inst_addr >= first_block_addr && inst_addr <
102 std::set<int> leaders;
106 if (instruction->isBranch()) {
107 const int target_pc = instruction->getTargetPc();
108 leaders.insert(target_pc);
109 leaders.insert(instruction->nextInstAddr());
113 size_t block_size = 0;
114 for (
const auto &instruction : instructions) {
115 if (leaders.find(instruction->instAddr()) != leaders.end()) {
140 bb->successorIds.insert(exit_bb->
id);
146 bb->successorIds.insert(target_bb->
id);
152 bb->successorIds.insert(next_bb->
id);
162 std::set<uint32_t>::iterator it = a.begin();
163 while (it != a.end()) {
164 it = b.find(*it) != b.end() ? ++it : a.erase(it);
176 if (!block->isExit()) {
177 for (uint32_t
i = 0;
i < basicBlocks.size();
i++) {
178 block->postDominatorIds.insert(
i);
186 for (
int h = basicBlocks.size() - 2; h >= 0; --h) {
187 size_t num_postdominators =
188 basicBlocks[h]->postDominatorIds.size();
189 for (
int s : basicBlocks[h]->successorIds) {
190 intersect(basicBlocks[h]->postDominatorIds,
191 basicBlocks[
s]->postDominatorIds);
193 basicBlocks[h]->postDominatorIds.insert(h);
194 change |= (num_postdominators
195 != basicBlocks[h]->postDominatorIds.size());
204 const std::set<uint32_t>&
b, uint32_t exception)
206 for (uint32_t b_elem : b) {
207 if (b_elem != exception) {
229 basicBlocks[postDominatorId]->postDominatorIds,
233 assert(candidates.size() == 1);
235 BasicBlock* ipd_block = basicBlocks[*(candidates.begin())].
get();
236 if (!ipd_block->isExit()) {
240 last_instruction->ipdInstNum(last_instruction->nextInstAddr());
249 std::cout <<
"PD(" << block->id <<
") = {";
250 std::copy(block->postDominatorIds.begin(),
251 block->postDominatorIds.end(),
252 std::ostream_iterator<uint32_t>(std::cout,
", "));
253 std::cout <<
"}" << std::endl;
261 if (block->isExit()) {
264 std::cout <<
"IPD(" << block->id <<
") = ";
267 std::cout << std::endl;
273 int inst_addr = inst->instAddr();
274 std::cout << inst_addr <<
" [" <<
basicBlock(inst_addr)->
id
275 <<
"]: " << inst->disassemble();
276 if (inst->isBranch()) {
277 std::cout <<
", PC = " << inst->getTargetPc();
279 std::cout << std::endl;
286 printf(
"digraph {\n");
289 for (uint32_t successorId : basic_block->successorIds) {
290 printf(
"%d -> %d; ", basic_block->id, successorId);
void instAddr(int inst_addr)
void printPostDominators() const
BasicBlock * basicBlock(int inst_addr) const
std::vector< std::unique_ptr< BasicBlock > > basicBlocks
std::vector< GPUStaticInst * > instructions
static void assignImmediatePostDominators(const std::vector< GPUStaticInst * > &instructions)
Compute immediate post-dominator instruction for kernel instructions.
void findPostDominators()
static void setDifference(std::set< uint32_t > &a, const std::set< uint32_t > &b, uint32_t exception)
GPUStaticInst * firstInstruction
Pointer to first instruction of the block.
void findImmediatePostDominators()
void connectBasicBlocks()
const uint32_t id
Unique identifier for the block within a given kernel.
size_t size
Number of instructions contained in the block.
virtual uint32_t getTargetPc()
bool isUnconditionalJump() const
void printBasicBlocks() const
std::set< uint32_t > postDominatorIds
Identifiers of the blocks that will be visited from this block.
void printImmediatePostDominators() const
GPUStaticInst * lastInstruction(const BasicBlock *block) const
static void intersect(std::set< uint32_t > &a, const std::set< uint32_t > &b)
void printBasicBlockDot() const
BasicBlock * postDominator(const BasicBlock *block) const
ControlFlowInfo(const std::vector< GPUStaticInst * > &instructions)