14

I have three questions:

1) What are the differences between Invoke and Call operations in IR codes of LLVM?

2) Why Call instruction is not considered as Terminator operation in BasicBlocks here?

3) Is it possible for both of the Invoke and Call operations to generate indirect Calls in assembly level language?

Thank you in advance,

Farzane
  • 173
  • 1
  • 8

3 Answers3

11

1) R\ Invoke is a call to a function that can launch an exception. If you realize, invoke define a block for handle exceptions and another for continue the normal flow.

2) R\ Call instruction are not considered terminator instructions because of the control flow is transmited to another function. In LLVM, a terminator instruction must reflect the next (or more than one) basic blocks that can be excecuted.

3) R\ Sorry, I don't know

Jordy Baylac
  • 510
  • 6
  • 18
1

Regarding 3), it's not clear whether you're asking w.r.t. writing a) an own backend or b) regarding an existing backend.

a) yes, obviously / generally you could generate anything you want if you'd implement that in your backend. b) which backend? i.e. ARM's call already is an indirect branch (i.e. bl instruction) while X86's CALL has side effects on X86 HW (i.e. saving return address, also non-functional side effects like support for call-stack branch prediction) and hence can't just be replaced by an indirect call without emulation what CALL would do. AFAIK a CALL emulation using indirect branches is not part of X86's LLVM backend.

hendrik
  • 21
  • 3
1

invoke and call are used to make a call to a function. call instruction is the normal C-style call where program resumes from the next instruction following the function call once function returns.

invoke can be used to handle exception in a way that when the function did not return normally, it would 'resume' from a different basic block (a.k.a landing pad). the landing pad would have the information to handle exception.

indirect calls can be generated using both call and invoke instructions AIUI. More details are in the llvm langref: https://llvm.org/docs/LangRef.html

A. K.
  • 34,395
  • 15
  • 52
  • 89