blob: 0637cd0debf45db67df60854d3caf4f9043c8b32 [file] [log] [blame]
Shih-wei Liao0d4984b2011-01-09 04:39:00 -08001============================================
2libbcc: A Versatile Bitcode Execution Engine
3============================================
Logan36fafd92011-01-08 22:55:19 +08004
5
6Introduction
7------------
8
Shih-wei Liao7fff2282011-01-09 13:57:01 -08009libbcc is an LLVM bitcode execution engine that compiles the bitcode
10to an in-memory executable.
11
12libbcc provides:
13
14* a *just-in-time (JIT) bitcode compiler*, which translates the bitcode into
15 machine code
16
17* a *caching mechanism*, which can:
18
19 * after the compilation, serialize the in-memory executable into a cache file.
20 Note that the compilation is triggered by a cache miss.
21 * load from the cache file upon cache-hit.
22
Logan36fafd92011-01-08 22:55:19 +080023Here are some highlights of libbcc:
24
Shih-wei Liao7fff2282011-01-09 13:57:01 -080025* libbcc supports bitcode from various language frontends, such as
Logan36fafd92011-01-08 22:55:19 +080026 RenderScript, GLSL.
27
28* libbcc strives to balance between library size, launch time and
29 steady-state performance:
30
Shih-wei Liao7fff2282011-01-09 13:57:01 -080031 * The size of libbcc is aggressively reduced for mobile devices.
Logan36fafd92011-01-08 22:55:19 +080032 We customize and we don't use Execution Engine.
33
34 * To reduce launch time, we support caching of binaries.
35
36 * For steady-state performance, we enable VFP3 and aggressive
37 optimizations.
38
Shih-wei Liao0d4984b2011-01-09 04:39:00 -080039* Currently we disable Lazy JITting.
40
Logan36fafd92011-01-08 22:55:19 +080041
42
43API
44---
45
Shih-wei Liao7fff2282011-01-09 13:57:01 -080046**Basic:**
Logan36fafd92011-01-08 22:55:19 +080047
48* **bccCreateScript** - Create new bcc script
49
50* **bccRegisterSymbolCallback** - Register the callback function for external
51 symbol lookup
52
53* **bccReadBC** - Set the source bitcode for compilation
54
55* **bccReadModule** - Set the llvm::Module for compilation
56
57* **bccLinkBC** - Set the library bitcode for linking
58
Shih-wei Liao7fff2282011-01-09 13:57:01 -080059* **bccPrepareExecutable** - Create the in-memory executable by either
Logan36fafd92011-01-08 22:55:19 +080060 just-in-time compilation or cache loading
61
62* **bccDeleteScript** - Destroy bcc script and release the resources
63
64* **bccGetError** - Get the error code
65
Shih-wei Liao7fff2282011-01-09 13:57:01 -080066* **bccGetScriptInfoLog** - *deprecated* - Don't use this
Logan36fafd92011-01-08 22:55:19 +080067
68
Shih-wei Liao7fff2282011-01-09 13:57:01 -080069**Reflection:**
Logan36fafd92011-01-08 22:55:19 +080070
71* **bccGetExportVars** - Get the addresses of exported variables
72
73* **bccGetExportFuncs** - Get the addresses of exported functions
74
75* **bccGetPragmas** - Get the pragmas
76
77
Shih-wei Liao7fff2282011-01-09 13:57:01 -080078**Debug:**
Logan36fafd92011-01-08 22:55:19 +080079
80* **bccGetFunctions** - Get the function name list
81
Shih-wei Liao7fff2282011-01-09 13:57:01 -080082* **bccGetFunctionBinary** - Get the address and the size of a function binary
Logan36fafd92011-01-08 22:55:19 +080083
84
85
86Cache File Format
87-----------------
88
Shih-wei Liao0d4984b2011-01-09 04:39:00 -080089A cache file (denoted as \*.oBCC) for libbcc consists of several sections:
Logan36fafd92011-01-08 22:55:19 +080090header, string pool, dependencies table, relocation table, exported
91variable list, exported function list, pragma list, function information
92table, and bcc context. Every section should be aligned to a word size.
Shih-wei Liao0d4984b2011-01-09 04:39:00 -080093Here is the brief description of each sections:
Logan36fafd92011-01-08 22:55:19 +080094
Shih-wei Liao0d4984b2011-01-09 04:39:00 -080095* **Header** (OBCC_Header) - The header of a cache file. It contains the
Logan36fafd92011-01-08 22:55:19 +080096 magic word, version, machine integer type information, and the size
97 and the offset of other sections. The header section is guaranteed
98 to be at the beginning of the cache file.
99
Shih-wei Liao0d4984b2011-01-09 04:39:00 -0800100* **String Pool** (OBCC_StringPool) - A collection of serialized variable
Logan36fafd92011-01-08 22:55:19 +0800101 length strings. The strp_index in the other part of the cache file
102 represents the index of such string in this string pool.
103
104* **Dependencies Table** (OBCC_DependencyTable) - The dependencies table.
Shih-wei Liao8538dfa2011-01-09 15:42:28 -0800105 This table stores the resource name (or file path), the resource
Logan36fafd92011-01-08 22:55:19 +0800106 type (rather in APK or on the file system), and the SHA1 checksum.
107
Shih-wei Liao0d4984b2011-01-09 04:39:00 -0800108* **Relocation Table** (OBCC_RelocationTable) - *not enabled*
Logan36fafd92011-01-08 22:55:19 +0800109
110* **Exported Variable List** (OBCC_ExportVarList),
111 **Exported Function List** (OBCC_ExportFuncList) -
112 The list of the addresses of exported variables and exported functions.
113
114* **Pragma List** (OBCC_PragmaList) - The list of pragma key-value pair.
115
116* **Function Information Table** (OBCC_FuncTable) - This is a table of
117 function information, such as function name, function entry address,
118 and function binary size. Besides, the table should be ordered by
119 function name.
120
121* **Context** - The context of the in-memory executable, including
122 the code and the data. The offset of context should aligned to
123 a page size, so that we can mmap the context directly into the memory.
124
125For furthur information, you may read `bcc_cache.h <include/bcc/bcc_cache.h>`_,
126`CacheReader.cpp <lib/bcc/CacheReader.cpp>`_, and
127`CacheWriter.cpp <lib/bcc/CacheWriter.cpp>`_ for details.
128
129
130
131JIT'ed Code Calling Conventions
132-------------------------------
133
1341. Calls from Execution Environment or from/to within script:
135
136 On ARM, the first 4 arguments will go into r0, r1, r2, and r3, in that order.
137 The remaining (if any) will go through stack.
138
139 For ext_vec_types such as float2, a set of registers will be used. In the case
140 of float2, a register pair will be used. Specifically, if float2 is the first
141 argument in the function prototype, float2.x will go into r0, and float2.y,
142 r1.
143
144 Note: stack will be aligned to the coarsest-grained argument. In the case of
145 float2 above as an argument, parameter stack will be aligned to an 8-byte
146 boundary (if the sizes of other arguments are no greater than 8.)
147
1482. Calls from/to a separate compilation unit: (E.g., calls to Execution
149 Environment if those runtime library callees are not compiled using LLVM.)
150
151 On ARM, we use hardfp. Note that double will be placed in a register pair.