Skip to content

Commit

Permalink
BuildProgram Optimizations #1 call LinkBuiltInLibrary for the cases i…
Browse files Browse the repository at this point in the history
…t needs by checking information GLES EXT and replacable builtins pass.

Fix one small issue with builtins enumeration to match the names with OpenCL spec
  • Loading branch information
lpavank committed Mar 24, 2023
1 parent 26eda91 commit 1242482
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/BuiltinsEnum.h
Expand Up @@ -225,8 +225,8 @@ enum BuiltinType : unsigned int {
kLog1p,
kLogb,
kMad,
kMagmax,
kMagmin,
kMaxmag,
kMinmag,
kModf,
kNan,
kNextafter,
Expand Down
4 changes: 2 additions & 2 deletions lib/BuiltinsMap.inc
Expand Up @@ -942,8 +942,8 @@ static std::unordered_map<const char *, Builtins::BuiltinType, cstr_hash,
{"log1p", Builtins::kLog1p},
{"logb", Builtins::kLogb},
{"mad", Builtins::kMad},
{"magmax", Builtins::kMagmax},
{"magmin", Builtins::kMagmin},
{"maxmag", Builtins::kMaxmag},
{"minmag", Builtins::kMinmag},
{"modf", Builtins::kModf},
{"nan", Builtins::kNan},
{"nextafter", Builtins::kNextafter},
Expand Down
23 changes: 21 additions & 2 deletions lib/Compiler.cpp
Expand Up @@ -67,6 +67,7 @@
#include <string>

using namespace clang;
using namespace clspv;

namespace {
enum class SPIRArch : uint32_t {
Expand Down Expand Up @@ -993,8 +994,26 @@ int CompileModule(const llvm::StringRef &input_filename,
return GenerateIRFile(module, output_buffer);
}

if (!LinkBuiltinLibrary(module.get())) {
return -1;
// check whether any math builtins is available or not
// for which we really need to call LinkBuiltinLibrary
// e.g. cbrt, hypot etc.
bool isBuiltInAvailable = false;
for (auto &F : module->getFunctionList()){
auto &func_info = clspv::Builtins::Lookup(&F);
auto func_type = func_info.getType();
if(BUILTIN_IN_GROUP(func_type, Math)){
if((Builtins::getExtInstEnum(func_info) == Builtins::kGlslExtInstBad) &&
(ReplaceOpenCLBuiltinPass::ReplaceableBuiltins.count(func_type) == 0)){
isBuiltInAvailable = true;
break;
}
}
}

// call LinkBuiltinLibrary only if math builtins e.g cbrt, hypot
// are available in kernel else ignore it to save few milliseconds
if(isBuiltInAvailable && !LinkBuiltinLibrary(module.get())){
return -1;
}

// Run the passes to produce SPIR-V.
Expand Down

0 comments on commit 1242482

Please sign in to comment.