Skip to content

Commit 958ea36

Browse files
committed
[flang][NFC] move loadIfRef to FIRBuilder
This will be useful for OpenMP too. I changed the definition slightly to use `fir::isa_ref_type` (which also includes llvm pointers) because I think it reads better using the common type helpers. There shouldn't be any llvm pointers in lowering so this isn't a functional change. Commit series for by-ref openmp reductions: 1/3
1 parent 5830d1a commit 958ea36

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
309309
void createStoreWithConvert(mlir::Location loc, mlir::Value val,
310310
mlir::Value addr);
311311

312+
/// Create a fir.load if \p val is a reference or pointer type. Return the
313+
/// result of the load if it was created, otherwise return \p val
314+
mlir::Value loadIfRef(mlir::Location loc, mlir::Value val);
315+
312316
/// Create a new FuncOp. If the function may have already been created, use
313317
/// `addNamedFunction` instead.
314318
mlir::func::FuncOp createFunction(mlir::Location loc, llvm::StringRef name,

flang/lib/Lower/OpenACC.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,14 +1041,6 @@ static mlir::Value genLogicalCombiner(fir::FirOpBuilder &builder,
10411041
return builder.create<fir::ConvertOp>(loc, value1.getType(), combined);
10421042
}
10431043

1044-
static mlir::Value loadIfRef(fir::FirOpBuilder &builder, mlir::Location loc,
1045-
mlir::Value value) {
1046-
if (mlir::isa<fir::ReferenceType, fir::PointerType, fir::HeapType>(
1047-
value.getType()))
1048-
return builder.create<fir::LoadOp>(loc, value);
1049-
return value;
1050-
}
1051-
10521044
static mlir::Value genComparisonCombiner(fir::FirOpBuilder &builder,
10531045
mlir::Location loc,
10541046
mlir::arith::CmpIPredicate pred,
@@ -1066,8 +1058,8 @@ static mlir::Value genScalarCombiner(fir::FirOpBuilder &builder,
10661058
mlir::acc::ReductionOperator op,
10671059
mlir::Type ty, mlir::Value value1,
10681060
mlir::Value value2) {
1069-
value1 = loadIfRef(builder, loc, value1);
1070-
value2 = loadIfRef(builder, loc, value2);
1061+
value1 = builder.loadIfRef(loc, value1);
1062+
value2 = builder.loadIfRef(loc, value2);
10711063
if (op == mlir::acc::ReductionOperator::AccAdd) {
10721064
if (ty.isIntOrIndex())
10731065
return builder.create<mlir::arith::AddIOp>(loc, value1, value2);

flang/lib/Optimizer/Builder/FIRBuilder.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "flang/Optimizer/Builder/Todo.h"
1717
#include "flang/Optimizer/Dialect/FIRAttr.h"
1818
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
19+
#include "flang/Optimizer/Dialect/FIRType.h"
1920
#include "flang/Optimizer/Support/FatalError.h"
2021
#include "flang/Optimizer/Support/InternalNames.h"
2122
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
@@ -404,6 +405,12 @@ void fir::FirOpBuilder::createStoreWithConvert(mlir::Location loc,
404405
create<fir::StoreOp>(loc, cast, addr);
405406
}
406407

408+
mlir::Value fir::FirOpBuilder::loadIfRef(mlir::Location loc, mlir::Value val) {
409+
if (fir::isa_ref_type(val.getType()))
410+
return create<fir::LoadOp>(loc, val);
411+
return val;
412+
}
413+
407414
fir::StringLitOp fir::FirOpBuilder::createStringLitOp(mlir::Location loc,
408415
llvm::StringRef data) {
409416
auto type = fir::CharacterType::get(getContext(), 1, data.size());

0 commit comments

Comments
 (0)