mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
Merge topic 'ispc_improvements'
a020787a9bISPC: Support generation for multiple instruction sets5a1750017eISPC: Add compiler launcher support Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5173
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 =
|
||||
@@ -5067,6 +5088,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()(
|
||||
@@ -6038,6 +6064,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);
|
||||
|
||||
@@ -448,6 +448,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;
|
||||
@@ -820,6 +822,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);
|
||||
|
||||
@@ -1000,6 +1007,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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,4 +594,9 @@ 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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -832,7 +841,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
|
||||
std::string compilerLauncher;
|
||||
if (!compileCommands.empty() &&
|
||||
(lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA" ||
|
||||
lang == "OBJC" || lang == "OBJCXX")) {
|
||||
lang == "ISPC" || lang == "OBJC" || lang == "OBJCXX")) {
|
||||
std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
|
||||
cmProp clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
|
||||
if (cmNonempty(clauncher)) {
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -813,7 +813,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
|
||||
std::string compilerLauncher;
|
||||
if (!compileCmds.empty() &&
|
||||
(lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA" ||
|
||||
lang == "OBJC" || lang == "OBJCXX")) {
|
||||
lang == "ISPC" || lang == "OBJC" || lang == "OBJCXX")) {
|
||||
std::string const clauncher_prop = cmStrCat(lang, "_COMPILER_LAUNCHER");
|
||||
cmProp clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
|
||||
if (cmNonempty(clauncher)) {
|
||||
@@ -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);
|
||||
|
||||
@@ -367,7 +367,9 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
|
||||
initProp("JOB_POOL_COMPILE");
|
||||
initProp("JOB_POOL_LINK");
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user