Skip to content

Commit

Permalink
[SYCL] Simplify arguments to computeModuleProperties (intel#15271)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sarnex authored Sep 10, 2024
1 parent bd17800 commit 594ae74
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
4 changes: 1 addition & 3 deletions llvm/include/llvm/SYCLLowerIR/ComputeModuleRuntimeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ using EntryPointSet = SetVector<Function *>;

PropSetRegTy computeModuleProperties(const Module &M,
const EntryPointSet &EntryPoints,
const GlobalBinImageProps &GlobProps,
bool SpecConstsMet,
bool IsSpecConstantDefault);
const GlobalBinImageProps &GlobProps);

std::string computeModuleSymbolTable(const Module &M,
const EntryPointSet &EntryPoints);
Expand Down
10 changes: 10 additions & 0 deletions llvm/include/llvm/SYCLLowerIR/SpecConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ class SpecConstantsPass : public PassInfoMixin<SpecConstantsPass> {
collectSpecConstantDefaultValuesMetadata(const Module &M,
std::vector<char> &DefaultValues);

// Name of the metadata which holds a list of all specialization constants
// (with associated information) encountered in the module
static constexpr char SPEC_CONST_MD_STRING[] =
"sycl.specialization-constants";

// Name of the metadata which indicates this module was proccessed with the
// default values handing mode.
static constexpr char SPEC_CONST_DEFAULT_VAL_MODULE_MD_STRING[] =
"sycl.specialization-constants-default-values-module";

private:
HandlingMode Mode;
};
Expand Down
13 changes: 9 additions & 4 deletions llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ uint32_t getKernelWorkGroupNumDim(const Function &Func) {

PropSetRegTy computeModuleProperties(const Module &M,
const EntryPointSet &EntryPoints,
const GlobalBinImageProps &GlobProps,
bool SpecConstsMet,
bool IsSpecConstantDefault) {
const GlobalBinImageProps &GlobProps) {

PropSetRegTy PropSet;
{
Expand All @@ -152,6 +150,10 @@ PropSetRegTy computeModuleProperties(const Module &M,
PropSet.add(PropSetRegTy::SYCL_DEVICE_REQUIREMENTS,
computeDeviceRequirements(M, EntryPoints).asMap());
}
auto *SpecConstsMD =
M.getNamedMetadata(SpecConstantsPass::SPEC_CONST_MD_STRING);
bool SpecConstsMet =
SpecConstsMD != nullptr && SpecConstsMD->getNumOperands() != 0;
if (SpecConstsMet) {
// extract spec constant maps per each module
SpecIDMapTy TmpSpecIDMap;
Expand Down Expand Up @@ -369,7 +371,10 @@ PropSetRegTy computeModuleProperties(const Module &M,
if (!HostPipePropertyMap.empty()) {
PropSet.add(PropSetRegTy::SYCL_HOST_PIPES, HostPipePropertyMap);
}

bool IsSpecConstantDefault =
M.getNamedMetadata(
SpecConstantsPass::SPEC_CONST_DEFAULT_VAL_MODULE_MD_STRING) !=
nullptr;
if (IsSpecConstantDefault)
PropSet.add(PropSetRegTy::SYCL_MISC_PROP, "specConstsReplacedWithDefault",
1);
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/SYCLLowerIR/SpecConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ constexpr char SPIRV_GET_SPEC_CONST_VAL[] = "__spirv_SpecConstant";
constexpr char SPIRV_GET_SPEC_CONST_COMPOSITE[] =
"__spirv_SpecConstantComposite";

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

if (Mode == HandlingMode::default_values)
M.getOrInsertNamedMetadata(SPEC_CONST_DEFAULT_VAL_MODULE_MD_STRING);

return IRModified ? PreservedAnalyses::none() : PreservedAnalyses::all();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

; CHECK: %bool1 = trunc i8 1 to i1
; CHECK: %frombool = zext i1 %bool1 to i8
; CHECK: !sycl.specialization-constants-default-values-module = !{}
; CHECK-LOG: sycl.specialization-constants
; CHECK-LOG:[[UNIQUE_PREFIX:[0-9a-zA-Z]+]]={0, 0, 1}
; CHECK-LOG: sycl.specialization-constants-default-values
Expand Down
5 changes: 2 additions & 3 deletions llvm/tools/sycl-post-link/sycl-post-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,8 @@ std::string saveModuleIR(Module &M, int I, StringRef Suff) {
std::string saveModuleProperties(module_split::ModuleDesc &MD,
const GlobalBinImageProps &GlobProps, int I,
StringRef Suff, StringRef Target = "") {
auto PropSet = computeModuleProperties(MD.getModule(), MD.entries(),
GlobProps, MD.Props.SpecConstsMet,
MD.isSpecConstantDefault());
auto PropSet =
computeModuleProperties(MD.getModule(), MD.entries(), GlobProps);

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

0 comments on commit 594ae74

Please sign in to comment.