Excuse the ads! We need some help to keep our site up.

List

IR(Intermediate Representation)

Intermediate language

  • 물리적인 컴퓨터 자체나 프로그램 언어 같은 기능까지 포함하며, 컴퓨터 시스템의 기능을 추상화한 모델 기계.

Three-address code

Example

t1 := b * c
t2 := a + t1
t3 := t2 / 2
x := t3
for(i = 0; i < 100; i++){
	val[i] = i;
}
     t1 := 0
L1:  if t1 >= 100 goto L2
     t2 := t1 * 4
     t3 := val + t2
     *t3 := t1
     t1 := t1 + 1
     goto L1
L2:

Intermediate Representation

QEMU의 TCG(Tiny code generator)

Valgrind의 VEX

Example

subs R2, R2, #8
t0 = GET:I32(16)
t1 = 0x8:I32
t3 = Sub32(t0,t1)
PUT(16) = t3
PUT(68) = 0x59FC8:I32

LLVM(Low Level Virtual Machine) IR:

Example

$ sudo aptitude install llvm clang
int sample(int a,int b) {
    	return a*b;
}
lazenca0x0@ubuntu:~$ cat sample.ll 
; ModuleID = 'test.c'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

; Function Attrs: norecurse nounwind optsize readnone uwtable
define i32 @sample(i32 %a, i32 %b) #0 {
  %1 = mul nsw i32 %b, %a
  ret i32 %1
}

attributes #0 = { norecurse nounwind optsize readnone uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.ident = !{!0}

!0 = !{!"clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)"}
lazenca0x0@ubuntu:~$ 

Related info