@@ -5,10 +5,10 @@ Copyright (C) 2022 Intel Corporation
55SPDX-License-Identifier: MIT
66
77============================= end_copyright_notice ===========================*/
8- #include < Probe/Assertion.h>
98#include < igc/Options/Options.h>
109
1110#include < llvm/ADT/SmallVector.h>
11+ #include < llvm/ADT/StringExtras.h>
1212#include < llvm/ADT/StringRef.h>
1313#include < llvm/ADT/Twine.h>
1414#include < llvm/IR/LLVMContext.h>
@@ -23,6 +23,8 @@ SPDX-License-Identifier: MIT
2323
2424#include < llvm/Transforms/Utils/Cloning.h>
2525
26+ #include < Probe/Assertion.h>
27+
2628using namespace llvm ;
2729
2830static cl::opt<std::string>
@@ -78,6 +80,10 @@ std::unique_ptr<MemoryBuffer> vcbGetFile(StringRef fileName) {
7880// ...
7981// }
8082// ```
83+ static std::string renderPlatformLiteral (StringRef Platform) {
84+ return (Twine (" \" " ) + Platform + " \" " ).str ();
85+ };
86+
8187void generateBifSelectionProcedure (
8288 std::map<std::string, UniquePltf> &HashedUniquePltfs, std::string &Output) {
8389 int FD;
@@ -88,6 +94,10 @@ void generateBifSelectionProcedure(
8894
8995 OS << " // This file is auto generated by vcb tool, DO NOT EDIT\n\n " ;
9096
97+ OS << " #include \" IGC/common/StringMacros.hpp\"\n " ;
98+ OS << " #include \" llvm/ADT/StringRef.h\"\n " ;
99+ OS << " \n " ;
100+
91101 // For each unique bitcode generate a C array that contains binary data
92102 // representing the bitcode
93103 for (const auto &[ByteCode, UniPltf] : HashedUniquePltfs) {
@@ -105,24 +115,23 @@ void generateBifSelectionProcedure(
105115 OS << " \n };\n\n "
106116 << " unsigned int " << Pltf << " _size = " << ByteCode.size () << " ;\n\n " ;
107117 }
108- OS << " #include \" llvm/ADT/StringRef.h\"\n\n "
109- << " llvm::StringRef get" << SymbolPrefix
118+ OS << " llvm::StringRef get" << SymbolPrefix
110119 << " Impl(llvm::StringRef CPUStr) {\n " ;
111120
112121 // Generate a selection procedure that for each supported platform
113122 // (taken from configuration file) selects a BLOB that represents a
114123 // platform-specific emulation BiF corresponding to that platform.
115124 for (const auto &[ByteCode, UniPltf] : HashedUniquePltfs) {
116125 const auto &PltfList = UniPltf.Platforms ;
117- bool FirstIn = true ;
118- for ( auto &Pltf : PltfList) {
119- if (FirstIn ) {
120- OS << " if ( CPUStr.equals(\" " << Pltf << " \" ) " ;
121- FirstIn = false ;
122- } else
123- OS << " \n || CPUStr.equals( \" " << Pltf << " \" ) " ;
124- }
125- OS << " )\n "
126+ std::vector<std::string> PlatformCompareExpressions ;
127+ llvm::transform (PltfList, std::back_inserter (PlatformCompareExpressions),
128+ []( const auto &Pltf ) {
129+ return ( Twine ( " CPUStr.equals(" ) +
130+ renderPlatformLiteral (Pltf) + " ) " )
131+ . str ();
132+ }) ;
133+ OS << " if ( " << llvm::join (PlatformCompareExpressions, " \n || " )
134+ << " )\n "
126135 << " return {reinterpret_cast<const char*>(" << SymbolPrefix
127136 << " PLTF" << UniPltf.Num << " ),\n "
128137 << " " << SymbolPrefix << " PLTF" << UniPltf.Num
0 commit comments