Skip to content

Commit 594ae74

Browse files
authored
[SYCL] Simplify arguments to computeModuleProperties (#15271)
Computing information about spec consts is difficult for callers when module properties generation and splitting are separate. Simplify it by storing information in module we can use invisibly to the caller. This will be used for thinLTO, where we split early and compute module properties later. This should be basically NFC. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent bd17800 commit 594ae74

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

llvm/include/llvm/SYCLLowerIR/ComputeModuleRuntimeInfo.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ using EntryPointSet = SetVector<Function *>;
3434

3535
PropSetRegTy computeModuleProperties(const Module &M,
3636
const EntryPointSet &EntryPoints,
37-
const GlobalBinImageProps &GlobProps,
38-
bool SpecConstsMet,
39-
bool IsSpecConstantDefault);
37+
const GlobalBinImageProps &GlobProps);
4038

4139
std::string computeModuleSymbolTable(const Module &M,
4240
const EntryPointSet &EntryPoints);

llvm/include/llvm/SYCLLowerIR/SpecConstants.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ class SpecConstantsPass : public PassInfoMixin<SpecConstantsPass> {
7272
collectSpecConstantDefaultValuesMetadata(const Module &M,
7373
std::vector<char> &DefaultValues);
7474

75+
// Name of the metadata which holds a list of all specialization constants
76+
// (with associated information) encountered in the module
77+
static constexpr char SPEC_CONST_MD_STRING[] =
78+
"sycl.specialization-constants";
79+
80+
// Name of the metadata which indicates this module was proccessed with the
81+
// default values handing mode.
82+
static constexpr char SPEC_CONST_DEFAULT_VAL_MODULE_MD_STRING[] =
83+
"sycl.specialization-constants-default-values-module";
84+
7585
private:
7686
HandlingMode Mode;
7787
};

llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ uint32_t getKernelWorkGroupNumDim(const Function &Func) {
138138

139139
PropSetRegTy computeModuleProperties(const Module &M,
140140
const EntryPointSet &EntryPoints,
141-
const GlobalBinImageProps &GlobProps,
142-
bool SpecConstsMet,
143-
bool IsSpecConstantDefault) {
141+
const GlobalBinImageProps &GlobProps) {
144142

145143
PropSetRegTy PropSet;
146144
{
@@ -152,6 +150,10 @@ PropSetRegTy computeModuleProperties(const Module &M,
152150
PropSet.add(PropSetRegTy::SYCL_DEVICE_REQUIREMENTS,
153151
computeDeviceRequirements(M, EntryPoints).asMap());
154152
}
153+
auto *SpecConstsMD =
154+
M.getNamedMetadata(SpecConstantsPass::SPEC_CONST_MD_STRING);
155+
bool SpecConstsMet =
156+
SpecConstsMD != nullptr && SpecConstsMD->getNumOperands() != 0;
155157
if (SpecConstsMet) {
156158
// extract spec constant maps per each module
157159
SpecIDMapTy TmpSpecIDMap;
@@ -369,7 +371,10 @@ PropSetRegTy computeModuleProperties(const Module &M,
369371
if (!HostPipePropertyMap.empty()) {
370372
PropSet.add(PropSetRegTy::SYCL_HOST_PIPES, HostPipePropertyMap);
371373
}
372-
374+
bool IsSpecConstantDefault =
375+
M.getNamedMetadata(
376+
SpecConstantsPass::SPEC_CONST_DEFAULT_VAL_MODULE_MD_STRING) !=
377+
nullptr;
373378
if (IsSpecConstantDefault)
374379
PropSet.add(PropSetRegTy::SYCL_MISC_PROP, "specConstsReplacedWithDefault",
375380
1);

llvm/lib/SYCLLowerIR/SpecConstants.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ constexpr char SPIRV_GET_SPEC_CONST_VAL[] = "__spirv_SpecConstant";
4747
constexpr char SPIRV_GET_SPEC_CONST_COMPOSITE[] =
4848
"__spirv_SpecConstantComposite";
4949

50-
// Name of the metadata which holds a list of all specialization constants (with
51-
// associated information) encountered in the module
52-
constexpr char SPEC_CONST_MD_STRING[] = "sycl.specialization-constants";
5350
// Name of the metadata which holds a default value list of all specialization
5451
// constants encountered in the module
5552
constexpr char SPEC_CONST_DEFAULT_VAL_MD_STRING[] =
@@ -1029,6 +1026,9 @@ PreservedAnalyses SpecConstantsPass::run(Module &M,
10291026
for (const auto &P : DefaultsMetadata)
10301027
MDDefaults->addOperand(P);
10311028

1029+
if (Mode == HandlingMode::default_values)
1030+
M.getOrInsertNamedMetadata(SPEC_CONST_DEFAULT_VAL_MODULE_MD_STRING);
1031+
10321032
return IRModified ? PreservedAnalyses::none() : PreservedAnalyses::all();
10331033
}
10341034

llvm/test/tools/sycl-post-link/spec-constants/default-value/bool.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
; CHECK: %bool1 = trunc i8 1 to i1
88
; CHECK: %frombool = zext i1 %bool1 to i8
9+
; CHECK: !sycl.specialization-constants-default-values-module = !{}
910
; CHECK-LOG: sycl.specialization-constants
1011
; CHECK-LOG:[[UNIQUE_PREFIX:[0-9a-zA-Z]+]]={0, 0, 1}
1112
; CHECK-LOG: sycl.specialization-constants-default-values

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,8 @@ std::string saveModuleIR(Module &M, int I, StringRef Suff) {
307307
std::string saveModuleProperties(module_split::ModuleDesc &MD,
308308
const GlobalBinImageProps &GlobProps, int I,
309309
StringRef Suff, StringRef Target = "") {
310-
auto PropSet = computeModuleProperties(MD.getModule(), MD.entries(),
311-
GlobProps, MD.Props.SpecConstsMet,
312-
MD.isSpecConstantDefault());
310+
auto PropSet =
311+
computeModuleProperties(MD.getModule(), MD.entries(), GlobProps);
313312

314313
std::string NewSuff = Suff.str();
315314
if (!Target.empty()) {

0 commit comments

Comments
 (0)