Skip to content

Commit e256292

Browse files
Revert "[flang][nfc] Support volatility in Fir ops (#134858)"
This reverts commit e42f860.
1 parent ad9f6d3 commit e256292

File tree

9 files changed

+25
-250
lines changed

9 files changed

+25
-250
lines changed

flang/include/flang/Optimizer/Builder/FIRBuilder.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,6 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
397397
mlir::Value createConvert(mlir::Location loc, mlir::Type toTy,
398398
mlir::Value val);
399399

400-
/// Create a fir.convert op with a volatile cast if the source value's type
401-
/// does not match the target type's volatility.
402-
mlir::Value createConvertWithVolatileCast(mlir::Location loc, mlir::Type toTy,
403-
mlir::Value val);
404-
405400
/// Create a fir.store of \p val into \p addr. A lazy conversion
406401
/// of \p val to the element type of \p addr is created if needed.
407402
void createStoreWithConvert(mlir::Location loc, mlir::Value val,

flang/include/flang/Optimizer/Dialect/FIROps.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ struct DebuggingResource
5050
mlir::StringRef getName() final { return "DebuggingResource"; }
5151
};
5252

53-
/// Model operations which read from/write to volatile memory
54-
struct VolatileMemoryResource
55-
: public mlir::SideEffects::Resource::Base<VolatileMemoryResource> {
56-
mlir::StringRef getName() final { return "VolatileMemoryResource"; }
57-
};
58-
5953
class CoordinateIndicesAdaptor;
6054
using IntOrValue = llvm::PointerUnion<mlir::IntegerAttr, mlir::Value>;
6155

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ def fir_FreeMemOp : fir_Op<"freemem", [MemoryEffects<[MemFree]>]> {
286286
let assemblyFormat = "$heapref attr-dict `:` qualified(type($heapref))";
287287
}
288288

289-
def fir_LoadOp : fir_OneResultOp<"load", [FirAliasTagOpInterface,
290-
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
289+
def fir_LoadOp : fir_OneResultOp<"load", [FirAliasTagOpInterface]> {
291290
let summary = "load a value from a memory reference";
292291
let description = [{
293292
Load a value from a memory reference into an ssa-value (virtual register).
@@ -303,7 +302,7 @@ def fir_LoadOp : fir_OneResultOp<"load", [FirAliasTagOpInterface,
303302
or null.
304303
}];
305304

306-
let arguments = (ins AnyReferenceLike:$memref,
305+
let arguments = (ins Arg<AnyReferenceLike, "", [MemRead]>:$memref,
307306
OptionalAttr<LLVM_TBAATagArrayAttr>:$tbaa);
308307

309308
let builders = [OpBuilder<(ins "mlir::Value":$refVal)>,
@@ -316,8 +315,7 @@ def fir_LoadOp : fir_OneResultOp<"load", [FirAliasTagOpInterface,
316315
}];
317316
}
318317

319-
def fir_StoreOp : fir_Op<"store", [FirAliasTagOpInterface,
320-
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
318+
def fir_StoreOp : fir_Op<"store", [FirAliasTagOpInterface]> {
321319
let summary = "store an SSA-value to a memory location";
322320

323321
let description = [{
@@ -337,7 +335,7 @@ def fir_StoreOp : fir_Op<"store", [FirAliasTagOpInterface,
337335
}];
338336

339337
let arguments = (ins AnyType:$value,
340-
AnyReferenceLike:$memref,
338+
Arg<AnyReferenceLike, "", [MemWrite]>:$memref,
341339
OptionalAttr<LLVM_TBAATagArrayAttr>:$tbaa);
342340

343341
let builders = [OpBuilder<(ins "mlir::Value":$value, "mlir::Value":$memref)>];
@@ -350,7 +348,7 @@ def fir_StoreOp : fir_Op<"store", [FirAliasTagOpInterface,
350348
}];
351349
}
352350

353-
def fir_CopyOp : fir_Op<"copy", [DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
351+
def fir_CopyOp : fir_Op<"copy", []> {
354352
let summary = "copy constant size memory";
355353

356354
let description = [{
@@ -371,8 +369,8 @@ def fir_CopyOp : fir_Op<"copy", [DeclareOpInterfaceMethods<MemoryEffectsOpInterf
371369
TODO: add FirAliasTagOpInterface to carry TBAA.
372370
}];
373371

374-
let arguments = (ins AnyRefOfConstantSizeAggregateType:$source,
375-
AnyRefOfConstantSizeAggregateType:$destination,
372+
let arguments = (ins Arg<AnyRefOfConstantSizeAggregateType, "", [MemRead]>:$source,
373+
Arg<AnyRefOfConstantSizeAggregateType, "", [MemWrite]>:$destination,
376374
OptionalAttr<UnitAttr>:$no_overlap);
377375

378376
let builders = [OpBuilder<(ins "mlir::Value":$source,
@@ -1375,8 +1373,7 @@ def fir_BoxTypeDescOp : fir_SimpleOneResultOp<"box_tdesc", [NoMemoryEffect]> {
13751373
// !- Merge the new and old values into the memory for "A"
13761374
// array_merge_store <updated A> to <A's address>
13771375

1378-
def fir_ArrayLoadOp : fir_Op<"array_load", [AttrSizedOperandSegments,
1379-
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
1376+
def fir_ArrayLoadOp : fir_Op<"array_load", [AttrSizedOperandSegments]> {
13801377

13811378
let summary = "Load an array as a value.";
13821379

@@ -1415,7 +1412,7 @@ def fir_ArrayLoadOp : fir_Op<"array_load", [AttrSizedOperandSegments,
14151412
}];
14161413

14171414
let arguments = (ins
1418-
AnyRefOrBox:$memref,
1415+
Arg<AnyRefOrBox, "", [MemRead]>:$memref,
14191416
Optional<AnyShapeOrShiftType>:$shape,
14201417
Optional<fir_SliceType>:$slice,
14211418
Variadic<AnyIntegerType>:$typeparams
@@ -1627,7 +1624,7 @@ def fir_ArrayAccessOp : fir_Op<"array_access", [AttrSizedOperandSegments,
16271624

16281625
It is only possible to use `array_access` on an `array_load` result value or
16291626
a value that can be trace back transitively to an `array_load` as the
1630-
dominating source. Other array operations such as `array_amend` can be in
1627+
dominating source. Other array operation such as `array_amend` can be in
16311628
between.
16321629

16331630
TODO: The above restriction is not enforced. The design of the operation
@@ -1688,7 +1685,7 @@ def fir_ArrayAmendOp : fir_Op<"array_amend", [NoMemoryEffect]> {
16881685
}
16891686

16901687
def fir_ArrayMergeStoreOp : fir_Op<"array_merge_store",
1691-
[AttrSizedOperandSegments, DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
1688+
[AttrSizedOperandSegments]> {
16921689

16931690
let summary = "Store merged array value to memory.";
16941691

@@ -1717,7 +1714,7 @@ def fir_ArrayMergeStoreOp : fir_Op<"array_merge_store",
17171714
let arguments = (ins
17181715
fir_SequenceType:$original,
17191716
fir_SequenceType:$sequence,
1720-
AnyRefOrBox:$memref,
1717+
Arg<AnyRefOrBox, "", [MemWrite]>:$memref,
17211718
Optional<fir_SliceType>:$slice,
17221719
Variadic<AnyIntegerType>:$typeparams
17231720
);
@@ -2755,22 +2752,6 @@ def fir_AddrOfOp : fir_OneResultOp<"address_of", [NoMemoryEffect]> {
27552752
let assemblyFormat = "`(` $symbol `)` attr-dict `:` type($resTy)";
27562753
}
27572754

2758-
def fir_VolatileCastOp : fir_SimpleOneResultOp<"volatile_cast", [NoMemoryEffect]> {
2759-
let summary = "cast between volatile and non-volatile types";
2760-
let description = [{
2761-
Cast between volatile and non-volatile types. The types must be otherwise
2762-
identical. A value's volatility cannot be changed by a fir.convert operation.
2763-
Reinterpreting a value as volatile must be done explicitly using this operation.
2764-
}];
2765-
let arguments = (ins AnyRefOrBox:$value);
2766-
let results = (outs AnyRefOrBox:$res);
2767-
let assemblyFormat = [{
2768-
$value attr-dict `:` functional-type($value, results)
2769-
}];
2770-
let hasVerifier = 1;
2771-
let hasFolder = 1;
2772-
}
2773-
27742755
def fir_ConvertOp : fir_SimpleOneResultOp<"convert", [NoMemoryEffect]> {
27752756
let summary = "encapsulates all Fortran entity type conversions";
27762757

flang/include/flang/Optimizer/Dialect/FIROpsSupport.h

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,13 @@
1515

1616
namespace fir {
1717

18-
/// The LLVM dialect represents volatile memory accesses as read and write
19-
/// effects to an unknown memory location, but this may be overly conservative.
20-
/// LLVM Language Reference only specifies that volatile memory accesses
21-
/// must not be reordered relative to other volatile memory accesses, so it
22-
/// is more precise to use a separate memory resource for volatile memory
23-
/// accesses.
24-
inline void addVolatileMemoryEffects(
25-
mlir::TypeRange type,
26-
llvm::SmallVectorImpl<
27-
mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>
28-
&effects) {
29-
for (mlir::Type t : type) {
30-
if (fir::isa_volatile_type(t)) {
31-
effects.emplace_back(mlir::MemoryEffects::Read::get(),
32-
fir::VolatileMemoryResource::get());
33-
effects.emplace_back(mlir::MemoryEffects::Write::get(),
34-
fir::VolatileMemoryResource::get());
35-
break;
36-
}
37-
}
18+
/// Return true iff the Operation is a non-volatile LoadOp or ArrayLoadOp.
19+
inline bool nonVolatileLoad(mlir::Operation *op) {
20+
if (auto load = mlir::dyn_cast<fir::LoadOp>(op))
21+
return !load->getAttr("volatile");
22+
if (auto arrLoad = mlir::dyn_cast<fir::ArrayLoadOp>(op))
23+
return !arrLoad->getAttr("volatile");
24+
return false;
3825
}
3926

4027
/// Return true iff the Operation is a call.

flang/lib/Lower/ConvertExprToHLFIR.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,8 @@ class HlfirDesignatorBuilder {
415415
.Case<fir::SequenceType>([&](fir::SequenceType seqTy) -> mlir::Type {
416416
return fir::SequenceType::get(seqTy.getShape(), newEleTy);
417417
})
418-
.Case<fir::ReferenceType, fir::BoxType, fir::ClassType>(
419-
[&](auto t) -> mlir::Type {
420-
using FIRT = decltype(t);
421-
return FIRT::get(changeElementType(t.getEleTy(), newEleTy),
422-
t.isVolatile());
423-
})
424-
.Case<fir::PointerType, fir::HeapType>([&](auto t) -> mlir::Type {
418+
.Case<fir::PointerType, fir::HeapType, fir::ReferenceType, fir::BoxType,
419+
fir::ClassType>([&](auto t) -> mlir::Type {
425420
using FIRT = decltype(t);
426421
return FIRT::get(changeElementType(t.getEleTy(), newEleTy));
427422
})

flang/lib/Optimizer/Builder/FIRBuilder.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,17 +577,6 @@ mlir::Value fir::FirOpBuilder::convertWithSemantics(
577577
return createConvert(loc, toTy, val);
578578
}
579579

580-
mlir::Value fir::FirOpBuilder::createConvertWithVolatileCast(mlir::Location loc,
581-
mlir::Type toTy,
582-
mlir::Value val) {
583-
if (fir::isa_volatile_type(val.getType()) != fir::isa_volatile_type(toTy)) {
584-
mlir::Type volatileAdjustedType = fir::updateTypeWithVolatility(
585-
val.getType(), fir::isa_volatile_type(toTy));
586-
val = create<fir::VolatileCastOp>(loc, volatileAdjustedType, val);
587-
}
588-
return createConvert(loc, toTy, val);
589-
}
590-
591580
mlir::Value fir::factory::createConvert(mlir::OpBuilder &builder,
592581
mlir::Location loc, mlir::Type toTy,
593582
mlir::Value val) {
@@ -750,20 +739,19 @@ mlir::Value fir::FirOpBuilder::createBox(mlir::Location loc,
750739
<< itemAddr.getType();
751740
llvm_unreachable("not a memory reference type");
752741
}
753-
const bool isVolatile = fir::isa_volatile_type(itemAddr.getType());
754742
mlir::Type boxTy;
755743
mlir::Value tdesc;
756744
// Avoid to wrap a box/class with box/class.
757745
if (mlir::isa<fir::BaseBoxType>(elementType)) {
758746
boxTy = elementType;
759747
} else {
760-
boxTy = fir::BoxType::get(elementType, isVolatile);
748+
boxTy = fir::BoxType::get(elementType);
761749
if (isPolymorphic) {
762750
elementType = fir::updateTypeForUnlimitedPolymorphic(elementType);
763751
if (isAssumedType)
764-
boxTy = fir::BoxType::get(elementType, isVolatile);
752+
boxTy = fir::BoxType::get(elementType);
765753
else
766-
boxTy = fir::ClassType::get(elementType, isVolatile);
754+
boxTy = fir::ClassType::get(elementType);
767755
}
768756
}
769757

0 commit comments

Comments
 (0)