Skip to content
Merged
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
4 changes: 1 addition & 3 deletions clang/include/clang/AST/OpenACCClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,7 @@ struct OpenACCPrivateRecipe {
VarDecl *AllocaDecl;
Expr *InitExpr;

OpenACCPrivateRecipe(VarDecl *A, Expr *I) : AllocaDecl(A), InitExpr(I) {
assert(!AllocaDecl || AllocaDecl->getInit() == nullptr);
}
OpenACCPrivateRecipe(VarDecl *A, Expr *I) : AllocaDecl(A), InitExpr(I) {}

bool isSet() const { return AllocaDecl; }

Expand Down
7 changes: 7 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1715,8 +1715,15 @@ class CIRGenFunction : public CIRGenTypeCache {
mlir::Location beginLoc;
mlir::Value varValue;
std::string name;
// The type of the original variable reference: that is, after 'bounds' have
// removed pointers/array types/etc. So in the case of int arr[5], and a
// private(arr[1]), 'origType' is 'int', but 'baseType' is 'int[5]'.
QualType origType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the "element type"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It isn't QUITE element type (since you don't have to be 'fully decended' with bounds), but yes, it is the original type of the expression that the user typed, after accessing the bounds they typed.

QualType baseType;
llvm::SmallVector<mlir::Value> bounds;
// The list of types that we found when going through the bounds, which we
// can use to properly set the alloca section.
llvm::SmallVector<QualType> boundTypes;
};
// Gets the collection of info required to lower and OpenACC clause or cache
// construct variable reference.
Expand Down
36 changes: 32 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,33 @@ mlir::Value CIRGenFunction::createOpenACCConstantInt(mlir::Location loc,
CIRGenFunction::OpenACCDataOperandInfo
CIRGenFunction::getOpenACCDataOperandInfo(const Expr *e) {
const Expr *curVarExpr = e->IgnoreParenImpCasts();
QualType origType =
curVarExpr->getType().getNonReferenceType().getUnqualifiedType();
// Array sections are special, and we have to treat them that way.
if (const auto *section =
dyn_cast<ArraySectionExpr>(curVarExpr->IgnoreParenImpCasts()))
origType = ArraySectionExpr::getBaseOriginalType(section);

mlir::Location exprLoc = cgm.getLoc(curVarExpr->getBeginLoc());
llvm::SmallVector<mlir::Value> bounds;
llvm::SmallVector<QualType> boundTypes;

std::string exprString;
llvm::raw_string_ostream os(exprString);
e->printPretty(os, nullptr, getContext().getPrintingPolicy());

auto addBoundType = [&](const Expr *e) {
if (const auto *section = dyn_cast<ArraySectionExpr>(curVarExpr)) {
QualType baseTy = ArraySectionExpr::getBaseOriginalType(
section->getBase()->IgnoreParenImpCasts());
boundTypes.push_back(QualType(baseTy->getPointeeOrArrayElementType(), 0));
} else {
boundTypes.push_back(curVarExpr->getType());
}
};

addBoundType(curVarExpr);

while (isa<ArraySectionExpr, ArraySubscriptExpr>(curVarExpr)) {
mlir::Location boundLoc = cgm.getLoc(curVarExpr->getBeginLoc());
mlir::Value lowerBound;
Expand Down Expand Up @@ -115,19 +134,28 @@ CIRGenFunction::getOpenACCDataOperandInfo(const Expr *e) {

bounds.push_back(createBound(*this, this->builder, boundLoc, lowerBound,
upperBound, extent));
addBoundType(curVarExpr);
}

if (const auto *memExpr = dyn_cast<MemberExpr>(curVarExpr))
return {exprLoc, emitMemberExpr(memExpr).getPointer(), exprString,
return {exprLoc,
emitMemberExpr(memExpr).getPointer(),
exprString,
origType,
curVarExpr->getType().getNonReferenceType().getUnqualifiedType(),
std::move(bounds)};
std::move(bounds),
std::move(boundTypes)};

// Sema has made sure that only 4 types of things can get here, array
// subscript, array section, member expr, or DRE to a var decl (or the
// former 3 wrapping a var-decl), so we should be able to assume this is
// right.
const auto *dre = cast<DeclRefExpr>(curVarExpr);
return {exprLoc, emitDeclRefLValue(dre).getPointer(), exprString,
return {exprLoc,
emitDeclRefLValue(dre).getPointer(),
exprString,
origType,
curVarExpr->getType().getNonReferenceType().getUnqualifiedType(),
std::move(bounds)};
std::move(bounds),
std::move(boundTypes)};
}
43 changes: 21 additions & 22 deletions clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,20 +988,16 @@ class OpenACCClauseCIREmitter final

{
mlir::OpBuilder::InsertionGuard guardCase(builder);
// TODO: OpenACC: At the moment this is a bit of a hacky way of doing
// this, and won't work when we get to bounds/etc. Do this for now to
// limit the scope of this refactor.
VarDecl *allocaDecl = varRecipe.AllocaDecl;
allocaDecl->setInit(varRecipe.InitExpr);
allocaDecl->setInitStyle(VarDecl::CallInit);

auto recipe =
OpenACCRecipeBuilder<mlir::acc::PrivateRecipeOp>(cgf, builder)
.getOrCreateRecipe(cgf.getContext(), varExpr, allocaDecl,
/*temporary=*/nullptr,
OpenACCReductionOperator::Invalid,
Decl::castToDeclContext(cgf.curFuncDecl),
opInfo.baseType, privateOp.getResult());
.getOrCreateRecipe(
cgf.getContext(), varExpr, varRecipe.AllocaDecl,
varRecipe.InitExpr,
/*temporary=*/nullptr, OpenACCReductionOperator::Invalid,
Decl::castToDeclContext(cgf.curFuncDecl), opInfo.origType,
opInfo.bounds.size(), opInfo.boundTypes, opInfo.baseType,
privateOp.getResult());
// TODO: OpenACC: The dialect is going to change in the near future to
// have these be on a different operation, so when that changes, we
// probably need to change these here.
Expand Down Expand Up @@ -1042,12 +1038,13 @@ class OpenACCClauseCIREmitter final
auto recipe =
OpenACCRecipeBuilder<mlir::acc::FirstprivateRecipeOp>(cgf,
builder)
.getOrCreateRecipe(cgf.getContext(), varExpr, allocaDecl,
varRecipe.InitFromTemporary,
OpenACCReductionOperator::Invalid,
Decl::castToDeclContext(cgf.curFuncDecl),
opInfo.baseType,
firstPrivateOp.getResult());
.getOrCreateRecipe(
cgf.getContext(), varExpr, varRecipe.AllocaDecl,
varRecipe.InitExpr, varRecipe.InitFromTemporary,
OpenACCReductionOperator::Invalid,
Decl::castToDeclContext(cgf.curFuncDecl), opInfo.origType,
opInfo.bounds.size(), opInfo.boundTypes, opInfo.baseType,
firstPrivateOp.getResult());

// TODO: OpenACC: The dialect is going to change in the near future to
// have these be on a different operation, so when that changes, we
Expand Down Expand Up @@ -1089,11 +1086,13 @@ class OpenACCClauseCIREmitter final

auto recipe =
OpenACCRecipeBuilder<mlir::acc::ReductionRecipeOp>(cgf, builder)
.getOrCreateRecipe(cgf.getContext(), varExpr, allocaDecl,
/*temporary=*/nullptr,
clause.getReductionOp(),
Decl::castToDeclContext(cgf.curFuncDecl),
opInfo.baseType, reductionOp.getResult());
.getOrCreateRecipe(
cgf.getContext(), varExpr, varRecipe.AllocaDecl,
varRecipe.InitExpr,
/*temporary=*/nullptr, clause.getReductionOp(),
Decl::castToDeclContext(cgf.curFuncDecl), opInfo.origType,
opInfo.bounds.size(), opInfo.boundTypes, opInfo.baseType,
reductionOp.getResult());

operation.addReduction(builder.getContext(), reductionOp, recipe);
}
Expand Down
Loading