diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2020-07-28 18:52:36 (GMT) |
---|---|---|
committer | Robert Maynard <robert.maynard@kitware.com> | 2020-09-04 12:37:07 (GMT) |
commit | a020787a9b7ede3aa490345bd446e469fb1713d2 (patch) | |
tree | f96ef2b1d84515fda4288ffaf39e9abfb8c9cc1a /Source | |
parent | 5a1750017e65727660167ae1953746a3fd3d2c7b (diff) | |
download | CMake-a020787a9b7ede3aa490345bd446e469fb1713d2.zip CMake-a020787a9b7ede3aa490345bd446e469fb1713d2.tar.gz CMake-a020787a9b7ede3aa490345bd446e469fb1713d2.tar.bz2 |
ISPC: Support generation for multiple instruction sets
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 2 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 55 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 9 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 6 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 62 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 5 | ||||
-rw-r--r-- | Source/cmMakefileTargetGenerator.cxx | 18 | ||||
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 7 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 13 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 1 |
10 files changed, 173 insertions, 5 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 6af3429..77a6d4b 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -200,6 +200,7 @@ SETUP_LANGUAGE(swift_properties, Swift); std::string const kCMAKE_CUDA_ARCHITECTURES = "CMAKE_CUDA_ARCHITECTURES"; std::string const kCMAKE_CUDA_RUNTIME_LIBRARY = "CMAKE_CUDA_RUNTIME_LIBRARY"; std::string const kCMAKE_ENABLE_EXPORTS = "CMAKE_ENABLE_EXPORTS"; +std::string const kCMAKE_ISPC_INSTRUCTION_SETS = "CMAKE_ISPC_INSTRUCTION_SETS"; std::string const kCMAKE_LINK_SEARCH_END_STATIC = "CMAKE_LINK_SEARCH_END_STATIC"; std::string const kCMAKE_LINK_SEARCH_START_STATIC = @@ -716,6 +717,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, vars.insert(kCMAKE_CUDA_ARCHITECTURES); vars.insert(kCMAKE_CUDA_RUNTIME_LIBRARY); vars.insert(kCMAKE_ENABLE_EXPORTS); + vars.insert(kCMAKE_ISPC_INSTRUCTION_SETS); vars.insert(kCMAKE_LINK_SEARCH_END_STATIC); vars.insert(kCMAKE_LINK_SEARCH_START_STATIC); vars.insert(kCMAKE_OSX_ARCHITECTURES); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 05c8cc8..a298682 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3302,6 +3302,27 @@ void cmGeneratorTarget::AddCUDAArchitectureFlags(std::string& flags) const } } +void cmGeneratorTarget::AddISPCTargetFlags(std::string& flags) const +{ + const std::string& property = this->GetSafeProperty("ISPC_INSTRUCTION_SETS"); + + // If ISPC_TARGET is false we don't add any architectures. + if (cmIsOff(property)) { + return; + } + + std::string const& compiler = + this->Makefile->GetSafeDefinition("CMAKE_ISPC_COMPILER_ID"); + + if (compiler == "Intel") { + std::vector<std::string> targets; + cmExpandList(property, targets); + if (!targets.empty()) { + flags += cmStrCat(" --target=", cmWrap("", targets, "", ",")); + } + } +} + void cmGeneratorTarget::AddCUDAToolkitFlags(std::string& flags) const { std::string const& compiler = @@ -5071,6 +5092,11 @@ void cmGeneratorTarget::GetTargetObjectNames( assert(!map_it->second.empty()); objects.push_back(map_it->second); } + + auto ispcObjects = this->GetGeneratedISPCObjects(config); + for (std::string const& output : ispcObjects) { + objects.push_back(cmSystemTools::GetFilenameName(output)); + } } bool cmGeneratorTarget::StrictTargetComparison::operator()( @@ -6042,6 +6068,35 @@ std::vector<std::string> cmGeneratorTarget::GetGeneratedISPCHeaders( return iter->second; } +void cmGeneratorTarget::AddISPCGeneratedObject(std::vector<std::string>&& objs, + std::string const& config) +{ + std::string config_upper; + if (!config.empty()) { + config_upper = cmSystemTools::UpperCase(config); + } + auto iter = this->ISPCGeneratedObjects.find(config_upper); + if (iter == this->ISPCGeneratedObjects.end()) { + this->ISPCGeneratedObjects.insert({ config_upper, objs }); + } else { + iter->second.insert(iter->second.end(), objs.begin(), objs.end()); + } +} + +std::vector<std::string> cmGeneratorTarget::GetGeneratedISPCObjects( + std::string const& config) const +{ + std::string config_upper; + if (!config.empty()) { + config_upper = cmSystemTools::UpperCase(config); + } + auto iter = this->ISPCGeneratedObjects.find(config_upper); + if (iter == this->ISPCGeneratedObjects.end()) { + return std::vector<std::string>{}; + } + return iter->second; +} + std::string cmGeneratorTarget::GetFrameworkVersion() const { assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY); diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 246eede..95da169 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -449,6 +449,8 @@ public: void AddCUDAArchitectureFlags(std::string& flags) const; void AddCUDAToolkitFlags(std::string& flags) const; + void AddISPCTargetFlags(std::string& flags) const; + std::string GetFeatureSpecificLinkRuleVariable( std::string const& var, std::string const& lang, std::string const& config) const; @@ -821,6 +823,11 @@ public: std::vector<std::string> GetGeneratedISPCHeaders( std::string const& config) const; + void AddISPCGeneratedObject(std::vector<std::string>&& objs, + std::string const& config); + std::vector<std::string> GetGeneratedISPCObjects( + std::string const& config) const; + private: void AddSourceCommon(const std::string& src, bool before = false); @@ -1001,6 +1008,8 @@ private: std::unordered_map<std::string, std::vector<std::string>> ISPCGeneratedHeaders; + std::unordered_map<std::string, std::vector<std::string>> + ISPCGeneratedObjects; bool IsLinkLookupScope(std::string const& n, cmLocalGenerator const*& lg) const; diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index e3a51dd..006925d 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -1165,6 +1165,12 @@ void cmGlobalNinjaGenerator::AppendTargetDepends( gg->MapToNinjaPath()); outputDeps.insert(outputDeps.end(), headers.begin(), headers.end()); } + auto objs = depTarget->GetGeneratedISPCObjects(targetConfig); + if (!objs.empty()) { + std::transform(objs.begin(), objs.end(), objs.begin(), + gg->MapToNinjaPath()); + outputDeps.insert(outputDeps.end(), objs.begin(), objs.end()); + } } }; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f76770a..0ec0757 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1966,6 +1966,8 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, "See CMake issue #20726."); } } + } else if (lang == "ISPC") { + target->AddISPCTargetFlags(flags); } // Add VFS Overlay for Clang compiliers if (compiler == "Clang") { @@ -2428,7 +2430,17 @@ void cmLocalGenerator::AppendFlagEscape(std::string& flags, void cmLocalGenerator::AddISPCDependencies(cmGeneratorTarget* target) { - // + std::vector<std::string> enabledLanguages = + this->GetState()->GetEnabledLanguages(); + if (std::find(enabledLanguages.begin(), enabledLanguages.end(), "ISPC") == + enabledLanguages.end()) { + return; + } + + std::vector<std::string> ispcSuffixes = + detail::ComputeISPCObjectSuffixes(target); + const bool extra_objects = (ispcSuffixes.size() > 1); + std::vector<std::string> configsList = this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); for (std::string const& config : configsList) { @@ -2442,7 +2454,8 @@ void cmLocalGenerator::AddISPCDependencies(cmGeneratorTarget* target) std::vector<cmSourceFile*> sources; target->GetSourceFiles(sources, config); - // build up the list of ispc headers that this target is generating + // build up the list of ispc headers and extra objects that this target is + // generating for (cmSourceFile const* sf : sources) { // Generate this object file's rule file. const std::string& lang = sf->GetLanguage(); @@ -2453,6 +2466,11 @@ void cmLocalGenerator::AddISPCDependencies(cmGeneratorTarget* target) auto headerPath = cmStrCat(perConfigDir, '/', ispcSource, ".h"); target->AddISPCGeneratedHeader(headerPath, config); + if (extra_objects) { + std::vector<std::string> objs = detail::ComputeISPCExtraObjects( + objectName, perConfigDir, ispcSuffixes); + target->AddISPCGeneratedObject(std::move(objs), config); + } } } } @@ -4028,4 +4046,44 @@ void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, target->AddSource(force.NameCMP0049); } } + +std::vector<std::string> ComputeISPCObjectSuffixes(cmGeneratorTarget* target) +{ + const std::string& targetProperty = + target->GetSafeProperty("ISPC_INSTRUCTION_SETS"); + std::vector<std::string> ispcTargets; + + if (!cmIsOff(targetProperty)) { + cmExpandList(targetProperty, ispcTargets); + for (auto& ispcTarget : ispcTargets) { + // transform targets into the suffixes + auto pos = ispcTarget.find('-'); + auto target_suffix = ispcTarget.substr(0, pos); + if (target_suffix == + "avx1") { // when targetting avx1 ISPC uses the 'avx' output string + target_suffix = "avx"; + } + ispcTarget = target_suffix; + } + } + return ispcTargets; +} + +std::vector<std::string> ComputeISPCExtraObjects( + std::string const& objectName, std::string const& buildDirectory, + std::vector<std::string> const& ispcSuffixes) +{ + std::vector<std::string> computedObjects; + computedObjects.reserve(ispcSuffixes.size()); + + auto extension = cmSystemTools::GetFilenameLastExtension(objectName); + auto objNameNoExt = + cmSystemTools::GetFilenameWithoutLastExtension(objectName); + for (const auto& ispcTarget : ispcSuffixes) { + computedObjects.emplace_back( + cmStrCat(buildDirectory, "/", objNameNoExt, "_", ispcTarget, extension)); + } + + return computedObjects; +} } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index cf2bce1..0f03440 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -595,6 +595,11 @@ void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, bool escapeOldStyle, const char* comment, bool uses_terminal, bool command_expand_lists, const std::string& job_pool, bool stdPipesUTF8); + +std::vector<std::string> ComputeISPCObjectSuffixes(cmGeneratorTarget* target); +std::vector<std::string> ComputeISPCExtraObjects( + std::string const& objectName, std::string const& buildDirectory, + std::vector<std::string> const& ispcSuffixes); } #endif diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index ee97429..ebfddb9 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -197,6 +197,17 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() } } + std::string currentBinDir = + this->LocalGenerator->GetCurrentBinaryDirectory(); + + // Look for ISPC extra object files generated by this target + auto ispcAdditionalObjs = + this->GeneratorTarget->GetGeneratedISPCObjects(this->GetConfigName()); + for (std::string const& ispcObj : ispcAdditionalObjs) { + this->CleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath( + currentBinDir, ispcObj)); + } + // add custom commands to the clean rules? bool clean = cmIsOff(this->Makefile->GetProperty("CLEAN_NO_CUSTOM")); @@ -205,8 +216,6 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() std::vector<cmSourceFile const*> customCommands; this->GeneratorTarget->GetCustomCommands(customCommands, this->GetConfigName()); - std::string currentBinDir = - this->LocalGenerator->GetCurrentBinaryDirectory(); for (cmSourceFile const* sf : customCommands) { cmCustomCommandGenerator ccg(*sf->GetCustomCommand(), this->GetConfigName(), this->LocalGenerator); @@ -1494,6 +1503,11 @@ void cmMakefileTargetGenerator::WriteObjectsStrings( for (std::string const& obj : this->ExternalObjects) { helper.Feed(obj); } + auto ispcAdditionalObjs = + this->GeneratorTarget->GetGeneratedISPCObjects(this->GetConfigName()); + for (std::string const& obj : ispcAdditionalObjs) { + helper.Feed(obj); + } helper.Done(); } diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 59f5e25..210b36e 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -911,11 +911,16 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( linkBuild.ExplicitDeps.push_back( this->ConvertToNinjaPath(this->GetSourceFilePath(source))); } - linkBuild.Outputs.push_back(vars["SWIFT_MODULE"]); } else { linkBuild.ExplicitDeps = this->GetObjects(config); } + + std::vector<std::string> extraISPCObjects = + this->GetGeneratorTarget()->GetGeneratedISPCObjects(config); + std::transform(extraISPCObjects.begin(), extraISPCObjects.end(), + std::back_inserter(linkBuild.ExplicitDeps), MapToNinjaPath()); + linkBuild.ImplicitDeps = this->ComputeLinkDeps(this->TargetLinkLanguage(config), config); diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index b19b620..accdcf1 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1398,6 +1398,19 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement( // Make sure ninja knows how to clean the generated header this->GetGlobalGenerator()->AddAdditionalCleanFile(ispcHeader, config); + auto ispcSuffixes = + detail::ComputeISPCObjectSuffixes(this->GeneratorTarget); + if (ispcSuffixes.size() > 1) { + auto ispcSideEfffectObjects = detail::ComputeISPCExtraObjects( + objectName, ispcDirectory, ispcSuffixes); + + for (auto sideEffect : ispcSideEfffectObjects) { + sideEffect = this->ConvertToNinjaPath(sideEffect); + objBuild.ImplicitOuts.emplace_back(sideEffect); + this->GetGlobalGenerator()->AddAdditionalCleanFile(sideEffect, config); + } + } + vars["ISPC_HEADER_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat( ispcHeader, cmOutputConverter::SHELL); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 63df96a..b3e498f 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -369,6 +369,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("JOB_POOL_PRECOMPILE_HEADER"); initProp("ISPC_COMPILER_LAUNCHER"); initProp("ISPC_HEADER_DIRECTORY"); + initProp("ISPC_INSTRUCTION_SETS"); initProp("LINK_SEARCH_START_STATIC"); initProp("LINK_SEARCH_END_STATIC"); initProp("Swift_LANGUAGE_VERSION"); |