Skip to content

Commit 02b854d

Browse files
committed
Fix several review issues
1 parent 0a791e7 commit 02b854d

File tree

8 files changed

+37
-39
lines changed

8 files changed

+37
-39
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,10 @@ static void convertLinkerOptionsOp(ArrayAttr options,
273273
static void convertModuleFlagsOp(ArrayAttr flags, llvm::IRBuilderBase &builder,
274274
LLVM::ModuleTranslation &moduleTranslation) {
275275
llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
276-
for (auto flagAttr : flags.getAsRange<ModuleFlagAttr>()) {
277-
auto flag = cast<ModuleFlagAttr>(attr);
278-
auto intVal = dyn_cast<IntegerAttr>(flag.getValue());
279-
assert(intVal && "expected integer attribute");
276+
for (auto flagAttr : flags.getAsRange<ModuleFlagAttr>())
280277
llvmModule->addModuleFlag(
281-
static_cast<llvm::Module::ModFlagBehavior>(flag.getBehavior().getValue()),
282-
flag.getKey().getValue(), (uint32_t)intVal.getUInt());
283-
}
278+
static_cast<llvm::Module::ModFlagBehavior>(flagAttr.getBehavior()),
279+
flagAttr.getKey().getValue(), flagAttr.getValue());
284280
}
285281

286282
static LogicalResult

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,16 +536,16 @@ LogicalResult ModuleImport::convertModuleFlagsMetadata() {
536536
<< diagMD(val, llvmModule.get())
537537
<< ", only constant integer currently supported";
538538
}
539-
auto valAttr = builder.getIntegerAttr(
540-
IntegerType::get(context, constInt->getType()->getIntegerBitWidth()),
541-
constInt->getValue());
539+
// auto valAttr = builder.getIntegerAttr(
540+
// IntegerType::get(context, constInt->getType()->getIntegerBitWidth()),
541+
// constInt->getValue());
542542

543-
ModFlagBehaviorAttr behaviorAttr = ModFlagBehaviorAttr::get(
544-
builder.getContext(), (ModFlagBehavior)behavior);
543+
// ModFlagBehaviorAttr behaviorAttr = ModFlagBehaviorAttr::get(
544+
// builder.getContext(), (ModFlagBehavior)behavior);
545545

546-
moduleFlags.push_back(
547-
builder.getAttr<ModuleFlagAttr>(behaviorAttr, builder.getStringAttr(key->getString()),
548-
valAttr));
546+
moduleFlags.push_back(builder.getAttr<ModuleFlagAttr>(
547+
(ModFlagBehavior)behavior, builder.getStringAttr(key->getString()),
548+
constInt->getZExtValue()));
549549
}
550550

551551
if (!moduleFlags.empty()) {

mlir/test/Dialect/LLVMIR/invalid.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ llvm.mlir.alias external @y5 : i32 {
17671767
// -----
17681768

17691769
module {
1770-
// expected-error@+2 {{invalid kind of attribute specified}}
1771-
// expected-error@+1 {{failed to parse ModuleFlagAttr parameter 'value' which is to be a `IntegerAttr`}}
1772-
llvm.module_flags [#llvm.mlir.module_flag<1 : i64, "wchar_size", "yolo">]
1770+
// expected-error@+2 {{expected integer value}}
1771+
// expected-error@+1 {{failed to parse ModuleFlagAttr parameter 'value' which is to be a `uint32_t`}}
1772+
llvm.module_flags [#llvm.mlir.module_flag<error, "wchar_size", "yolo">]
17731773
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// RUN: mlir-opt %s | mlir-opt | FileCheck %s
22

33
module {
4-
llvm.module_flags [#llvm.mlir.module_flag<1 : i64, "wchar_size", 4 : i32>,
5-
#llvm.mlir.module_flag<8 : i64, "PIC Level", 2 : i32>,
6-
#llvm.mlir.module_flag<7 : i64, "PIE Level", 2 : i32>,
7-
#llvm.mlir.module_flag<7 : i64, "uwtable", 2 : i32>,
8-
#llvm.mlir.module_flag<7 : i64, "frame-pointer", 1 : i32>]
4+
llvm.module_flags [#llvm.mlir.module_flag<error, "wchar_size", 4>,
5+
#llvm.mlir.module_flag<min, "PIC Level", 2>,
6+
#llvm.mlir.module_flag<max, "PIE Level", 2>,
7+
#llvm.mlir.module_flag<max, "uwtable", 2>,
8+
#llvm.mlir.module_flag<max, "frame-pointer", 1>]
99
}
1010

1111
// CHECK: llvm.module_flags [
12-
// CHECK-SAME: #llvm.mlir.module_flag<1 : i64, "wchar_size", 4 : i32>,
13-
// CHECK-SAME: #llvm.mlir.module_flag<8 : i64, "PIC Level", 2 : i32>,
14-
// CHECK-SAME: #llvm.mlir.module_flag<7 : i64, "PIE Level", 2 : i32>,
15-
// CHECK-SAME: #llvm.mlir.module_flag<7 : i64, "uwtable", 2 : i32>,
16-
// CHECK-SAME: #llvm.mlir.module_flag<7 : i64, "frame-pointer", 1 : i32>]
12+
// CHECK-SAME: #llvm.mlir.module_flag<error, "wchar_size", 4>,
13+
// CHECK-SAME: #llvm.mlir.module_flag<min, "PIC Level", 2>,
14+
// CHECK-SAME: #llvm.mlir.module_flag<max, "PIE Level", 2>,
15+
// CHECK-SAME: #llvm.mlir.module_flag<max, "uwtable", 2>,
16+
// CHECK-SAME: #llvm.mlir.module_flag<max, "frame-pointer", 1>]

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
; CHECK-LABEL: module attributes {{.*}} {
1212
; CHECK: llvm.module_flags [
13-
; CHECK-SAME: #llvm.mlir.module_flag<1 : i64, "wchar_size", 4 : i32>,
14-
; CHECK-SAME: #llvm.mlir.module_flag<8 : i64, "PIC Level", 2 : i32>,
15-
; CHECK-SAME: #llvm.mlir.module_flag<7 : i64, "PIE Level", 2 : i32>,
16-
; CHECK-SAME: #llvm.mlir.module_flag<7 : i64, "uwtable", 2 : i32>,
17-
; CHECK-SAME: #llvm.mlir.module_flag<7 : i64, "frame-pointer", 1 : i32>]
13+
; CHECK-SAME: #llvm.mlir.module_flag<error, "wchar_size", 4>,
14+
; CHECK-SAME: #llvm.mlir.module_flag<min, "PIC Level", 2>,
15+
; CHECK-SAME: #llvm.mlir.module_flag<max, "PIE Level", 2>,
16+
; CHECK-SAME: #llvm.mlir.module_flag<max, "uwtable", 2>,
17+
; CHECK-SAME: #llvm.mlir.module_flag<max, "frame-pointer", 1>]
1818
; CHECK: }
1919

2020
; // -----

mlir/test/Target/LLVMIR/llvmir-invalid.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ llvm.func @foo() {
350350

351351
llvm.func @foo() {
352352
// expected-error @below{{must appear at the module level}}
353-
llvm.module_flags [#llvm.mlir.module_flag<1 : i64, "wchar_size", 4 : i32>]
353+
llvm.module_flags [#llvm.mlir.module_flag<error, "wchar_size", 4>]
354354
}
355355

356356
// -----

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,11 +2767,11 @@ llvm.func @call_intrin_with_opbundle(%arg0 : !llvm.ptr) {
27672767
// -----
27682768

27692769
module {
2770-
llvm.module_flags [#llvm.mlir.module_flag<1 : i64, "wchar_size", 4 : i32>,
2771-
#llvm.mlir.module_flag<8 : i64, "PIC Level", 2 : i32>,
2772-
#llvm.mlir.module_flag<7 : i64, "PIE Level", 2 : i32>,
2773-
#llvm.mlir.module_flag<7 : i64, "uwtable", 2 : i32>,
2774-
#llvm.mlir.module_flag<7 : i64, "frame-pointer", 1 : i32>]
2770+
llvm.module_flags [#llvm.mlir.module_flag<error, "wchar_size", 4>,
2771+
#llvm.mlir.module_flag<min, "PIC Level", 2>,
2772+
#llvm.mlir.module_flag<max, "PIE Level", 2>,
2773+
#llvm.mlir.module_flag<max, "uwtable", 2>,
2774+
#llvm.mlir.module_flag<max, "frame-pointer", 1>]
27752775
}
27762776

27772777
// CHECK: !llvm.module.flags = !{![[#DBG:]], ![[#WCHAR:]], ![[#PIC:]], ![[#PIE:]], ![[#UWTABLE:]], ![[#FP:]]}

mlir/test/mlir-translate/split-markers.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// CHECK-OUTPUT-NEXT: ModuleID
2222

2323
// CHECK-ROUNDTRIP: module {{.*}} {
24+
// FIXME: importer forces debug info version even without importing one.
25+
// CHECK-ROUNDTRIP-NEXT: llvm.module_flag
2426
// CHECK-ROUNDTRIP-NEXT: }
2527
// CHECK-ROUNDTRIP-EMPTY:
2628
// CHECK-ROUNDTRIP: module

0 commit comments

Comments
 (0)