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("reactor.gni") 16import("../swiftshader.gni") 17 18config("swiftshader_llvm_reactor_private_config") { 19 if (is_win) { 20 cflags = [ 21 "/wd4141", # 'inline' used more than once. (LLVM 7.0) 22 "/wd4146", # unary minus operator applied to unsigned type. (LLVM 7.0) 23 "/wd4201", # nameless struct/union 24 "/wd4244", # conversion' conversion from 'type1' to 'type2' 25 "/wd4245", # conversion from int to unsigned int (llvm) 26 "/wd4624", # destructor was implicitly defined as deleted (LLVM 7.0) 27 ] 28 } else { 29 cflags = [ "-Wno-unused-local-typedef" ] 30 } 31} 32 33config("swiftshader_reactor_base_private_config") { 34 defines = [ 35 "REACTOR_ANONYMOUS_MMAP_NAME=swiftshader_jit", 36 ] 37} 38 39swiftshader_source_set("swiftshader_reactor_base") { 40 sources = [ 41 "Assert.cpp", 42 "Debug.cpp", 43 "ExecutableMemory.cpp", 44 "Pragma.cpp", 45 "Reactor.cpp", 46 ] 47 48 configs = [ 49 ":swiftshader_reactor_base_private_config", 50 ] 51} 52 53if (supports_subzero) { 54 # Need a separate config to ensure the warnings are added to the end. 55 config("swiftshader_subzero_common_private_config") { 56 defines = [ 57 "ALLOW_DUMP=0", 58 "ALLOW_TIMERS=0", 59 "ALLOW_LLVM_CL=0", 60 "ALLOW_LLVM_IR=0", 61 "ALLOW_LLVM_IR_AS_INPUT=0", 62 "ALLOW_MINIMAL_BUILD=0", 63 "ALLOW_WASM=0", 64 "ICE_THREAD_LOCAL_HACK=0", 65 ] 66 67 if (current_cpu == "x64") { 68 defines += [ 69 "SZTARGET=X8664", 70 "SUBZERO_TARGET=X8664", 71 ] 72 } else if (current_cpu == "x86") { 73 defines += [ 74 "SZTARGET=X8632", 75 "SUBZERO_TARGET=X8632", 76 ] 77 } else if (current_cpu == "mipsel") { 78 defines += [ 79 "SZTARGET=MIPS32", 80 "SUBZERO_TARGET=MIPS32", 81 ] 82 } else if (current_cpu == "arm") { 83 defines += [ 84 "SZTARGET=ARM32", 85 "SUBZERO_TARGET=ARM32", 86 ] 87 } 88 89 include_dirs = [ 90 "../../third_party/subzero", 91 "../../third_party/subzero/pnacl-llvm/include/", 92 "../../third_party/llvm-subzero/include/", 93 ] 94 95 if (is_win) { 96 include_dirs += 97 [ "../../third_party/llvm-subzero/build/Windows/include/" ] 98 } else if (is_linux || is_chromeos) { 99 include_dirs += [ "../../third_party/llvm-subzero/build/Linux/include/" ] 100 } else if (is_fuchsia) { 101 include_dirs += 102 [ "../../third_party/llvm-subzero/build/Fuchsia/include/" ] 103 } else if (is_mac) { 104 include_dirs += [ "../../third_party/llvm-subzero/build/MacOS/include/" ] 105 } 106 } 107 108 config("swiftshader_subzero_private_config") { 109 cflags = [] 110 111 if (is_win) { 112 cflags += [ 113 "/wd4005", 114 "/wd4018", 115 "/wd4141", 116 "/wd4146", 117 "/wd4245", # conversion from int to unsigned int (llvm) 118 "/wd4267", 119 "/wd4291", 120 "/wd4310", 121 "/wd4334", 122 "/wd4389", 123 "/wd4701", 124 "/wd4702", 125 "/wd4703", 126 "/wd4706", 127 "/wd4800", 128 ] 129 130 if (!is_debug) { 131 cflags += [ "/wd4718" ] 132 } 133 134 if (is_clang) { 135 if (is_debug) { 136 cflags += [ "-Wno-sign-compare" ] 137 } 138 } 139 } else if (is_linux || is_chromeos || is_mac || is_fuchsia) { 140 cflags += [ "-Wno-macro-redefined" ] 141 } 142 143 if (is_clang) { 144 cflags += [ 145 "-Wno-header-hygiene", 146 "-Wno-deprecated-declarations", # (llvm) 147 "-Wno-enum-compare-switch", 148 "-Wno-unused-lambda-capture", 149 "-Wno-unused-function", 150 ] 151 } 152 } 153 154 config("swiftshader_reactor_with_subzero_private_config") { 155 cflags = [] 156 157 if (is_win) { 158 cflags += [ 159 "/wd4141", 160 "/wd4146", 161 "/wd4245", # conversion from int to unsigned int (llvm) 162 "/wd4267", 163 "/wd4291", 164 "/wd4309", 165 "/wd4702", 166 "/wd4800", 167 ] 168 169 cflags += [ 170 "/wd4018", # signed/unsigned mismatch (llvm) 171 "/wd4310", # cast truncates constant value (llvm) 172 ] 173 174 if (is_clang) { 175 if (is_debug) { 176 cflags += [ "-Wno-sign-compare" ] 177 } 178 } 179 } 180 181 if (is_clang) { 182 cflags += [ 183 "-Wno-header-hygiene", 184 "-Wno-deprecated-declarations", # (llvm) 185 ] 186 } 187 } 188 189 swiftshader_source_set("swiftshader_subzero") { 190 subzero_dir = "../../third_party/subzero" 191 subzero_llvm_dir = "../../third_party/llvm-subzero" 192 193 sources = [ 194 "$subzero_dir/src/IceAssembler.cpp", 195 "$subzero_dir/src/IceCfg.cpp", 196 "$subzero_dir/src/IceCfgNode.cpp", 197 "$subzero_dir/src/IceClFlags.cpp", 198 "$subzero_dir/src/IceELFObjectWriter.cpp", 199 "$subzero_dir/src/IceELFSection.cpp", 200 "$subzero_dir/src/IceFixups.cpp", 201 "$subzero_dir/src/IceGlobalContext.cpp", 202 "$subzero_dir/src/IceGlobalInits.cpp", 203 "$subzero_dir/src/IceInst.cpp", 204 "$subzero_dir/src/IceInstrumentation.cpp", 205 "$subzero_dir/src/IceIntrinsics.cpp", 206 "$subzero_dir/src/IceLiveness.cpp", 207 "$subzero_dir/src/IceLoopAnalyzer.cpp", 208 "$subzero_dir/src/IceMangling.cpp", 209 "$subzero_dir/src/IceMemory.cpp", 210 "$subzero_dir/src/IceOperand.cpp", 211 "$subzero_dir/src/IceRangeSpec.cpp", 212 "$subzero_dir/src/IceRegAlloc.cpp", 213 "$subzero_dir/src/IceRevision.cpp", 214 "$subzero_dir/src/IceSwitchLowering.cpp", 215 "$subzero_dir/src/IceTargetLowering.cpp", 216 "$subzero_dir/src/IceThreading.cpp", 217 "$subzero_dir/src/IceTimerTree.cpp", 218 "$subzero_dir/src/IceTypes.cpp", 219 "$subzero_dir/src/IceVariableSplitting.cpp", 220 "$subzero_llvm_dir/lib/Demangle/ItaniumDemangle.cpp", 221 "$subzero_llvm_dir/lib/Support/APInt.cpp", 222 "$subzero_llvm_dir/lib/Support/Atomic.cpp", 223 "$subzero_llvm_dir/lib/Support/CommandLine.cpp", 224 "$subzero_llvm_dir/lib/Support/ConvertUTF.cpp", 225 "$subzero_llvm_dir/lib/Support/ConvertUTFWrapper.cpp", 226 "$subzero_llvm_dir/lib/Support/Debug.cpp", 227 "$subzero_llvm_dir/lib/Support/Errno.cpp", 228 "$subzero_llvm_dir/lib/Support/ErrorHandling.cpp", 229 "$subzero_llvm_dir/lib/Support/Hashing.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/Threading.cpp", 246 "$subzero_llvm_dir/lib/Support/Timer.cpp", 247 "$subzero_llvm_dir/lib/Support/Twine.cpp", 248 "$subzero_llvm_dir/lib/Support/circular_raw_ostream.cpp", 249 "$subzero_llvm_dir/lib/Support/raw_os_ostream.cpp", 250 "$subzero_llvm_dir/lib/Support/raw_ostream.cpp", 251 "$subzero_llvm_dir/lib/Support/regcomp.c", 252 "$subzero_llvm_dir/lib/Support/regerror.c", 253 "$subzero_llvm_dir/lib/Support/regexec.c", 254 "$subzero_llvm_dir/lib/Support/regfree.c", 255 "$subzero_llvm_dir/lib/Support/regstrlcpy.c", 256 ] 257 258 if (current_cpu == "x64") { 259 sources += [ 260 "$subzero_dir/src/IceAssemblerX8664.cpp", 261 "$subzero_dir/src/IceInstX8664.cpp", 262 "$subzero_dir/src/IceTargetLoweringX8664.cpp", 263 ] 264 } else if (current_cpu == "x86") { 265 sources += [ 266 "$subzero_dir/src/IceAssemblerX8632.cpp", 267 "$subzero_dir/src/IceInstX8632.cpp", 268 "$subzero_dir/src/IceTargetLoweringX8632.cpp", 269 ] 270 } else if (current_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 (current_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 swiftshader_source_set("swiftshader_subzero_reactor") { 291 deps = [ 292 "../../third_party/marl:Marl", 293 ":swiftshader_reactor_base", 294 ":swiftshader_subzero", 295 ] 296 297 sources = [ 298 "Optimizer.cpp", 299 "SubzeroReactor.cpp", 300 ] 301 302 configs = [ 303 ":swiftshader_subzero_common_private_config", 304 ":swiftshader_reactor_with_subzero_private_config", 305 ] 306 } 307} 308 309if (supports_llvm) { 310 swiftshader_source_set("swiftshader_llvm_reactor") { 311 llvm_dir = "../../third_party/llvm-10.0" 312 313 deps = [ 314 ":swiftshader_reactor_base", 315 "$llvm_dir:swiftshader_llvm", 316 ] 317 318 sources = [ 319 "CPUID.cpp", 320 "LLVMJIT.cpp", 321 "LLVMReactor.cpp", 322 ] 323 324 configs = [ ":swiftshader_llvm_reactor_private_config" ] 325 326 include_dirs = [ 327 "$llvm_dir/llvm/include/", 328 "$llvm_dir/configs/common/include/", 329 ] 330 331 if (is_linux || is_chromeos) { 332 include_dirs += [ "$llvm_dir/configs/linux/include/" ] 333 } else if (is_fuchsia) { 334 include_dirs += [ "$llvm_dir/configs/fuchsia/include/" ] 335 } else if (is_win) { 336 include_dirs += [ "$llvm_dir/configs/windows/include/" ] 337 } else if (is_android) { 338 include_dirs += [ "$llvm_dir/configs/android/include/" ] 339 } else if (is_mac) { 340 include_dirs += [ "$llvm_dir/configs/darwin/include/" ] 341 } else { 342 assert(false, "llvm not configured for target platform") 343 } 344 } 345} 346 347swiftshader_source_set("swiftshader_reactor") { 348 if (use_swiftshader_with_subzero) { 349 deps = [ 350 ":swiftshader_subzero_reactor", 351 ] 352 } else { 353 deps = [ 354 ":swiftshader_llvm_reactor", 355 ] 356 } 357} 358