File: compiler_options.cpp

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (95 lines) | stat: -rw-r--r-- 3,058 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright (C) 2019-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/compiler_interface/compiler_options.h"

#include "shared/source/compiler_interface/tokenized_string.h"
#include "shared/source/debug_settings/debug_settings_manager.h"

#include <cstring>

namespace NEO {
namespace CompilerOptions {

bool contains(const char *options, ConstStringRef optionToFind) {
    auto it = strstr(options, optionToFind.data());
    while (it != nullptr) {
        const auto delimiter = it[optionToFind.size()];
        if ((' ' == delimiter) || ('\0' == delimiter)) {
            if ((it == options) || (it[-1] == ' ')) {
                return true;
            }
        }
        it = strstr(it + 1, optionToFind.data());
    }
    return false;
}

bool contains(const std::string &options, ConstStringRef optionToFind) {
    return contains(options.c_str(), optionToFind);
}

std::string wrapInQuotes(const std::string &stringToWrap) {
    std::string quoteEscape{"\""};
    return std::string{quoteEscape + stringToWrap + quoteEscape};
}

TokenizedString tokenize(ConstStringRef src, char separator) {
    TokenizedString ret;
    const char *it = src.begin();
    while (it < src.end()) {
        const char *beg = it;
        while ((beg < src.end()) && (*beg == separator)) {
            ++beg;
        }
        const char *end = beg;
        while ((end < src.end()) && (*end != separator)) {
            ++end;
        }
        it = end;
        if (end != beg) {
            ret.push_back(ConstStringRef(beg, end - beg));
        }
    }
    return ret;
};

void applyAdditionalInternalOptions(std::string &internalOptions) {
    size_t pos;
    if (debugManager.flags.ForceLargeGrfCompilationMode.get()) {
        pos = internalOptions.find(CompilerOptions::largeGrf.data());
        if (pos == std::string::npos) {
            CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::largeGrf);
        }
    } else if (debugManager.flags.ForceDefaultGrfCompilationMode.get()) {
        pos = internalOptions.find(CompilerOptions::defaultGrf.data());
        if (pos == std::string::npos) {
            CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::defaultGrf.data());
        }
        pos = internalOptions.find(CompilerOptions::largeGrf.data());
        if (pos != std::string::npos) {
            internalOptions.erase(pos, CompilerOptions::largeGrf.size());
        }
    }
}

void applyAdditionalApiOptions(std::string &apiOptions) {
    size_t pos;
    if (debugManager.flags.ForceAutoGrfCompilationMode.get() == 1) {
        pos = apiOptions.find(CompilerOptions::autoGrf.data());
        if (pos == std::string::npos) {
            CompilerOptions::concatenateAppend(apiOptions, CompilerOptions::autoGrf);
        }
        pos = apiOptions.find(CompilerOptions::largeGrf.data());
        if (pos != std::string::npos) {
            apiOptions.erase(pos, CompilerOptions::largeGrf.size());
        }
    }
}

} // namespace CompilerOptions
} // namespace NEO