blob: 78a934a4e365cf89d2535b8e98aded2d43b6d461 [file] [log] [blame]
Zonr Chang2fcbd022012-01-06 21:04:31 +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
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
28typedef struct CompilerOption {
29 llvm::TargetOptions TargetOpt;
30 llvm::CodeModel::Model CodeModelOpt;
31 llvm::Reloc::Model RelocModelOpt;
32 bool LoadAfterCompile;
33
34 // Constructor setup "default configuration". The "default configuration"
35 // here means the configuration for running RenderScript (more specifically,
36 // one can declare a CompilerOption object (call default constructor) and then
37 // pass to the Compiler::compiler() without any modification for RenderScript,
Shih-wei Liao4deffde2012-01-17 20:38:17 +080038 // see Script::prepareExecutable(...)).
39 //
Shih-wei Liao9e81e372012-01-17 16:38:40 -080040 // Must be invoked after calling Compiler::GlobalInitialization() at least once.
Shih-wei Liao4deffde2012-01-17 20:38:17 +080041 //
Zonr Chang2fcbd022012-01-06 21:04:31 +080042 CompilerOption() {
43 //-- Setup options to llvm::TargetMachine --//
44
Shih-wei Liao4deffde2012-01-17 20:38:17 +080045 //-- Setup Frame Pointer Elimination Optimization --//
46#if defined(__HOST__)
47 // Disable frame pointer elimination optimization for X86_64 and X86
48 if ((Compiler::getTargetArchType() == llvm::Triple::x86_64) ||
Shih-wei Liao9e81e372012-01-17 16:38:40 -080049 (Compiler::getTargetArchType() == llvm::Triple::x86)) {
Shih-wei Liao4deffde2012-01-17 20:38:17 +080050 TargetOpt.NoFramePointerElim = true;
Shih-wei Liao9e81e372012-01-17 16:38:40 -080051 } else {
Shih-wei Liao4deffde2012-01-17 20:38:17 +080052 TargetOpt.NoFramePointerElim = false;
Shih-wei Liao9e81e372012-01-17 16:38:40 -080053 }
Shih-wei Liao4deffde2012-01-17 20:38:17 +080054#elif defined(DEFAULT_X86_64_CODEGEN)
55 TargetOpt.NoFramePointerElim = true;
56#elif defined(DEFAULT_X86_CODEGEN)
57 TargetOpt.NoFramePointerElim = true;
58#else
59 TargetOpt.NoFramePointerElim = false;
60#endif
61
Zonr Chang2fcbd022012-01-06 21:04:31 +080062 // Use hardfloat ABI
63 //
64 // TODO(all): Need to detect the CPU capability and decide whether to use
65 // softfp. To use softfp, change following 2 lines to
66 //
67 // options.FloatABIType = llvm::FloatABI::Soft;
68 // options.UseSoftFloat = true;
69 TargetOpt.FloatABIType = llvm::FloatABI::Soft;
70 TargetOpt.UseSoftFloat = false;
71
72 //-- Setup relocation model --//
73 RelocModelOpt = llvm::Reloc::Static;
74
Shih-wei Liao4deffde2012-01-17 20:38:17 +080075 //-- Setup code model --//
76#if defined(__HOST__)
77 // Data address in X86_64 architecture may reside in a far-away place
78 if (Compiler::getTargetArchType() == llvm::Triple::x86_64)
79 CodeModelOpt = llvm::CodeModel::Medium;
80 else
81 CodeModelOpt = llvm::CodeModel::Small;
82#elif defined(DEFAULT_X86_64_CODEGEN)
83 CodeModelOpt = llvm::CodeModel::Medium;
84#else
85 CodeModelOpt = llvm::CodeModel::Small;
86#endif
87
Zonr Chang2fcbd022012-01-06 21:04:31 +080088 //-- Load the result object after successful compilation --//
89 LoadAfterCompile = true;
90 }
91} CompilerOption;
92
93} // namespace bcc
94
95#endif // BCC_COMPILER_OPTION_H