// File: luooofan[P]hblzbd_compiler/src/Pass/convert_ssa.cpp
// Function: ConvertSSA::FillPhiInst(IRFunction*, SSAFunction*, std::unordered_map<IRBasicBlock*, SSABasicBlock*, std::hash<IRBasicBlock*>, std::equal_to<IRBasicBlock*>, std::allocator<std::pair<IRBasicBlock* const, SSABasicBlock*>>>&)
void ConvertSSA::FillPhiInst(IRFunction* irfunc, SSAFunction* ssafunc,
                             std::unordered_map<IRBasicBlock*, SSABasicBlock*>& bb_map) {
  // 遍历每个irbb 如果bb开头有phi结点 就填充对应的ssabb中的phi结点
  for (auto bb : irfunc->bb_list_) {
    auto ssabb = bb_map[bb];
    int i = 0;
    for (auto ssa_inst : ssabb->GetInstList()) {
      if (auto phi_inst = dynamic_cast<PhiInst*>(ssa_inst)) {
        auto ir = *(bb->ir_list_[i]);
        for (int i = 0; i < ir.phi_args_.size(); ++i) {
          auto arg_val = ResolveOpn2Value(&ir.phi_args_[i], ssabb);
          phi_inst->AddParam(arg_val, bb_map[bb->pred_[i]]->GetValue());
        }
        ++i;
      } else {
        break;
      }
    }
  }
}

// Assembly:
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, 0x1c0(%rsp)
movq %rsi, 0x1b8(%rsp)
movq %rdx, 0x1b0(%rsp)
movq %rcx, 0x1a8(%rsp)
movq 0x1c0(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x1b8(%rsp), %rax
addq $0x30, %rax
movq %rax, 0x1a0(%rsp)
movq 0x1a0(%rsp), %rdi
callq 0x1cc40
movq %rax, 0x198(%rsp)
movq 0x1a0(%rsp), %rdi
callq 0x1cac0
movq %rax, 0x190(%rsp)
leaq 0x198(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x492e0
testb $0x1, %al
jne 0x8c820
jmp 0x8caae
leaq 0x198(%rsp), %rdi
callq 0x49320
movq (%rax), %rax
movq %rax, 0x188(%rsp)
movq 0x1a8(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x8d4b0
movq (%rax), %rax
movq %rax, 0x180(%rsp)
movl $0x0, 0x17c(%rsp)
movq 0x180(%rsp), %rdi
callq 0x62860
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rdi
callq 0x62870
movq %rax, 0x168(%rsp)
movq 0x170(%rsp), %rdi
callq 0x628a0
movq %rax, 0x160(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x628d0
testb $0x1, %al
jne 0x8c8c0
jmp 0x8ca9a
leaq 0x168(%rsp), %rdi
callq 0x628f0
movq (%rax), %rax
movq %rax, 0x158(%rsp)
movq 0x158(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, %rax
je 0x8c90e
movq 0x40(%rsp), %rdi
leaq 0xbeb21(%rip), %rsi     # 0x14b418
leaq 0xbef92(%rip), %rdx     # 0x14b890
xorl %eax, %eax
movl %eax, %ecx
callq 0x8410
movq %rax, 0x38(%rsp)
jmp 0x8c917
xorl %eax, %eax
movq %rax, 0x38(%rsp)
jmp 0x8c917
movq 0x38(%rsp), %rax
movq %rax, 0x150(%rsp)
cmpq $0x0, 0x150(%rsp)
je 0x8ca84
movq 0x188(%rsp), %rdi
addq $0x8, %rdi
movslq 0x17c(%rsp), %rsi
callq 0x18460
movq (%rax), %rsi
leaq 0x70(%rsp), %rdi
callq 0x8d7d0
movl $0x0, 0x6c(%rsp)
movslq 0x6c(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x70(%rsp), %rdi
addq $0xc8, %rdi
callq 0x8ed30
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x8ca67
leaq 0x138(%rsp), %rdi
movslq 0x6c(%rsp), %rsi
callq 0x8ed50
movq 0x48(%rsp), %rdi
movq %rax, %rsi
movq 0x180(%rsp), %rdx
callq 0x876c0
movq %rax, 0x28(%rsp)
jmp 0x8c9bb
movq 0x28(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x188(%rsp), %rdi
addq $0x28, %rdi
movslq 0x6c(%rsp), %rsi
callq 0x8ee50
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x8d4b0
movq %rax, 0x20(%rsp)
jmp 0x8ca13
movq 0x20(%rsp), %rax
movq (%rax), %rdi
callq 0x8ee70
movq %rax, (%rsp)
jmp 0x8ca26
movq (%rsp), %rdx
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x8ed70
jmp 0x8ca3b
jmp 0x8ca3d
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x8c961
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x49400
jmp 0x8cab6
movl 0x17c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x17c(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x49400
jmp 0x8ca86
jmp 0x8ca9a
jmp 0x8ca88
leaq 0x168(%rsp), %rdi
callq 0x62960
jmp 0x8c8a2
jmp 0x8ca9c
leaq 0x198(%rsp), %rdi
callq 0x49330
jmp 0x8c802
addq $0x1c8, %rsp            # imm = 0x1C8
retq
movq 0x58(%rsp), %rdi
callq 0x8670