Skip to content

Commit b4acc60

Browse files
committed
Use std::optional when possible for attr params
1 parent abfcb67 commit b4acc60

File tree

7 files changed

+16
-18
lines changed

7 files changed

+16
-18
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ def ModuleFlagProfileSummaryAttr
14071407
#llvm.profile_summary<format = "InstrProf", total_count = 263646, max_count = 86427,
14081408
max_internal_count = 86427, max_function_count = 4691,
14091409
num_counts = 3712, num_functions = 796,
1410-
is_partial_profile = 0 : i64,
1410+
is_partial_profile = 0,
14111411
partial_profile_ratio = 0.000000e+00 : f64,
14121412
detailed_summary =
14131413
<cut_off = 10000, min_count = 86427, num_counts = 1>,
@@ -1419,7 +1419,7 @@ def ModuleFlagProfileSummaryAttr
14191419
ins "StringAttr":$format, "uint64_t":$total_count, "uint64_t":$max_count,
14201420
"uint64_t":$max_internal_count, "uint64_t":$max_function_count,
14211421
"uint64_t":$num_counts, "uint64_t":$num_functions,
1422-
OptionalParameter<"IntegerAttr">:$is_partial_profile,
1422+
OptionalParameter<"std::optional<uint64_t>">:$is_partial_profile,
14231423
OptionalParameter<"FloatAttr">:$partial_profile_ratio,
14241424
ArrayRefParameter<"ModuleFlagProfileSummaryDetailedAttr">:$detailed_summary);
14251425

mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ static llvm::Metadata *convertModuleFlagProfileSummaryAttr(
333333
};
334334

335335
if (summaryAttr.getIsPartialProfile())
336-
vals.push_back(getIntTuple("IsPartialProfile",
337-
summaryAttr.getIsPartialProfile().getUInt()));
336+
vals.push_back(
337+
getIntTuple("IsPartialProfile", *summaryAttr.getIsPartialProfile()));
338338

339339
if (summaryAttr.getPartialProfileRatio()) {
340340
SmallVector<llvm::Metadata *> tupleNodes{

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -657,16 +657,15 @@ convertProfileSummaryModuleFlagValue(ModuleOp mlirModule,
657657
};
658658

659659
auto getOptIntValue = [&](const llvm::MDOperand &md, StringRef matchKey,
660-
IntegerAttr &attr) -> LogicalResult {
660+
std::optional<uint64_t> &val) -> LogicalResult {
661661
if (!getConstantMD(md, matchKey, /*optional=*/true))
662662
return success();
663663
if (checkOptionalPosition(md, matchKey).failed())
664664
return failure();
665-
uint64_t val = 0;
666-
if (!getInt64Value(md, matchKey, val))
665+
uint64_t tmpVal = 0;
666+
if (!getInt64Value(md, matchKey, tmpVal))
667667
return failure();
668-
attr =
669-
IntegerAttr::get(IntegerType::get(mlirModule->getContext(), 64), val);
668+
val = tmpVal;
670669
return success();
671670
};
672671

@@ -771,12 +770,12 @@ convertProfileSummaryModuleFlagValue(ModuleOp mlirModule,
771770
return nullptr;
772771

773772
// Handle optional keys.
774-
IntegerAttr isPartialProfile;
773+
std::optional<uint64_t> isPartialProfile;
775774
if (getOptIntValue(mdTuple->getOperand(summayIdx), "IsPartialProfile",
776775
isPartialProfile)
777776
.failed())
778777
return nullptr;
779-
if (isPartialProfile)
778+
if (isPartialProfile.has_value())
780779
summayIdx++;
781780

782781
FloatAttr partialProfileRatio;
@@ -795,8 +794,7 @@ convertProfileSummaryModuleFlagValue(ModuleOp mlirModule,
795794
// Build the final profile summary attribute.
796795
return ModuleFlagProfileSummaryAttr::get(
797796
mlirModule->getContext(), format, totalCount, maxCount, maxInternalCount,
798-
maxFunctionCount, numCounts, numFunctions,
799-
isPartialProfile ? isPartialProfile : nullptr,
797+
maxFunctionCount, numCounts, numFunctions, isPartialProfile,
800798
partialProfileRatio ? partialProfileRatio : nullptr, detailedSummary);
801799
}
802800

mlir/test/Dialect/LLVMIR/invalid.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ llvm.module_flags [#llvm.mlir.module_flag<error, "ProfileSummary",
18121812
#llvm.profile_summary<format = "YoloFmt", total_count = 263646, max_count = 86427,
18131813
max_internal_count = 86427, max_function_count = 4691,
18141814
num_counts = 3712, num_functions = 796,
1815-
is_partial_profile = 0 : i64,
1815+
is_partial_profile = 0,
18161816
partial_profile_ratio = 0.000000e+00 : f64,
18171817
detailed_summary =
18181818
<cut_off = 10000, min_count = 86427, num_counts = 1>,

mlir/test/Dialect/LLVMIR/module-roundtrip.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module {
1616
#llvm.profile_summary<format = "InstrProf", total_count = 263646, max_count = 86427,
1717
max_internal_count = 86427, max_function_count = 4691,
1818
num_counts = 3712, num_functions = 796,
19-
is_partial_profile = 0 : i64,
19+
is_partial_profile = 0,
2020
partial_profile_ratio = 0.000000e+00 : f64,
2121
detailed_summary =
2222
<cut_off = 10000, min_count = 86427, num_counts = 1>,
@@ -40,7 +40,7 @@ module {
4040
// CHECK-SAME: #llvm.profile_summary<format = "InstrProf", total_count = 263646, max_count = 86427,
4141
// CHECK-SAME: max_internal_count = 86427, max_function_count = 4691,
4242
// CHECK-SAME: num_counts = 3712, num_functions = 796,
43-
// CHECK-SAME: is_partial_profile = 0 : i64,
43+
// CHECK-SAME: is_partial_profile = 0,
4444
// CHECK-SAME: partial_profile_ratio = 0.000000e+00 : f64,
4545
// CHECK-SAME: detailed_summary =
4646
// CHECK-SAME: <cut_off = 10000, min_count = 86427, num_counts = 1>,

mlir/test/Target/LLVMIR/Import/module-flags.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ declare void @to()
6060
; CHECK: llvm.module_flags [#llvm.mlir.module_flag<error, "ProfileSummary",
6161
; CHECK-SAME: #llvm.profile_summary<format = "InstrProf", total_count = 263646,
6262
; CHECK-SAME: max_count = 86427, max_internal_count = 86427, max_function_count = 4691,
63-
; CHECK-SAME: num_counts = 3712, num_functions = 796, is_partial_profile = 0 : i64,
63+
; CHECK-SAME: num_counts = 3712, num_functions = 796, is_partial_profile = 0,
6464
; CHECK-SAME: partial_profile_ratio = 0.000000e+00 : f64,
6565
; CHECK-SAME: detailed_summary =
6666
; CHECK-SAME: <cut_off = 10000, min_count = 86427, num_counts = 1>,

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2887,7 +2887,7 @@ llvm.module_flags [#llvm.mlir.module_flag<error, "ProfileSummary",
28872887
#llvm.profile_summary<format = "InstrProf", total_count = 263646, max_count = 86427,
28882888
max_internal_count = 86427, max_function_count = 4691,
28892889
num_counts = 3712, num_functions = 796,
2890-
is_partial_profile = 0 : i64,
2890+
is_partial_profile = 0,
28912891
partial_profile_ratio = 0.000000e+00 : f64,
28922892
detailed_summary =
28932893
<cut_off = 10000, min_count = 86427, num_counts = 1>,

0 commit comments

Comments
 (0)