blob: f7c1e502b3901689002c1ff4e324ed866e33f0e8 [file] [log] [blame]
Zonr Chang2fcbd022012-01-06 21:04:31 +08001/*
Shih-wei Liao16e84cf2012-01-17 21:25:21 -08002 * Copyright 2012, The Android Open Source Project
Zonr Chang2fcbd022012-01-06 21:04:31 +08003 *
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#ifndef BCC_COMPILER_OPTION_H
18#define BCC_COMPILER_OPTION_H
19
20#include "Config.h"
Shih-wei Liao4deffde2012-01-17 20:38:17 +080021#include "Compiler.h"
Zonr Chang2fcbd022012-01-06 21:04:31 +080022
23#include "llvm/Target/TargetOptions.h"
24#include "llvm/Support/CodeGen.h"
25
26namespace bcc {
27
Shih-wei Liao16e84cf2012-01-17 21:25:21 -080028class CompilerOption {
29 public:
Zonr Chang2fcbd022012-01-06 21:04:31 +080030 // Constructor setup "default configuration". The "default configuration"
31 // here means the configuration for running RenderScript (more specifically,
32 // one can declare a CompilerOption object (call default constructor) and then
33 // pass to the Compiler::compiler() without any modification for RenderScript,
Shih-wei Liao4deffde2012-01-17 20:38:17 +080034 // see Script::prepareExecutable(...)).
35 //
Shih-wei Liao9e81e372012-01-17 16:38:40 -080036 // Must be invoked after calling Compiler::GlobalInitialization() at least once.
Shih-wei Liao4deffde2012-01-17 20:38:17 +080037 //
Zonr Chang2fcbd022012-01-06 21:04:31 +080038 CompilerOption() {
39 //-- Setup options to llvm::TargetMachine --//
40
Shih-wei Liao4deffde2012-01-17 20:38:17 +080041 //-- Setup Frame Pointer Elimination Optimization --//
42#if defined(__HOST__)
43 // Disable frame pointer elimination optimization for X86_64 and X86
44 if ((Compiler::getTargetArchType() == llvm::Triple::x86_64) ||
Shih-wei Liao9e81e372012-01-17 16:38:40 -080045 (Compiler::getTargetArchType() == llvm::Triple::x86)) {
Shih-wei Liao4deffde2012-01-17 20:38:17 +080046 TargetOpt.NoFramePointerElim = true;
Shih-wei Liao9e81e372012-01-17 16:38:40 -080047 } else {
Shih-wei Liao4deffde2012-01-17 20:38:17 +080048 TargetOpt.NoFramePointerElim = false;
Shih-wei Liao9e81e372012-01-17 16:38:40 -080049 }
Shih-wei Liao4deffde2012-01-17 20:38:17 +080050#elif defined(DEFAULT_X86_64_CODEGEN)
51 TargetOpt.NoFramePointerElim = true;
52#elif defined(DEFAULT_X86_CODEGEN)
53 TargetOpt.NoFramePointerElim = true;
54#else
55 TargetOpt.NoFramePointerElim = false;
56#endif
57
Zonr Chang2fcbd022012-01-06 21:04:31 +080058 // Use hardfloat ABI
59 //
60 // TODO(all): Need to detect the CPU capability and decide whether to use
61 // softfp. To use softfp, change following 2 lines to
62 //
63 // options.FloatABIType = llvm::FloatABI::Soft;
64 // options.UseSoftFloat = true;
65 TargetOpt.FloatABIType = llvm::FloatABI::Soft;
66 TargetOpt.UseSoftFloat = false;
67
68 //-- Setup relocation model --//
69 RelocModelOpt = llvm::Reloc::Static;
70
Shih-wei Liao4deffde2012-01-17 20:38:17 +080071 //-- Setup code model --//
72#if defined(__HOST__)
73 // Data address in X86_64 architecture may reside in a far-away place
Shih-wei Liao2b7db0e2012-01-17 17:49:46 -080074 if (Compiler::getTargetArchType() == llvm::Triple::x86_64) {
Shih-wei Liao4deffde2012-01-17 20:38:17 +080075 CodeModelOpt = llvm::CodeModel::Medium;
Shih-wei Liao2b7db0e2012-01-17 17:49:46 -080076 } else {
Shih-wei Liao4deffde2012-01-17 20:38:17 +080077 CodeModelOpt = llvm::CodeModel::Small;
Shih-wei Liao2b7db0e2012-01-17 17:49:46 -080078 }
Shih-wei Liao4deffde2012-01-17 20:38:17 +080079#elif defined(DEFAULT_X86_64_CODEGEN)
80 CodeModelOpt = llvm::CodeModel::Medium;
81#else
82 CodeModelOpt = llvm::CodeModel::Small;
83#endif
84
Shih-wei Liao4ce024b2012-04-25 03:40:50 -070085 //-- Run LTO passes --//
86 RunLTO = true;
87
Zonr Chang2fcbd022012-01-06 21:04:31 +080088 //-- Load the result object after successful compilation --//
89 LoadAfterCompile = true;
90 }
Shih-wei Liao16e84cf2012-01-17 21:25:21 -080091
Shih-wei Liao16e84cf2012-01-17 21:25:21 -080092 llvm::TargetOptions TargetOpt;
93 llvm::CodeModel::Model CodeModelOpt;
94 llvm::Reloc::Model RelocModelOpt;
Shih-wei Liao4ce024b2012-04-25 03:40:50 -070095 bool RunLTO;
Shih-wei Liao16e84cf2012-01-17 21:25:21 -080096 bool LoadAfterCompile;
97
98};
Zonr Chang2fcbd022012-01-06 21:04:31 +080099
100} // namespace bcc
101
102#endif // BCC_COMPILER_OPTION_H