blob: cb6a5de4f1310e306889806b25c31331daa60811 [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 //
40 // Must be invoked after call Compiler::GlobalInitialization() at least once.
41 //
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) ||
49 (Compiler::getTargetArchType() == llvm::Triple::x86))
50 TargetOpt.NoFramePointerElim = true;
51 else
52 TargetOpt.NoFramePointerElim = false;
53#elif defined(DEFAULT_X86_64_CODEGEN)
54 TargetOpt.NoFramePointerElim = true;
55#elif defined(DEFAULT_X86_CODEGEN)
56 TargetOpt.NoFramePointerElim = true;
57#else
58 TargetOpt.NoFramePointerElim = false;
59#endif
60
Zonr Chang2fcbd022012-01-06 21:04:31 +080061 // Use hardfloat ABI
62 //
63 // TODO(all): Need to detect the CPU capability and decide whether to use
64 // softfp. To use softfp, change following 2 lines to
65 //
66 // options.FloatABIType = llvm::FloatABI::Soft;
67 // options.UseSoftFloat = true;
68 TargetOpt.FloatABIType = llvm::FloatABI::Soft;
69 TargetOpt.UseSoftFloat = false;
70
71 //-- Setup relocation model --//
72 RelocModelOpt = llvm::Reloc::Static;
73
Shih-wei Liao4deffde2012-01-17 20:38:17 +080074 //-- Setup code model --//
75#if defined(__HOST__)
76 // Data address in X86_64 architecture may reside in a far-away place
77 if (Compiler::getTargetArchType() == llvm::Triple::x86_64)
78 CodeModelOpt = llvm::CodeModel::Medium;
79 else
80 CodeModelOpt = llvm::CodeModel::Small;
81#elif defined(DEFAULT_X86_64_CODEGEN)
82 CodeModelOpt = llvm::CodeModel::Medium;
83#else
84 CodeModelOpt = llvm::CodeModel::Small;
85#endif
86
Zonr Chang2fcbd022012-01-06 21:04:31 +080087 //-- Load the result object after successful compilation --//
88 LoadAfterCompile = true;
89 }
90} CompilerOption;
91
92} // namespace bcc
93
94#endif // BCC_COMPILER_OPTION_H