Skip to content

Commit 8b18f2f

Browse files
authored
[flang][OpenMP] Add sym() member function to omp::Object (#94493)
The object identity requires more than just `Symbol`. Don't use `id()` to get the Symbol associated with the object, becase the return value will need to change. Instead use `sym()` which is added for that reason.
1 parent a3d9ca9 commit 8b18f2f

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static void addUseDeviceClause(
175175
useDeviceLocs.push_back(operand.getLoc());
176176
}
177177
for (const omp::Object &object : objects)
178-
useDeviceSyms.push_back(object.id());
178+
useDeviceSyms.push_back(object.sym());
179179
}
180180

181181
static void convertLoopBounds(lower::AbstractConverter &converter,
@@ -525,7 +525,7 @@ bool ClauseProcessor::processCopyin() const {
525525
bool hasCopyin = findRepeatableClause<omp::clause::Copyin>(
526526
[&](const omp::clause::Copyin &clause, const parser::CharBlock &) {
527527
for (const omp::Object &object : clause.v) {
528-
semantics::Symbol *sym = object.id();
528+
semantics::Symbol *sym = object.sym();
529529
assert(sym && "Expecting symbol");
530530
if (const auto *commonDetails =
531531
sym->detailsIf<semantics::CommonBlockDetails>()) {
@@ -698,7 +698,7 @@ bool ClauseProcessor::processCopyprivate(
698698
bool hasCopyPrivate = findRepeatableClause<clause::Copyprivate>(
699699
[&](const clause::Copyprivate &clause, const parser::CharBlock &) {
700700
for (const Object &object : clause.v) {
701-
semantics::Symbol *sym = object.id();
701+
semantics::Symbol *sym = object.sym();
702702
if (const auto *commonDetails =
703703
sym->detailsIf<semantics::CommonBlockDetails>()) {
704704
for (const auto &mem : commonDetails->objects())
@@ -739,7 +739,7 @@ bool ClauseProcessor::processDepend(mlir::omp::DependClauseOps &result) const {
739739
"array sections not supported for task depend");
740740
}
741741

742-
semantics::Symbol *sym = object.id();
742+
semantics::Symbol *sym = object.sym();
743743
const mlir::Value variable = converter.getSymbolAddress(*sym);
744744
result.dependVars.push_back(variable);
745745
}
@@ -870,11 +870,11 @@ bool ClauseProcessor::processMap(
870870
lower::AddrAndBoundsInfo info =
871871
lower::gatherDataOperandAddrAndBounds<mlir::omp::MapBoundsOp,
872872
mlir::omp::MapBoundsType>(
873-
converter, firOpBuilder, semaCtx, stmtCtx, *object.id(),
873+
converter, firOpBuilder, semaCtx, stmtCtx, *object.sym(),
874874
object.ref(), clauseLocation, asFortran, bounds,
875875
treatIndexAsSection);
876876

877-
auto origSymbol = converter.getSymbolAddress(*object.id());
877+
auto origSymbol = converter.getSymbolAddress(*object.sym());
878878
mlir::Value symAddr = info.addr;
879879
if (origSymbol && fir::isTypeWithDescriptor(origSymbol.getType()))
880880
symAddr = origSymbol;
@@ -894,12 +894,12 @@ bool ClauseProcessor::processMap(
894894
mapTypeBits),
895895
mlir::omp::VariableCaptureKind::ByRef, symAddr.getType());
896896

897-
if (object.id()->owner().IsDerivedType()) {
897+
if (object.sym()->owner().IsDerivedType()) {
898898
addChildIndexAndMapToParent(object, parentMemberIndices, mapOp,
899899
semaCtx);
900900
} else {
901901
result.mapVars.push_back(mapOp);
902-
ptrMapSyms->push_back(object.id());
902+
ptrMapSyms->push_back(object.sym());
903903
if (mapSymTypes)
904904
mapSymTypes->push_back(symAddr.getType());
905905
if (mapSymLocs)

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
205205
lower::AddrAndBoundsInfo info =
206206
lower::gatherDataOperandAddrAndBounds<mlir::omp::MapBoundsOp,
207207
mlir::omp::MapBoundsType>(
208-
converter, firOpBuilder, semaCtx, stmtCtx, *object.id(),
208+
converter, firOpBuilder, semaCtx, stmtCtx, *object.sym(),
209209
object.ref(), clauseLocation, asFortran, bounds,
210210
treatIndexAsSection);
211211

212-
auto origSymbol = converter.getSymbolAddress(*object.id());
212+
auto origSymbol = converter.getSymbolAddress(*object.sym());
213213
mlir::Value symAddr = info.addr;
214214
if (origSymbol && fir::isTypeWithDescriptor(origSymbol.getType()))
215215
symAddr = origSymbol;
@@ -226,12 +226,12 @@ bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
226226
mapTypeBits),
227227
mlir::omp::VariableCaptureKind::ByRef, symAddr.getType());
228228

229-
if (object.id()->owner().IsDerivedType()) {
229+
if (object.sym()->owner().IsDerivedType()) {
230230
addChildIndexAndMapToParent(object, parentMemberIndices, mapOp,
231231
semaCtx);
232232
} else {
233233
result.mapVars.push_back(mapOp);
234-
mapSymbols.push_back(object.id());
234+
mapSymbols.push_back(object.sym());
235235
}
236236
}
237237
});

flang/lib/Lower/OpenMP/Clauses.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include <type_traits>
2222
#include <utility>
2323

24+
namespace Fortran::semantics {
25+
class Symbol;
26+
}
27+
2428
namespace Fortran::lower::omp {
2529
using namespace Fortran;
2630
using SomeExpr = semantics::SomeExpr;
@@ -45,7 +49,8 @@ struct ObjectT<Fortran::lower::omp::IdTy, Fortran::lower::omp::ExprTy> {
4549
using IdTy = Fortran::lower::omp::IdTy;
4650
using ExprTy = Fortran::lower::omp::ExprTy;
4751

48-
const IdTy &id() const { return symbol; }
52+
IdTy id() const { return symbol; }
53+
Fortran::semantics::Symbol *sym() const { return symbol; }
4954
const std::optional<ExprTy> &ref() const { return designator; }
5055

5156
IdTy symbol;

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void DataSharingProcessor::collectOmpObjectListSymbol(
139139
const omp::ObjectList &objects,
140140
llvm::SetVector<const semantics::Symbol *> &symbolSet) {
141141
for (const omp::Object &object : objects)
142-
symbolSet.insert(object.id());
142+
symbolSet.insert(object.sym());
143143
}
144144

145145
void DataSharingProcessor::collectSymbolsForPrivatization() {

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
14341434
mlir::OpBuilder::InsertPoint insp = builder.saveInsertionPoint();
14351435
const auto &objList = std::get<ObjectList>(lastp->t);
14361436
for (const Object &object : objList) {
1437-
semantics::Symbol *sym = object.id();
1437+
semantics::Symbol *sym = object.sym();
14381438
converter.copyHostAssociateVar(*sym, &insp);
14391439
}
14401440
}

flang/lib/Lower/OpenMP/ReductionProcessor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace omp {
3737
ReductionProcessor::ReductionIdentifier ReductionProcessor::getReductionType(
3838
const omp::clause::ProcedureDesignator &pd) {
3939
auto redType = llvm::StringSwitch<std::optional<ReductionIdentifier>>(
40-
getRealName(pd.v.id()).ToString())
40+
getRealName(pd.v.sym()).ToString())
4141
.Case("max", ReductionIdentifier::MAX)
4242
.Case("min", ReductionIdentifier::MIN)
4343
.Case("iand", ReductionIdentifier::IAND)
@@ -72,7 +72,7 @@ ReductionProcessor::ReductionIdentifier ReductionProcessor::getReductionType(
7272

7373
bool ReductionProcessor::supportedIntrinsicProcReduction(
7474
const omp::clause::ProcedureDesignator &pd) {
75-
semantics::Symbol *sym = pd.v.id();
75+
semantics::Symbol *sym = pd.v.sym();
7676
if (!sym->GetUltimate().attrs().test(semantics::Attr::INTRINSIC))
7777
return false;
7878
auto redType = llvm::StringSwitch<bool>(getRealName(sym).ToString())
@@ -707,7 +707,7 @@ void ReductionProcessor::addDeclareReduction(
707707
// should happen byref
708708
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
709709
for (const Object &object : objectList) {
710-
const semantics::Symbol *symbol = object.id();
710+
const semantics::Symbol *symbol = object.sym();
711711
if (reductionSymbols)
712712
reductionSymbols->push_back(symbol);
713713
mlir::Value symVal = converter.getSymbolAddress(*symbol);
@@ -825,7 +825,7 @@ ReductionProcessor::getRealName(const semantics::Symbol *symbol) {
825825

826826
const semantics::SourceName
827827
ReductionProcessor::getRealName(const omp::clause::ProcedureDesignator &pd) {
828-
return getRealName(pd.v.id());
828+
return getRealName(pd.v.sym());
829829
}
830830

831831
int ReductionProcessor::getOperationIdentity(ReductionIdentifier redId,

flang/lib/Lower/OpenMP/Utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void genObjectList(const ObjectList &objects,
5555
lower::AbstractConverter &converter,
5656
llvm::SmallVectorImpl<mlir::Value> &operands) {
5757
for (const Object &object : objects) {
58-
const semantics::Symbol *sym = object.id();
58+
const semantics::Symbol *sym = object.sym();
5959
assert(sym && "Expected Symbol");
6060
if (mlir::Value variable = converter.getSymbolAddress(*sym)) {
6161
operands.push_back(variable);
@@ -107,7 +107,7 @@ void gatherFuncAndVarSyms(
107107
const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
108108
llvm::SmallVectorImpl<DeclareTargetCapturePair> &symbolAndClause) {
109109
for (const Object &object : objects)
110-
symbolAndClause.emplace_back(clause, *object.id());
110+
symbolAndClause.emplace_back(clause, *object.sym());
111111
}
112112

113113
mlir::omp::MapInfoOp
@@ -175,7 +175,7 @@ generateMemberPlacementIndices(const Object &object,
175175
semantics::SemanticsContext &semaCtx) {
176176
auto compObj = getComponentObject(object, semaCtx);
177177
while (compObj) {
178-
indices.push_back(getComponentPlacementInParent(compObj->id()));
178+
indices.push_back(getComponentPlacementInParent(compObj->sym()));
179179
compObj =
180180
getComponentObject(getBaseObject(compObj.value(), semaCtx), semaCtx);
181181
}

0 commit comments

Comments
 (0)