Skip to content

Commit a523b7d

Browse files
committed
Address last round of comments
1 parent f85e6d5 commit a523b7d

File tree

7 files changed

+28
-15
lines changed

7 files changed

+28
-15
lines changed

mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ class ModuleTranslation {
148148
/// Maps a blockaddress operation to its corresponding placeholder LLVM
149149
/// value.
150150
void mapBlockTag(BlockAddressAttr attr, BlockTagOp blockTag) {
151-
// Attempts to map already mapped block labels are fine given labels are
152-
// verified to be unique.
151+
// Attempts to map already mapped block labels which is fine if the given
152+
// labels are verified to be unique.
153153
blockTagMapping[attr] = blockTag;
154154
}
155155

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3862,8 +3862,10 @@ LLVMFuncOp BlockAddressOp::getFunction(SymbolTableCollection &symbolTable) {
38623862
}
38633863

38643864
BlockTagOp BlockAddressOp::getBlockTagOp() {
3865-
auto funcOp = cast<LLVMFuncOp>(mlir::SymbolTable::lookupNearestSymbolFrom(
3865+
auto funcOp = dyn_cast<LLVMFuncOp>(mlir::SymbolTable::lookupNearestSymbolFrom(
38663866
parentLLVMModule(*this), getBlockAddr().getFunction()));
3867+
if (!funcOp)
3868+
return nullptr;
38673869

38683870
BlockTagOp blockTagOp = nullptr;
38693871
funcOp.walk([&](LLVM::BlockTagOp labelOp) {

mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,9 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
731731
}
732732

733733
bool isLegalToInline(Operation *op, Region *, bool, IRMapping &) const final {
734-
// The inliner cannot handle variadic function arguments nor blocktag
735-
// operations.
734+
// The inliner cannot handle variadic function arguments and blocktag
735+
// operations prevent inlining since they the blockaddress operations
736+
// reference them via the callee symbol.
736737
return !(isa<LLVM::VaStartOp>(op) || isa<LLVM::BlockTagOp>(op));
737738
}
738739

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,9 +2459,9 @@ LogicalResult ModuleImport::processFunction(llvm::Function *func) {
24592459
// Skip unreachable blocks.
24602460
if (!reachable.contains(&basicBlock)) {
24612461
if (basicBlock.hasAddressTaken())
2462-
emitError(funcOp.getLoc())
2463-
<< "unreachable block '" << basicBlock.getName()
2464-
<< "' with address taken";
2462+
return emitError(funcOp.getLoc())
2463+
<< "unreachable block '" << basicBlock.getName()
2464+
<< "' with address taken";
24652465
continue;
24662466
}
24672467
Region &body = funcOp.getBody();

mlir/test/Dialect/LLVMIR/blockaddress-canonicalize.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
// RUN: mlir-opt %s -pass-pipeline='builtin.module(llvm.func(canonicalize{region-simplify=aggressive}))' -split-input-file | FileCheck %s
22

3+
llvm.mlir.global private @x() {addr_space = 0 : i32, dso_local} : !llvm.ptr {
4+
%0 = llvm.blockaddress <function = @ba, tag = <id = 2>> : !llvm.ptr
5+
llvm.return %0 : !llvm.ptr
6+
}
7+
38
// CHECK-LABEL: llvm.func @ba()
49
llvm.func @ba() -> !llvm.ptr {
510
%0 = llvm.blockaddress <function = @ba, tag = <id = 1>> : !llvm.ptr
611
llvm.br ^bb1
712
^bb1:
813
// CHECK: llvm.blocktag <id = 1>
914
llvm.blocktag <id = 1>
15+
llvm.br ^bb2
16+
^bb2:
17+
// CHECK: llvm.blocktag <id = 2>
18+
llvm.blocktag <id = 2>
1019
llvm.return %0 : !llvm.ptr
1120
}
1221

mlir/test/Dialect/LLVMIR/inlining.mlir

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,11 +700,12 @@ func.func @func(%arg0 : i32) -> i32 {
700700
llvm.blocktag <id = 1>
701701
llvm.return %arg0 : i32
702702
}
703+
703704
// CHECK-LABEL: @llvm_ret
704-
// CHECK-NOT: llvm.blocktag
705-
// CHECK: %[[R:.*]] = call
706-
// CHECK: return %[[R]]
707705
func.func @llvm_ret(%arg0 : i32) -> i32 {
706+
// CHECK-NOT: llvm.blocktag
707+
// CHECK: %[[R:.*]] = call
708708
%res = call @func(%arg0) : (i32) -> (i32)
709+
// CHECK: return %[[R]]
709710
return %res : i32
710711
}

mlir/test/Target/LLVMIR/blockaddress.mlir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ llvm.func @fn() {
1414

1515
// CHECK: @g = private global ptr blockaddress(@fn, %1)
1616
// CHECK: define void @fn() {
17-
// CHECK: br label %1
18-
// CHECK: 1:
17+
// CHECK: br label %[[RET:.*]]
18+
// CHECK: [[RET]]:
1919
// CHECK: ret void
2020
// CHECK: }
2121

@@ -30,7 +30,7 @@ llvm.func @blockaddr0() -> !llvm.ptr {
3030
}
3131

3232
// CHECK: define ptr @blockaddr0() {
33-
// CHECK: br label %1
34-
// CHECK: 1:
33+
// CHECK: br label %[[RET:.*]]
34+
// CHECK: [[RET]]:
3535
// CHECK: ret ptr blockaddress(@blockaddr0, %1)
3636
// CHECK: }

0 commit comments

Comments
 (0)