blob: 367696b734536bc754c7e6dbc0b00064e0044cb8 [file] [log] [blame]
Zonr Changf74ee192012-04-12 15:34:58 +08001/*
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 Brouilleta2dd52f2017-02-16 20:57:26 -080017#include "bcc/Initialization.h"
18
19#include "Log.h"
20#include "bcc/Config.h"
Zonr Changf74ee192012-04-12 15:34:58 +080021
22#include <cstdlib>
23
Tim Murrayc46a3f52015-01-08 14:52:15 -080024#include <llvm/InitializePasses.h>
25#include <llvm/PassRegistry.h>
Zonr Changf74ee192012-04-12 15:34:58 +080026#include <llvm/Support/ErrorHandling.h>
27#include <llvm/Support/TargetSelect.h>
28
Zonr Changf74ee192012-04-12 15:34:58 +080029namespace {
30
Stephen Hines86e45062013-05-06 16:23:18 -070031void llvm_error_handler(void *pUserData, const std::string &pMessage,
32 bool pGenCrashDiag) {
Stephen Hines5db508c2015-01-06 01:42:56 -080033 ALOGE("bcc: Internal Error - %s", pMessage.c_str());
Zonr Changf74ee192012-04-12 15:34:58 +080034 ::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();
Chris Wailes900c6c12014-08-13 15:40:00 -070048 llvm::install_fatal_error_handler(llvm_error_handler, nullptr);
Zonr Changf74ee192012-04-12 15:34:58 +080049
Zonr Changf74ee192012-04-12 15:34:58 +080050
Tim Murrayc46a3f52015-01-08 14:52:15 -080051 llvm::InitializeAllTargets();
52 llvm::InitializeAllTargetMCs();
53 llvm::InitializeAllAsmPrinters();
Stephen Hinese1c7d292015-04-15 13:20:00 -070054
Tim Murrayc46a3f52015-01-08 14:52:15 -080055 llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry();
56 llvm::initializeCore(Registry);
Tim Murrayc46a3f52015-01-08 14:52:15 -080057 llvm::initializeScalarOpts(Registry);
58 llvm::initializeVectorization(Registry);
59 llvm::initializeIPO(Registry);
60 llvm::initializeAnalysis(Registry);
Tim Murrayc46a3f52015-01-08 14:52:15 -080061 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 Murrayc2074ca2014-04-08 15:39:08 -070068
Zonr Changf74ee192012-04-12 15:34:58 +080069 is_initialized = true;
70
71 return;
72}