Skip to content

[SYCL][Do not merge][WIP]Patch collecting information to class #3408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/Diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/SyclOptReport.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
Expand Down Expand Up @@ -499,6 +500,8 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
DiagnosticsEngine &operator=(const DiagnosticsEngine &) = delete;
~DiagnosticsEngine();

SyclOptReport SyclOptReportHandler;

LLVM_DUMP_METHOD void dump() const;
LLVM_DUMP_METHOD void dump(StringRef DiagName) const;

Expand Down
53 changes: 53 additions & 0 deletions clang/include/clang/Basic/SyclOptReport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===---------------------- SyclOptReport.h ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Defines clang::SyclOptReport class.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_BASIC_SYCLOPTREPORT_H
#define LLVM_CLANG_BASIC_SYCLOPTREPORT_H

#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/DenseMap.h"

namespace clang {

class FunctionDecl;

class SyclOptReport {
struct OptReportInfo {
StringRef KernelName;
StringRef KernelArg;
StringRef ArgType;
SourceLocation KernelArgLoc;

OptReportInfo(StringRef KernelName, StringRef KernelArg, StringRef ArgType,
SourceLocation KernelArgLoc)
: KernelName(KernelName), KernelArg(KernelArg), ArgType(ArgType),
KernelArgLoc(KernelArgLoc) {}
};
llvm::DenseMap<const FunctionDecl *, SmallVector<OptReportInfo, 4>> Map;

public:
void AddKernelArg(const FunctionDecl *FD, StringRef KernelName,
StringRef KernelArg, StringRef ArgType,
SourceLocation KernelArgLoc) {
Map[FD].emplace_back(KernelName, KernelArg, ArgType, KernelArgLoc);
}

SmallVector<OptReportInfo, 4> &getInfo(const FunctionDecl *FD) {
auto It = Map.find(FD);
return It->second;
}
};

} // namespace clang

#endif
28 changes: 28 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "clang/Basic/TargetInfo.h"
#include "clang/CodeGen/CGFunctionInfo.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Dominators.h"
Expand Down Expand Up @@ -1349,6 +1350,33 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
// Emit the standard function prologue.
StartFunction(GD, ResTy, Fn, FnInfo, Args, Loc, BodyRange.getBegin());

if (FD->hasAttr<OpenCLKernelAttr>()) {
// Technically, we get most of the information required in the OptReport
// here (without the need for SyclOptReport class). The only information
// we do not have is source location because by this time we are dealing
// with compiler generated OpenCL kernel where there is no source location.
// In order to obtain source location for field corresponding to generated
// argument, I decided to use SyclOptReport class to collect all information
// about the parameter at the time of it's creation, including source
// locations. The commented code below was how I first accessed the kernel
// arguments need to emit in OptReport
/*for (auto KernelArg : Args)
QualType KernelArgType = KernelArg->getType();*/

// llvm::OptimizationRemarkEmitter ORE(Fn);
SyclOptReport &OptReportHandler = CGM.getDiags().SyclOptReportHandler;
for (auto &ORI : OptReportHandler.getInfo(FD)) {
StringRef KernelName = ORI.KernelName;
StringRef KernelArg = ORI.KernelArg;
StringRef ArgType = ORI.ArgType;
SourceLocation KernelArgLoc = ORI.KernelArgLoc;
llvm::DiagnosticLocation DL = SourceLocToDebugLoc(KernelArgLoc);
// StringRef RemarkName = "testthisstr";
// llvm::OptimizationRemark R("SYCL", RemarkName, Fn);
// ORE.emit(R);
}
}

// Generate the body of the function.
PGO.assignRegionCounters(GD, CurFn);
if (isa<CXXDestructorDecl>(FD))
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1348,12 +1348,18 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
if (CAT)
FieldTy = CAT->getElementType();
ParamDesc newParamDesc = makeParamDesc(FD, FieldTy);
SemaRef.getDiagnostics().SyclOptReportHandler.AddKernelArg(
KernelDecl, KernelDecl->getName(), FD->getName(), FieldTy.getAsString(),
FD->getLocation());
addParam(newParamDesc, FieldTy);
}

void addParam(const CXXBaseSpecifier &BS, QualType FieldTy) {
ParamDesc newParamDesc =
makeParamDesc(SemaRef.getASTContext(), BS, FieldTy);
SemaRef.getDiagnostics().SyclOptReportHandler.AddKernelArg(
KernelDecl, KernelDecl->getName(), "_arg__base", FieldTy.getAsString(),
BS.getBaseTypeLoc());
addParam(newParamDesc, FieldTy);
}

Expand Down