Skip to content

Commit 89d078b

Browse files
committed
address reviews
1 parent 4a00d2a commit 89d078b

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ def LLVM_Dialect : Dialect {
8888
return "llvm.dependent_libraries";
8989
}
9090

91+
/// Names of known llvm module flag keys.
92+
static StringRef getModuleFlagKeyCGProfileName() {
93+
return "CG Profile";
94+
}
95+
9196
/// Returns `true` if the given type is compatible with the LLVM dialect.
9297
static bool isCompatibleType(Type);
9398

mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,10 @@ LogicalResult
380380
ModuleFlagAttr::verify(function_ref<InFlightDiagnostic()> emitError,
381381
LLVM::ModFlagBehavior flagBehavior, StringAttr key,
382382
Attribute value) {
383-
if (key == "CG Profile") {
383+
if (key == LLVM::LLVMDialect::getModuleFlagKeyCGProfileName()) {
384384
auto arrayAttr = dyn_cast<ArrayAttr>(value);
385-
if ((!arrayAttr) || (!llvm::all_of(arrayAttr, [](Attribute v) {
386-
return isa<ModuleFlagCGProfileEntryAttr>(v);
385+
if ((!arrayAttr) || (!llvm::all_of(arrayAttr, [](Attribute attr) {
386+
return isa<ModuleFlagCGProfileEntryAttr>(attr);
387387
})))
388388
return emitError()
389389
<< "'CG Profile' key expects an array of '#llvm.cgprofile_entry'";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ convertModuleFlagValue(StringRef key, ArrayAttr arrayAttr,
279279
llvm::MDBuilder mdb(context);
280280
SmallVector<llvm::Metadata *> nodes;
281281

282-
if (key == "CG Profile") {
282+
if (key == LLVM::LLVMDialect::getModuleFlagKeyCGProfileName()) {
283283
for (auto entry : arrayAttr.getAsRange<ModuleFlagCGProfileEntryAttr>()) {
284284
llvm::Function *fromFn =
285285
moduleTranslation.lookupFunction(entry.getFrom().getValue());

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ static Attribute convertCGProfileModuleFlagValue(ModuleOp mlirModule,
531531
SmallVector<Attribute> cgProfile;
532532
for (unsigned i = 0; i < mdTuple->getNumOperands(); i++) {
533533
const llvm::MDOperand &mdo = mdTuple->getOperand(i);
534-
auto *cgEntry = dyn_cast_or_null<llvm::MDNode>(mdo);
534+
auto *cgEntry = cast<llvm::MDNode>(mdo);
535535
llvm::Constant *llvmConstant =
536536
cast<llvm::ConstantAsMetadata>(cgEntry->getOperand(2))->getValue();
537537
uint64_t count = cast<llvm::ConstantInt>(llvmConstant)->getZExtValue();
@@ -542,12 +542,12 @@ static Attribute convertCGProfileModuleFlagValue(ModuleOp mlirModule,
542542
return ArrayAttr::get(mlirModule->getContext(), cgProfile);
543543
}
544544

545-
// Invoke specific handlers for each known module flag value, returns nullptr if
546-
// the key is unknown or unimplemented.
545+
/// Invoke specific handlers for each known module flag value, returns nullptr
546+
/// if the key is unknown or unimplemented.
547547
static Attribute convertModuleFlagValueFromMDTuple(ModuleOp mlirModule,
548548
StringRef key,
549549
llvm::MDTuple *mdTuple) {
550-
if (key == "CG Profile")
550+
if (key == LLVM::LLVMDialect::getModuleFlagKeyCGProfileName())
551551
return convertCGProfileModuleFlagValue(mlirModule, mdTuple);
552552
return nullptr;
553553
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module {
88
#llvm.mlir.module_flag<max, "frame-pointer", 1 : i32>,
99
#llvm.mlir.module_flag<override, "probe-stack", "inline-asm">,
1010
#llvm.mlir.module_flag<append, "CG Profile", [
11-
#llvm.cgprofile_entry<from = @from, to = @to, count = 222>,
12-
#llvm.cgprofile_entry<from = @from, to = @from, count = 222>,
13-
#llvm.cgprofile_entry<from = @to, to = @from, count = 222>
11+
#llvm.cgprofile_entry<from = @from, to = @to, count = 222>,
12+
#llvm.cgprofile_entry<from = @from, to = @from, count = 222>,
13+
#llvm.cgprofile_entry<from = @to, to = @from, count = 222>
1414
]>]
1515
}
1616

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,15 +2838,13 @@ module {
28382838

28392839
// -----
28402840

2841-
module {
2842-
llvm.module_flags [#llvm.mlir.module_flag<append, "CG Profile", [
2843-
#llvm.cgprofile_entry<from = @from, to = @to, count = 222>,
2844-
#llvm.cgprofile_entry<from = @from, to = @from, count = 222>,
2845-
#llvm.cgprofile_entry<from = @to, to = @from, count = 222>
2846-
]>]
2847-
llvm.func @from(i32)
2848-
llvm.func @to()
2849-
}
2841+
llvm.module_flags [#llvm.mlir.module_flag<append, "CG Profile", [
2842+
#llvm.cgprofile_entry<from = @from, to = @to, count = 222>,
2843+
#llvm.cgprofile_entry<from = @from, to = @from, count = 222>,
2844+
#llvm.cgprofile_entry<from = @to, to = @from, count = 222>
2845+
]>]
2846+
llvm.func @from(i32)
2847+
llvm.func @to()
28502848

28512849
// CHECK: !llvm.module.flags = !{![[#CGPROF:]], ![[#DBG:]]}
28522850

0 commit comments

Comments
 (0)