OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UDFCompiler.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, Inc.
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 
25 #ifndef UDF_COMPILER_H
26 #define UDF_COMPILER_H
27 
28 #include <clang/Driver/Compilation.h>
29 #include <clang/Driver/Driver.h>
30 #include <clang/Frontend/CompilerInstance.h>
31 #include <string>
32 #include <vector>
33 
34 #include "CudaMgr/CudaMgr.h"
35 
37  public:
38  UdfClangDriver(const std::string&);
39  clang::driver::Driver* getClangDriver() { return &the_driver; }
40 
41  private:
42  llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diag_options;
43  clang::DiagnosticConsumer* diag_client;
44  llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diag_id;
45  clang::DiagnosticsEngine diags;
46  std::unique_ptr<clang::DiagnosticConsumer> diag_client_owner;
47  clang::driver::Driver the_driver;
48 };
49 
50 class UdfCompiler {
51  public:
52  UdfCompiler(const std::string& udf_file_name,
54  const std::string& clang_path = "");
55  UdfCompiler(const std::string& udf_file_name,
57  const std::string& clang_path,
58  const std::vector<std::string> clang_options);
59  int compileUdf();
60  const std::string& getAstFileName() const;
61 
62  private:
63  void init(const std::string& clang_path);
64  std::string removeFileExtension(const std::string& path);
65  std::string getFileExt(std::string& s);
66  int parseToAst(const char* file_name);
67  std::string genGpuIrFilename(const char* udf_file_name);
68  std::string genCpuIrFilename(const char* udf_file_name);
69  int compileToGpuByteCode(const char* udf_file_name, bool cpu_mode);
70  int compileToCpuByteCode(const char* udf_file_name);
71  void replaceExtn(std::string& s, const std::string& new_ext);
72  int compileFromCommandLine(const std::vector<std::string>& command_line);
73  void readCompiledModules();
74  void readGpuCompiledModule();
75  void readCpuCompiledModule();
76  int compileForGpu();
77 
78  private:
79  std::string udf_file_name_;
80  std::string udf_ast_file_name_;
82  std::string clang_path_;
83  std::vector<std::string> clang_options_;
84 };
85 #endif
clang::driver::Driver * getClangDriver()
Definition: UDFCompiler.h:39
std::string genCpuIrFilename(const char *udf_file_name)
int compileToCpuByteCode(const char *udf_file_name)
void readCompiledModules()
std::vector< std::string > clang_options_
Definition: UDFCompiler.h:83
UdfCompiler(const std::string &udf_file_name, CudaMgr_Namespace::NvidiaDeviceArch target_arch, const std::string &clang_path="")
const std::string & getAstFileName() const
void readCpuCompiledModule()
std::string genGpuIrFilename(const char *udf_file_name)
std::string removeFileExtension(const std::string &path)
llvm::IntrusiveRefCntPtr< clang::DiagnosticIDs > diag_id
Definition: UDFCompiler.h:44
int compileToGpuByteCode(const char *udf_file_name, bool cpu_mode)
std::string udf_ast_file_name_
Definition: UDFCompiler.h:80
UdfClangDriver(const std::string &)
int parseToAst(const char *file_name)
CudaMgr_Namespace::NvidiaDeviceArch target_arch_
Definition: UDFCompiler.h:81
void init(const std::string &clang_path)
std::string udf_file_name_
Definition: UDFCompiler.h:79
int compileUdf()
void replaceExtn(std::string &s, const std::string &new_ext)
std::unique_ptr< clang::DiagnosticConsumer > diag_client_owner
Definition: UDFCompiler.h:46
void readGpuCompiledModule()
std::string getFileExt(std::string &s)
int compileForGpu()
clang::driver::Driver the_driver
Definition: UDFCompiler.h:47
clang::DiagnosticsEngine diags
Definition: UDFCompiler.h:45
llvm::IntrusiveRefCntPtr< clang::DiagnosticOptions > diag_options
Definition: UDFCompiler.h:42
clang::DiagnosticConsumer * diag_client
Definition: UDFCompiler.h:43
int compileFromCommandLine(const std::vector< std::string > &command_line)
std::string clang_path_
Definition: UDFCompiler.h:82