Skip to content

Commit 1acc4c0

Browse files
committed
merge main into amd-stg-open
Change-Id: Ib6a8b3b1bfd0ca876e2e55024f0aa9b39b33114c
2 parents 17835bc + 8391bb3 commit 1acc4c0

File tree

111 files changed

+1250
-661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1250
-661
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7315,7 +7315,7 @@ this usage is debugger-dependent.
73157315
}
73167316

73177317
def CleanupDocs : Documentation {
7318-
let Category = DocCatType;
7318+
let Category = DocCatVariable;
73197319
let Content = [{
73207320
This attribute allows a function to be run when a local variable goes out of
73217321
scope. The attribute takes the identifier of a function with a parameter type

clang/include/clang/Sema/Overload.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,7 @@ class Sema;
257257
/// sequence (C++ 13.3.3.1.1). A standard conversion sequence
258258
/// contains between zero and three conversions. If a particular
259259
/// conversion is not needed, it will be set to the identity conversion
260-
/// (ICK_Identity). Note that the three conversions are
261-
/// specified as separate members (rather than in an array) so that
262-
/// we can keep the size of a standard conversion sequence to a
263-
/// single word.
260+
/// (ICK_Identity).
264261
class StandardConversionSequence {
265262
public:
266263
/// First -- The first conversion can be an lvalue-to-rvalue

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,6 @@ void Flang::addCodegenOptions(const ArgList &Args,
142142
if (shouldLoopVersion(Args))
143143
CmdArgs.push_back("-fversion-loops-for-stride");
144144

145-
Arg *aliasAnalysis = Args.getLastArg(options::OPT_falias_analysis,
146-
options::OPT_fno_alias_analysis);
147-
// only pass on the argument if it does not match that implied by the
148-
// optimization level: so if optimization is requested, only forward
149-
// -fno-alias-analysis. If optimization is not requested, only forward
150-
// -falias-analysis.
151-
Arg *optLevel =
152-
Args.getLastArg(options::OPT_Ofast, options::OPT_O, options::OPT_O4);
153-
if (aliasAnalysis) {
154-
bool faliasAnalysis =
155-
aliasAnalysis->getOption().matches(options::OPT_falias_analysis);
156-
if (optLevel && !faliasAnalysis) {
157-
CmdArgs.push_back("-fno-alias-analysis");
158-
} else {
159-
if (faliasAnalysis)
160-
// requested alias analysis but no optimization enabled
161-
CmdArgs.push_back("-falias-analysis");
162-
}
163-
}
164-
165145
Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
166146
options::OPT_flang_deprecated_no_hlfir,
167147
options::OPT_flang_experimental_polymorphism,

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class DSAStackTy {
161161
LoopControlVariablesMapTy LCVMap;
162162
DefaultDataSharingAttributes DefaultAttr = DSA_unspecified;
163163
SourceLocation DefaultAttrLoc;
164-
DefaultmapInfo DefaultmapMap[OMPC_DEFAULTMAP_unknown];
164+
DefaultmapInfo DefaultmapMap[OMPC_DEFAULTMAP_unknown + 1];
165165
OpenMPDirectiveKind Directive = OMPD_unknown;
166166
/// GenericLoopDirective with bind clause is mapped to other directives,
167167
/// like for, distribute and simd. Presently, set MappedDirective to
@@ -3689,7 +3689,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
36893689
bool ErrorFound = false;
36903690
bool TryCaptureCXXThisMembers = false;
36913691
CapturedStmt *CS = nullptr;
3692-
const static unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1;
3692+
const static unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_unknown + 1;
36933693
llvm::SmallVector<Expr *, 4> ImplicitFirstprivate;
36943694
llvm::SmallVector<Expr *, 4> ImplicitPrivate;
36953695
llvm::SmallVector<Expr *, 4> ImplicitMap[DefaultmapKindNum][OMPC_MAP_delete];
@@ -6278,7 +6278,7 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
62786278
SmallVector<Expr *, 4> ImplicitPrivates(
62796279
DSAChecker.getImplicitPrivate().begin(),
62806280
DSAChecker.getImplicitPrivate().end());
6281-
const unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1;
6281+
const unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_unknown + 1;
62826282
SmallVector<Expr *, 4> ImplicitMaps[DefaultmapKindNum][OMPC_MAP_delete];
62836283
SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers>
62846284
ImplicitMapModifiers[DefaultmapKindNum];

clang/test/OpenMP/target_ast_print.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,8 @@ T tmain(T argc, T *argv) {
11101110
foo();
11111111
#pragma omp target thread_limit(C)
11121112
foo();
1113+
#pragma omp target defaultmap(present)
1114+
foo();
11131115

11141116
return 0;
11151117
}
@@ -1123,6 +1125,8 @@ T tmain(T argc, T *argv) {
11231125
// OMP51-NEXT: foo()
11241126
// OMP51-NEXT: #pragma omp target thread_limit(C)
11251127
// OMP51-NEXT: foo()
1128+
// OMP51-NEXT: #pragma omp target defaultmap(present)
1129+
// OMP51-NEXT: foo()
11261130

11271131
// OMP51-LABEL: int main(int argc, char **argv) {
11281132
int main (int argc, char **argv) {

flang/include/flang/Lower/ConvertExpr.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,6 @@ mlir::Value createSubroutineCall(AbstractConverter &converter,
225225
SymMap &symMap, StatementContext &stmtCtx,
226226
bool isUserDefAssignment);
227227

228-
// Attribute for an alloca that is a trivial adaptor for converting a value to
229-
// pass-by-ref semantics for a VALUE parameter. The optimizer may be able to
230-
// eliminate these.
231-
inline mlir::NamedAttribute getAdaptToByRefAttr(fir::FirOpBuilder &builder) {
232-
return {mlir::StringAttr::get(builder.getContext(),
233-
fir::getAdaptToByRefAttrName()),
234-
builder.getUnitAttr()};
235-
}
236-
237228
mlir::Value addCrayPointerInst(mlir::Location loc, fir::FirOpBuilder &builder,
238229
mlir::Value ptrVal, mlir::Type ptrTy,
239230
mlir::Type pteTy);

flang/include/flang/Optimizer/Builder/HLFIRTools.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ fir::FortranVariableOpInterface genDeclare(mlir::Location loc,
239239
/// Generate an hlfir.associate to build a variable from an expression value.
240240
/// The type of the variable must be provided so that scalar logicals are
241241
/// properly typed when placed in memory.
242-
hlfir::AssociateOp genAssociateExpr(mlir::Location loc,
243-
fir::FirOpBuilder &builder,
244-
hlfir::Entity value,
245-
mlir::Type variableType,
246-
llvm::StringRef name);
242+
hlfir::AssociateOp
243+
genAssociateExpr(mlir::Location loc, fir::FirOpBuilder &builder,
244+
hlfir::Entity value, mlir::Type variableType,
245+
llvm::StringRef name,
246+
std::optional<mlir::NamedAttribute> attr = std::nullopt);
247247

248248
/// Get the raw address of a variable (simple fir.ref/fir.ptr, or fir.heap
249249
/// value). The returned value should be used with care, it does not contain any

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ mlir::ParseResult parseSelector(mlir::OpAsmParser &parser,
3838
mlir::OpAsmParser::UnresolvedOperand &selector,
3939
mlir::Type &type);
4040

41-
static constexpr llvm::StringRef getAdaptToByRefAttrName() {
42-
return "adapt.valuebyref";
43-
}
44-
4541
static constexpr llvm::StringRef getNormalizedLowerBoundAttrName() {
4642
return "normalized.lb";
4743
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ inline std::optional<std::int64_t> getIntIfConstant(mlir::Value value) {
141141
return {};
142142
}
143143

144+
static constexpr llvm::StringRef getAdaptToByRefAttrName() {
145+
return "adapt.valuebyref";
146+
}
147+
148+
// Attribute for an alloca that is a trivial adaptor for converting a value to
149+
// pass-by-ref semantics for a VALUE parameter. The optimizer may be able to
150+
// eliminate these.
151+
// Template is used to avoid compiler errors in places that don't include
152+
// FIRBuilder.h
153+
template <typename Builder>
154+
inline mlir::NamedAttribute getAdaptToByRefAttr(Builder &builder) {
155+
return {mlir::StringAttr::get(builder.getContext(),
156+
fir::getAdaptToByRefAttrName()),
157+
builder.getUnitAttr()};
158+
}
159+
144160
} // namespace fir
145161

146162
#endif // FORTRAN_OPTIMIZER_DIALECT_FIROPSSUPPORT_H

flang/include/flang/Optimizer/HLFIR/HLFIROps.td

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def hlfir_AssociateOp : hlfir_Op<"associate", [AttrSizedOperandSegments,
660660
AnyFortranValue:$source,
661661
Optional<AnyShapeOrShiftType>:$shape,
662662
Variadic<AnyIntegerType>:$typeparams,
663-
Builtin_StringAttr:$uniq_name,
663+
OptionalAttr<Builtin_StringAttr>:$uniq_name,
664664
OptionalAttr<fir_FortranVariableFlagsAttr>:$fortran_attrs
665665
);
666666

@@ -672,9 +672,13 @@ def hlfir_AssociateOp : hlfir_Op<"associate", [AttrSizedOperandSegments,
672672
}];
673673

674674
let builders = [
675-
OpBuilder<(ins "mlir::Value":$source, "llvm::StringRef":$uniq_name,
675+
OpBuilder<(ins "mlir::Value":$source, CArg<"llvm::StringRef", "{}">:$uniq_name,
676676
CArg<"mlir::Value", "{}">:$shape, CArg<"mlir::ValueRange", "{}">:$typeparams,
677-
CArg<"fir::FortranVariableFlagsAttr", "{}">:$fortran_attrs)>];
677+
CArg<"fir::FortranVariableFlagsAttr", "{}">:$fortran_attrs)>,
678+
OpBuilder<(ins "mlir::Value":$memref, CArg<"mlir::Value", "{}">:$shape,
679+
CArg<"mlir::ValueRange", "{}">:$typeparams,
680+
CArg<"fir::FortranVariableFlagsAttr", "{}">:$fortran_attrs,
681+
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>];
678682

679683
let extraClassDeclaration = [{
680684
/// Override FortranVariableInterface default implementation

flang/include/flang/Optimizer/Support/Utils.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
#define FORTRAN_OPTIMIZER_SUPPORT_UTILS_H
1515

1616
#include "flang/Common/default-kinds.h"
17+
#include "flang/Optimizer/Builder/FIRBuilder.h"
18+
#include "flang/Optimizer/Builder/Todo.h"
1719
#include "flang/Optimizer/Dialect/FIROps.h"
1820
#include "flang/Optimizer/Dialect/FIRType.h"
21+
#include "flang/Optimizer/Support/FatalError.h"
1922
#include "mlir/Dialect/Arith/IR/Arith.h"
2023
#include "mlir/Dialect/Func/IR/FuncOps.h"
2124
#include "mlir/IR/BuiltinAttributes.h"
@@ -70,6 +73,66 @@ fromDefaultKinds(const Fortran::common::IntrinsicTypeDefaultKinds &defKinds) {
7073
static_cast<fir::KindTy>(
7174
defKinds.GetDefaultKind(Fortran::common::TypeCategory::Real))};
7275
}
76+
77+
inline std::string mlirTypeToString(mlir::Type type) {
78+
std::string result{};
79+
llvm::raw_string_ostream sstream(result);
80+
sstream << type;
81+
return result;
82+
}
83+
84+
inline std::string numericMlirTypeToFortran(fir::FirOpBuilder &builder,
85+
mlir::Type type, mlir::Location loc,
86+
const llvm::Twine &name) {
87+
if (type.isF16())
88+
return "REAL(KIND=2)";
89+
else if (type.isBF16())
90+
return "REAL(KIND=3)";
91+
else if (type.isTF32())
92+
return "REAL(KIND=unknown)";
93+
else if (type.isF32())
94+
return "REAL(KIND=4)";
95+
else if (type.isF64())
96+
return "REAL(KIND=8)";
97+
else if (type.isF80())
98+
return "REAL(KIND=10)";
99+
else if (type.isF128())
100+
return "REAL(KIND=16)";
101+
else if (type.isInteger(8))
102+
return "INTEGER(KIND=1)";
103+
else if (type.isInteger(16))
104+
return "INTEGER(KIND=2)";
105+
else if (type.isInteger(32))
106+
return "INTEGER(KIND=4)";
107+
else if (type.isInteger(64))
108+
return "INTEGER(KIND=8)";
109+
else if (type.isInteger(128))
110+
return "INTEGER(KIND=16)";
111+
else if (type == fir::ComplexType::get(builder.getContext(), 2))
112+
return "COMPLEX(KIND=2)";
113+
else if (type == fir::ComplexType::get(builder.getContext(), 3))
114+
return "COMPLEX(KIND=3)";
115+
else if (type == fir::ComplexType::get(builder.getContext(), 4))
116+
return "COMPLEX(KIND=4)";
117+
else if (type == fir::ComplexType::get(builder.getContext(), 8))
118+
return "COMPLEX(KIND=8)";
119+
else if (type == fir::ComplexType::get(builder.getContext(), 10))
120+
return "COMPLEX(KIND=10)";
121+
else if (type == fir::ComplexType::get(builder.getContext(), 16))
122+
return "COMPLEX(KIND=16)";
123+
else
124+
fir::emitFatalError(loc, "unsupported type in " + name + ": " +
125+
fir::mlirTypeToString(type));
126+
}
127+
128+
inline void intrinsicTypeTODO(fir::FirOpBuilder &builder, mlir::Type type,
129+
mlir::Location loc,
130+
const llvm::Twine &intrinsicName) {
131+
TODO(loc,
132+
"intrinsic: " +
133+
fir::numericMlirTypeToFortran(builder, type, loc, intrinsicName) +
134+
" in " + intrinsicName);
135+
}
73136
} // namespace fir
74137

75138
#endif // FORTRAN_OPTIMIZER_SUPPORT_UTILS_H

flang/include/flang/Tools/CLOptions.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ inline void addDebugFoundationPass(mlir::PassManager &pm) {
158158
}
159159

160160
inline void addFIRToLLVMPass(
161-
mlir::PassManager &pm, const MLIRToLLVMPassPipelineConfig &config) {
161+
mlir::PassManager &pm, llvm::OptimizationLevel optLevel = defaultOptLevel) {
162162
fir::FIRToLLVMPassOptions options;
163163
options.ignoreMissingTypeDescriptors = ignoreMissingTypeDescriptors;
164-
options.applyTBAA = config.AliasAnalysis;
164+
options.applyTBAA = optLevel.isOptimizingForSpeed();
165165
options.forceUnifiedTBAATree = useOldAliasTags;
166166
addPassConditionally(pm, disableFirToLlvmIr,
167167
[&]() { return fir::createFIRToLLVMPass(options); });
@@ -311,7 +311,7 @@ inline void createDefaultFIRCodeGenPassPipeline(
311311
if (config.VScaleMin != 0)
312312
pm.addPass(fir::createVScaleAttrPass({config.VScaleMin, config.VScaleMax}));
313313

314-
fir::addFIRToLLVMPass(pm, config);
314+
fir::addFIRToLLVMPass(pm, config.OptLevel);
315315
}
316316

317317
/// Create a pass pipeline for lowering from MLIR to LLVM IR

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,10 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
242242
clang::driver::options::OPT_fno_loop_versioning, false))
243243
opts.LoopVersioning = 1;
244244

245-
opts.AliasAnalysis = opts.OptimizationLevel > 0;
246-
if (auto *arg =
247-
args.getLastArg(clang::driver::options::OPT_falias_analysis,
248-
clang::driver::options::OPT_fno_alias_analysis))
249-
opts.AliasAnalysis =
250-
arg->getOption().matches(clang::driver::options::OPT_falias_analysis);
245+
opts.AliasAnalysis =
246+
args.hasFlag(clang::driver::options::OPT_falias_analysis,
247+
clang::driver::options::OPT_fno_alias_analysis,
248+
/*default=*/false);
251249

252250
for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
253251
opts.LLVMPassPlugins.push_back(a->getValue());

flang/lib/Lower/Bridge.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,10 +2083,10 @@ class FirConverter : public Fortran::lower::AbstractConverter {
20832083
assert(sym && "There must be a symbol to bind");
20842084
mlir::Type toTy = genType(*sym);
20852085
// FIXME: this should be a "per iteration" temporary.
2086-
mlir::Value tmp = builder->createTemporary(
2087-
loc, toTy, toStringRef(sym->name()),
2088-
llvm::ArrayRef<mlir::NamedAttribute>{
2089-
Fortran::lower::getAdaptToByRefAttr(*builder)});
2086+
mlir::Value tmp =
2087+
builder->createTemporary(loc, toTy, toStringRef(sym->name()),
2088+
llvm::ArrayRef<mlir::NamedAttribute>{
2089+
fir::getAdaptToByRefAttr(*builder)});
20902090
mlir::Value cast = builder->createConvert(loc, toTy, inducVar);
20912091
builder->create<fir::StoreOp>(loc, cast, tmp);
20922092
addSymbol(*sym, tmp, /*force=*/true);

flang/lib/Lower/ConvertCall.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "flang/Lower/ConvertCall.h"
1414
#include "flang/Lower/Allocatable.h"
15+
#include "flang/Lower/ConvertExpr.h"
1516
#include "flang/Lower/ConvertExprToHLFIR.h"
1617
#include "flang/Lower/ConvertVariable.h"
1718
#include "flang/Lower/CustomIntrinsicCall.h"
@@ -958,8 +959,9 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
958959
// Make a copy in a temporary.
959960
auto copy = builder.create<hlfir::AsExprOp>(loc, entity);
960961
mlir::Type storageType = entity.getType();
962+
mlir::NamedAttribute byRefAttr = fir::getAdaptToByRefAttr(builder);
961963
hlfir::AssociateOp associate = hlfir::genAssociateExpr(
962-
loc, builder, hlfir::Entity{copy}, storageType, "adapt.valuebyref");
964+
loc, builder, hlfir::Entity{copy}, storageType, "", byRefAttr);
963965
entity = hlfir::Entity{associate.getBase()};
964966
// Register the temporary destruction after the call.
965967
preparedDummy.pushExprAssociateCleanUp(associate);
@@ -986,8 +988,9 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
986988
// The actual is an expression value, place it into a temporary
987989
// and register the temporary destruction after the call.
988990
mlir::Type storageType = converter.genType(expr);
991+
mlir::NamedAttribute byRefAttr = fir::getAdaptToByRefAttr(builder);
989992
hlfir::AssociateOp associate = hlfir::genAssociateExpr(
990-
loc, builder, entity, storageType, "adapt.valuebyref");
993+
loc, builder, entity, storageType, "", byRefAttr);
991994
entity = hlfir::Entity{associate.getBase()};
992995
preparedDummy.pushExprAssociateCleanUp(associate);
993996
if (mustSetDynamicTypeToDummyType) {
@@ -1395,8 +1398,9 @@ static std::optional<hlfir::EntityWithAttributes> genCustomIntrinsicRefCore(
13951398
CallContext &callContext) {
13961399
auto &builder = callContext.getBuilder();
13971400
const auto &loc = callContext.loc;
1398-
assert(intrinsic && Fortran::lower::intrinsicRequiresCustomOptionalHandling(
1399-
callContext.procRef, *intrinsic, callContext.converter));
1401+
assert(intrinsic &&
1402+
Fortran::lower::intrinsicRequiresCustomOptionalHandling(
1403+
callContext.procRef, *intrinsic, callContext.converter));
14001404

14011405
// helper to get a particular prepared argument
14021406
auto getArgument = [&](std::size_t i, bool loadArg) -> fir::ExtendedValue {

0 commit comments

Comments
 (0)