Skip to content

Commit

Permalink
Extend label clause to support. See more
Browse files Browse the repository at this point in the history
Our label implementation was limited to a string
per task_info. Clang allowed to specify non constant
strings but it was a hacky feature. Also don't work
because every task creation will overwrite the task_info label.

This new implementation keeps the constant string for the task_info
(task type), and introduces a new string that is passed to the
runtime in nanos6_create_* functions. This new string will be
instantiation dependent and will be used to improve tracing.
  • Loading branch information
mikaoP committed May 24, 2022
1 parent a4974ca commit c5d3838
Show file tree
Hide file tree
Showing 39 changed files with 461 additions and 249 deletions.
65 changes: 37 additions & 28 deletions clang/include/clang/AST/OmpSsClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,44 +379,53 @@ class OSSPriorityClause : public OSSClause {
/// \endcode
/// In this example directive '#pragma oss task' T1 has a 'label' 'string-literal' and
/// a T2 a 'label' the string contained in variable 's'
class OSSLabelClause : public OSSClause {
friend class OSSClauseReader;

/// Location of '('.
SourceLocation LParenLoc;

/// Expression of the 'label' clause.
Stmt *Expression = nullptr;

/// Set expression.
void setExpression(Expr *E) { Expression = E; }
class OSSLabelClause final
: public OSSVarListClause<OSSLabelClause>,
private llvm::TrailingObjects<OSSLabelClause, Expr *> {
friend OSSVarListClause;
friend TrailingObjects;

public:
/// Build 'label' clause with expression \a E.
/// Build clause with number of variables \a N.
///
/// \param StartLoc Starting location of the clause.
/// \param LParenLoc Location of '('.
/// \param E Expression of the clause.
/// \param EndLoc Ending location of the clause.
OSSLabelClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc)
: OSSClause(OSSC_label, StartLoc, EndLoc), LParenLoc(LParenLoc),
Expression(E) {}
/// \param N Number of the variables in the clause.
OSSLabelClause(SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc, unsigned N)
: OSSVarListClause<OSSLabelClause>(OSSC_label, StartLoc, LParenLoc,
EndLoc, N) {}

/// Build an empty clause.
OSSLabelClause()
: OSSClause(OSSC_label, SourceLocation(), SourceLocation()) {}

/// Sets the location of '('.
void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
///
/// \param N Number of variables.
explicit OSSLabelClause(unsigned N)
: OSSVarListClause<OSSLabelClause>(OSSC_label, SourceLocation(),
SourceLocation(), SourceLocation(),
N) {}

/// Returns the location of '('.
SourceLocation getLParenLoc() const { return LParenLoc; }
public:
/// Creates clause with a list of variables \a VL.
///
/// \param C AST context.
/// \param StartLoc Starting location of the clause.
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
/// \param VL List of references to the variables.
static OSSLabelClause *Create(const ASTContext &C, SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc, ArrayRef<Expr *> VL);

/// Returns expression.
Expr *getExpression() const { return cast_or_null<Expr>(Expression); }
/// Creates an empty clause with \a N variables.
///
/// \param C AST context.
/// \param N The number of variables.
static OSSLabelClause *CreateEmpty(const ASTContext &C, unsigned N);

child_range children() { return child_range(&Expression, &Expression + 1); }
child_range children() {
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
reinterpret_cast<Stmt **>(varlist_end()));
}

static bool classof(const OSSClause *T) {
return T->getClauseKind() == OSSC_label;
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -3672,9 +3672,9 @@ def OSSTaskDecl : Attr {
let Args = [
ExprArgument<"IfExpr">, ExprArgument<"FinalExpr">,
ExprArgument<"CostExpr">, ExprArgument<"PriorityExpr">,
ExprArgument<"LabelExpr">,
BoolArgument<"Wait", 0>,
ExprArgument<"OnreadyExpr">,
VariadicExprArgument<"LabelExprs">,
// in()
VariadicExprArgument<"Ins">, VariadicExprArgument<"Outs">,
VariadicExprArgument<"Inouts">,
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11385,6 +11385,8 @@ def err_oss_expected_base_var_name : Error<
def err_oss_reduction_wrong_type : Error<"reduction type cannot be %select{qualified with 'const', 'volatile' or 'restrict'|a function|a reference|an array}0 type">;
def err_oss_declare_reduction_redefinition : Error<"redefinition of user-defined reduction for type %0">;

def err_oss_non_const_variable : Error<
"this variable cannot be used here">;
def err_oss_const_variable : Error<
"const-qualified variable cannot be %0">;
def err_oss_const_not_mutable_variable : Error<
Expand Down
18 changes: 18 additions & 0 deletions clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3210,6 +3210,18 @@ class Parser : public CodeCompletionHandler {
OSSClause *ParseOmpSsClause(OmpSsDirectiveKind DKind,
OmpSsClauseKind CKind, bool FirstClause);

/// Parses clause with the list of variables of a kind \a Kind with a
/// max limit of N
///
/// \param Kind Kind of current clause.
/// \param ParseOnly true to skip the clause's semantic actions and return
/// \param N Specifies the maximum number of variables to be parsed.
/// nullptr.
///
template<int N>
OSSClause *ParseOmpSsFixedListClause(
OmpSsDirectiveKind DKind, OmpSsClauseKind Kind, bool ParseOnly);

/// Parses clause with the list of variables of a kind \a Kind.
///
/// \param Kind Kind of current clause.
Expand Down Expand Up @@ -3270,6 +3282,12 @@ class Parser : public CodeCompletionHandler {
DeclarationNameInfo ReductionId;
};

/// Parses clauses with list with a max limit of N
template<int N>
bool ParseOmpSsFixedList(
OmpSsDirectiveKind DKind, OmpSsClauseKind Kind,
SmallVectorImpl<Expr *> &Vars, SourceLocation &RLoc);

/// Parses clauses with list.
bool ParseOmpSsVarList(OmpSsDirectiveKind DKind, OmpSsClauseKind Kind,
SmallVectorImpl<Expr *> &Vars,
Expand Down
13 changes: 9 additions & 4 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -11624,7 +11624,7 @@ class Sema final {
ExprResult
CheckSignedIntegerValue(Expr *ValExpr);
ExprResult
CheckIsConstCharPtrConvertibleExpr(Expr *E);
CheckIsConstCharPtrConvertibleExpr(Expr *E, bool ConstConstraint = false);
ExprResult
VerifyPositiveIntegerConstant(Expr *E,
OmpSsClauseKind CKind,
Expand Down Expand Up @@ -11731,8 +11731,8 @@ class Sema final {
DeclGroupPtrTy ActOnOmpSsDeclareTaskDirective(
DeclGroupPtrTy DG,
Expr *If, Expr *Final, Expr *Cost, Expr *Priority,
Expr *Label, Expr *Onready,
bool Wait,
Expr *Onready, bool Wait,
ArrayRef<Expr *> Labels,
ArrayRef<Expr *> Ins, ArrayRef<Expr *> Outs, ArrayRef<Expr *> Inouts,
ArrayRef<Expr *> Concurrents, ArrayRef<Expr *> Commutatives,
ArrayRef<Expr *> WeakIns, ArrayRef<Expr *> WeakOuts,
Expand All @@ -11754,6 +11754,11 @@ class Sema final {
CXXScopeSpec &ReductionIdScopeSpec,
DeclarationNameInfo &ReductionId);

OSSClause *ActOnOmpSsFixedListClause(
OmpSsClauseKind Kind, ArrayRef<Expr *> Vars,
SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc);

OSSClause *ActOnOmpSsSimpleClause(OmpSsClauseKind Kind,
unsigned Argument,
SourceLocation ArgumentLoc,
Expand Down Expand Up @@ -11836,7 +11841,7 @@ class Sema final {
SourceLocation LParenLoc,
SourceLocation EndLoc);
/// Called on well-formed 'label' clause.
OSSClause *ActOnOmpSsLabelClause(Expr *E, SourceLocation StartLoc,
OSSClause *ActOnOmpSsLabelClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc);
/// Called on well-formed 'onready' clause.
Expand Down
6 changes: 1 addition & 5 deletions clang/lib/AST/AttrImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void OSSTaskDeclAttr::printPrettyPragma(
OS << ")";
}
};
l("label", "(", labelExprs_size(), labelExprs_begin(), labelExprs_end(), OS, Policy);
l("in", "(", ins_size(), ins_begin(), ins_end(), OS, Policy);
l("out", "(", outs_size(), outs_begin(), outs_end(), OS, Policy);
l("inout", "(", inouts_size(), inouts_begin(), inouts_end(), OS, Policy);
Expand Down Expand Up @@ -189,11 +190,6 @@ void OSSTaskDeclAttr::printPrettyPragma(
E->printPretty(OS, nullptr, Policy);
OS << ")";
}
if (auto *E = getLabelExpr()) {
OS << " label(";
E->printPretty(OS, nullptr, Policy);
OS << ")";
}
if (getWait())
OS << " wait";
if (auto *E = getOnreadyExpr()) {
Expand Down
17 changes: 17 additions & 0 deletions clang/lib/AST/OmpSsClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ OSSClause::child_range OSSClause::children() {
llvm_unreachable("unknown OSSClause");
}

OSSLabelClause *OSSLabelClause::Create(const ASTContext &C,
SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc,
ArrayRef<Expr *> VL) {
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(VL.size()));
OSSLabelClause *Clause =
new (Mem) OSSLabelClause(StartLoc, LParenLoc, EndLoc, VL.size());
Clause->setVarRefs(VL);
return Clause;
}

OSSLabelClause *OSSLabelClause::CreateEmpty(const ASTContext &C, unsigned N) {
void *Mem = C.Allocate(totalSizeToAlloc<Expr *>(N));
return new (Mem) OSSLabelClause(N);
}

void OSSPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
assert(VL.size() == varlist_size() &&
"Number of private copies is not the same as the preallocated buffer");
Expand Down
8 changes: 5 additions & 3 deletions clang/lib/AST/StmtPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,11 @@ void OSSClausePrinter::VisitOSSPriorityClause(OSSPriorityClause *Node) {
}

void OSSClausePrinter::VisitOSSLabelClause(OSSLabelClause *Node) {
OS << "label(";
Node->getExpression()->printPretty(OS, nullptr, Policy, 0);
OS << ")";
if (!Node->varlist_empty()) {
OS << "label";
VisitOSSClauseList(Node, '(');
OS << ")";
}
}

void OSSClausePrinter::VisitOSSChunksizeClause(OSSChunksizeClause *Node) {
Expand Down
10 changes: 6 additions & 4 deletions clang/lib/CodeGen/CGOmpSsRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2586,9 +2586,11 @@ void CGOmpSsRuntime::EmitDirectiveData(
EmitScalarWrapperCallBundle(
getBundleStr(OSSB_priority), "compute_priority", CGF, Data.Priority, TaskInfo);
}
if (Data.Label) {
llvm::Value *V = CGF.EmitScalarExpr(Data.Label);
TaskInfo.emplace_back(getBundleStr(OSSB_label), V);
if (!Data.Labels.empty()) {
SmallVector<llvm::Value *, 2> LabelValues;
for (const Expr *E : Data.Labels)
LabelValues.push_back(CGF.EmitScalarExpr(E));
TaskInfo.emplace_back(getBundleStr(OSSB_label), LabelValues);
}
if (Data.Wait) {
TaskInfo.emplace_back(
Expand Down Expand Up @@ -2905,7 +2907,7 @@ RValue CGOmpSsRuntime::emitTaskFunction(CodeGenFunction &CGF,
EmitScalarWrapperCallBundle(
getBundleStr(OSSB_priority), "compute_priority", CGF, E, TaskInfo);
}
if (const Expr *E = Attr->getLabelExpr()) {
for (const Expr *E : Attr->labelExprs()) {
llvm::Value *V = CGF.EmitScalarExpr(E);
TaskInfo.emplace_back(getBundleStr(OSSB_label), V);
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGOmpSsRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ struct OSSTaskDataTy final {
const Expr *Final = nullptr;
const Expr *Cost = nullptr;
const Expr *Priority = nullptr;
const Expr *Label = nullptr;
SmallVector<const Expr *, 2> Labels;
bool Wait = false;
const Expr *Onready = nullptr;

bool empty() const {
return DSAs.empty() && Deps.empty() &&
Reductions.empty() &&
!If && !Final && !Cost && !Priority &&
!Label && !Onready;
Labels.empty() && !Onready;
}
};

Expand Down
7 changes: 4 additions & 3 deletions clang/lib/CodeGen/CGStmtOmpSs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,13 @@ static void AddPriorityData(const OSSExecutableDirective &S, const Expr * &Prior
}
}

static void AddLabelData(const OSSExecutableDirective &S, const Expr * &LabelExpr) {
static void AddLabelData(
const OSSExecutableDirective &S, SmallVectorImpl<const Expr *> &Labels) {
bool Found = false;
for (const auto *C : S.getClausesOfKind<OSSLabelClause>()) {
assert(!Found);
Found = true;
LabelExpr = C->getExpression();
Labels.append(C->varlist_begin(), C->varlist_end());
}
}

Expand Down Expand Up @@ -202,7 +203,7 @@ static void AddTaskData(const OSSExecutableDirective &S, OSSTaskDataTy &TaskData
AddFinalData(S, TaskData.Final);
AddCostData(S, TaskData.Cost);
AddPriorityData(S, TaskData.Priority);
AddLabelData(S, TaskData.Label);
AddLabelData(S, TaskData.Labels);
AddWaitData(S, TaskData.Wait);
AddOnreadyData(S, TaskData.Onready);
AddReductionData(S, TaskData.Reductions);
Expand Down
Loading

0 comments on commit c5d3838

Please sign in to comment.