blob: d77c6655bb6f81fca5f405ff900657ab28e09a74 [file] [log] [blame]
Logan36fafd92011-01-08 22:55:19 +08001=========================================
2libbcc: A Hybrid Bitcode Execution Engine
3=========================================
4
5
6Introduction
7------------
8
9libbcc is an LLVM bitcode execution engine which compiles the bitcode
10to an in-memory executable. It comes with a *just-in-time bitcode
11compiler*, which translates the bitcode to machine code, and a *caching
12mechanism*, which saves the in-memory executable after the compilation.
13Here are some highlights of libbcc:
14
15* libbcc supports bit code from various language frontends, such as
16 RenderScript, GLSL.
17
18* libbcc strives to balance between library size, launch time and
19 steady-state performance:
20
21 * The size of libbcc is aggressively reduced for a mobile device.
22 We customize and we don't use Execution Engine.
23
24 * To reduce launch time, we support caching of binaries.
25
26 * For steady-state performance, we enable VFP3 and aggressive
27 optimizations.
28
29
30
31API
32---
33
34Basic:
35
36* **bccCreateScript** - Create new bcc script
37
38* **bccRegisterSymbolCallback** - Register the callback function for external
39 symbol lookup
40
41* **bccReadBC** - Set the source bitcode for compilation
42
43* **bccReadModule** - Set the llvm::Module for compilation
44
45* **bccLinkBC** - Set the library bitcode for linking
46
47* **bccPrepareExecutable** Create the in-memory executable by either
48 just-in-time compilation or cache loading
49
50* **bccDeleteScript** - Destroy bcc script and release the resources
51
52* **bccGetError** - Get the error code
53
54* **bccGetScriptInfoLog** *deprecated* - Don't use this
55
56
57Reflection:
58
59* **bccGetExportVars** - Get the addresses of exported variables
60
61* **bccGetExportFuncs** - Get the addresses of exported functions
62
63* **bccGetPragmas** - Get the pragmas
64
65
66Debug:
67
68* **bccGetFunctions** - Get the function name list
69
70* **bccGetFunctionBinary** - Get the address and the size of function binary
71
72
73
74Cache File Format
75-----------------
76
77The cache file of libbcc (\*.oBCC) is consisted of several sections:
78header, string pool, dependencies table, relocation table, exported
79variable list, exported function list, pragma list, function information
80table, and bcc context. Every section should be aligned to a word size.
81Here's the brief description of each sections:
82
83* **Header** (OBCC_Header) - The header of the cache file. Contains the
84 magic word, version, machine integer type information, and the size
85 and the offset of other sections. The header section is guaranteed
86 to be at the beginning of the cache file.
87
88* **String Pool** (OBCC_StringPool) - A collection of serialized variadic
89 length strings. The strp_index in the other part of the cache file
90 represents the index of such string in this string pool.
91
92* **Dependencies Table** (OBCC_DependencyTable) - The dependencies table.
93 This table will store the resource name (or file path), the resouece
94 type (rather in APK or on the file system), and the SHA1 checksum.
95
96* **Relocation Table** (OBCC_RelocationTable) *not finished*
97
98* **Exported Variable List** (OBCC_ExportVarList),
99 **Exported Function List** (OBCC_ExportFuncList) -
100 The list of the addresses of exported variables and exported functions.
101
102* **Pragma List** (OBCC_PragmaList) - The list of pragma key-value pair.
103
104* **Function Information Table** (OBCC_FuncTable) - This is a table of
105 function information, such as function name, function entry address,
106 and function binary size. Besides, the table should be ordered by
107 function name.
108
109* **Context** - The context of the in-memory executable, including
110 the code and the data. The offset of context should aligned to
111 a page size, so that we can mmap the context directly into the memory.
112
113For furthur information, you may read `bcc_cache.h <include/bcc/bcc_cache.h>`_,
114`CacheReader.cpp <lib/bcc/CacheReader.cpp>`_, and
115`CacheWriter.cpp <lib/bcc/CacheWriter.cpp>`_ for details.
116
117
118
119JIT'ed Code Calling Conventions
120-------------------------------
121
1221. Calls from Execution Environment or from/to within script:
123
124 On ARM, the first 4 arguments will go into r0, r1, r2, and r3, in that order.
125 The remaining (if any) will go through stack.
126
127 For ext_vec_types such as float2, a set of registers will be used. In the case
128 of float2, a register pair will be used. Specifically, if float2 is the first
129 argument in the function prototype, float2.x will go into r0, and float2.y,
130 r1.
131
132 Note: stack will be aligned to the coarsest-grained argument. In the case of
133 float2 above as an argument, parameter stack will be aligned to an 8-byte
134 boundary (if the sizes of other arguments are no greater than 8.)
135
1362. Calls from/to a separate compilation unit: (E.g., calls to Execution
137 Environment if those runtime library callees are not compiled using LLVM.)
138
139 On ARM, we use hardfp. Note that double will be placed in a register pair.