// File: /workspace/github_cpp_makefile_star2_O3/luooofan[P]hblzbd_compiler/src/Pass/dominant.cpp
// Function: ComputeDominance::ComputeIDomInfo(IRFunction*)
void ComputeDominance::ComputeIDomInfo(IRFunction* f) {
  // 构造深度优先生成树 构造完后 保证vertex dfnum有效完整 parent[r]为空
  DFS(nullptr, f->bb_list_.front());
  // std::cout << N << " " << f->bb_list_.size() << std::endl;
  // MyAssert(N == f->bb_list_.size());

  // 基于半必经结点定理计算所有 非根节点 的半必经结点
  for (int i = N - 1; i > 0; --i) {
    BB* n = vertex[i];
    auto p = parent[n];
    MyAssert(nullptr != p);
    auto s = p;  // s即n的半必经结点
    for (auto pred : n->pred_) {
      BB* s_temp = nullptr;
      if (dfnum[pred] <= dfnum[n]) {  // 该前驱在生成树上是n的祖先
        s_temp = pred;                // 则该结点是semi[n]的候选
      } else {                        // 该前驱在生成树上不是n的祖先
        s_temp = semi[AncestorWithLowestSemi(pred)];
        // 则该前驱到其公共祖先的路径上的y:min(dfnum[semi[y]]) semi[y]成为semi[n]候选
      }
      if (dfnum[s_temp] < dfnum[s]) {  // 半必经结点是dfnum最小的
        s = s_temp;
      }
    }
    semi.insert({n, s});  // semi和bucket和ancestor中不会有key为root的pair
    bucket[s].insert(n);
    Link(p, n);  // 把p->n链入到生成树森林

    // 计算 以p为半必经结点的 结点v 的 必经结点 这里可以保证会把semi为root结点的结点的idom都计算到
    for (auto v : bucket[p]) {
      BB* y = AncestorWithLowestSemi(v);  // min(dfnum[semi[y]]) y: from p to v(included). dfnum[v]>dfnum[y].
      if (semi[y] == p /*semi[v]*/) {     // 没有旁路p的分支
        // idom.insert({v, p});
        v->idom_ = p;
        p->doms_.push_back(v);
      } else {
        samedom.insert({v, y});  // fill idom[samedom.key]=idom[samedom.value] later.
      }
    }
    bucket[p].clear();
  }

  // fill idom[samedom.key]=idom[samedom.value]
  for (int i = 1; i < N; ++i) {
    auto n = vertex[i];
    if (samedom.find(n) != samedom.end()) {
      auto idom = samedom[n]->idom_;
      // MyAssert(idom.find(samedom[n]) != idom.end());
      // idom.insert({n, idom[samedom[n]]});
      MyAssert(nullptr != idom);
      n->idom_ = idom;
      idom->doms_.push_back(n);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x30(%rsi), %rax
movq (%rax), %rdx
xorl %esi, %esi
callq 0x4a848
movslq 0x34(%rbx), %r14
cmpq $0x2, %r14
jl 0x4aeb8
leaq 0x88(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0x50(%rbx), %r12
leaq 0x130(%rbx), %r13
leaq 0x1a0(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0xc0(%rbx), %rax
movq %rax, 0x48(%rsp)
leaq 0xf8(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x168(%rbx), %rbp
movq %rbp, 0x50(%rsp)
movq 0x38(%rbx), %rax
movq %r14, 0x60(%rsp)
movq -0x8(%rax,%r14,8), %rax
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x4b71e
movq (%rax), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x4aec7
movq %rax, 0x28(%rsp)
movq 0x18(%rsp), %rcx
movq 0x28(%rcx), %r15
movq 0x30(%rcx), %r14
cmpq %r14, %r15
je 0x4acd9
movq (%r15), %rax
movq %rax, (%rsp)
movq $0x0, 0x10(%rsp)
movq %r12, %rdi
movq %rsp, %rsi
callq 0x4b7d6
movl (%rax), %ebp
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4b7d6
cmpl (%rax), %ebp
jle 0x4ac8f
movq (%rsp), %rsi
movq %rbx, %rdi
callq 0x4a93c
movq %rax, 0x20(%rsp)
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x4baaa
movq (%rax), %rax
jmp 0x4ac93
movq (%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x4b7d6
movl (%rax), %ebp
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
callq 0x4b7d6
cmpl (%rax), %ebp
jge 0x4acc2
movq 0x10(%rsp), %rax
movq %rax, 0x28(%rsp)
addq $0x8, %r15
cmpq %r14, %r15
jne 0x4ac3e
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rsp)
movq %rax, 0x8(%rsp)
movq %r13, %rdi
movq %rsp, %rbp
movq %rbp, %rsi
callq 0x4b430
movq 0x38(%rsp), %r15
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x4bb62
movq %rax, (%rsp)
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
movq %rbp, %rdx
callq 0x47f24
movq 0x30(%rsp), %rax
movq 0x18(%rsp), %r14
movq %r14, (%rsp)
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x4b430
movq %r14, (%rsp)
movq %r14, 0x8(%rsp)
movq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x4b430
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x4bb62
movq 0x10(%rax), %r14
testq %r14, %r14
movq 0x50(%rsp), %rbp
movq 0x60(%rsp), %r15
je 0x4ae03
movq 0x8(%r14), %rsi
movq %rsi, 0x10(%rsp)
movq %rbx, %rdi
callq 0x4a93c
movq %rax, 0x20(%rsp)
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x4b71e
movq 0x30(%rsp), %rdi
cmpq %rdi, (%rax)
je 0x4adbd
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbp, %rdi
movq %rsp, %rsi
callq 0x4b430
jmp 0x4adf7
movq 0x10(%rsp), %rax
movq %rdi, 0x250(%rax)
movq 0x260(%rdi), %rsi
cmpq 0x268(%rdi), %rsi
je 0x4ade6
movq %rax, (%rsi)
addq $0x8, 0x260(%rdi)
jmp 0x4adf7
addq $0x258, %rdi            # imm = 0x258
leaq 0x10(%rsp), %rdx
callq 0x117de
movq (%r14), %r14
testq %r14, %r14
jne 0x4ad70
leaq -0x1(%r15), %r14
movq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4bb62
movq %rax, %rdi
callq 0x2bfc8
cmpq $0x2, %r15
jg 0x4abf0
cmpl $0x2, 0x34(%rbx)
jl 0x4aeb8
movl $0x1, %r15d
movq %rsp, %r14
movq 0x38(%rbx), %rax
movq (%rax,%r15,8), %rax
movq %rax, (%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4b6c2
testq %rax, %rax
je 0x4aeac
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4b71e
movq (%rax), %rax
movq 0x250(%rax), %rdi
testq %rdi, %rdi
je 0x4af02
movq (%rsp), %rax
movq %rdi, 0x250(%rax)
movq 0x260(%rdi), %rsi
cmpq 0x268(%rdi), %rsi
je 0x4ae9d
movq %rax, (%rsi)
addq $0x8, 0x260(%rdi)
jmp 0x4aeac
addq $0x258, %rdi            # imm = 0x258
movq %r14, %rdx
callq 0x117de
incq %r15
movslq 0x34(%rbx), %rax
cmpq %rax, %r15
jl 0x4ae3b
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4411a(%rip), %rdi     # 0x8efe8
leaq 0x23293(%rip), %rsi     # 0x6e168
callq 0x8280
leaq 0x26945(%rip), %rsi     # 0x71826
movq %rax, %rdi
callq 0x8280
leaq 0x244d0(%rip), %rsi     # 0x6f3c0
movq %rax, %rdi
callq 0x8280
movq %rax, %rdi
movl $0x42, %esi
jmp 0x4af3b
movq 0x440df(%rip), %rdi     # 0x8efe8
leaq 0x23258(%rip), %rsi     # 0x6e168
callq 0x8280
leaq 0x2690a(%rip), %rsi     # 0x71826
movq %rax, %rdi
callq 0x8280
leaq 0x24495(%rip), %rsi     # 0x6f3c0
movq %rax, %rdi
callq 0x8280
movq %rax, %rdi
movl $0x69, %esi
callq 0x8520
movq %rax, %rdi
callq 0x8180
movl $0xff, %edi
callq 0x8380