Skip to content

Commit 76db259

Browse files
Revert "[MLIR][LLVM] Support for indirectbr" (llvm#135695)
Reverts llvm#135092, broke https://lab.llvm.org/buildbot/#/builders/169/builds/10469
1 parent a9f73ae commit 76db259

File tree

11 files changed

+40
-413
lines changed

11 files changed

+40
-413
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,8 @@ def LLVM_BlockTagOp : LLVM_Op<"blocktag"> {
16901690
the target address.
16911691

16921692
A given function should have at most one `llvm.blocktag` operation with a
1693-
given `tag`. This operation cannot be used as a terminator.
1693+
given `tag`. This operation cannot be used as a terminator but can be
1694+
placed everywhere else in a block.
16941695

16951696
Example:
16961697

@@ -1710,66 +1711,6 @@ def LLVM_BlockTagOp : LLVM_Op<"blocktag"> {
17101711
let hasVerifier = 0;
17111712
}
17121713

1713-
//===----------------------------------------------------------------------===//
1714-
// IndirectBrOp
1715-
//===----------------------------------------------------------------------===//
1716-
1717-
def LLVM_IndirectBrOp : LLVM_TerminatorOp<"indirectbr",
1718-
[SameVariadicOperandSize, DeclareOpInterfaceMethods<BranchOpInterface>,
1719-
Pure]> {
1720-
let description = [{
1721-
Transfer control flow to address in `$addr`. A list of possible target
1722-
blocks in `$successors` can be provided and maybe used as a hint in LLVM:
1723-
1724-
```mlir
1725-
...
1726-
llvm.func @g(...
1727-
%dest = llvm.blockaddress <function = @g, tag = <id = 0>> : !llvm.ptr
1728-
llvm.indirectbr %dest : !llvm.ptr, [
1729-
^head
1730-
]
1731-
^head:
1732-
llvm.blocktag <id = 0>
1733-
llvm.return %arg0 : i32
1734-
...
1735-
```
1736-
1737-
It also supports a list of operands that can be passed to a target block:
1738-
1739-
```mlir
1740-
llvm.indirectbr %dest : !llvm.ptr, [
1741-
^head(%arg0 : i32),
1742-
^tail(%arg1, %arg0 : i32, i32)
1743-
]
1744-
^head(%r0 : i32):
1745-
llvm.return %r0 : i32
1746-
^tail(%r1 : i32, %r2 : i32):
1747-
...
1748-
```
1749-
}];
1750-
let arguments = (ins LLVM_AnyPointer:$addr,
1751-
VariadicOfVariadic<AnyType, "indbr_operand_segments">:$succOperands,
1752-
DenseI32ArrayAttr:$indbr_operand_segments
1753-
);
1754-
let successors = (successor VariadicSuccessor<AnySuccessor>:$successors);
1755-
let assemblyFormat = [{
1756-
$addr `:` type($addr) `,`
1757-
custom<IndirectBrOpSucessors>(ref(type($addr)),
1758-
$successors,
1759-
$succOperands,
1760-
type($succOperands))
1761-
attr-dict
1762-
}];
1763-
1764-
let skipDefaultBuilders = 1;
1765-
let builders = [
1766-
OpBuilder<(ins "Value":$addr,
1767-
CArg<"ArrayRef<ValueRange>", "{}">:$succOperands,
1768-
CArg<"BlockRange", "{}">:$successors
1769-
)>
1770-
];
1771-
}
1772-
17731714
def LLVM_ComdatSelectorOp : LLVM_Op<"comdat_selector", [Symbol]> {
17741715
let arguments = (ins
17751716
SymbolNameAttr:$sym_name,

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

Lines changed: 17 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,21 +2240,24 @@ static LogicalResult verifyComdat(Operation *op,
22402240

22412241
static LogicalResult verifyBlockTags(LLVMFuncOp funcOp) {
22422242
llvm::DenseSet<BlockTagAttr> blockTags;
2243-
// Note that presence of `BlockTagOp`s currently can't prevent an unrecheable
2244-
// block to be removed by canonicalizer's region simplify pass, which needs to
2245-
// be dialect aware to allow extra constraints to be described.
2246-
WalkResult res = funcOp.walk([&](BlockTagOp blockTagOp) {
2247-
if (blockTags.contains(blockTagOp.getTag())) {
2248-
blockTagOp.emitError()
2249-
<< "duplicate block tag '" << blockTagOp.getTag().getId()
2250-
<< "' in the same function: ";
2251-
return WalkResult::interrupt();
2252-
}
2253-
blockTags.insert(blockTagOp.getTag());
2254-
return WalkResult::advance();
2255-
});
2243+
BlockTagOp badBlockTagOp;
2244+
if (funcOp
2245+
.walk([&](BlockTagOp blockTagOp) {
2246+
if (blockTags.contains(blockTagOp.getTag())) {
2247+
badBlockTagOp = blockTagOp;
2248+
return WalkResult::interrupt();
2249+
}
2250+
blockTags.insert(blockTagOp.getTag());
2251+
return WalkResult::advance();
2252+
})
2253+
.wasInterrupted()) {
2254+
badBlockTagOp.emitError()
2255+
<< "duplicate block tag '" << badBlockTagOp.getTag().getId()
2256+
<< "' in the same function: ";
2257+
return failure();
2258+
}
22562259

2257-
return failure(res.wasInterrupted());
2260+
return success();
22582261
}
22592262

22602263
/// Parse common attributes that might show up in the same order in both
@@ -3815,78 +3818,6 @@ LogicalResult BlockAddressOp::verify() {
38153818
/// attribute.
38163819
OpFoldResult BlockAddressOp::fold(FoldAdaptor) { return getBlockAddr(); }
38173820

3818-
//===----------------------------------------------------------------------===//
3819-
// LLVM::IndirectBrOp
3820-
//===----------------------------------------------------------------------===//
3821-
3822-
SuccessorOperands IndirectBrOp::getSuccessorOperands(unsigned index) {
3823-
assert(index < getNumSuccessors() && "invalid successor index");
3824-
return SuccessorOperands(getSuccOperandsMutable()[index]);
3825-
}
3826-
3827-
void IndirectBrOp::build(OpBuilder &odsBuilder, OperationState &odsState,
3828-
Value addr, ArrayRef<ValueRange> succOperands,
3829-
BlockRange successors) {
3830-
odsState.addOperands(addr);
3831-
for (ValueRange range : succOperands)
3832-
odsState.addOperands(range);
3833-
SmallVector<int32_t> rangeSegments;
3834-
for (ValueRange range : succOperands)
3835-
rangeSegments.push_back(range.size());
3836-
odsState.getOrAddProperties<Properties>().indbr_operand_segments =
3837-
odsBuilder.getDenseI32ArrayAttr(rangeSegments);
3838-
odsState.addSuccessors(successors);
3839-
}
3840-
3841-
static ParseResult parseIndirectBrOpSucessors(
3842-
OpAsmParser &parser, Type &flagType,
3843-
SmallVectorImpl<Block *> &succOperandBlocks,
3844-
SmallVectorImpl<SmallVector<OpAsmParser::UnresolvedOperand>> &succOperands,
3845-
SmallVectorImpl<SmallVector<Type>> &succOperandsTypes) {
3846-
if (failed(parser.parseCommaSeparatedList(
3847-
OpAsmParser::Delimiter::Square,
3848-
[&]() {
3849-
Block *destination = nullptr;
3850-
SmallVector<OpAsmParser::UnresolvedOperand> operands;
3851-
SmallVector<Type> operandTypes;
3852-
3853-
if (parser.parseSuccessor(destination).failed())
3854-
return failure();
3855-
3856-
if (succeeded(parser.parseOptionalLParen())) {
3857-
if (failed(parser.parseOperandList(
3858-
operands, OpAsmParser::Delimiter::None)) ||
3859-
failed(parser.parseColonTypeList(operandTypes)) ||
3860-
failed(parser.parseRParen()))
3861-
return failure();
3862-
}
3863-
succOperandBlocks.push_back(destination);
3864-
succOperands.emplace_back(operands);
3865-
succOperandsTypes.emplace_back(operandTypes);
3866-
return success();
3867-
},
3868-
"successor blocks")))
3869-
return failure();
3870-
return success();
3871-
}
3872-
3873-
static void
3874-
printIndirectBrOpSucessors(OpAsmPrinter &p, IndirectBrOp op, Type flagType,
3875-
SuccessorRange succs, OperandRangeRange succOperands,
3876-
const TypeRangeRange &succOperandsTypes) {
3877-
p << "[";
3878-
llvm::interleave(
3879-
llvm::zip(succs, succOperands),
3880-
[&](auto i) {
3881-
p.printNewline();
3882-
p.printSuccessorAndUseList(std::get<0>(i), std::get<1>(i));
3883-
},
3884-
[&] { p << ','; });
3885-
if (!succOperands.empty())
3886-
p.printNewline();
3887-
p << "]";
3888-
}
3889-
38903821
//===----------------------------------------------------------------------===//
38913822
// AssumeOp (intrinsic)
38923823
//===----------------------------------------------------------------------===//

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,6 @@ convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder,
505505
moduleTranslation.mapBranch(&opInst, switchInst);
506506
return success();
507507
}
508-
if (auto indBrOp = dyn_cast<LLVM::IndirectBrOp>(opInst)) {
509-
llvm::IndirectBrInst *indBr = builder.CreateIndirectBr(
510-
moduleTranslation.lookupValue(indBrOp.getAddr()),
511-
indBrOp->getNumSuccessors());
512-
for (auto *succ : indBrOp.getSuccessors())
513-
indBr->addDestination(moduleTranslation.lookupBlock(succ));
514-
moduleTranslation.mapBranch(&opInst, indBr);
515-
return success();
516-
}
517508

518509
// Emit addressof. We need to look up the global value referenced by the
519510
// operation and store it in the MLIR-to-LLVM value mapping. This does not

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,35 +1988,6 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) {
19881988
return success();
19891989
}
19901990

1991-
if (inst->getOpcode() == llvm::Instruction::IndirectBr) {
1992-
auto *indBrInst = cast<llvm::IndirectBrInst>(inst);
1993-
1994-
FailureOr<Value> basePtr = convertValue(indBrInst->getAddress());
1995-
if (failed(basePtr))
1996-
return failure();
1997-
1998-
SmallVector<Block *> succBlocks;
1999-
// `succBlockArgs` is storage for the block arguments ranges used in
2000-
// `succBlockArgsRange`, so the later references live data.
2001-
SmallVector<SmallVector<Value>> succBlockArgs;
2002-
SmallVector<ValueRange> succBlockArgsRange;
2003-
for (auto i : llvm::seq<unsigned>(0, indBrInst->getNumSuccessors())) {
2004-
llvm::BasicBlock *succ = indBrInst->getSuccessor(i);
2005-
SmallVector<Value> blockArgs;
2006-
if (failed(convertBranchArgs(indBrInst, succ, blockArgs)))
2007-
return failure();
2008-
succBlocks.push_back(lookupBlock(succ));
2009-
succBlockArgs.push_back(blockArgs);
2010-
succBlockArgsRange.push_back(succBlockArgs.back());
2011-
}
2012-
Location loc = translateLoc(inst->getDebugLoc());
2013-
auto indBrOp = builder.create<LLVM::IndirectBrOp>(
2014-
loc, *basePtr, succBlockArgsRange, succBlocks);
2015-
2016-
mapNoResultOp(inst, indBrOp);
2017-
return success();
2018-
}
2019-
20201991
// Convert all instructions that have an mlirBuilder.
20211992
if (succeeded(convertInstructionImpl(builder, inst, *this, iface)))
20221993
return success();
@@ -2027,8 +1998,8 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) {
20271998
LogicalResult ModuleImport::processInstruction(llvm::Instruction *inst) {
20281999
// FIXME: Support uses of SubtargetData.
20292000
// FIXME: Add support for call / operand attributes.
2030-
// FIXME: Add support for the cleanupret, catchret, catchswitch, callbr,
2031-
// vaarg, catchpad, cleanuppad instructions.
2001+
// FIXME: Add support for the indirectbr, cleanupret, catchret, catchswitch,
2002+
// callbr, vaarg, catchpad, cleanuppad instructions.
20322003

20332004
// Convert LLVM intrinsics calls to MLIR intrinsics.
20342005
if (auto *intrinsic = dyn_cast<llvm::IntrinsicInst>(inst))

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -805,14 +805,6 @@ static Value getPHISourceValue(Block *current, Block *pred,
805805
return switchOp.getCaseOperands(i.index())[index];
806806
}
807807

808-
if (auto indBrOp = dyn_cast<LLVM::IndirectBrOp>(terminator)) {
809-
// For indirect branches we take operands for each successor.
810-
for (const auto &i : llvm::enumerate(indBrOp->getSuccessors())) {
811-
if (indBrOp->getSuccessor(i.index()) == current)
812-
return indBrOp.getSuccessorOperands(i.index())[index];
813-
}
814-
}
815-
816808
if (auto invokeOp = dyn_cast<LLVM::InvokeOp>(terminator)) {
817809
return invokeOp.getNormalDest() == current
818810
? invokeOp.getNormalDestOperands()[index]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s -pass-pipeline='builtin.module(llvm.func(canonicalize{region-simplify=aggressive}))' -verify-diagnostics -split-input-file | FileCheck %s
1+
// RUN: mlir-opt %s -pass-pipeline='builtin.module(llvm.func(canonicalize{region-simplify=aggressive}))' -split-input-file | FileCheck %s
22

33
llvm.mlir.global private @x() {addr_space = 0 : i32, dso_local} : !llvm.ptr {
44
%0 = llvm.blockaddress <function = @ba, tag = <id = 2>> : !llvm.ptr

mlir/test/Dialect/LLVMIR/indirectbr.mlir

Lines changed: 0 additions & 83 deletions
This file was deleted.

mlir/test/Target/LLVMIR/Import/import-failure.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
; RUN: not mlir-translate -import-llvm -emit-expensive-warnings -split-input-file %s 2>&1 -o /dev/null | FileCheck %s
22

3+
; CHECK: <unknown>
4+
; CHECK-SAME: error: unhandled instruction: indirectbr ptr %dst, [label %bb1, label %bb2]
5+
define i32 @unhandled_instruction(ptr %dst) {
6+
indirectbr ptr %dst, [label %bb1, label %bb2]
7+
bb1:
8+
ret i32 0
9+
bb2:
10+
ret i32 1
11+
}
12+
13+
; // -----
14+
315
; Check that debug intrinsics with an unsupported argument are dropped.
416

517
declare void @llvm.dbg.value(metadata, metadata, metadata)

0 commit comments

Comments
 (0)