Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012, 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 | |
Jean-Luc Brouillet | a2dd52f | 2017-02-16 20:57:26 -0800 | [diff] [blame] | 17 | #include "bcc/Initialization.h" |
| 18 | |
| 19 | #include "Log.h" |
| 20 | #include "bcc/Config.h" |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 21 | |
| 22 | #include <cstdlib> |
| 23 | |
Tim Murray | c46a3f5 | 2015-01-08 14:52:15 -0800 | [diff] [blame] | 24 | #include <llvm/InitializePasses.h> |
| 25 | #include <llvm/PassRegistry.h> |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 26 | #include <llvm/Support/ErrorHandling.h> |
| 27 | #include <llvm/Support/TargetSelect.h> |
| 28 | |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 29 | namespace { |
| 30 | |
Stephen Hines | 86e4506 | 2013-05-06 16:23:18 -0700 | [diff] [blame] | 31 | void llvm_error_handler(void *pUserData, const std::string &pMessage, |
| 32 | bool pGenCrashDiag) { |
Stephen Hines | 5db508c | 2015-01-06 01:42:56 -0800 | [diff] [blame] | 33 | ALOGE("bcc: Internal Error - %s", pMessage.c_str()); |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 34 | ::exit(1); |
| 35 | } |
| 36 | |
| 37 | } // end anonymous namespace |
| 38 | |
| 39 | void bcc::init::Initialize() { |
| 40 | static bool is_initialized = false; |
| 41 | |
| 42 | if (is_initialized) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | // Setup error handler for LLVM. |
| 47 | llvm::remove_fatal_error_handler(); |
Chris Wailes | 900c6c1 | 2014-08-13 15:40:00 -0700 | [diff] [blame] | 48 | llvm::install_fatal_error_handler(llvm_error_handler, nullptr); |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 49 | |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 50 | |
Tim Murray | c46a3f5 | 2015-01-08 14:52:15 -0800 | [diff] [blame] | 51 | llvm::InitializeAllTargets(); |
| 52 | llvm::InitializeAllTargetMCs(); |
| 53 | llvm::InitializeAllAsmPrinters(); |
Stephen Hines | e1c7d29 | 2015-04-15 13:20:00 -0700 | [diff] [blame] | 54 | |
Tim Murray | c46a3f5 | 2015-01-08 14:52:15 -0800 | [diff] [blame] | 55 | llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry(); |
| 56 | llvm::initializeCore(Registry); |
Tim Murray | c46a3f5 | 2015-01-08 14:52:15 -0800 | [diff] [blame] | 57 | llvm::initializeScalarOpts(Registry); |
| 58 | llvm::initializeVectorization(Registry); |
| 59 | llvm::initializeIPO(Registry); |
| 60 | llvm::initializeAnalysis(Registry); |
Tim Murray | c46a3f5 | 2015-01-08 14:52:15 -0800 | [diff] [blame] | 61 | llvm::initializeTransformUtils(Registry); |
| 62 | llvm::initializeInstCombine(Registry); |
| 63 | llvm::initializeInstrumentation(Registry); |
| 64 | llvm::initializeTarget(Registry); |
| 65 | llvm::initializeCodeGenPreparePass(Registry); |
| 66 | llvm::initializeAtomicExpandPass(Registry); |
| 67 | llvm::initializeRewriteSymbolsPass(Registry); |
Tim Murray | c2074ca | 2014-04-08 15:39:08 -0700 | [diff] [blame] | 68 | |
Zonr Chang | f74ee19 | 2012-04-12 15:34:58 +0800 | [diff] [blame] | 69 | is_initialized = true; |
| 70 | |
| 71 | return; |
| 72 | } |