more target independent bitcode

35
IMRC in KIST Jin-Gu Kang

Post on 23-Oct-2014

54 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: More Target Independent Bitcode

IMRC in KIST Jin-Gu Kang

Page 2: More Target Independent Bitcode

Contents Motivation Target Dependent Properties New Compilation Strategy More Target Independent Bitcode Application

Page 3: More Target Independent Bitcode

A compiled code can be executed identically on all of machines using virtual machine.

Is it possibe to use LLVM Bitcode like Java Bytecode??

Motivation

Page 4: More Target Independent Bitcode

Java Compilation Flow

Static compilation flow

Dynamic compilation flow

Java source code

Java Bytecode

OS

HW

Interpreter

JIT

AOTC

Page 5: More Target Independent Bitcode

Java Compilation Flow

Static compilation flow

Dynamic compilation flow

Java source code (Target independent)

Java Bytecode (Target independent)

OS

HW

Interpreter

JIT

AOTC

Java language is not affetcted by specific machine. Java bytecode is same among machines.

Page 6: More Target Independent Bitcode

LLVM Compilation Flow

Static compilation flow

Dynamic compilation flow

C/C++ source code

LLVM Bitcode

OS

HW

Interpreter (LLI)

JIT (LLI)

AOTC (LLC)

Page 7: More Target Independent Bitcode

LLVM Compilation Flow

Static compilation flow

Dynamic compilation flow

C/C++ source code (Target dependent)

LLVM Bitcode (Target dependent)

OS

HW

Interpreter (LLI)

JIT (LLI)

AOTC (LLC)

C/C++ language is affetcted by specific machine. LLVM bitcode is not same among machines.

Page 8: More Target Independent Bitcode

Target Dependent Properties LLVM frontend

LLVM frontend generates some target dependent bitcodes with common LLVM IR. Function type Sizeof() keyword

LLVM IR Bitcode does not support common IR in some cases.

Long double type Struct type with bitfield

Source language Inline assembly Target dependent source codes

Page 9: More Target Independent Bitcode

Target Dependent Properties LLVM frontend

LLVM frontend generates some target dependent bitcodes with common LLVM IR. Function type Sizeof() keyword

LLVM IR Bitcode does not support common IR in some cases.

Long double type Struct type with bitfield

Source language Inline assembly Target dependent source codes

Page 10: More Target Independent Bitcode

Function Type ABI compatibility

Function Type

Page 11: More Target Independent Bitcode

Function Type x86

ARM

Page 12: More Target Independent Bitcode

Sizeof() keyword x86

ARM

Page 13: More Target Independent Bitcode

Target Dependent Properties LLVM frontend

LLVM frontend generates some target dependent bitcodes with common LLVM IR. Function type Sizeof() keyword

LLVM IR LLVM does not support common IR in some cases.

Long double type Struct type with bitfield

Source language Inline assembly Target dependent source codes

Page 14: More Target Independent Bitcode

Target Dependent Properties long double type

Various encoding formats

IEEE double precision format

IEEE extended precision format

IEEE quadruple precision format

ARM

X86

PPC

Page 15: More Target Independent Bitcode

Target Dependent Properties

LLVM Bitcode For X86

LLVM does not support common IR type for long double type.

LLVM Bitcode for ARM

Page 16: More Target Independent Bitcode

Target Dependent Properties IEEE_double format encoding

variable “c” as parameter for printf function

Printf function waits X86_fp80 format encoding

Variable for “%Lf” on X86 architecture

Application

Library

Source for

ARM

SystemX86

Page 17: More Target Independent Bitcode

Target Dependent Properties Strcut type with bitfield

struct foo { char a:4; long long b:61; int c:30; };

<{ i8, [7 x i8], i64, i32, [4 x i8]}>

<{ i8, [3 x i8], i64, i32 }>

ARM

x86

a

b

c

Memory

LLVM IR

Memory

LLVM IR

a b

c

Page 18: More Target Independent Bitcode

Target Dependent Properties Strcut type with bitfield

struct foo { char a:4; long long b:61; int c:30; };

<{ i8, [7 x i8], i64, i32, [4 x i8]}>

<{ i8, [3 x i8], i64, i32 }>

ARM

x86

a

b

c

Memory

LLVM IR

Memory

LLVM IR

a b

c

Long long type’s align is 4 byte on x86 and is 8byte on ARM. Struct type’s align is biggest field’s align.

padding

padding

Page 19: More Target Independent Bitcode

Target Dependent Properties LLVM frontend

LLVM frontend generates some target dependent bitcodes with common LLVM IR. Function type ABI compatibility Sizeof() keyword

LLVM IR Bitcode does not support common IR in some cases.

Long double type Struct type with bitfield

Source language Inline assembly Target dependent source codes

Discard

Page 20: More Target Independent Bitcode

New Compilation Strategy C/C++ source code

Target Independent Bitcode (Wordcode)

OS

HW

AOTC (LLC)

Translator

Target Dependent Bitcode (Wordcode)

Page 21: More Target Independent Bitcode

New Compilation Strategy C/C++ source code

Target Independent Bitcode (Wordcode)

OS

HW

AOTC (LLC)

Translator

Target Dependent Bitcode (Wordcode) This target independent bitcode is same among machines except some cases. (ex: inline assembly)

Page 22: More Target Independent Bitcode

New Compilation Strategy C/C++ source code

Target Independent Bitcode (Wordcode)

OS

HW

AOTC (LLC)

Translator

Target Dependent Bitcode (Wordcode)

This target dependent is similar to LLVM bitcode.

Page 23: More Target Independent Bitcode

Wordcode Wordcode can be target dependent or target

independent. Target independent Wordcode IntegerTypes with align information from source code StructType with bitfield Long double type Etc…

Target dependent Wordcode It is similar to LLVM bitcode.

Wordcode is applied to almost passes on LLVM.

Page 24: More Target Independent Bitcode

Wordcode Target independent Wordcode

Page 25: More Target Independent Bitcode

Wordcode Target independent Wordcode Target dependent Wordcode (ARM)

Page 26: More Target Independent Bitcode

Long Double Type

Long Double

Type

Input

Intermediate Representation

Target Independent Wordcode

X86_fp80

IEEE_double

IEEE_quad

Target Dependent Wordcode

Page 27: More Target Independent Bitcode

Long Double Type Target independent Wordcode

Page 28: More Target Independent Bitcode

Long Double Type Target dependent Wordcode (x86)

Result

Page 29: More Target Independent Bitcode

Long Double Type Target dependent Wordcode (ARM)

Result

Page 30: More Target Independent Bitcode

Struct Type with Bitfield

Input

{ i4(char), i61(longlong), i30(int) }

Target Independent

Wordcode ARM

x86

Target Dependent Wordcode

struct foo { char a:4; long long b:61; int c:30; };

<{ i8, [7 x i8], i64, i32, [4 x i8]}>

<{ i8, [3 x i8], i64, i32 }>

Page 31: More Target Independent Bitcode

Struct Type with Bitfield Target independent Wordcode

Page 32: More Target Independent Bitcode

Struct Type with Bitfield Target dependent Wordcode (x86)

Result

Page 33: More Target Independent Bitcode

Struct Type with Bitfield Target dependent Wordcode (ARM)

Result

Page 34: More Target Independent Bitcode

Application

C/C++ Source Code

Linux

OceanVM

Runtime Engine

Execution Engine

Wordcode

AppStore

Linux Package

Brower Plugin

Compiler

Page 35: More Target Independent Bitcode

Happy Hacking!