1 /*========================== begin_copyright_notice ============================ 2 3 Copyright (C) 2020-2021 Intel Corporation 4 5 SPDX-License-Identifier: MIT 6 7 ============================= end_copyright_notice ===========================*/ 8 9 #pragma once 10 11 #include "vc/GenXCodeGen/GenXOCLRuntimeInfo.h" 12 #include "vc/Support/BackendConfig.h" 13 #include "vc/Support/ShaderDump.h" 14 #include "vc/Support/ShaderOverride.h" 15 16 #include <JitterDataStruct.h> 17 #include <RelocationInfo.h> 18 19 #include <inc/common/sku_wa.h> 20 21 #include <llvm/ADT/ArrayRef.h> 22 #include <llvm/ADT/Optional.h> 23 #include <llvm/Support/Error.h> 24 #include <llvm/Support/MemoryBuffer.h> 25 #include <llvm/Target/TargetOptions.h> 26 27 #include <memory> 28 #include <string> 29 #include <variant> 30 #include <vector> 31 32 namespace vc { 33 34 namespace ocl { 35 using CompileOutput = llvm::GenXOCLRuntimeInfo::CompiledModuleT; 36 } // namespace ocl 37 38 namespace cm { 39 struct CompileOutput { 40 std::string IsaBinary; 41 }; 42 } // namespace cm 43 44 using CompileOutput = std::variant<cm::CompileOutput, ocl::CompileOutput>; 45 46 enum class FileType { SPIRV, LLVM_TEXT, LLVM_BINARY }; 47 48 enum class OptimizerLevel { None, Full }; 49 50 enum class BinaryKind { CM, OpenCL, ZE }; 51 52 enum class GlobalsLocalizationMode { All, No, Vector, Partial }; 53 54 enum class DisableLRCoalescingControl { Default, Disable, Enable }; 55 56 enum class NoOptFinalizerControl { Default, Disable, Enable }; 57 58 struct CompileOptions { 59 FileType FType = FileType::SPIRV; 60 std::string CPUStr; 61 int RevId; 62 // Non-owning pointer to WA table. 63 const WA_TABLE *WATable = nullptr; 64 // Optional shader dumper. 65 std::unique_ptr<ShaderDumper> Dumper = nullptr; 66 // Optional Shader Overrider 67 std::unique_ptr<vc::ShaderOverrider> ShaderOverrider = nullptr; 68 69 // Api accessible options. 70 // -ze-no-vector-decomposition 71 bool NoVecDecomp = false; 72 // -g 73 bool EmitDebuggableKernels = false; 74 // -fno-jump-tables 75 bool NoJumpTables = false; 76 // -ftranslate-legacy-memory-intrinsics 77 bool TranslateLegacyMemoryIntrinsics = false; 78 // -disable-finalizer-msg 79 bool DisableFinalizerMsg = false; 80 // -fno-struct-splitting 81 bool DisableStructSplitting = false; 82 83 OptimizerLevel OptLevel = OptimizerLevel::Full; 84 llvm::Optional<unsigned> StackMemSize; 85 bool ForceLiveRangesLocalizationForAccUsage = false; 86 bool ForceDisableNonOverlappingRegionOpt = false; 87 bool IsLargeGRFMode = false; 88 DisableLRCoalescingControl DisableLRCoalescingMode = 89 DisableLRCoalescingControl::Default; 90 NoOptFinalizerControl NoOptFinalizerMode = NoOptFinalizerControl::Default; 91 bool ForceDebugInfoValidation = false; 92 bool EnablePreemption = false; 93 94 llvm::FPOpFusion::FPOpFusionMode AllowFPOpFusion = llvm::FPOpFusion::Standard; 95 96 bool UsePlain2DImages = false; 97 98 // Internal options. 99 std::string FeaturesString; // format is: [+-]<feature1>,[+-]<feature2>,... 100 BinaryKind Binary = BinaryKind::OpenCL; 101 bool DumpIsa = false; 102 bool DumpIR = false; 103 bool DumpAsm = false; 104 bool DumpDebugInfo = false; 105 bool TimePasses = false; 106 bool ShowStats = false; 107 std::string StatsFile; 108 std::string LLVMOptions; 109 bool UseBindlessBuffers = false; 110 bool HasL1ReadOnlyCache = false; 111 bool HasLocalMemFenceSupress = false; 112 // from IGC_XXX env 113 FunctionControl FCtrl = FunctionControl::Default; 114 bool SaveStackCallLinkage = false; 115 }; 116 117 struct ExternalData { 118 std::unique_ptr<llvm::MemoryBuffer> OCLGenericBIFModule; 119 std::unique_ptr<llvm::MemoryBuffer> VCPrintf32BIFModule; 120 std::unique_ptr<llvm::MemoryBuffer> VCPrintf64BIFModule; 121 std::unique_ptr<llvm::MemoryBuffer> VCEmulationBIFModule; 122 std::unique_ptr<llvm::MemoryBuffer> VCSPIRVBuiltinsBIFModule; 123 }; 124 125 llvm::Expected<CompileOutput> Compile(llvm::ArrayRef<char> Input, 126 const CompileOptions &Opts, 127 const ExternalData &ExtData, 128 llvm::ArrayRef<uint32_t> SpecConstIds, 129 llvm::ArrayRef<uint64_t> SpecConstValues); 130 131 llvm::Expected<CompileOptions> ParseOptions(llvm::StringRef ApiOptions, 132 llvm::StringRef InternalOptions, 133 bool IsStrictMode); 134 } // namespace vc 135