Skip to content

Commit 95c9aac

Browse files
committed
omit null entries
1 parent 70ba174 commit 95c9aac

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,16 +1371,11 @@ def ModuleFlagCGProfileEntryAttr
13711371
```
13721372
}];
13731373
let parameters = (
1374-
ins OptionalParameter<"std::optional<FlatSymbolRefAttr>">:$from,
1375-
OptionalParameter<"std::optional<FlatSymbolRefAttr>">:$to,
1374+
ins OptionalParameter<"FlatSymbolRefAttr">:$from,
1375+
OptionalParameter<"FlatSymbolRefAttr">:$to,
13761376
"uint64_t":$count);
1377-
let assemblyFormat = [{
1378-
`<`
1379-
`from` `=` ($from^) : (`null`)? `,`
1380-
`to` `=` ($to^) : (`null`)? `,`
1381-
`count` `=` $count
1382-
`>`
1383-
}];
1377+
1378+
let assemblyFormat = "`<` struct(params) `>`";
13841379
}
13851380

13861381
//===----------------------------------------------------------------------===//

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ convertModuleFlagValue(StringRef key, ArrayAttr arrayAttr,
284284
llvm::Metadata *fromMetadata =
285285
entry.getFrom()
286286
? llvm::ValueAsMetadata::get(moduleTranslation.lookupFunction(
287-
entry.getFrom()->getValue()))
287+
entry.getFrom().getValue()))
288288
: nullptr;
289289
llvm::Metadata *toMetadata =
290290
entry.getTo()
291291
? llvm::ValueAsMetadata::get(
292-
moduleTranslation.lookupFunction(entry.getTo()->getValue()))
292+
moduleTranslation.lookupFunction(entry.getTo().getValue()))
293293
: nullptr;
294294

295295
llvm::Metadata *vals[] = {

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,14 @@ void ModuleImport::addDebugIntrinsic(llvm::CallInst *intrinsic) {
521521

522522
static Attribute convertCGProfileModuleFlagValue(ModuleOp mlirModule,
523523
llvm::MDTuple *mdTuple) {
524-
auto getFunctionSymbol =
525-
[&](const llvm::MDOperand &funcMDO) -> std::optional<FlatSymbolRefAttr> {
524+
auto getLLVMFunction =
525+
[&](const llvm::MDOperand &funcMDO) -> llvm::Function * {
526526
auto *f = cast_or_null<llvm::ValueAsMetadata>(funcMDO);
527527
// nullptr is a valid value for the function pointer.
528528
if (!f)
529-
return std::nullopt;
529+
return nullptr;
530530
auto *llvmFn = cast<llvm::Function>(f->getValue()->stripPointerCasts());
531-
return FlatSymbolRefAttr::get(mlirModule->getContext(), llvmFn->getName());
531+
return llvmFn;
532532
};
533533

534534
// Each tuple element becomes one ModuleFlagCGProfileEntryAttr.
@@ -539,9 +539,17 @@ static Attribute convertCGProfileModuleFlagValue(ModuleOp mlirModule,
539539
llvm::Constant *llvmConstant =
540540
cast<llvm::ConstantAsMetadata>(cgEntry->getOperand(2))->getValue();
541541
uint64_t count = cast<llvm::ConstantInt>(llvmConstant)->getZExtValue();
542+
auto *fromFn = getLLVMFunction(cgEntry->getOperand(0));
543+
auto *toFn = getLLVMFunction(cgEntry->getOperand(1));
544+
// FlatSymbolRefAttr::get(mlirModule->getContext(), llvmFn->getName());
542545
cgProfile.push_back(ModuleFlagCGProfileEntryAttr::get(
543-
mlirModule->getContext(), getFunctionSymbol(cgEntry->getOperand(0)),
544-
getFunctionSymbol(cgEntry->getOperand(1)), count));
546+
mlirModule->getContext(),
547+
fromFn ? FlatSymbolRefAttr::get(mlirModule->getContext(),
548+
fromFn->getName())
549+
: nullptr,
550+
toFn ? FlatSymbolRefAttr::get(mlirModule->getContext(), toFn->getName())
551+
: nullptr,
552+
count));
545553
}
546554
return ArrayAttr::get(mlirModule->getContext(), cgProfile);
547555
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module {
99
#llvm.mlir.module_flag<override, "probe-stack", "inline-asm">,
1010
#llvm.mlir.module_flag<append, "CG Profile", [
1111
#llvm.cgprofile_entry<from = @from, to = @to, count = 222>,
12-
#llvm.cgprofile_entry<from = @from, to = null, count = 222>,
12+
#llvm.cgprofile_entry<from = @from, count = 222>,
1313
#llvm.cgprofile_entry<from = @to, to = @from, count = 222>
1414
]>]
1515
}
@@ -23,6 +23,6 @@ module {
2323
// CHECK-SAME: #llvm.mlir.module_flag<override, "probe-stack", "inline-asm">,
2424
// CHECK-SAME: #llvm.mlir.module_flag<append, "CG Profile", [
2525
// CHECK-SAME: #llvm.cgprofile_entry<from = @from, to = @to, count = 222>,
26-
// CHECK-SAME: #llvm.cgprofile_entry<from = @from, to = null, count = 222>,
26+
// CHECK-SAME: #llvm.cgprofile_entry<from = @from, count = 222>,
2727
// CHECK-SAME: #llvm.cgprofile_entry<from = @to, to = @from, count = 222>
2828
// CHECK-SAME: ]>]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ declare void @to()
4141

4242
; CHECK: llvm.module_flags [#llvm.mlir.module_flag<append, "CG Profile", [
4343
; CHECK-SAME: #llvm.cgprofile_entry<from = @from, to = @to, count = 222>,
44-
; CHECK-SAME: #llvm.cgprofile_entry<from = @from, to = null, count = 222>,
44+
; CHECK-SAME: #llvm.cgprofile_entry<from = @from, count = 222>,
4545
; CHECK-SAME: #llvm.cgprofile_entry<from = @to, to = @from, count = 222>
4646
; CHECK-SAME: ]>]

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2840,7 +2840,7 @@ module {
28402840

28412841
llvm.module_flags [#llvm.mlir.module_flag<append, "CG Profile", [
28422842
#llvm.cgprofile_entry<from = @from, to = @to, count = 222>,
2843-
#llvm.cgprofile_entry<from = @from, to = null, count = 222>,
2843+
#llvm.cgprofile_entry<from = @from, count = 222>,
28442844
#llvm.cgprofile_entry<from = @to, to = @from, count = 222>
28452845
]>]
28462846
llvm.func @from(i32)

0 commit comments

Comments
 (0)