2 // Copyright 2012-2016 Francisco Jerez
3 // Copyright 2012-2016 Advanced Micro Devices, Inc.
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 // OTHER DEALINGS IN THE SOFTWARE.
24 #ifndef CLOVER_LLVM_UTIL_HPP
25 #define CLOVER_LLVM_UTIL_HPP
27 #include "util/u_debug.h"
36 template<typename E> void
37 fail(std::string &r_log, E &&e, const std::string &s) {
42 inline std::vector<std::string>
43 tokenize(const std::string &s) {
44 std::vector<std::string> ss;
45 std::istringstream iss(s);
48 while (getline(iss, t, ' '))
55 target(const std::string &s) :
56 cpu(s.begin(), s.begin() + s.find_first_of("-")),
57 triple(s.begin() + s.find_first_of("-") + 1, s.end()) {}
72 static const struct debug_named_value debug_options[] = {
73 { "clc", clc, "Dump the OpenCL C code for all kernels." },
74 { "llvm", llvm, "Dump the generated LLVM IR for all kernels." },
75 { "native", native, "Dump kernel assembly code for targets "
76 "specifying PIPE_SHADER_IR_NATIVE" },
79 static const unsigned flags =
80 debug_get_flags_option("CLOVER_DEBUG", debug_options, 0);
86 log(const std::string &suffix, const std::string &s) {
87 const std::string path = debug_get_option("CLOVER_DEBUG_FILE",
92 std::ofstream(path + suffix, std::ios::app) << s;