Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions llvm/tools/sycl-post-link/SpecConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@ void collectCompositeElementsDefaultValuesRecursive(

// Assume that we encountered some scalar element
size_t NumBytes = M.getDataLayout().getTypeStoreSize(C->getType());
if (auto IntConst = dyn_cast<ConstantInt>(C)) {
if (auto *IntConst = dyn_cast<ConstantInt>(C)) {
auto Val = IntConst->getValue().getZExtValue();
std::copy_n(reinterpret_cast<char *>(&Val), NumBytes,
std::back_inserter(DefaultValues));
} else if (auto FPConst = dyn_cast<ConstantFP>(C)) {
} else if (auto *FPConst = dyn_cast<ConstantFP>(C)) {
auto Val = FPConst->getValue();

if (NumBytes == 2) {
Expand All @@ -383,12 +383,12 @@ void collectCompositeElementsDefaultValuesRecursive(
std::copy_n(reinterpret_cast<char *>(&Storage), NumBytes,
std::back_inserter(DefaultValues));
} else if (NumBytes == 4) {
float v = Val.convertToFloat();
std::copy_n(reinterpret_cast<char *>(&v), NumBytes,
float V = Val.convertToFloat();
std::copy_n(reinterpret_cast<char *>(&V), NumBytes,
std::back_inserter(DefaultValues));
} else if (NumBytes == 8) {
double v = Val.convertToDouble();
std::copy_n(reinterpret_cast<char *>(&v), NumBytes,
double V = Val.convertToDouble();
std::copy_n(reinterpret_cast<char *>(&V), NumBytes,
std::back_inserter(DefaultValues));
} else {
llvm_unreachable("Unexpected constant floating point type");
Expand Down
14 changes: 7 additions & 7 deletions llvm/tools/sycl-post-link/sycl-post-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ void groupEntryPoints(const Module &M, EntryPointGroupMap &EntryPointsGroups,
// This function traverses over reversed call graph by BFS algorithm.
// It means that an edge links some function @func with functions
// which contain call of function @func. It starts from
// @StartingFunction and lifts up until it reach all reachable functions
// @StartingFunction and lifts up until it reach all reachable functions,
// or it reaches some function containing "referenced-indirectly" attribute.
// If it reaches "referenced-indirectly" attribute than it returns an empty
// Optional.
// Otherwise, it returns an Optional containing a list of reached
// SPIR kernel function's names.
Optional<std::vector<StringRef>>
TraverseCGToFindSPIRKernels(const Function *StartingFunction) {
traverseCGToFindSPIRKernels(const Function *StartingFunction) {
std::queue<const Function *> FunctionsToVisit;
std::unordered_set<const Function *> VisitedFunctions;
FunctionsToVisit.push(StartingFunction);
Expand Down Expand Up @@ -411,19 +411,19 @@ TraverseCGToFindSPIRKernels(const Function *StartingFunction) {
}
}

return std::move(KernelNames);
return {std::move(KernelNames)};
}

std::vector<StringRef> getKernelNamesUsingAssert(const Module &M) {
auto DevicelibAssertFailFunction = M.getFunction("__devicelib_assert_fail");
auto *DevicelibAssertFailFunction = M.getFunction("__devicelib_assert_fail");
if (!DevicelibAssertFailFunction)
return {};

auto TraverseResult =
TraverseCGToFindSPIRKernels(DevicelibAssertFailFunction);
traverseCGToFindSPIRKernels(DevicelibAssertFailFunction);

if (TraverseResult.hasValue())
return std::move(*TraverseResult);
return std::move(*TraverseResult); // TODO remove std::move after C++17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why after C++17? Isn't it work since C++11?

Copy link
Author

@ghost ghost Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should remove this comment at all. My intent was the following, in C++17 copy elision is guaranteed by the Standard and there is no need in std::move here (before C++17 compilers do such optimization too but it was not guaranteed). Usually compilers warn about using std::move in return statements since it prevents RVO/NRVO optimization but not in this case, there is no warning during sycl-post-link compilation at least on MSVC. I've tried a small example, a function that returns a vector of verbose copyable objects, but I see no copies regardless of std::move using. @maksimsab Could you comment the using of std::move here? I understand why std::move is used in the last return statement there https://github.com/intel/llvm/pull/5552/files#diff-7d1ae2c6e3e847852b55edea2a54fc5309328f32e56800a636a4e3d9c906948bR414 (we just fill the instance of llvm::Optional) but not here.


// Here we reached "referenced-indirectly", so we need to find all kernels and
// return them.
Expand All @@ -438,7 +438,7 @@ std::vector<StringRef> getKernelNamesUsingAssert(const Module &M) {

// Gets reqd_work_group_size information for function Func.
std::vector<uint32_t> getKernelReqdWorkGroupSizeMetadata(const Function &Func) {
auto ReqdWorkGroupSizeMD = Func.getMetadata("reqd_work_group_size");
auto *ReqdWorkGroupSizeMD = Func.getMetadata("reqd_work_group_size");
if (!ReqdWorkGroupSizeMD)
return {};
// TODO: Remove 3-operand assumption when it is relaxed.
Expand Down