Home | History | Annotate | Download | only in ExecutionEngine
      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 #ifndef BCC_COMPILER_OPTION_H
     18 #define BCC_COMPILER_OPTION_H
     19 
     20 #include "Config.h"
     21 #include "Compiler.h"
     22 
     23 #include "llvm/Target/TargetOptions.h"
     24 #include "llvm/Support/CodeGen.h"
     25 
     26 namespace bcc {
     27 
     28 class CompilerOption {
     29  public:
     30   // 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,
     34   // see Script::prepareExecutable(...)).
     35   //
     36   // Must be invoked after calling Compiler::GlobalInitialization() at least once.
     37   //
     38   CompilerOption() {
     39     //-- Setup options to llvm::TargetMachine --//
     40 
     41     //-- 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) ||
     45         (Compiler::getTargetArchType() == llvm::Triple::x86)) {
     46       TargetOpt.NoFramePointerElim = true;
     47     } else {
     48       TargetOpt.NoFramePointerElim = false;
     49     }
     50 #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 
     58     // 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 
     71     //-- Setup code model  --//
     72 #if defined(__HOST__)
     73     // Data address in X86_64 architecture may reside in a far-away place
     74     if (Compiler::getTargetArchType() == llvm::Triple::x86_64) {
     75       CodeModelOpt = llvm::CodeModel::Medium;
     76     } else {
     77       CodeModelOpt = llvm::CodeModel::Small;
     78     }
     79 #elif defined(DEFAULT_X86_64_CODEGEN)
     80     CodeModelOpt = llvm::CodeModel::Medium;
     81 #else
     82     CodeModelOpt = llvm::CodeModel::Small;
     83 #endif
     84 
     85     //-- Load the result object after successful compilation  --//
     86     LoadAfterCompile = true;
     87   }
     88 
     89   llvm::TargetOptions TargetOpt;
     90   llvm::CodeModel::Model CodeModelOpt;
     91   llvm::Reloc::Model RelocModelOpt;
     92   bool LoadAfterCompile;
     93 
     94 };
     95 
     96 } // namespace bcc
     97 
     98 #endif  // BCC_COMPILER_OPTION_H
     99