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 17#include "bcc/Initialization.h" 18 19#include "Log.h" 20#include "bcc/Config.h" 21 22#include <cstdlib> 23 24#include <llvm/InitializePasses.h> 25#include <llvm/PassRegistry.h> 26#include <llvm/Support/ErrorHandling.h> 27#include <llvm/Support/TargetSelect.h> 28 29namespace { 30 31void llvm_error_handler(void *pUserData, const std::string &pMessage, 32 bool pGenCrashDiag) { 33 ALOGE("bcc: Internal Error - %s", pMessage.c_str()); 34 ::exit(1); 35} 36 37} // end anonymous namespace 38 39void 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(); 48 llvm::install_fatal_error_handler(llvm_error_handler, nullptr); 49 50 51 llvm::InitializeAllTargets(); 52 llvm::InitializeAllTargetMCs(); 53 llvm::InitializeAllAsmPrinters(); 54 55 llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry(); 56 llvm::initializeCore(Registry); 57 llvm::initializeScalarOpts(Registry); 58 llvm::initializeVectorization(Registry); 59 llvm::initializeIPO(Registry); 60 llvm::initializeAnalysis(Registry); 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); 68 69 is_initialized = true; 70 71 return; 72} 73