Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call vs Invoke in IR codes of LLVM

Tags:

llvm

llvm-ir

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,

like image 723
Farzane Avatar asked Feb 12 '16 17:02

Farzane


2 Answers

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.

like image 24
hendrik Avatar answered Sep 25 '22 01:09

hendrik


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

like image 151
A. K. Avatar answered Sep 23 '22 01:09

A. K.