// File: luooofan[P]hblzbd_compiler/src/Pass/dead_code_eliminate.cpp
// Function: DeadCodeEliminate::IsSideEffect(SSAInstruction*)
bool DeadCodeEliminate::IsSideEffect(SSAInstruction* inst) {
  if (nullptr == inst) return true;
  // 除callinst外 如果本身无定值[no used]视为有副作用
  if (dynamic_cast<BinaryOperator*>(inst) || dynamic_cast<UnaryOperator*>(inst) || dynamic_cast<LoadInst*>(inst) ||
      dynamic_cast<MovInst*>(inst) || dynamic_cast<PhiInst*>(inst)) {
    return false;
  } else if (auto call_inst = dynamic_cast<CallInst*>(inst)) {
    // 如果call语句无副作用 即便没有定值 也可删除
    auto func_val = dynamic_cast<FunctionValue*>(call_inst->GetOperand(0));
    MyAssert(nullptr != func_val);
    if (no_side_effect_funcs.find(func_val->GetFunction()) != no_side_effect_funcs.end()) return false;
  }
  return true;
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xb8(%rsp)
movq %rsi, 0xb0(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x80(%rsp)
xorl %eax, %eax
cmpq 0xb0(%rsp), %rax
jne 0xa0a00
movb $0x1, 0xc7(%rsp)
jmp 0xa0d26
movq 0xb0(%rsp), %rax
movq %rax, 0x78(%rsp)
cmpq $0x0, %rax
je 0xa0a36
movq 0x78(%rsp), %rdi
leaq 0xaa9f9(%rip), %rsi     # 0x14b418
leaq 0xaac2a(%rip), %rdx     # 0x14b650
xorl %eax, %eax
movl %eax, %ecx
callq 0x8410
movq %rax, 0x70(%rsp)
jmp 0xa0a3f
xorl %eax, %eax
movq %rax, 0x70(%rsp)
jmp 0xa0a3f
movq 0x70(%rsp), %rax
cmpq $0x0, %rax
jne 0xa0b7e
movq 0xb0(%rsp), %rax
movq %rax, 0x68(%rsp)
cmpq $0x0, %rax
je 0xa0a84
movq 0x68(%rsp), %rdi
leaq 0xaa9ab(%rip), %rsi     # 0x14b418
leaq 0xaac1c(%rip), %rdx     # 0x14b690
xorl %eax, %eax
movl %eax, %ecx
callq 0x8410
movq %rax, 0x60(%rsp)
jmp 0xa0a8d
xorl %eax, %eax
movq %rax, 0x60(%rsp)
jmp 0xa0a8d
movq 0x60(%rsp), %rax
cmpq $0x0, %rax
jne 0xa0b7e
movq 0xb0(%rsp), %rax
movq %rax, 0x58(%rsp)
cmpq $0x0, %rax
je 0xa0ad2
movq 0x58(%rsp), %rdi
leaq 0xaa95d(%rip), %rsi     # 0x14b418
leaq 0xaad0e(%rip), %rdx     # 0x14b7d0
xorl %eax, %eax
movl %eax, %ecx
callq 0x8410
movq %rax, 0x50(%rsp)
jmp 0xa0adb
xorl %eax, %eax
movq %rax, 0x50(%rsp)
jmp 0xa0adb
movq 0x50(%rsp), %rax
cmpq $0x0, %rax
jne 0xa0b7e
movq 0xb0(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, %rax
je 0xa0b20
movq 0x48(%rsp), %rdi
leaq 0xaa90f(%rip), %rsi     # 0x14b418
leaq 0xaad40(%rip), %rdx     # 0x14b850
xorl %eax, %eax
movl %eax, %ecx
callq 0x8410
movq %rax, 0x40(%rsp)
jmp 0xa0b29
xorl %eax, %eax
movq %rax, 0x40(%rsp)
jmp 0xa0b29
movq 0x40(%rsp), %rax
cmpq $0x0, %rax
jne 0xa0b7e
movq 0xb0(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpq $0x0, %rax
je 0xa0b6a
movq 0x38(%rsp), %rdi
leaq 0xaa8c5(%rip), %rsi     # 0x14b418
leaq 0xaad36(%rip), %rdx     # 0x14b890
xorl %eax, %eax
movl %eax, %ecx
callq 0x8410
movq %rax, 0x30(%rsp)
jmp 0xa0b73
xorl %eax, %eax
movq %rax, 0x30(%rsp)
jmp 0xa0b73
movq 0x30(%rsp), %rax
cmpq $0x0, %rax
je 0xa0b8b
movb $0x0, 0xc7(%rsp)
jmp 0xa0d26
movq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0xa0bc1
movq 0x28(%rsp), %rdi
leaq 0xaa86e(%rip), %rsi     # 0x14b418
leaq 0xaab5f(%rip), %rdx     # 0x14b710
xorl %eax, %eax
movl %eax, %ecx
callq 0x8410
movq %rax, 0x20(%rsp)
jmp 0xa0bca
xorl %eax, %eax
movq %rax, 0x20(%rsp)
jmp 0xa0bca
movq 0x20(%rsp), %rax
movq %rax, 0xa8(%rsp)
cmpq $0x0, 0xa8(%rsp)
je 0xa0d1c
movq 0xa8(%rsp), %rdi
xorl %esi, %esi
callq 0x5c850
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0xa0c23
movq 0x18(%rsp), %rdi
leaq 0xaa8c4(%rip), %rsi     # 0x14b4d0
leaq 0xaa915(%rip), %rdx     # 0x14b528
xorl %eax, %eax
movl %eax, %ecx
callq 0x8410
movq %rax, 0x10(%rsp)
jmp 0xa0c2c
xorl %eax, %eax
movq %rax, 0x10(%rsp)
jmp 0xa0c2c
movq 0x10(%rsp), %rax
movq %rax, 0xa0(%rsp)
xorl %eax, %eax
cmpq 0xa0(%rsp), %rax
jne 0xa0c9c
movq 0xab39c(%rip), %rdi     # 0x14bfe8
leaq 0x594a5(%rip), %rsi     # 0xfa0f8
callq 0x8330
movq %rax, %rdi
leaq 0x5cc74(%rip), %rsi     # 0xfd8d6
callq 0x8330
movq %rax, %rdi
leaq 0x5a779(%rip), %rsi     # 0xfb3ea
callq 0x8330
movq %rax, %rdi
movl $0x44, %esi
callq 0x8650
movq %rax, %rdi
movq 0xab2f3(%rip), %rsi     # 0x14bf80
callq 0x8380
movl $0xff, %edi
callq 0x8460
movq 0x80(%rsp), %rax
addq $0x38, %rax
movq %rax, 0x8(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x5e2a0
movq 0x8(%rsp), %rdi
movq %rax, 0x90(%rsp)
leaq 0x90(%rsp), %rsi
callq 0xa0f50
movq 0x80(%rsp), %rdi
movq %rax, 0x98(%rsp)
addq $0x38, %rdi
callq 0x62a60
movq %rax, 0x88(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x62a90
testb $0x1, %al
jne 0xa0d10
jmp 0xa0d1a
movb $0x0, 0xc7(%rsp)
jmp 0xa0d26
jmp 0xa0d1c
jmp 0xa0d1e
movb $0x1, 0xc7(%rsp)
movb 0xc7(%rsp), %al
andb $0x1, %al
addq $0xc8, %rsp
retq
nopw (%rax,%rax)