Emitting if-else condition IR

An if-else statement has a condition expression and two code paths to execute, depending on the condition evaluating to true or false. The condition expression is generally a comparison statement. Let's emit a condition statement at the start of the block. For example, let the condition be like a<100.

 Value *val2 = Builder.getInt32(100);
 Value *Compare = Builder.CreateICmpULT(val, val2, "cmptmp"); 

On compilation, we get following output:

; ModuleID = 'my compiler'

@x = common global i32, align 4

define i32 @foo(i32 %a, i32 %b) {
  %multmp = mul i32 %a, 16
  %cmptmp = icmp ult i32 %multmp, 100
  ret i32 %multmp

The next step is to define the then and else block expressions, which will be executed depending on the ...

Get LLVM Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.