1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements.  See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership.  The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License.  You may obtain a copy of the License at
8 //
9 //   http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied.  See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 #pragma once
19 
20 #include <memory>
21 #include <string>
22 
23 #include "arrow/status.h"
24 #include "gandiva/visibility.h"
25 
26 namespace gandiva {
27 
28 class ConfigurationBuilder;
29 /// \brief runtime config for gandiva
30 ///
31 /// It contains elements to customize gandiva execution
32 /// at run time.
33 class GANDIVA_EXPORT Configuration {
34  public:
35   friend class ConfigurationBuilder;
36 
Configuration()37   Configuration() : optimize_(true), target_host_cpu_(true) {}
Configuration(bool optimize)38   explicit Configuration(bool optimize) : optimize_(optimize), target_host_cpu_(true) {}
39 
40   std::size_t Hash() const;
41   bool operator==(const Configuration& other) const;
42   bool operator!=(const Configuration& other) const;
43 
optimize()44   bool optimize() const { return optimize_; }
target_host_cpu()45   bool target_host_cpu() const { return target_host_cpu_; }
46 
set_optimize(bool optimize)47   void set_optimize(bool optimize) { optimize_ = optimize; }
target_host_cpu(bool target_host_cpu)48   void target_host_cpu(bool target_host_cpu) { target_host_cpu_ = target_host_cpu; }
49 
50  private:
51   bool optimize_;        /* optimise the generated llvm IR */
52   bool target_host_cpu_; /* set the mcpu flag to host cpu while compiling llvm ir */
53 };
54 
55 /// \brief configuration builder for gandiva
56 ///
57 /// Provides a default configuration and convenience methods
58 /// to override specific values and build a custom instance
59 class GANDIVA_EXPORT ConfigurationBuilder {
60  public:
build()61   std::shared_ptr<Configuration> build() {
62     std::shared_ptr<Configuration> configuration(new Configuration());
63     return configuration;
64   }
65 
build(bool optimize)66   std::shared_ptr<Configuration> build(bool optimize) {
67     std::shared_ptr<Configuration> configuration(new Configuration(optimize));
68     return configuration;
69   }
70 
DefaultConfiguration()71   static std::shared_ptr<Configuration> DefaultConfiguration() {
72     return default_configuration_;
73   }
74 
75  private:
InitDefaultConfig()76   static std::shared_ptr<Configuration> InitDefaultConfig() {
77     std::shared_ptr<Configuration> configuration(new Configuration());
78     return configuration;
79   }
80 
81   static const std::shared_ptr<Configuration> default_configuration_;
82 };
83 
84 }  // namespace gandiva
85