]>
Commit | Line | Data |
---|---|---|
4e935e75 JP |
1 | From cda32e18a08fa2f2289a7409f37f44d5643e6aea Mon Sep 17 00:00:00 2001 |
2 | From: Khem Raj <raj.khem@gmail.com> | |
3 | Date: Fri, 23 Jun 2023 01:20:38 -0700 | |
4 | Subject: [PATCH] gallium: Fix build with llvm 17 | |
5 | ||
6 | These headers are not available for C files in llvm 17+ | |
7 | and they seem to be not needed to compile after all with llvm 17 | |
8 | so add conditions to exclude them for llvm >= 17 | |
9 | ||
10 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | |
11 | --- | |
12 | src/gallium/auxiliary/gallivm/lp_bld_init.c | 6 +++++- | |
13 | 1 file changed, 5 insertions(+), 1 deletion(-) | |
14 | ||
15 | diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c | |
16 | index cd2108f3a088d..b1a4d0388a6a0 100644 | |
17 | --- a/src/gallium/auxiliary/gallivm/lp_bld_init.c | |
18 | +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c | |
19 | @@ -46,15 +46,19 @@ | |
20 | #if GALLIVM_USE_NEW_PASS == 1 | |
21 | #include <llvm-c/Transforms/PassBuilder.h> | |
22 | #elif GALLIVM_HAVE_CORO == 1 | |
23 | +#if LLVM_VERSION_MAJOR < 17 | |
24 | #include <llvm-c/Transforms/Scalar.h> | |
25 | -#if LLVM_VERSION_MAJOR >= 7 | |
26 | +#endif | |
27 | +#if LLVM_VERSION_MAJOR >= 7 && LLVM_VERSION_MAJOR < 17 | |
28 | #include <llvm-c/Transforms/Utils.h> | |
29 | #endif | |
30 | #if LLVM_VERSION_MAJOR <= 8 && (DETECT_ARCH_AARCH64 || DETECT_ARCH_ARM || DETECT_ARCH_S390 || DETECT_ARCH_MIPS64) | |
31 | #include <llvm-c/Transforms/IPO.h> | |
32 | #endif | |
33 | +#if LLVM_VERSION_MAJOR < 17 | |
34 | #include <llvm-c/Transforms/Coroutines.h> | |
35 | #endif | |
36 | +#endif | |
37 | ||
38 | unsigned gallivm_perf = 0; | |
39 | ||
40 | -- | |
41 | GitLab | |
42 | ||
43 | From 2d4fe5f229791fde52846b3f583c12508b5109d6 Mon Sep 17 00:00:00 2001 | |
44 | From: Dave Airlie <airlied@redhat.com> | |
45 | Date: Fri, 25 Aug 2023 12:43:44 +1000 | |
46 | Subject: [PATCH] clover/llvm: move to modern pass manager. | |
47 | MIME-Version: 1.0 | |
48 | Content-Type: text/plain; charset=UTF-8 | |
49 | Content-Transfer-Encoding: 8bit | |
50 | ||
51 | This seems like it should work, but I haven't tested it yet. | |
52 | ||
53 | Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de> | |
54 | Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24879> | |
55 | --- | |
56 | .../frontends/clover/llvm/invocation.cpp | 64 +++++++++++++++---- | |
57 | 1 file changed, 51 insertions(+), 13 deletions(-) | |
58 | ||
59 | diff --git a/src/gallium/frontends/clover/llvm/invocation.cpp b/src/gallium/frontends/clover/llvm/invocation.cpp | |
60 | index 7a50fea332395..43d26fe1abbce 100644 | |
61 | --- a/src/gallium/frontends/clover/llvm/invocation.cpp | |
62 | +++ b/src/gallium/frontends/clover/llvm/invocation.cpp | |
63 | @@ -27,13 +27,17 @@ | |
64 | #include <llvm/IR/DiagnosticPrinter.h> | |
65 | #include <llvm/IR/DiagnosticInfo.h> | |
66 | #include <llvm/IR/LLVMContext.h> | |
67 | +#include <llvm/IR/Module.h> | |
68 | #include <llvm/Support/raw_ostream.h> | |
69 | -#include <llvm/Transforms/IPO/PassManagerBuilder.h> | |
70 | +#include <llvm/Transforms/IPO/Internalize.h> | |
71 | #include <llvm-c/Target.h> | |
72 | #ifdef HAVE_CLOVER_SPIRV | |
73 | #include <LLVMSPIRVLib/LLVMSPIRVLib.h> | |
74 | #endif | |
75 | ||
76 | +#include <llvm-c/TargetMachine.h> | |
77 | +#include <llvm-c/Transforms/PassBuilder.h> | |
78 | +#include <llvm/Support/CBindingWrapping.h> | |
79 | #include <clang/CodeGen/CodeGenAction.h> | |
80 | #include <clang/Lex/PreprocessorOptions.h> | |
81 | #include <clang/Frontend/TextDiagnosticBuffer.h> | |
82 | @@ -439,10 +443,10 @@ clover::llvm::compile_program(const std::string &source, | |
83 | ||
84 | namespace { | |
85 | void | |
86 | - optimize(Module &mod, unsigned optimization_level, | |
87 | + optimize(Module &mod, | |
88 | + const std::string& ir_target, | |
89 | + unsigned optimization_level, | |
90 | bool internalize_symbols) { | |
91 | - ::llvm::legacy::PassManager pm; | |
92 | - | |
93 | // By default, the function internalizer pass will look for a function | |
94 | // called "main" and then mark all other functions as internal. Marking | |
95 | // functions as internal enables the optimizer to perform optimizations | |
96 | @@ -458,19 +462,53 @@ namespace { | |
97 | if (internalize_symbols) { | |
98 | std::vector<std::string> names = | |
99 | map(std::mem_fn(&Function::getName), get_kernels(mod)); | |
100 | - pm.add(::llvm::createInternalizePass( | |
101 | + internalizeModule(mod, | |
102 | [=](const ::llvm::GlobalValue &gv) { | |
103 | return std::find(names.begin(), names.end(), | |
104 | gv.getName()) != names.end(); | |
105 | - })); | |
106 | + }); | |
107 | } | |
108 | ||
109 | - ::llvm::PassManagerBuilder pmb; | |
110 | - pmb.OptLevel = optimization_level; | |
111 | - pmb.LibraryInfo = new ::llvm::TargetLibraryInfoImpl( | |
112 | - ::llvm::Triple(mod.getTargetTriple())); | |
113 | - pmb.populateModulePassManager(pm); | |
114 | - pm.run(mod); | |
115 | + | |
116 | + const char *opt_str = NULL; | |
117 | + LLVMCodeGenOptLevel level; | |
118 | + switch (optimization_level) { | |
119 | + case 0: | |
120 | + default: | |
121 | + opt_str = "default<O0>"; | |
122 | + level = LLVMCodeGenLevelNone; | |
123 | + break; | |
124 | + case 1: | |
125 | + opt_str = "default<O1>"; | |
126 | + level = LLVMCodeGenLevelLess; | |
127 | + break; | |
128 | + case 2: | |
129 | + opt_str = "default<O2>"; | |
130 | + level = LLVMCodeGenLevelDefault; | |
131 | + break; | |
132 | + case 3: | |
133 | + opt_str = "default<O3>"; | |
134 | + level = LLVMCodeGenLevelAggressive; | |
135 | + break; | |
136 | + } | |
137 | + | |
138 | + const target &target = ir_target; | |
139 | + LLVMTargetRef targ; | |
140 | + char *err_message; | |
141 | + | |
142 | + if (LLVMGetTargetFromTriple(target.triple.c_str(), &targ, &err_message)) | |
143 | + return; | |
144 | + LLVMTargetMachineRef tm = | |
145 | + LLVMCreateTargetMachine(targ, target.triple.c_str(), | |
146 | + target.cpu.c_str(), "", level, | |
147 | + LLVMRelocDefault, LLVMCodeModelDefault); | |
148 | + | |
149 | + if (!tm) | |
150 | + return; | |
151 | + LLVMPassBuilderOptionsRef opts = LLVMCreatePassBuilderOptions(); | |
152 | + LLVMRunPasses(wrap(&mod), opt_str, tm, opts); | |
153 | + | |
154 | + LLVMDisposeTargetMachine(tm); | |
155 | } | |
156 | ||
157 | std::unique_ptr<Module> | |
158 | @@ -500,7 +538,7 @@ clover::llvm::link_program(const std::vector<binary> &binaries, | |
159 | auto c = create_compiler_instance(dev, dev.ir_target(), options, r_log); | |
160 | auto mod = link(*ctx, *c, binaries, r_log); | |
161 | ||
162 | - optimize(*mod, c->getCodeGenOpts().OptimizationLevel, !create_library); | |
163 | + optimize(*mod, dev.ir_target(), c->getCodeGenOpts().OptimizationLevel, !create_library); | |
164 | ||
165 | static std::atomic_uint seq(0); | |
166 | const std::string id = "." + mod->getModuleIdentifier() + "-" + | |
167 | -- | |
168 | GitLab | |
169 |