Skip to content

Commit b6b8ef8

Browse files
committed
[flang][NFC] use llvm.intr.stacksave/restore instead of opaque calls
The new LLVM stack save/restore intrinsic operations are more convenient than function calls because they do not add function declarations to the module and therefore do not block the parallelisation of passes. Furthermore they could be much more easily marked with memory effects than function calls if that ever proved useful. This builds on top of llvm#107879. Resolves llvm#108016
1 parent c0b3e49 commit b6b8ef8

25 files changed

+107
-155
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,15 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
253253
mlir::ValueRange lenParams = {},
254254
llvm::ArrayRef<mlir::NamedAttribute> attrs = {});
255255

256+
/// Create an LLVM stack save intrinsic op. Returns the saved stack pointer.
257+
/// The stack address space is fetched from the data layout of the current
258+
/// module.
259+
mlir::Value genStackSave(mlir::Location loc);
260+
261+
/// Create an LLVM stack restore intrinsic op. stackPointer should be a value
262+
/// previously returned from genStackSave.
263+
void genStackRestore(mlir::Location loc, mlir::Value stackPointer);
264+
256265
/// Create a global value.
257266
fir::GlobalOp createGlobal(mlir::Location loc, mlir::Type type,
258267
llvm::StringRef name,
@@ -729,6 +738,9 @@ elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
729738
llvm::SmallVector<mlir::Value>
730739
elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
731740

741+
/// Get the address space which should be used for allocas
742+
uint64_t getAllocaAddressSpace(mlir::DataLayout *dataLayout);
743+
732744
} // namespace fir::factory
733745

734746
#endif // FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H

flang/include/flang/Optimizer/Builder/LowLevelIntrinsics.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ mlir::func::FuncOp getLlvmGetRounding(FirOpBuilder &builder);
4242
/// Get the `llvm.set.rounding` intrinsic.
4343
mlir::func::FuncOp getLlvmSetRounding(FirOpBuilder &builder);
4444

45-
/// Get the `llvm.stacksave` intrinsic.
46-
mlir::func::FuncOp getLlvmStackSave(FirOpBuilder &builder);
47-
48-
/// Get the `llvm.stackrestore` intrinsic.
49-
mlir::func::FuncOp getLlvmStackRestore(FirOpBuilder &builder);
50-
5145
/// Get the `llvm.init.trampoline` intrinsic.
5246
mlir::func::FuncOp getLlvmInitTrampoline(FirOpBuilder &builder);
5347

flang/include/flang/Optimizer/Support/DataLayout.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ void setMLIRDataLayoutFromAttributes(mlir::ModuleOp mlirModule,
4545
/// std::nullopt.
4646
std::optional<mlir::DataLayout>
4747
getOrSetDataLayout(mlir::ModuleOp mlirModule, bool allowDefaultLayout = false);
48-
4948
} // namespace fir::support
5049

5150
#endif // FORTRAN_OPTIMIZER_SUPPORT_DATALAYOUT_H

flang/lib/Lower/Bridge.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,15 +3256,10 @@ class FirConverter : public Fortran::lower::AbstractConverter {
32563256
const Fortran::parser::CharBlock &endPosition =
32573257
eval.getLastNestedEvaluation().position;
32583258
localSymbols.pushScope();
3259-
mlir::func::FuncOp stackSave = fir::factory::getLlvmStackSave(*builder);
3260-
mlir::func::FuncOp stackRestore =
3261-
fir::factory::getLlvmStackRestore(*builder);
3262-
mlir::Value stackPtr =
3263-
builder->create<fir::CallOp>(toLocation(), stackSave).getResult(0);
3259+
mlir::Value stackPtr = builder->genStackSave(toLocation());
32643260
mlir::Location endLoc = genLocation(endPosition);
3265-
stmtCtx.attachCleanup([=]() {
3266-
builder->create<fir::CallOp>(endLoc, stackRestore, stackPtr);
3267-
});
3261+
stmtCtx.attachCleanup(
3262+
[=]() { builder->genStackRestore(endLoc, stackPtr); });
32683263
Fortran::semantics::Scope &scope =
32693264
bridge.getSemanticsContext().FindScope(endPosition);
32703265
scopeBlockIdMap.try_emplace(&scope, ++blockId);

flang/lib/Lower/ConvertCall.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -368,22 +368,9 @@ std::pair<fir::ExtendedValue, bool> Fortran::lower::genCallOpAndResult(
368368

369369
if (!extents.empty() || !lengths.empty()) {
370370
auto *bldr = &converter.getFirOpBuilder();
371-
auto stackSaveFn = fir::factory::getLlvmStackSave(builder);
372-
auto stackSaveSymbol = bldr->getSymbolRefAttr(stackSaveFn.getName());
373-
mlir::Value sp;
374-
fir::CallOp call = bldr->create<fir::CallOp>(
375-
loc, stackSaveSymbol, stackSaveFn.getFunctionType().getResults(),
376-
mlir::ValueRange{});
377-
if (call.getNumResults() != 0)
378-
sp = call.getResult(0);
379-
stmtCtx.attachCleanup([bldr, loc, sp]() {
380-
auto stackRestoreFn = fir::factory::getLlvmStackRestore(*bldr);
381-
auto stackRestoreSymbol =
382-
bldr->getSymbolRefAttr(stackRestoreFn.getName());
383-
bldr->create<fir::CallOp>(loc, stackRestoreSymbol,
384-
stackRestoreFn.getFunctionType().getResults(),
385-
mlir::ValueRange{sp});
386-
});
371+
mlir::Value sp = bldr->genStackSave(loc);
372+
stmtCtx.attachCleanup(
373+
[bldr, loc, sp]() { bldr->genStackRestore(loc, sp); });
387374
}
388375
mlir::Value temp =
389376
builder.createTemporary(loc, type, ".result", extents, resultLengths);

flang/lib/Optimizer/Builder/FIRBuilder.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "flang/Optimizer/Dialect/FIRAttr.h"
1919
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
2020
#include "flang/Optimizer/Dialect/FIRType.h"
21+
#include "flang/Optimizer/Support/DataLayout.h"
2122
#include "flang/Optimizer/Support/FatalError.h"
2223
#include "flang/Optimizer/Support/InternalNames.h"
2324
#include "flang/Optimizer/Support/Utils.h"
@@ -328,6 +329,18 @@ mlir::Value fir::FirOpBuilder::createHeapTemporary(
328329
name, dynamicLength, dynamicShape, attrs);
329330
}
330331

332+
mlir::Value fir::FirOpBuilder::genStackSave(mlir::Location loc) {
333+
mlir::DataLayout dataLayout(getModule());
334+
mlir::Type voidPtr = mlir::LLVM::LLVMPointerType::get(
335+
getContext(), fir::factory::getAllocaAddressSpace(&dataLayout));
336+
return create<mlir::LLVM::StackSaveOp>(loc, voidPtr);
337+
}
338+
339+
void fir::FirOpBuilder::genStackRestore(mlir::Location loc,
340+
mlir::Value stackPointer) {
341+
create<mlir::LLVM::StackRestoreOp>(loc, stackPointer);
342+
}
343+
331344
/// Create a global variable in the (read-only) data section. A global variable
332345
/// must have a unique name to identify and reference it.
333346
fir::GlobalOp fir::FirOpBuilder::createGlobal(
@@ -1664,3 +1677,10 @@ void fir::factory::setInternalLinkage(mlir::func::FuncOp func) {
16641677
mlir::LLVM::LinkageAttr::get(func->getContext(), internalLinkage);
16651678
func->setAttr("llvm.linkage", linkage);
16661679
}
1680+
1681+
uint64_t fir::factory::getAllocaAddressSpace(mlir::DataLayout *dataLayout) {
1682+
if (dataLayout)
1683+
if (mlir::Attribute addrSpace = dataLayout->getAllocaMemorySpace())
1684+
return mlir::cast<mlir::IntegerAttr>(addrSpace).getUInt();
1685+
return 0;
1686+
}

flang/lib/Optimizer/Builder/LowLevelIntrinsics.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,6 @@ fir::factory::getLlvmSetRounding(fir::FirOpBuilder &builder) {
7676
funcTy);
7777
}
7878

79-
mlir::func::FuncOp fir::factory::getLlvmStackSave(fir::FirOpBuilder &builder) {
80-
// FIXME: This should query the target alloca address space
81-
auto ptrTy = builder.getRefType(builder.getIntegerType(8));
82-
auto funcTy =
83-
mlir::FunctionType::get(builder.getContext(), std::nullopt, {ptrTy});
84-
return builder.createFunction(builder.getUnknownLoc(), "llvm.stacksave.p0",
85-
funcTy);
86-
}
87-
88-
mlir::func::FuncOp
89-
fir::factory::getLlvmStackRestore(fir::FirOpBuilder &builder) {
90-
// FIXME: This should query the target alloca address space
91-
auto ptrTy = builder.getRefType(builder.getIntegerType(8));
92-
auto funcTy =
93-
mlir::FunctionType::get(builder.getContext(), {ptrTy}, std::nullopt);
94-
return builder.createFunction(builder.getUnknownLoc(), "llvm.stackrestore.p0",
95-
funcTy);
96-
}
97-
9879
mlir::func::FuncOp
9980
fir::factory::getLlvmInitTrampoline(fir::FirOpBuilder &builder) {
10081
auto ptrTy = builder.getRefType(builder.getIntegerType(8));

flang/lib/Optimizer/CodeGen/TargetRewrite.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,25 +1236,18 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
12361236

12371237
inline void clearMembers() { setMembers(nullptr, nullptr, nullptr); }
12381238

1239-
uint64_t getAllocaAddressSpace() const {
1240-
if (dataLayout)
1241-
if (mlir::Attribute addrSpace = dataLayout->getAllocaMemorySpace())
1242-
return llvm::cast<mlir::IntegerAttr>(addrSpace).getUInt();
1243-
return 0;
1244-
}
1245-
12461239
// Inserts a call to llvm.stacksave at the current insertion
12471240
// point and the given location. Returns the call's result Value.
12481241
inline mlir::Value genStackSave(mlir::Location loc) {
1249-
mlir::Type voidPtr = mlir::LLVM::LLVMPointerType::get(
1250-
rewriter->getContext(), getAllocaAddressSpace());
1251-
return rewriter->create<mlir::LLVM::StackSaveOp>(loc, voidPtr);
1242+
fir::FirOpBuilder builder(*rewriter, getModule());
1243+
return builder.genStackSave(loc);
12521244
}
12531245

12541246
// Inserts a call to llvm.stackrestore at the current insertion
12551247
// point and the given location and argument.
12561248
inline void genStackRestore(mlir::Location loc, mlir::Value sp) {
1257-
rewriter->create<mlir::LLVM::StackRestoreOp>(loc, sp);
1249+
fir::FirOpBuilder builder(*rewriter, getModule());
1250+
return builder.genStackRestore(loc, sp);
12581251
}
12591252

12601253
fir::CodeGenSpecifics *specifics = nullptr;

flang/lib/Optimizer/Transforms/StackArrays.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -734,28 +734,12 @@ void AllocMemConversion::insertStackSaveRestore(
734734
auto mod = oldAlloc->getParentOfType<mlir::ModuleOp>();
735735
fir::FirOpBuilder builder{rewriter, mod};
736736

737-
mlir::func::FuncOp stackSaveFn = fir::factory::getLlvmStackSave(builder);
738-
mlir::SymbolRefAttr stackSaveSym =
739-
builder.getSymbolRefAttr(stackSaveFn.getName());
740-
741737
builder.setInsertionPoint(oldAlloc);
742-
mlir::Value sp =
743-
builder
744-
.create<fir::CallOp>(oldAlloc.getLoc(), stackSaveSym,
745-
stackSaveFn.getFunctionType().getResults(),
746-
mlir::ValueRange{})
747-
.getResult(0);
748-
749-
mlir::func::FuncOp stackRestoreFn =
750-
fir::factory::getLlvmStackRestore(builder);
751-
mlir::SymbolRefAttr stackRestoreSym =
752-
builder.getSymbolRefAttr(stackRestoreFn.getName());
738+
mlir::Value sp = builder.genStackSave(oldAlloc.getLoc());
753739

754740
auto createStackRestoreCall = [&](mlir::Operation *user) {
755741
builder.setInsertionPoint(user);
756-
builder.create<fir::CallOp>(user->getLoc(), stackRestoreSym,
757-
stackRestoreFn.getFunctionType().getResults(),
758-
mlir::ValueRange{sp});
742+
builder.genStackRestore(user->getLoc(), sp);
759743
};
760744

761745
for (mlir::Operation *user : oldAlloc->getUsers()) {

flang/lib/Optimizer/Transforms/StackReclaim.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "flang/Common/Fortran.h"
10+
#include "flang/Optimizer/Builder/FIRBuilder.h"
1011
#include "flang/Optimizer/Dialect/FIRDialect.h"
1112
#include "flang/Optimizer/Dialect/FIROps.h"
1213
#include "flang/Optimizer/Transforms/Passes.h"
@@ -31,34 +32,20 @@ class StackReclaimPass : public fir::impl::StackReclaimBase<StackReclaimPass> {
3132
};
3233
} // namespace
3334

34-
uint64_t getAllocaAddressSpace(Operation *op) {
35-
mlir::ModuleOp module = mlir::dyn_cast_or_null<mlir::ModuleOp>(op);
36-
if (!module)
37-
module = op->getParentOfType<mlir::ModuleOp>();
38-
39-
if (mlir::Attribute addrSpace =
40-
mlir::DataLayout(module).getAllocaMemorySpace())
41-
return llvm::cast<mlir::IntegerAttr>(addrSpace).getUInt();
42-
return 0;
43-
}
44-
4535
void StackReclaimPass::runOnOperation() {
4636
auto *op = getOperation();
47-
auto *context = &getContext();
48-
mlir::OpBuilder builder(context);
49-
mlir::Type voidPtr =
50-
mlir::LLVM::LLVMPointerType::get(context, getAllocaAddressSpace(op));
37+
fir::FirOpBuilder builder(op, fir::getKindMapping(op));
5138

5239
op->walk([&](fir::DoLoopOp loopOp) {
5340
mlir::Location loc = loopOp.getLoc();
5441

5542
if (!loopOp.getRegion().getOps<fir::AllocaOp>().empty()) {
5643
builder.setInsertionPointToStart(&loopOp.getRegion().front());
57-
auto stackSaveOp = builder.create<LLVM::StackSaveOp>(loc, voidPtr);
44+
mlir::Value sp = builder.genStackSave(loc);
5845

5946
auto *terminator = loopOp.getRegion().back().getTerminator();
6047
builder.setInsertionPoint(terminator);
61-
builder.create<LLVM::StackRestoreOp>(loc, stackSaveOp);
48+
builder.genStackRestore(loc, sp);
6249
}
6350
});
6451
}

flang/test/HLFIR/order_assignments/where-scheduling.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ end function f
134134
!CHECK-NEXT: run 1 save : where/mask
135135
!CHECK-NEXT: run 2 evaluate: where/region_assign1
136136
!CHECK-LABEL: ------------ scheduling where in _QPonly_once ------------
137-
!CHECK-NEXT: unknown effect: %{{[0-9]+}} = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
137+
!CHECK-NEXT: unknown effect: %{{[0-9]+}} = llvm.intr.stacksave : !llvm.ptr
138138
!CHECK-NEXT: run 1 save (w): where/mask
139139
!CHECK-NEXT: run 2 evaluate: where/region_assign1
140140
!CHECK-NEXT: run 3 evaluate: where/region_assign2

flang/test/Lower/HLFIR/block_bindc_pocs.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ subroutine test_proc() bind(C)
88
end subroutine test_proc
99
end interface
1010
end module m
11-
!CHECK-DAG: %[[S0:.*]] = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
11+
!CHECK-DAG: %[[S0:.*]] = llvm.intr.stacksave : !llvm.ptr
1212
!CHECK-DAG: fir.call @test_proc() proc_attrs<bind_c> fastmath<contract> : () -> ()
13-
!CHECK-DAG: fir.call @llvm.stackrestore.p0(%[[S0]]) fastmath<contract> : (!fir.ref<i8>) -> ()
13+
!CHECK-DAG: llvm.intr.stackrestore %[[S0]] : !llvm.ptr
1414
!CHECK-DAG: func.func private @test_proc() attributes {fir.bindc_name = "test_proc"}
1515
subroutine test
1616
BLOCK

flang/test/Lower/HLFIR/elemental-array-ops.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ end subroutine char_return
182182
! CHECK: %[[VAL_23:.*]] = arith.constant 0 : index
183183
! CHECK: %[[VAL_24:.*]] = arith.cmpi sgt, %[[VAL_22]], %[[VAL_23]] : index
184184
! CHECK: %[[VAL_25:.*]] = arith.select %[[VAL_24]], %[[VAL_22]], %[[VAL_23]] : index
185-
! CHECK: %[[VAL_26:.*]] = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
185+
! CHECK: %[[VAL_26:.*]] = llvm.intr.stacksave : !llvm.ptr
186186
! CHECK: %[[VAL_27:.*]] = fir.call @_QPcallee(%[[VAL_2]], %[[VAL_25]], %[[VAL_20]]) fastmath<contract> : (!fir.ref<!fir.char<1,3>>, index, !fir.boxchar<1>) -> !fir.boxchar<1>
187187
! CHECK: %[[VAL_28:.*]]:2 = hlfir.declare %[[VAL_2]] typeparams %[[VAL_25]] {uniq_name = ".tmp.func_result"} : (!fir.ref<!fir.char<1,3>>, index) -> (!fir.ref<!fir.char<1,3>>, !fir.ref<!fir.char<1,3>>)
188188
! CHECK: %[[MustFree:.*]] = arith.constant false
189189
! CHECK: %[[ResultTemp:.*]] = hlfir.as_expr %[[VAL_28]]#0 move %[[MustFree]] : (!fir.ref<!fir.char<1,3>>, i1) -> !hlfir.expr<!fir.char<1,3>>
190-
! CHECK: fir.call @llvm.stackrestore.p0(%[[VAL_26]]) fastmath<contract> : (!fir.ref<i8>) -> ()
190+
! CHECK: llvm.intr.stackrestore %[[VAL_26]] : !llvm.ptr
191191
! CHECK: hlfir.yield_element %[[ResultTemp]] : !hlfir.expr<!fir.char<1,3>>
192192
! CHECK: }
193193
! CHECK: %[[VAL_29:.*]] = arith.constant 0 : index

flang/test/Lower/HLFIR/proc-pointer-comp-pass.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@ subroutine test5(x)
105105
! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index
106106
! CHECK: %[[VAL_8:.*]] = arith.cmpi sgt, %[[VAL_6]], %[[VAL_7]] : index
107107
! CHECK: %[[VAL_9:.*]] = arith.select %[[VAL_8]], %[[VAL_6]], %[[VAL_7]] : index
108-
! CHECK: %[[VAL_10:.*]] = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
108+
! CHECK: %[[VAL_10:.*]] = llvm.intr.stacksave : !llvm.ptr
109109
! CHECK: %[[VAL_11:.*]] = fir.box_addr %[[VAL_4]] : (!fir.boxproc<(!fir.ref<!fir.char<1,4>>, index, !fir.ref<!fir.type<_QMmTt3{c:!fir.char<1,4>,p:!fir.boxproc<(!fir.ref<!fir.char<1,4>>, index, !fir.ref<!fir.type<_QMmTt3>>) -> !fir.boxchar<1>>}>>) -> !fir.boxchar<1>>) -> ((!fir.ref<!fir.char<1,4>>, index, !fir.ref<!fir.type<_QMmTt3{c:!fir.char<1,4>,p:!fir.boxproc<(!fir.ref<!fir.char<1,4>>, index, !fir.ref<!fir.type<_QMmTt3>>) -> !fir.boxchar<1>>}>>) -> !fir.boxchar<1>)
110110
! CHECK: %[[VAL_12:.*]] = fir.call %[[VAL_11]](%[[VAL_1]], %[[VAL_9]], %[[VAL_2]]#1) fastmath<contract> : (!fir.ref<!fir.char<1,4>>, index, !fir.ref<!fir.type<_QMmTt3{c:!fir.char<1,4>,p:!fir.boxproc<(!fir.ref<!fir.char<1,4>>, index, !fir.ref<!fir.type<_QMmTt3>>) -> !fir.boxchar<1>>}>>) -> !fir.boxchar<1>

flang/test/Lower/HLFIR/where-nonelemental.f90

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ real elemental function elem_func(x)
2626
! CHECK-LABEL: func.func @_QPtest_where(
2727
! CHECK: hlfir.where {
2828
! CHECK-NOT: hlfir.exactly_once
29-
! CHECK: %[[VAL_17:.*]] = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
29+
! CHECK: %[[VAL_17:.*]] = llvm.intr.stacksave : !llvm.ptr
3030
! CHECK: %[[VAL_19:.*]] = fir.call @_QPlogical_func1() fastmath<contract> : () -> !fir.array<100x!fir.logical<4>>
3131
! CHECK: hlfir.yield %{{.*}} : !hlfir.expr<100x!fir.logical<4>> cleanup {
32-
! CHECK: fir.call @llvm.stackrestore.p0(%[[VAL_17]]) fastmath<contract> : (!fir.ref<i8>) -> ()
32+
! CHECK: llvm.intr.stackrestore %[[VAL_17]] : !llvm.ptr
3333
! CHECK: }
3434
! CHECK: } do {
3535
! CHECK: hlfir.region_assign {
@@ -70,10 +70,10 @@ real elemental function elem_func(x)
7070
! CHECK: }
7171
! CHECK: hlfir.elsewhere mask {
7272
! CHECK: %[[VAL_62:.*]] = hlfir.exactly_once : !hlfir.expr<100x!fir.logical<4>> {
73-
! CHECK: %[[VAL_72:.*]] = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
73+
! CHECK: %[[VAL_72:.*]] = llvm.intr.stacksave : !llvm.ptr
7474
! CHECK: fir.call @_QPlogical_func2() fastmath<contract> : () -> !fir.array<100x!fir.logical<4>>
7575
! CHECK: hlfir.yield %{{.*}} : !hlfir.expr<100x!fir.logical<4>> cleanup {
76-
! CHECK: fir.call @llvm.stackrestore.p0(%[[VAL_72]]) fastmath<contract> : (!fir.ref<i8>) -> ()
76+
! CHECK: llvm.intr.stackrestore %[[VAL_72]] : !llvm.ptr
7777
! CHECK: }
7878
! CHECK: }
7979
! CHECK: hlfir.yield %[[VAL_62]] : !hlfir.expr<100x!fir.logical<4>>
@@ -123,11 +123,11 @@ integer pure function pure_ifoo()
123123
! CHECK: } (%[[VAL_10:.*]]: i32) {
124124
! CHECK: %[[VAL_11:.*]] = hlfir.forall_index "i" %[[VAL_10]] : (i32) -> !fir.ref<i32>
125125
! CHECK: hlfir.where {
126-
! CHECK: %[[VAL_21:.*]] = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
126+
! CHECK: %[[VAL_21:.*]] = llvm.intr.stacksave : !llvm.ptr
127127
! CHECK-NOT: hlfir.exactly_once
128128
! CHECK: %[[VAL_23:.*]] = fir.call @_QPpure_logical_func1() fastmath<contract> : () -> !fir.array<100x!fir.logical<4>>
129129
! CHECK: hlfir.yield %{{.*}} : !hlfir.expr<100x!fir.logical<4>> cleanup {
130-
! CHECK: fir.call @llvm.stackrestore.p0(%[[VAL_21]]) fastmath<contract> : (!fir.ref<i8>) -> ()
130+
! CHECK: llvm.intr.stackrestore %[[VAL_21]] : !llvm.ptr
131131
! CHECK: }
132132
! CHECK: } do {
133133
! CHECK: hlfir.region_assign {
@@ -172,10 +172,10 @@ integer pure function pure_ifoo()
172172
! CHECK: }
173173
! CHECK: hlfir.elsewhere mask {
174174
! CHECK: %[[VAL_129:.*]] = hlfir.exactly_once : !hlfir.expr<100x!fir.logical<4>> {
175-
! CHECK: %[[VAL_139:.*]] = fir.call @llvm.stacksave.p0() fastmath<contract> : () -> !fir.ref<i8>
175+
! CHECK: %[[VAL_139:.*]] = llvm.intr.stacksave : !llvm.ptr
176176
! CHECK: %[[VAL_141:.*]] = fir.call @_QPpure_logical_func2() fastmath<contract> : () -> !fir.array<100x!fir.logical<4>>
177177
! CHECK: hlfir.yield %{{.*}} : !hlfir.expr<100x!fir.logical<4>> cleanup {
178-
! CHECK: fir.call @llvm.stackrestore.p0(%[[VAL_139]]) fastmath<contract> : (!fir.ref<i8>) -> ()
178+
! CHECK: llvm.intr.stackrestore %[[VAL_139]] : !llvm.ptr
179179
! CHECK: }
180180
! CHECK: }
181181
! CHECK: hlfir.yield %[[VAL_129]] : !hlfir.expr<100x!fir.logical<4>>

flang/test/Lower/array-elemental-calls-char.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ subroutine foo6(c)
227227
! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> index
228228
! CHECK: %[[CMPI:.*]] = arith.cmpi sgt, %[[VAL_16]], %{{.*}} : index
229229
! CHECK: %[[SELECT:.*]] = arith.select %[[CMPI]], %[[VAL_16]], %{{.*}} : index
230-
! CHECK: %[[VAL_17:.*]] = fir.call @llvm.stacksave.p0() {{.*}}: () -> !fir.ref<i8>
230+
! CHECK: %[[VAL_17:.*]] = llvm.intr.stacksave : !llvm.ptr
231231
! CHECK: %[[VAL_18:.*]] = fir.alloca !fir.char<1,?>(%[[SELECT]] : index) {bindc_name = ".result"}
232232
! CHECK: %[[VAL_19:.*]] = fir.call @_QMchar_elemPelem_return_char(%[[VAL_18]], %[[SELECT]], %[[VAL_14]]) {{.*}}: (!fir.ref<!fir.char<1,?>>, index, !fir.boxchar<1>) -> !fir.boxchar<1>
233233
! CHECK: %[[VAL_20:.*]] = arith.cmpi slt, %[[VAL_6]]#1, %[[SELECT]] : index
@@ -253,7 +253,7 @@ subroutine foo6(c)
253253
! CHECK: %[[VAL_36:.*]] = arith.subi %[[VAL_31]], %[[VAL_2]] : index
254254
! CHECK: br ^bb3(%[[VAL_35]], %[[VAL_36]] : index, index)
255255
! CHECK: ^bb5:
256-
! CHECK: fir.call @llvm.stackrestore.p0(%[[VAL_17]]) {{.*}}: (!fir.ref<i8>) -> ()
256+
! CHECK: llvm.intr.stackrestore %[[VAL_17]] : !llvm.ptr
257257
! CHECK: %[[VAL_37:.*]] = arith.subi %[[VAL_10]], %[[VAL_2]] : index
258258
! CHECK: br ^bb1(%[[VAL_12]], %[[VAL_37]] : index, index)
259259
! CHECK: ^bb6:

0 commit comments

Comments
 (0)