blob: c079bc53bc6d30c512fc995a400a7dafc2bc15b0 [file] [log] [blame]
Logan1f028c02010-11-27 01:02:48 +08001/*
2 * Copyright 2010, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Loganc4395232010-11-27 18:54:17 +080017#include "Compiler.h"
Logan1f028c02010-11-27 01:02:48 +080018
Logan35849002011-01-15 07:30:43 +080019#include "Config.h"
20
Loganeb3d12b2010-12-16 06:20:18 +080021#include "ContextManager.h"
Logan4dcd6792011-02-28 05:12:00 +080022#include "DebugHelper.h"
Shih-wei Liao6c0c7b02011-05-21 21:47:14 -070023#include "FileHandle.h"
Logan Chienda5e0c32011-06-13 03:47:21 +080024#include "Runtime.h"
Logan2a6dc822011-01-06 04:05:20 +080025#include "ScriptCompiled.h"
Logan75cc8a52011-01-07 06:06:52 +080026#include "Sha1Helper.h"
Loganeb3d12b2010-12-16 06:20:18 +080027
Logan Chienda5e0c32011-06-13 03:47:21 +080028#include "librsloader.h"
29
Logandf23afa2010-11-27 11:04:54 +080030#include "llvm/ADT/StringRef.h"
Logan1f028c02010-11-27 01:02:48 +080031
Logandf23afa2010-11-27 11:04:54 +080032#include "llvm/Analysis/Passes.h"
Logan1f028c02010-11-27 01:02:48 +080033
Logan1f028c02010-11-27 01:02:48 +080034#include "llvm/Bitcode/ReaderWriter.h"
35
Logan1f028c02010-11-27 01:02:48 +080036#include "llvm/CodeGen/Passes.h"
Logan1f028c02010-11-27 01:02:48 +080037#include "llvm/CodeGen/RegAllocRegistry.h"
38#include "llvm/CodeGen/SchedulerRegistry.h"
Logan1f028c02010-11-27 01:02:48 +080039
Logandf23afa2010-11-27 11:04:54 +080040#include "llvm/Transforms/IPO.h"
41#include "llvm/Transforms/Scalar.h"
42
43#include "llvm/Target/SubtargetFeature.h"
44#include "llvm/Target/TargetData.h"
45#include "llvm/Target/TargetMachine.h"
46#include "llvm/Target/TargetOptions.h"
47#include "llvm/Target/TargetRegistry.h"
48#include "llvm/Target/TargetSelect.h"
49
Shih-wei Liao90cd3d12011-06-20 15:43:34 -070050#if USE_DISASSEMBLER
51#include "llvm/MC/MCAsmInfo.h"
52#include "llvm/MC/MCDisassembler.h"
53#include "llvm/MC/MCInst.h"
54#include "llvm/MC/MCInstPrinter.h"
55#include "llvm/Support/MemoryObject.h"
56#include "llvm/LLVMContext.h"
57#endif
58
Logandf23afa2010-11-27 11:04:54 +080059#include "llvm/Support/ErrorHandling.h"
Shih-wei Liao898c5a92011-05-18 07:02:39 -070060#include "llvm/Support/FormattedStream.h"
Logandf23afa2010-11-27 11:04:54 +080061#include "llvm/Support/MemoryBuffer.h"
62
Shih-wei Liao90cd3d12011-06-20 15:43:34 -070063#include "llvm/Type.h"
Logandf23afa2010-11-27 11:04:54 +080064#include "llvm/GlobalValue.h"
65#include "llvm/Linker.h"
66#include "llvm/LLVMContext.h"
67#include "llvm/Metadata.h"
68#include "llvm/Module.h"
69#include "llvm/PassManager.h"
70#include "llvm/Value.h"
71
72#include <errno.h>
73#include <sys/file.h>
Logandf23afa2010-11-27 11:04:54 +080074#include <sys/stat.h>
75#include <sys/types.h>
76#include <unistd.h>
77
Logan75cc8a52011-01-07 06:06:52 +080078#include <string.h>
Logan8b77a772010-12-21 09:11:01 +080079
Logandf23afa2010-11-27 11:04:54 +080080#include <string>
81#include <vector>
Logan1f028c02010-11-27 01:02:48 +080082
Shih-wei Liao90cd3d12011-06-20 15:43:34 -070083namespace {
84
85#if USE_DISASSEMBLER
86class BufferMemoryObject : public llvm::MemoryObject {
87private:
88 const uint8_t *mBytes;
89 uint64_t mLength;
90
91public:
92 BufferMemoryObject(const uint8_t *Bytes, uint64_t Length)
93 : mBytes(Bytes), mLength(Length) {
94 }
95
96 virtual uint64_t getBase() const { return 0; }
97 virtual uint64_t getExtent() const { return mLength; }
98
99 virtual int readByte(uint64_t Addr, uint8_t *Byte) const {
100 if (Addr > getExtent())
101 return -1;
102 *Byte = mBytes[Addr];
103 return 0;
104 }
105};
106#endif
107
108}; // namespace anonymous
109
110#define DEBUG_MCJIT REFLECT 0
111#define DEBUG_MCJIT_DISASSEMBLE 1
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700112
Logan1f028c02010-11-27 01:02:48 +0800113namespace bcc {
114
115//////////////////////////////////////////////////////////////////////////////
116// BCC Compiler Static Variables
117//////////////////////////////////////////////////////////////////////////////
118
119bool Compiler::GlobalInitialized = false;
120
Logan1f028c02010-11-27 01:02:48 +0800121// Code generation optimization level for the compiler
122llvm::CodeGenOpt::Level Compiler::CodeGenOptLevel;
123
124std::string Compiler::Triple;
125
126std::string Compiler::CPU;
127
128std::vector<std::string> Compiler::Features;
129
Stephen Hines071288a2011-01-27 14:38:26 -0800130// Name of metadata node where pragma info resides (should be synced with
Logan1f028c02010-11-27 01:02:48 +0800131// slang.cpp)
132const llvm::StringRef Compiler::PragmaMetadataName = "#pragma";
133
Stephen Hines071288a2011-01-27 14:38:26 -0800134// Name of metadata node where exported variable names reside (should be
Logan1f028c02010-11-27 01:02:48 +0800135// synced with slang_rs_metadata.h)
136const llvm::StringRef Compiler::ExportVarMetadataName = "#rs_export_var";
137
Stephen Hines071288a2011-01-27 14:38:26 -0800138// Name of metadata node where exported function names reside (should be
Logan1f028c02010-11-27 01:02:48 +0800139// synced with slang_rs_metadata.h)
140const llvm::StringRef Compiler::ExportFuncMetadataName = "#rs_export_func";
141
Stephen Hines071288a2011-01-27 14:38:26 -0800142// Name of metadata node where RS object slot info resides (should be
143// synced with slang_rs_metadata.h)
144const llvm::StringRef Compiler::ObjectSlotMetadataName = "#rs_object_slots";
Logan1f028c02010-11-27 01:02:48 +0800145
146//////////////////////////////////////////////////////////////////////////////
147// Compiler
148//////////////////////////////////////////////////////////////////////////////
149
150void Compiler::GlobalInitialization() {
151 if (GlobalInitialized)
152 return;
153
Logane1323992011-01-12 04:47:13 +0800154 LOGI("LIBBCC BUILD: %s\n", libbcc_build_time);
Logan87066272010-12-29 00:34:32 +0800155
Logan1f028c02010-11-27 01:02:48 +0800156 // if (!llvm::llvm_is_multithreaded())
157 // llvm::llvm_start_multithreaded();
158
159 // Set Triple, CPU and Features here
160 Triple = TARGET_TRIPLE_STRING;
161
Logan1f028c02010-11-27 01:02:48 +0800162 Features.push_back("+vfp3");
163 Features.push_back("+d16");
164
Logan4fe966f2011-02-27 08:26:40 +0800165 // NOTE: Currently, we have to turn off the support for NEON explicitly.
166 // Since the ARMCodeEmitter.cpp is not ready for JITing NEON
167 // instructions.
168 Features.push_back("-neon"); // TODO(sliao): NEON for JIT
169 Features.push_back("-neonfp");
170 Features.push_back("-vmlx");
171
Logan1f028c02010-11-27 01:02:48 +0800172#if defined(DEFAULT_ARM_CODEGEN) || defined(PROVIDE_ARM_CODEGEN)
173 LLVMInitializeARMTargetInfo();
174 LLVMInitializeARMTarget();
Logan35849002011-01-15 07:30:43 +0800175#if USE_DISASSEMBLER
Logan1f028c02010-11-27 01:02:48 +0800176 LLVMInitializeARMDisassembler();
177 LLVMInitializeARMAsmPrinter();
178#endif
179#endif
180
181#if defined(DEFAULT_X86_CODEGEN) || defined(PROVIDE_X86_CODEGEN)
182 LLVMInitializeX86TargetInfo();
183 LLVMInitializeX86Target();
Logan35849002011-01-15 07:30:43 +0800184#if USE_DISASSEMBLER
Logan1f028c02010-11-27 01:02:48 +0800185 LLVMInitializeX86Disassembler();
186 LLVMInitializeX86AsmPrinter();
187#endif
188#endif
189
190#if defined(DEFAULT_X64_CODEGEN) || defined(PROVIDE_X64_CODEGEN)
191 LLVMInitializeX86TargetInfo();
192 LLVMInitializeX86Target();
Logan35849002011-01-15 07:30:43 +0800193#if USE_DISASSEMBLER
Logan1f028c02010-11-27 01:02:48 +0800194 LLVMInitializeX86Disassembler();
195 LLVMInitializeX86AsmPrinter();
196#endif
197#endif
198
199 // -O0: llvm::CodeGenOpt::None
200 // -O1: llvm::CodeGenOpt::Less
201 // -O2: llvm::CodeGenOpt::Default
202 // -O3: llvm::CodeGenOpt::Aggressive
Shih-wei Liao72f67a62010-12-14 13:36:15 -0800203 CodeGenOptLevel = llvm::CodeGenOpt::Aggressive;
Logan1f028c02010-11-27 01:02:48 +0800204
205 // Below are the global settings to LLVM
206
207 // Disable frame pointer elimination optimization
208 llvm::NoFramePointerElim = false;
209
210 // Use hardfloat ABI
211 //
212 // TODO(all): Need to detect the CPU capability and decide whether to use
213 // softfp. To use softfp, change following 2 lines to
214 //
215 // llvm::FloatABIType = llvm::FloatABI::Soft;
216 // llvm::UseSoftFloat = true;
217 //
Shih-wei Liaoe728cb82010-12-15 15:20:47 -0800218 llvm::FloatABIType = llvm::FloatABI::Soft;
Logan1f028c02010-11-27 01:02:48 +0800219 llvm::UseSoftFloat = false;
220
221 // BCC needs all unknown symbols resolved at JIT/compilation time.
222 // So we don't need any dynamic relocation model.
223 llvm::TargetMachine::setRelocationModel(llvm::Reloc::Static);
224
225#if defined(DEFAULT_X64_CODEGEN)
226 // Data address in X86_64 architecture may reside in a far-away place
227 llvm::TargetMachine::setCodeModel(llvm::CodeModel::Medium);
228#else
229 // This is set for the linker (specify how large of the virtual addresses
230 // we can access for all unknown symbols.)
231 llvm::TargetMachine::setCodeModel(llvm::CodeModel::Small);
232#endif
233
234 // Register the scheduler
235 llvm::RegisterScheduler::setDefault(llvm::createDefaultScheduler);
236
237 // Register allocation policy:
238 // createFastRegisterAllocator: fast but bad quality
239 // createLinearScanRegisterAllocator: not so fast but good quality
240 llvm::RegisterRegAlloc::setDefault
241 ((CodeGenOptLevel == llvm::CodeGenOpt::None) ?
242 llvm::createFastRegisterAllocator :
243 llvm::createLinearScanRegisterAllocator);
244
Logan35849002011-01-15 07:30:43 +0800245#if USE_CACHE
Logan75cc8a52011-01-07 06:06:52 +0800246 // Calculate the SHA1 checksum of libbcc and libRS.
Logan35849002011-01-15 07:30:43 +0800247#if USE_LIBBCC_SHA1SUM
Logan75cc8a52011-01-07 06:06:52 +0800248 calcFileSHA1(sha1LibBCC, pathLibBCC);
Logane1323992011-01-12 04:47:13 +0800249#endif
Logan75cc8a52011-01-07 06:06:52 +0800250 calcFileSHA1(sha1LibRS, pathLibRS);
Logan35849002011-01-15 07:30:43 +0800251#endif
Logan75cc8a52011-01-07 06:06:52 +0800252
Logan1f028c02010-11-27 01:02:48 +0800253 GlobalInitialized = true;
254}
255
256
257void Compiler::LLVMErrorHandler(void *UserData, const std::string &Message) {
258 std::string *Error = static_cast<std::string*>(UserData);
259 Error->assign(Message);
260 LOGE("%s", Message.c_str());
261 exit(1);
262}
263
264
Logan Chienda5e0c32011-06-13 03:47:21 +0800265#if USE_OLD_JIT
Logan1f028c02010-11-27 01:02:48 +0800266CodeMemoryManager *Compiler::createCodeMemoryManager() {
267 mCodeMemMgr.reset(new CodeMemoryManager());
268 return mCodeMemMgr.get();
269}
Logan Chienda5e0c32011-06-13 03:47:21 +0800270#endif
Logan1f028c02010-11-27 01:02:48 +0800271
272
Logan Chienda5e0c32011-06-13 03:47:21 +0800273#if USE_OLD_JIT
Logan1f028c02010-11-27 01:02:48 +0800274CodeEmitter *Compiler::createCodeEmitter() {
Logan7dcaac92011-01-06 04:26:23 +0800275 mCodeEmitter.reset(new CodeEmitter(mpResult, mCodeMemMgr.get()));
Logan1f028c02010-11-27 01:02:48 +0800276 return mCodeEmitter.get();
277}
Logan Chienda5e0c32011-06-13 03:47:21 +0800278#endif
Logan1f028c02010-11-27 01:02:48 +0800279
280
Logan2a6dc822011-01-06 04:05:20 +0800281Compiler::Compiler(ScriptCompiled *result)
282 : mpResult(result),
Logan Chienda5e0c32011-06-13 03:47:21 +0800283#if USE_MCJIT
284 mRSExecutable(NULL),
285#endif
Logan1f028c02010-11-27 01:02:48 +0800286 mpSymbolLookupFn(NULL),
287 mpSymbolLookupContext(NULL),
288 mContext(NULL),
289 mModule(NULL),
290 mHasLinked(false) /* Turn off linker */ {
291 llvm::remove_fatal_error_handler();
292 llvm::install_fatal_error_handler(LLVMErrorHandler, &mError);
293 mContext = new llvm::LLVMContext();
294 return;
295}
296
Logan1f028c02010-11-27 01:02:48 +0800297
Logan Chienda5e0c32011-06-13 03:47:21 +0800298#if USE_MCJIT
Shih-wei Liao5c00f4f2011-05-20 04:14:54 -0700299// input objPath: For example,
300// /data/user/0/com.example.android.rs.fountain/cache/
301// @com.example.android.rs.fountain:raw@fountain.oBCC
302// output objPath: /data/user/0/com.example.android.rs.fountain/cache/
303// fountain.o
Shih-wei Liaode0ba062011-05-19 03:16:33 -0700304//
305bool Compiler::getObjPath(std::string &objPath) {
Shih-wei Liao5c00f4f2011-05-20 04:14:54 -0700306 size_t found0 = objPath.find("@");
307 size_t found1 = objPath.rfind("@");
308
309 if (found0 == found1 ||
Nowar Gu09b6c1c2011-05-24 23:49:07 +0800310 found0 == std::string::npos ||
311 found1 == std::string::npos) {
Shih-wei Liao5c00f4f2011-05-20 04:14:54 -0700312 LOGE("Ill formatted resource name '%s'. The name should contain 2 @s",
Shih-wei Liaode0ba062011-05-19 03:16:33 -0700313 objPath.c_str());
314 return false;
Shih-wei Liao898c5a92011-05-18 07:02:39 -0700315 }
316
Shih-wei Liao5c00f4f2011-05-20 04:14:54 -0700317 objPath.replace(found0, found1 - found0 + 1, "", 0);
318 objPath.resize(objPath.length() - 3);
Shih-wei Liao898c5a92011-05-18 07:02:39 -0700319
Shih-wei Liaode0ba062011-05-19 03:16:33 -0700320 LOGV("objPath = %s", objPath.c_str());
321 return true;
Shih-wei Liao898c5a92011-05-18 07:02:39 -0700322}
Logan Chienda5e0c32011-06-13 03:47:21 +0800323#endif
Shih-wei Liao898c5a92011-05-18 07:02:39 -0700324
325
Logan474cbd22011-01-31 01:47:44 +0800326llvm::Module *Compiler::parseBitcodeFile(llvm::MemoryBuffer *MEM) {
327 llvm::Module *result = llvm::ParseBitcodeFile(MEM, *mContext, &mError);
Logan1f028c02010-11-27 01:02:48 +0800328
Logan474cbd22011-01-31 01:47:44 +0800329 if (!result) {
330 LOGE("Unable to ParseBitcodeFile: %s\n", mError.c_str());
331 return NULL;
Logan1f028c02010-11-27 01:02:48 +0800332 }
333
Logan474cbd22011-01-31 01:47:44 +0800334 return result;
Logan1f028c02010-11-27 01:02:48 +0800335}
336
337
Logan474cbd22011-01-31 01:47:44 +0800338int Compiler::linkModule(llvm::Module *moduleWith) {
339 if (llvm::Linker::LinkModules(mModule, moduleWith, &mError) != 0) {
Logan1f028c02010-11-27 01:02:48 +0800340 return hasError();
341 }
342
Logan1f028c02010-11-27 01:02:48 +0800343 // Everything for linking should be settled down here with no error occurs
344 mHasLinked = true;
345 return hasError();
346}
347
348
Logan1f028c02010-11-27 01:02:48 +0800349int Compiler::compile() {
Logan Chienda5e0c32011-06-13 03:47:21 +0800350 llvm::Target const *Target = NULL;
Logan1f028c02010-11-27 01:02:48 +0800351 llvm::TargetData *TD = NULL;
Logan1f028c02010-11-27 01:02:48 +0800352 llvm::TargetMachine *TM = NULL;
Logan Chienda5e0c32011-06-13 03:47:21 +0800353
Logan1f028c02010-11-27 01:02:48 +0800354 std::string FeaturesStr;
355
Logan Chienda5e0c32011-06-13 03:47:21 +0800356 llvm::NamedMDNode const *PragmaMetadata;
357 llvm::NamedMDNode const *ExportVarMetadata;
358 llvm::NamedMDNode const *ExportFuncMetadata;
359 llvm::NamedMDNode const *ObjectSlotMetadata;
Logan1f028c02010-11-27 01:02:48 +0800360
Logan1f028c02010-11-27 01:02:48 +0800361 if (mModule == NULL) // No module was loaded
362 return 0;
363
364 // Create TargetMachine
365 Target = llvm::TargetRegistry::lookupTarget(Triple, mError);
366 if (hasError())
367 goto on_bcc_compile_error;
368
369 if (!CPU.empty() || !Features.empty()) {
370 llvm::SubtargetFeatures F;
371 F.setCPU(CPU);
Logana4994f52010-11-27 14:06:02 +0800372
373 for (std::vector<std::string>::const_iterator
374 I = Features.begin(), E = Features.end(); I != E; I++) {
Logan1f028c02010-11-27 01:02:48 +0800375 F.AddFeature(*I);
Logana4994f52010-11-27 14:06:02 +0800376 }
377
Logan1f028c02010-11-27 01:02:48 +0800378 FeaturesStr = F.getString();
379 }
380
381 TM = Target->createTargetMachine(Triple, FeaturesStr);
382 if (TM == NULL) {
383 setError("Failed to create target machine implementation for the"
384 " specified triple '" + Triple + "'");
385 goto on_bcc_compile_error;
386 }
387
Logan Chienda5e0c32011-06-13 03:47:21 +0800388 // Get target data from Module
389 TD = new llvm::TargetData(mModule);
390
391 // Load named metadata
392 ExportVarMetadata = mModule->getNamedMetadata(ExportVarMetadataName);
393 ExportFuncMetadata = mModule->getNamedMetadata(ExportFuncMetadataName);
394 PragmaMetadata = mModule->getNamedMetadata(PragmaMetadataName);
395 ObjectSlotMetadata = mModule->getNamedMetadata(ObjectSlotMetadataName);
396
397 // Perform link-time optimization if we have multiple modules
398 if (mHasLinked) {
399 runLTO(new llvm::TargetData(*TD), ExportVarMetadata, ExportFuncMetadata);
400 }
401
402 // Perform code generation
403#if USE_OLD_JIT
404 if (runCodeGen(new llvm::TargetData(*TD), TM,
405 ExportVarMetadata, ExportFuncMetadata) != 0) {
406 goto on_bcc_compile_error;
407 }
408#endif
409
410#if USE_MCJIT
411 if (runMCCodeGen(new llvm::TargetData(*TD), TM,
412 ExportVarMetadata, ExportFuncMetadata) != 0) {
413 goto on_bcc_compile_error;
414 }
Shih-wei Liao90cd3d12011-06-20 15:43:34 -0700415#if USE_DISASSEMBLER && DEBUG_MCJIT_DISASSEMBLE
416 {
417 llvm::LLVMContext Ctx;
418 LOGD("@ long long alignment: %d\n", TD->getABITypeAlignment((llvm::Type const *)llvm::Type::getInt64Ty(Ctx)));
Shih-wei Liaoe2019762011-06-20 16:04:09 -0700419 char const *func_list[] = { "root", "lookAt" };
Shih-wei Liao90cd3d12011-06-20 15:43:34 -0700420 size_t func_list_size = sizeof(func_list) / sizeof(char const *);
421
422 for (size_t i = 0; i < func_list_size; ++i) {
423 void *func = rsloaderGetSymbolAddress(mRSExecutable, func_list[i]);
424 if (func) {
425 size_t size = rsloaderGetSymbolSize(mRSExecutable, func_list[i]);
426 Disassemble(Target, TM, func_list[i], (unsigned char const *)func, size);
427 }
428 }
429 }
430#endif
Logan Chienda5e0c32011-06-13 03:47:21 +0800431#endif
432
433 // Read pragma information from the metadata node of the module.
434 if (PragmaMetadata) {
435 ScriptCompiled::PragmaList &pragmaList = mpResult->mPragmas;
436
437 for (int i = 0, e = PragmaMetadata->getNumOperands(); i != e; i++) {
438 llvm::MDNode *Pragma = PragmaMetadata->getOperand(i);
439 if (Pragma != NULL &&
440 Pragma->getNumOperands() == 2 /* should have exactly 2 operands */) {
441 llvm::Value *PragmaNameMDS = Pragma->getOperand(0);
442 llvm::Value *PragmaValueMDS = Pragma->getOperand(1);
443
444 if ((PragmaNameMDS->getValueID() == llvm::Value::MDStringVal) &&
445 (PragmaValueMDS->getValueID() == llvm::Value::MDStringVal)) {
446 llvm::StringRef PragmaName =
447 static_cast<llvm::MDString*>(PragmaNameMDS)->getString();
448 llvm::StringRef PragmaValue =
449 static_cast<llvm::MDString*>(PragmaValueMDS)->getString();
450
451 pragmaList.push_back(
452 std::make_pair(std::string(PragmaName.data(),
453 PragmaName.size()),
454 std::string(PragmaValue.data(),
455 PragmaValue.size())));
Shih-wei Liao90cd3d12011-06-20 15:43:34 -0700456#if DEBUG_MCJIT_REFLECT
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700457 LOGD("compile(): Pragma: %s -> %s\n", pragmaList.back().first.c_str(),
Logan Chien7d1bf582011-06-13 23:22:40 +0800458 pragmaList.back().second.c_str());
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700459#endif
Logan Chienda5e0c32011-06-13 03:47:21 +0800460 }
461 }
462 }
Logan Chienda5e0c32011-06-13 03:47:21 +0800463 }
464
465 if (ObjectSlotMetadata) {
466 ScriptCompiled::ObjectSlotList &objectSlotList = mpResult->mObjectSlots;
467
468 for (int i = 0, e = ObjectSlotMetadata->getNumOperands(); i != e; i++) {
469 llvm::MDNode *ObjectSlot = ObjectSlotMetadata->getOperand(i);
470 if (ObjectSlot != NULL &&
471 ObjectSlot->getNumOperands() == 1) {
472 llvm::Value *SlotMDS = ObjectSlot->getOperand(0);
473 if (SlotMDS->getValueID() == llvm::Value::MDStringVal) {
474 llvm::StringRef Slot =
475 static_cast<llvm::MDString*>(SlotMDS)->getString();
476 uint32_t USlot = 0;
477 if (Slot.getAsInteger(10, USlot)) {
478 setError("Non-integer object slot value '" + Slot.str() + "'");
479 goto on_bcc_compile_error;
480 }
481 objectSlotList.push_back(USlot);
Shih-wei Liao90cd3d12011-06-20 15:43:34 -0700482#if DEBUG_MCJIT_REFLECT
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700483 LOGD("compile(): RefCount Slot: %s @ %u\n", Slot.str().c_str(), USlot);
484#endif
Logan Chienda5e0c32011-06-13 03:47:21 +0800485 }
486 }
487 }
Logan Chienda5e0c32011-06-13 03:47:21 +0800488 }
489
490on_bcc_compile_error:
491 // LOGE("on_bcc_compiler_error");
492 if (TD) {
493 delete TD;
494 }
495
496 if (TM) {
497 delete TM;
498 }
499
500 if (mError.empty()) {
501 return 0;
502 }
503
504 // LOGE(getErrorMessage());
505 return 1;
506}
507
508
509#if USE_OLD_JIT
510int Compiler::runCodeGen(llvm::TargetData *TD, llvm::TargetMachine *TM,
511 llvm::NamedMDNode const *ExportVarMetadata,
512 llvm::NamedMDNode const *ExportFuncMetadata) {
Logan1f028c02010-11-27 01:02:48 +0800513 // Create memory manager for creation of code emitter later.
514 if (!mCodeMemMgr.get() && !createCodeMemoryManager()) {
515 setError("Failed to startup memory management for further compilation");
Logan Chienda5e0c32011-06-13 03:47:21 +0800516 return 1;
Logan1f028c02010-11-27 01:02:48 +0800517 }
Logan02286cb2011-01-07 00:30:47 +0800518
519 mpResult->mContext = (char *) (mCodeMemMgr.get()->getCodeMemBase());
Logan1f028c02010-11-27 01:02:48 +0800520
521 // Create code emitter
522 if (!mCodeEmitter.get()) {
523 if (!createCodeEmitter()) {
Logan Chienda5e0c32011-06-13 03:47:21 +0800524 setError("Failed to create machine code emitter for compilation");
525 return 1;
Logan1f028c02010-11-27 01:02:48 +0800526 }
527 } else {
528 // Reuse the code emitter
529 mCodeEmitter->reset();
530 }
531
532 mCodeEmitter->setTargetMachine(*TM);
533 mCodeEmitter->registerSymbolCallback(mpSymbolLookupFn,
534 mpSymbolLookupContext);
535
Logan1f028c02010-11-27 01:02:48 +0800536 // Create code-gen pass to run the code emitter
Logan Chienda5e0c32011-06-13 03:47:21 +0800537 llvm::OwningPtr<llvm::FunctionPassManager> CodeGenPasses(
538 new llvm::FunctionPassManager(mModule));
Logan1f028c02010-11-27 01:02:48 +0800539
Logan Chienda5e0c32011-06-13 03:47:21 +0800540 // Add TargetData to code generation pass manager
541 CodeGenPasses->add(TD);
542
543 // Add code emit passes
Logan1f028c02010-11-27 01:02:48 +0800544 if (TM->addPassesToEmitMachineCode(*CodeGenPasses,
545 *mCodeEmitter,
546 CodeGenOptLevel)) {
Logan Chienda5e0c32011-06-13 03:47:21 +0800547 setError("The machine code emission is not supported on '" + Triple + "'");
548 return 1;
Logan1f028c02010-11-27 01:02:48 +0800549 }
550
Logan Chienda5e0c32011-06-13 03:47:21 +0800551 // Run the code emitter on every non-declaration function in the module
Logan1f028c02010-11-27 01:02:48 +0800552 CodeGenPasses->doInitialization();
Logan Chienda5e0c32011-06-13 03:47:21 +0800553 for (llvm::Module::iterator
554 I = mModule->begin(), E = mModule->end(); I != E; I++) {
Logan1f028c02010-11-27 01:02:48 +0800555 if (!I->isDeclaration()) {
556 CodeGenPasses->run(*I);
557 }
558 }
559
560 CodeGenPasses->doFinalization();
Logan Chienb0ceca22011-06-12 13:34:49 +0800561
Logan1f028c02010-11-27 01:02:48 +0800562 // Copy the global address mapping from code emitter and remapping
563 if (ExportVarMetadata) {
Logan2a6dc822011-01-06 04:05:20 +0800564 ScriptCompiled::ExportVarList &varList = mpResult->mExportVars;
565
Logan1f028c02010-11-27 01:02:48 +0800566 for (int i = 0, e = ExportVarMetadata->getNumOperands(); i != e; i++) {
567 llvm::MDNode *ExportVar = ExportVarMetadata->getOperand(i);
568 if (ExportVar != NULL && ExportVar->getNumOperands() > 1) {
569 llvm::Value *ExportVarNameMDS = ExportVar->getOperand(0);
570 if (ExportVarNameMDS->getValueID() == llvm::Value::MDStringVal) {
571 llvm::StringRef ExportVarName =
572 static_cast<llvm::MDString*>(ExportVarNameMDS)->getString();
573
574 CodeEmitter::global_addresses_const_iterator I, E;
575 for (I = mCodeEmitter->global_address_begin(),
576 E = mCodeEmitter->global_address_end();
577 I != E; I++) {
578 if (I->first->getValueID() != llvm::Value::GlobalVariableVal)
579 continue;
580 if (ExportVarName == I->first->getName()) {
Logan2a6dc822011-01-06 04:05:20 +0800581 varList.push_back(I->second);
Shih-wei Liao90cd3d12011-06-20 15:43:34 -0700582#if DEBUG_MCJIT_REFLECT
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700583 LOGD("runCodeGen(): Exported VAR: %s @ %p\n", ExportVarName.str().c_str(), I->second);
584#endif
Logan1f028c02010-11-27 01:02:48 +0800585 break;
586 }
587 }
588 if (I != mCodeEmitter->global_address_end())
589 continue; // found
Logan Chien7d1bf582011-06-13 23:22:40 +0800590
Shih-wei Liao90cd3d12011-06-20 15:43:34 -0700591#if DEBUG_MCJIT_REFLECT
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700592 LOGD("runCodeGen(): Exported VAR: %s @ %p\n",
Logan Chien7d1bf582011-06-13 23:22:40 +0800593 ExportVarName.str().c_str(), (void *)0);
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700594#endif
Logan1f028c02010-11-27 01:02:48 +0800595 }
596 }
597 // if reaching here, we know the global variable record in metadata is
598 // not found. So we make an empty slot
Logan2a6dc822011-01-06 04:05:20 +0800599 varList.push_back(NULL);
Logan1f028c02010-11-27 01:02:48 +0800600 }
Logan2a6dc822011-01-06 04:05:20 +0800601
Stephen Hinesbbcef8a2011-05-04 19:40:10 -0700602 bccAssert((varList.size() == ExportVarMetadata->getNumOperands()) &&
603 "Number of slots doesn't match the number of export variables!");
Logan1f028c02010-11-27 01:02:48 +0800604 }
605
606 if (ExportFuncMetadata) {
Logan2a6dc822011-01-06 04:05:20 +0800607 ScriptCompiled::ExportFuncList &funcList = mpResult->mExportFuncs;
608
Logan1f028c02010-11-27 01:02:48 +0800609 for (int i = 0, e = ExportFuncMetadata->getNumOperands(); i != e; i++) {
610 llvm::MDNode *ExportFunc = ExportFuncMetadata->getOperand(i);
611 if (ExportFunc != NULL && ExportFunc->getNumOperands() > 0) {
612 llvm::Value *ExportFuncNameMDS = ExportFunc->getOperand(0);
613 if (ExportFuncNameMDS->getValueID() == llvm::Value::MDStringVal) {
614 llvm::StringRef ExportFuncName =
615 static_cast<llvm::MDString*>(ExportFuncNameMDS)->getString();
Logan7dcaac92011-01-06 04:26:23 +0800616 funcList.push_back(mpResult->lookup(ExportFuncName.str().c_str()));
Shih-wei Liao90cd3d12011-06-20 15:43:34 -0700617#if DEBUG_MCJIT_REFLECT
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700618 LOGD("runCodeGen(): Exported Func: %s @ %p\n", ExportFuncName.str().c_str(),
Logan Chien7d1bf582011-06-13 23:22:40 +0800619 funcList.back());
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700620#endif
Logan1f028c02010-11-27 01:02:48 +0800621 }
622 }
623 }
624 }
625
626 // Tell code emitter now can release the memory using during the JIT since
627 // we have done the code emission
628 mCodeEmitter->releaseUnnecessary();
629
Logan Chienda5e0c32011-06-13 03:47:21 +0800630 return 0;
Logan1f028c02010-11-27 01:02:48 +0800631}
Logan Chienda5e0c32011-06-13 03:47:21 +0800632#endif // USE_OLD_JIT
Logan1f028c02010-11-27 01:02:48 +0800633
634
Logan Chienda5e0c32011-06-13 03:47:21 +0800635#if USE_MCJIT
636int Compiler::runMCCodeGen(llvm::TargetData *TD, llvm::TargetMachine *TM,
637 llvm::NamedMDNode const *ExportVarMetadata,
638 llvm::NamedMDNode const *ExportFuncMetadata) {
639 // Decorate mEmittedELFExecutable with formatted ostream
640 llvm::raw_svector_ostream OutSVOS(mEmittedELFExecutable);
641
642 // Relax all machine instructions
643 TM->setMCRelaxAll(/* RelaxAll= */ true);
644
645 // Create MC code generation pass manager
646 llvm::PassManager MCCodeGenPasses;
647
648 // Add TargetData to MC code generation pass manager
649 MCCodeGenPasses.add(TD);
650
651 // Add MC code generation passes to pass manager
652 llvm::MCContext *Ctx;
653 if (TM->addPassesToEmitMC(MCCodeGenPasses, Ctx, OutSVOS,
654 CodeGenOptLevel, false)) {
655 setError("Fail to add passes to emit file");
656 return 1;
657 }
658
659 MCCodeGenPasses.run(*mModule);
660 OutSVOS.flush();
661
662 // Load the ELF Object
663 mRSExecutable =
664 rsloaderCreateExec((unsigned char *)&*mEmittedELFExecutable.begin(),
665 mEmittedELFExecutable.size(),
666 &resolveSymbolAdapter, this);
667
668 if (!mRSExecutable) {
669 setError("Fail to load emitted ELF relocatable file");
670 return 1;
671 }
672
673#if !USE_OLD_JIT
674 // Note: If old JIT is compiled then we prefer the old version instead of the
675 // new version.
676
677 if (ExportVarMetadata) {
678 ScriptCompiled::ExportVarList &varList = mpResult->mExportVars;
679
680 for (int i = 0, e = ExportVarMetadata->getNumOperands(); i != e; i++) {
681 llvm::MDNode *ExportVar = ExportVarMetadata->getOperand(i);
Logan Chien70dd9982011-06-13 23:21:39 +0800682 if (ExportVar != NULL && ExportVar->getNumOperands() > 1) {
683 llvm::Value *ExportVarNameMDS = ExportVar->getOperand(0);
684 if (ExportVarNameMDS->getValueID() == llvm::Value::MDStringVal) {
685 llvm::StringRef ExportVarName =
686 static_cast<llvm::MDString*>(ExportVarNameMDS)->getString();
687
688 varList.push_back(
689 rsloaderGetSymbolAddress(mRSExecutable,
690 ExportVarName.str().c_str()));
Shih-wei Liao90cd3d12011-06-20 15:43:34 -0700691#if DEBUG_MCJIT_REFLECT
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700692 LOGD("runMCCodeGen(): Exported Var: %s @ %p\n", ExportVarName.str().c_str(),
Logan Chien70dd9982011-06-13 23:21:39 +0800693 varList.back());
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700694#endif
Logan Chien70dd9982011-06-13 23:21:39 +0800695 continue;
696 }
Logan Chienda5e0c32011-06-13 03:47:21 +0800697 }
698
Logan Chien70dd9982011-06-13 23:21:39 +0800699 varList.push_back(NULL);
Logan Chienda5e0c32011-06-13 03:47:21 +0800700 }
701 }
702
703 if (ExportFuncMetadata) {
704 ScriptCompiled::ExportFuncList &funcList = mpResult->mExportFuncs;
705
706 for (int i = 0, e = ExportFuncMetadata->getNumOperands(); i != e; i++) {
707 llvm::MDNode *ExportFunc = ExportFuncMetadata->getOperand(i);
708 if (ExportFunc != NULL && ExportFunc->getNumOperands() > 0) {
709 llvm::Value *ExportFuncNameMDS = ExportFunc->getOperand(0);
710 if (ExportFuncNameMDS->getValueID() == llvm::Value::MDStringVal) {
711 llvm::StringRef ExportFuncName =
712 static_cast<llvm::MDString*>(ExportFuncNameMDS)->getString();
713
714 funcList.push_back(
715 rsloaderGetSymbolAddress(mRSExecutable,
716 ExportFuncName.str().c_str()));
Shih-wei Liao90cd3d12011-06-20 15:43:34 -0700717#if DEBUG_MCJIT_RELECT
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700718 LOGD("runMCCodeGen(): Exported Func: %s @ %p\n", ExportFuncName.str().c_str(),
Logan Chien7d1bf582011-06-13 23:22:40 +0800719 funcList.back());
Shih-wei Liao749a51c2011-06-17 16:02:18 -0700720#endif
Logan Chienda5e0c32011-06-13 03:47:21 +0800721 }
722 }
723 }
724 }
725#endif // !USE_OLD_JIT
726
727#if USE_CACHE
728 // Write generated executable to file.
729 if (writeELFExecToFile() != 0) {
730 setError("Fail to write mcjit-ed executable to file");
731 return 1;
732 }
733#endif
734
735 return 0;
736}
737#endif // USE_MCJIT
738
739
740int Compiler::runLTO(llvm::TargetData *TD,
741 llvm::NamedMDNode const *ExportVarMetadata,
742 llvm::NamedMDNode const *ExportFuncMetadata) {
Logan Chien4cc00332011-06-12 14:00:46 +0800743 llvm::PassManager LTOPasses;
744
745 // Add TargetData to LTO passes
746 LTOPasses.add(TD);
747
748 // Collect All Exported Symbols
749 std::vector<const char*> ExportSymbols;
750
751 // Note: This is a workaround for getting export variable and function name.
752 // We should refine it soon.
753 if (ExportVarMetadata) {
754 for (int i = 0, e = ExportVarMetadata->getNumOperands(); i != e; i++) {
755 llvm::MDNode *ExportVar = ExportVarMetadata->getOperand(i);
756 if (ExportVar != NULL && ExportVar->getNumOperands() > 1) {
757 llvm::Value *ExportVarNameMDS = ExportVar->getOperand(0);
758 if (ExportVarNameMDS->getValueID() == llvm::Value::MDStringVal) {
759 llvm::StringRef ExportVarName =
760 static_cast<llvm::MDString*>(ExportVarNameMDS)->getString();
761 ExportSymbols.push_back(ExportVarName.data());
762 }
763 }
764 }
765 }
766
767 if (ExportFuncMetadata) {
768 for (int i = 0, e = ExportFuncMetadata->getNumOperands(); i != e; i++) {
769 llvm::MDNode *ExportFunc = ExportFuncMetadata->getOperand(i);
770 if (ExportFunc != NULL && ExportFunc->getNumOperands() > 0) {
771 llvm::Value *ExportFuncNameMDS = ExportFunc->getOperand(0);
772 if (ExportFuncNameMDS->getValueID() == llvm::Value::MDStringVal) {
773 llvm::StringRef ExportFuncName =
774 static_cast<llvm::MDString*>(ExportFuncNameMDS)->getString();
775 ExportSymbols.push_back(ExportFuncName.data());
776 }
777 }
778 }
779 }
780
781 // root() and init() are born to be exported
782 ExportSymbols.push_back("root");
783 ExportSymbols.push_back("init");
784
785 // We now create passes list performing LTO. These are copied from
786 // (including comments) llvm::createStandardLTOPasses().
787
788 // Internalize all other symbols not listed in ExportSymbols
789 LTOPasses.add(llvm::createInternalizePass(ExportSymbols));
790
791 // Propagate constants at call sites into the functions they call. This
792 // opens opportunities for globalopt (and inlining) by substituting
793 // function pointers passed as arguments to direct uses of functions.
794 LTOPasses.add(llvm::createIPSCCPPass());
795
796 // Now that we internalized some globals, see if we can hack on them!
797 LTOPasses.add(llvm::createGlobalOptimizerPass());
798
799 // Linking modules together can lead to duplicated global constants, only
800 // keep one copy of each constant...
801 LTOPasses.add(llvm::createConstantMergePass());
802
803 // Remove unused arguments from functions...
804 LTOPasses.add(llvm::createDeadArgEliminationPass());
805
806 // Reduce the code after globalopt and ipsccp. Both can open up
807 // significant simplification opportunities, and both can propagate
808 // functions through function pointers. When this happens, we often have
809 // to resolve varargs calls, etc, so let instcombine do this.
810 LTOPasses.add(llvm::createInstructionCombiningPass());
811
812 // Inline small functions
813 LTOPasses.add(llvm::createFunctionInliningPass());
814
815 // Remove dead EH info.
816 LTOPasses.add(llvm::createPruneEHPass());
817
818 // Internalize the globals again after inlining
819 LTOPasses.add(llvm::createGlobalOptimizerPass());
820
821 // Remove dead functions.
822 LTOPasses.add(llvm::createGlobalDCEPass());
823
824 // If we didn't decide to inline a function, check to see if we can
825 // transform it to pass arguments by value instead of by reference.
826 LTOPasses.add(llvm::createArgumentPromotionPass());
827
828 // The IPO passes may leave cruft around. Clean up after them.
829 LTOPasses.add(llvm::createInstructionCombiningPass());
830 LTOPasses.add(llvm::createJumpThreadingPass());
831
832 // Break up allocas
833 LTOPasses.add(llvm::createScalarReplAggregatesPass());
834
835 // Run a few AA driven optimizations here and now, to cleanup the code.
836 LTOPasses.add(llvm::createFunctionAttrsPass()); // Add nocapture.
837 LTOPasses.add(llvm::createGlobalsModRefPass()); // IP alias analysis.
838
839 // Hoist loop invariants.
840 LTOPasses.add(llvm::createLICMPass());
841
842 // Remove redundancies.
843 LTOPasses.add(llvm::createGVNPass());
844
845 // Remove dead memcpys.
846 LTOPasses.add(llvm::createMemCpyOptPass());
847
848 // Nuke dead stores.
849 LTOPasses.add(llvm::createDeadStoreEliminationPass());
850
851 // Cleanup and simplify the code after the scalar optimizations.
852 LTOPasses.add(llvm::createInstructionCombiningPass());
853
854 LTOPasses.add(llvm::createJumpThreadingPass());
855
856 // Delete basic blocks, which optimization passes may have killed.
857 LTOPasses.add(llvm::createCFGSimplificationPass());
858
859 // Now that we have optimized the program, discard unreachable functions.
860 LTOPasses.add(llvm::createGlobalDCEPass());
861
862 LTOPasses.run(*mModule);
Logan Chienda5e0c32011-06-13 03:47:21 +0800863
864 return 0;
Logan Chien4cc00332011-06-12 14:00:46 +0800865}
866
867
Logan Chienda5e0c32011-06-13 03:47:21 +0800868#if USE_MCJIT
869int Compiler::writeELFExecToFile() {
870 std::string objPath(mCachePath);
871 if (!getObjPath(objPath)) {
872 LOGE("Fail to create objPath");
873 return 1;
874 }
875
876 FileHandle file;
877
878 int Fd = file.open(objPath.c_str(), OpenMode::Write);
879 if (Fd < 0) {
880 LOGE("Fail to open file '%s'", objPath.c_str());
881 return 1;
882 }
883
884 file.write(&*mEmittedELFExecutable.begin(), mEmittedELFExecutable.size());
885
886 return 0;
887}
888#endif
889
890
891#if USE_MCJIT
892void *Compiler::getSymbolAddress(char const *name) {
893 return rsloaderGetSymbolAddress(mRSExecutable, name);
894}
895#endif
896
897
898#if USE_MCJIT
899void *Compiler::resolveSymbolAdapter(void *context, char const *name) {
900 Compiler *self = reinterpret_cast<Compiler *>(context);
901
902 if (void *Addr = FindRuntimeFunction(name)) {
903 return Addr;
904 }
905
906 if (self->mpSymbolLookupFn) {
907 if (void *Addr = self->mpSymbolLookupFn(self->mpSymbolLookupContext, name)) {
908 return Addr;
909 }
910 }
911
912 LOGE("Unable to resolve symbol: %s\n", name);
913 return NULL;
914}
915#endif
916
917
Logan1f028c02010-11-27 01:02:48 +0800918Compiler::~Compiler() {
Logan1f028c02010-11-27 01:02:48 +0800919 delete mModule;
Logan1f028c02010-11-27 01:02:48 +0800920 delete mContext;
Logana4994f52010-11-27 14:06:02 +0800921
Logan Chienda5e0c32011-06-13 03:47:21 +0800922#if USE_MCJIT
923 rsloaderDisposeExec(mRSExecutable);
924#endif
925
Logana4994f52010-11-27 14:06:02 +0800926 // llvm::llvm_shutdown();
Logan1f028c02010-11-27 01:02:48 +0800927}
928
Shih-wei Liao90cd3d12011-06-20 15:43:34 -0700929#if USE_MCJIT && USE_DISASSEMBLER
930void Compiler::Disassemble(llvm::Target const *Target,
931 llvm::TargetMachine *TM,
932 std::string const &Name,
933 unsigned char const *Func,
934 size_t FuncSize) {
935 llvm::raw_ostream *OS;
936
937#if USE_DISASSEMBLER_FILE
938 std::string ErrorInfo;
939 OS = new llvm::raw_fd_ostream("/data/local/tmp/mcjit-dis.s", ErrorInfo,
940 llvm::raw_fd_ostream::F_Append);
941
942 if (!ErrorInfo.empty()) { // some errors occurred
943 // LOGE("Error in creating disassembly file");
944 delete OS;
945 return;
946 }
947#else
948 OS = &llvm::outs();
949#endif
950
951 *OS << "MC/ Disassembled code: " << Name << "\n";
952
953 const llvm::MCAsmInfo *AsmInfo;
954 const llvm::MCDisassembler *Disassmbler;
955 llvm::MCInstPrinter *IP;
956
957 AsmInfo = Target->createAsmInfo(Compiler::Triple);
958 Disassmbler = Target->createMCDisassembler();
959 IP = Target->createMCInstPrinter(*TM,
960 AsmInfo->getAssemblerDialect(),
961 *AsmInfo);
962
963 const BufferMemoryObject *BufferMObj = new BufferMemoryObject(Func, FuncSize);
964
965 uint64_t Size;
966 uint64_t Index;
967
968 for (Index = 0; Index < FuncSize; Index += Size) {
969 llvm::MCInst Inst;
970
971 if (Disassmbler->getInstruction(Inst, Size, *BufferMObj, Index,
972 /* REMOVED */ llvm::nulls())) {
973 OS->indent(4);
974 OS->write("0x", 2);
975 OS->write_hex((uint32_t)Func + Index);
976 OS->write(": 0x", 4);
977 OS->write_hex(*(uint32_t *)(Func + Index));
978 IP->printInst(&Inst, *OS);
979 *OS << "\n";
980 } else {
981 if (Size == 0)
982 Size = 1; // skip illegible bytes
983 }
984 }
985
986 *OS << "\n";
987 delete BufferMObj;
988
989 delete AsmInfo;
990 delete Disassmbler;
991 delete IP;
992
993#if USE_DISASSEMBLER_FILE
994 // If you want the disassemble results write to file, uncomment this.
995 ((llvm::raw_fd_ostream*)OS)->close();
996 delete OS;
997#endif
998}
999#endif
1000
1001
Logan1f028c02010-11-27 01:02:48 +08001002} // namespace bcc