• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import("../swiftshader.gni")
16
17declare_args() {
18  # Subzero produces smaller binaries, but doesn't support ARM64 and MIPS64.
19  use_swiftshader_with_subzero =
20      target_cpu != "arm64" && target_cpu != "mips64el"
21}
22
23# Need a separate config to ensure the warnings are added to the end.
24config("swiftshader_subzero_common_private_config") {
25  defines = [
26    "ALLOW_DUMP=0",
27    "ALLOW_TIMERS=0",
28    "ALLOW_LLVM_CL=0",
29    "ALLOW_LLVM_IR=0",
30    "ALLOW_LLVM_IR_AS_INPUT=0",
31    "ALLOW_MINIMAL_BUILD=0",
32    "ALLOW_WASM=0",
33    "ICE_THREAD_LOCAL_HACK=0",
34  ]
35
36  if (is_win) {
37    defines += [ "SUBZERO_USE_MICROSOFT_ABI" ]
38  }
39
40  if (target_cpu == "x64") {
41    defines += [
42      "SZTARGET=X8664",
43      "SUBZERO_TARGET=X8664",
44    ]
45  } else if (target_cpu == "x86") {
46    defines += [
47      "SZTARGET=X8632",
48      "SUBZERO_TARGET=X8632",
49    ]
50  } else if (target_cpu == "mipsel") {
51    defines += [
52      "SZTARGET=MIPS32",
53      "SUBZERO_TARGET=MIPS32",
54    ]
55  } else if (target_cpu == "arm") {
56    defines += [
57      "SZTARGET=ARM32",
58      "SUBZERO_TARGET=ARM32",
59    ]
60  }
61
62  include_dirs = [
63    "../../third_party/subzero",
64    "../../third_party/subzero/pnacl-llvm/include/",
65    "../../third_party/llvm-subzero/include/",
66  ]
67
68  if (is_win) {
69    include_dirs += [ "../../third_party/llvm-subzero/build/Windows/include/" ]
70  } else if (is_linux) {
71    include_dirs += [ "../../third_party/llvm-subzero/build/Linux/include/" ]
72  } else if (is_fuchsia) {
73    include_dirs += [ "../../third_party/llvm-subzero/build/Fuchsia/include/" ]
74  } else if (is_mac) {
75    include_dirs += [ "../../third_party/llvm-subzero/build/MacOS/include/" ]
76  }
77}
78
79config("swiftshader_subzero_private_config") {
80  cflags = []
81
82  if (is_win) {
83    cflags += [
84      "/wd4005",
85      "/wd4018",
86      "/wd4141",
87      "/wd4146",
88      "/wd4245",  # conversion from int to unsigned int (llvm)
89      "/wd4267",
90      "/wd4291",
91      "/wd4310",
92      "/wd4334",
93      "/wd4389",
94      "/wd4701",
95      "/wd4702",
96      "/wd4703",
97      "/wd4706",
98      "/wd4800",
99    ]
100
101    if (!is_debug) {
102      cflags += [ "/wd4718" ]
103    }
104
105    if (is_clang) {
106      if (is_debug) {
107        cflags += [ "-Wno-sign-compare" ]
108      }
109    }
110  } else if (is_linux || is_mac || is_fuchsia) {
111    cflags += [ "-Wno-macro-redefined" ]
112  }
113
114  if (is_clang) {
115    cflags += [
116      "-Wno-header-hygiene",
117      "-Wno-enum-compare-switch",
118      "-Wno-unused-lambda-capture",
119    ]
120  }
121
122  if (is_fuchsia) {
123    cflags += [ "-Wno-error" ]
124  }
125}
126
127config("swiftshader_reactor_with_subzero_private_config") {
128  cflags = []
129
130  if (is_win) {
131    cflags += [
132      "/wd4141",
133      "/wd4146",
134      "/wd4245",  # conversion from int to unsigned int (llvm)
135      "/wd4267",
136      "/wd4291",
137      "/wd4309",
138      "/wd4702",
139      "/wd4800",
140    ]
141
142    if (use_swiftshader_with_subzero) {
143      cflags += [
144        "/wd4018",  # signed/unsigned mismatch (llvm)
145        "/wd4310",  # cast truncates constant value (llvm)
146      ]
147    }
148
149    if (is_clang) {
150      if (is_debug) {
151        cflags += [ "-Wno-sign-compare" ]
152      }
153    }
154  }
155
156  if (is_clang) {
157    cflags += [ "-Wno-header-hygiene" ]
158  }
159
160  if (is_fuchsia) {
161    cflags += [ "-Wno-error" ]
162  }
163}
164
165config("swiftshader_reactor_private_config") {
166  if (is_win) {
167    cflags = [
168      "/wd4201",  # nameless struct/union
169      "/wd4245",  # conversion from int to unsigned int (llvm)
170    ]
171  } else {
172    cflags = [ "-Wno-unused-local-typedef" ]
173    defines = [
174      "__STDC_CONSTANT_MACROS",
175      "__STDC_LIMIT_MACROS",
176    ]
177
178    if (target_cpu == "x86" || target_cpu == "x64") {
179        cflags += [ "-msse2" ]
180    }
181  }
182}
183
184if (use_swiftshader_with_subzero) {
185  swiftshader_source_set("swiftshader_subzero") {
186    subzero_dir = "../../third_party/subzero"
187    subzero_llvm_dir = "../../third_party/llvm-subzero"
188
189    sources = [
190      "$subzero_dir/src/IceAssembler.cpp",
191      "$subzero_dir/src/IceCfg.cpp",
192      "$subzero_dir/src/IceCfgNode.cpp",
193      "$subzero_dir/src/IceClFlags.cpp",
194      "$subzero_dir/src/IceELFObjectWriter.cpp",
195      "$subzero_dir/src/IceELFSection.cpp",
196      "$subzero_dir/src/IceFixups.cpp",
197      "$subzero_dir/src/IceGlobalContext.cpp",
198      "$subzero_dir/src/IceGlobalInits.cpp",
199      "$subzero_dir/src/IceInst.cpp",
200      "$subzero_dir/src/IceInstrumentation.cpp",
201      "$subzero_dir/src/IceIntrinsics.cpp",
202      "$subzero_dir/src/IceLiveness.cpp",
203      "$subzero_dir/src/IceLoopAnalyzer.cpp",
204      "$subzero_dir/src/IceMangling.cpp",
205      "$subzero_dir/src/IceMemory.cpp",
206      "$subzero_dir/src/IceOperand.cpp",
207      "$subzero_dir/src/IceRNG.cpp",
208      "$subzero_dir/src/IceRangeSpec.cpp",
209      "$subzero_dir/src/IceRegAlloc.cpp",
210      "$subzero_dir/src/IceRevision.cpp",
211      "$subzero_dir/src/IceSwitchLowering.cpp",
212      "$subzero_dir/src/IceTargetLowering.cpp",
213      "$subzero_dir/src/IceTargetLoweringX86.cpp",
214      "$subzero_dir/src/IceThreading.cpp",
215      "$subzero_dir/src/IceTimerTree.cpp",
216      "$subzero_dir/src/IceTypes.cpp",
217      "$subzero_dir/src/IceVariableSplitting.cpp",
218      "$subzero_llvm_dir/lib/Demangle/ItaniumDemangle.cpp",
219      "$subzero_llvm_dir/lib/Support/APInt.cpp",
220      "$subzero_llvm_dir/lib/Support/Atomic.cpp",
221      "$subzero_llvm_dir/lib/Support/CommandLine.cpp",
222      "$subzero_llvm_dir/lib/Support/ConvertUTF.cpp",
223      "$subzero_llvm_dir/lib/Support/ConvertUTFWrapper.cpp",
224      "$subzero_llvm_dir/lib/Support/Debug.cpp",
225      "$subzero_llvm_dir/lib/Support/Errno.cpp",
226      "$subzero_llvm_dir/lib/Support/ErrorHandling.cpp",
227      "$subzero_llvm_dir/lib/Support/FoldingSet.cpp",
228      "$subzero_llvm_dir/lib/Support/Hashing.cpp",
229      "$subzero_llvm_dir/lib/Support/Host.cpp",
230      "$subzero_llvm_dir/lib/Support/ManagedStatic.cpp",
231      "$subzero_llvm_dir/lib/Support/MemoryBuffer.cpp",
232      "$subzero_llvm_dir/lib/Support/Mutex.cpp",
233      "$subzero_llvm_dir/lib/Support/NativeFormatting.cpp",
234      "$subzero_llvm_dir/lib/Support/Path.cpp",
235      "$subzero_llvm_dir/lib/Support/Process.cpp",
236      "$subzero_llvm_dir/lib/Support/Program.cpp",
237      "$subzero_llvm_dir/lib/Support/Regex.cpp",
238      "$subzero_llvm_dir/lib/Support/Signals.cpp",
239      "$subzero_llvm_dir/lib/Support/SmallPtrSet.cpp",
240      "$subzero_llvm_dir/lib/Support/SmallVector.cpp",
241      "$subzero_llvm_dir/lib/Support/StringExtras.cpp",
242      "$subzero_llvm_dir/lib/Support/StringMap.cpp",
243      "$subzero_llvm_dir/lib/Support/StringRef.cpp",
244      "$subzero_llvm_dir/lib/Support/StringSaver.cpp",
245      "$subzero_llvm_dir/lib/Support/TargetParser.cpp",
246      "$subzero_llvm_dir/lib/Support/Threading.cpp",
247      "$subzero_llvm_dir/lib/Support/Timer.cpp",
248      "$subzero_llvm_dir/lib/Support/Triple.cpp",
249      "$subzero_llvm_dir/lib/Support/Twine.cpp",
250      "$subzero_llvm_dir/lib/Support/circular_raw_ostream.cpp",
251      "$subzero_llvm_dir/lib/Support/raw_os_ostream.cpp",
252      "$subzero_llvm_dir/lib/Support/raw_ostream.cpp",
253      "$subzero_llvm_dir/lib/Support/regcomp.c",
254      "$subzero_llvm_dir/lib/Support/regerror.c",
255      "$subzero_llvm_dir/lib/Support/regexec.c",
256      "$subzero_llvm_dir/lib/Support/regfree.c",
257      "$subzero_llvm_dir/lib/Support/regstrlcpy.c",
258    ]
259
260    if (target_cpu == "x64") {
261      sources += [
262        "$subzero_dir/src/IceInstX8664.cpp",
263        "$subzero_dir/src/IceTargetLoweringX8664.cpp",
264      ]
265    } else if (target_cpu == "x86") {
266      sources += [
267        "$subzero_dir/src/IceInstX8632.cpp",
268        "$subzero_dir/src/IceTargetLoweringX8632.cpp",
269      ]
270    } else if (target_cpu == "mipsel") {
271      sources += [
272        "$subzero_dir/src/IceAssemblerMIPS32.cpp",
273        "$subzero_dir/src/IceInstMIPS32.cpp",
274        "$subzero_dir/src/IceTargetLoweringMIPS32.cpp",
275      ]
276    } else if (target_cpu == "arm") {
277      sources += [
278        "$subzero_dir/src/IceAssemblerARM32.cpp",
279        "$subzero_dir/src/IceInstARM32.cpp",
280        "$subzero_dir/src/IceTargetLoweringARM32.cpp",
281      ]
282    }
283
284    configs = [
285      ":swiftshader_subzero_common_private_config",
286      ":swiftshader_subzero_private_config",
287    ]
288  }
289}
290
291swiftshader_source_set("swiftshader_reactor") {
292  deps = [
293    "../OpenGL/common:swiftshader_opengl_common",
294  ]
295
296  sources = [
297    "Routine.cpp",
298    "Debug.cpp",
299    "ExecutableMemory.cpp",
300  ]
301
302  if (use_swiftshader_with_subzero) {
303    deps += [ ":swiftshader_subzero" ]
304
305    sources += [
306      "Optimizer.cpp",
307      "SubzeroReactor.cpp",
308    ]
309
310    configs = [
311      ":swiftshader_subzero_common_private_config",
312      ":swiftshader_reactor_with_subzero_private_config",
313    ]
314
315    include_dirs = [
316    ]
317  } else {
318    llvm7_dir = "../../third_party/llvm-7.0"
319
320    deps += [ "$llvm7_dir:swiftshader_llvm" ]
321
322    defines = [ "REACTOR_LLVM_VERSION=7" ]
323
324    sources += [
325      "LLVMReactor.cpp",
326      "LLVMRoutine.cpp",
327      "LLVMRoutineManager.cpp",
328      "CPUID.cpp",
329    ]
330
331    configs = [ ":swiftshader_reactor_private_config" ]
332
333    include_dirs = [
334      "$llvm7_dir/llvm/include/",
335      "$llvm7_dir/configs/common/include/",
336    ]
337
338    if (is_linux) {
339      include_dirs += [ "$llvm7_dir/configs/linux/include/" ]
340    } else if (is_fuchsia) {
341      include_dirs += [ "$llvm7_dir/configs/fuchsia/include/" ]
342    } else if (is_win) {
343      include_dirs += [ "$llvm7_dir/configs/windows/include/" ]
344    } else if (is_android) {
345      include_dirs += [ "$llvm7_dir/configs/android/include/" ]
346    } else {
347      assert(false, "llvm-7.0 not configured for target platform")
348    }
349  }
350}
351