Index: mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td =================================================================== --- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -323,6 +323,43 @@ def LLVM_FPTruncOp : LLVM_CastOp<"fptrunc", "CreateFPTrunc">; // Call-related operations. +def LLVM_InvokeOp : LLVM_Op<"invoke", [Terminator]>, + Arguments<(ins OptionalAttr:$callee, + Variadic)>, + Results<(outs Variadic)> { + let builders = [OpBuilder< + "Builder *b, OperationState &result, ArrayRef tys, " + "FlatSymbolRefAttr callee, ValueRange ops, Block* normal, " + "ValueRange normalOps, Block* unwind, ValueRange unwindOps", + [{ + result.addTypes(tys); + result.addOperands(ops); + result.addAttribute("callee", callee); + result.addSuccessor(normal, normalOps); + result.addSuccessor(unwind, unwindOps); + }]>, + OpBuilder< + "Builder *b, OperationState &result, ArrayRef tys, " + "ValueRange ops, Block* normal, " + "ValueRange normalOps, Block* unwind, ValueRange unwindOps", + [{ + result.addTypes(tys); + result.addOperands(ops); + result.addSuccessor(normal, normalOps); + result.addSuccessor(unwind, unwindOps); + }]>]; + let verifier = [{ return ::verify(*this); }]; + let parser = [{ return parseInvokeOp(parser, result); }]; + let printer = [{ printInvokeOp(p, *this); }]; +} + +def LLVM_LandingpadOp : LLVM_OneResultOp<"landingpad">, + Arguments<(ins UnitAttr:$cleanup, + Variadic)> { + let parser = [{ return parseLandingpadOp(parser, result); }]; + let printer = [{ printLandingpadOp(p, *this); }]; +} + def LLVM_CallOp : LLVM_Op<"call">, Arguments<(ins OptionalAttr:$callee, Variadic)>, Index: mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp =================================================================== --- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -286,6 +286,201 @@ return success(); } +//===----------------------------------------------------------------------===// +// Printing/parsing for LLVM::InvokeOp. +//===----------------------------------------------------------------------===// + +static LogicalResult verify(InvokeOp op) { + + if (op.getNumResults() > 1) + return op.emitOpError("must have 0 or 1 result"); + if (op.getNumSuccessors() != 2) + return op.emitOpError("must have normal and unwind destinations"); + + if (op.getSuccessor(1)->getOperations().size() == 0) + return op.emitError( + "must have atleast one operation in unwind destination"); + + // If the first instruction is not LandingpadOp + if (!isa(*op.getSuccessor(1)->begin())) + return op.emitError("first operation in unwind destination should be a " + "llvm.landingpad operation"); + + return success(); +} + +static void printInvokeOp(OpAsmPrinter &p, InvokeOp &op) { + auto callee = op.callee(); + bool isDirect = callee.hasValue(); + + p << op.getOperationName() << ' '; + + // Either function name or pointer + if (isDirect) + p.printSymbolName(callee.getValue()); + else + p << op.getOperand(0); + + p << '(' << op.getOperands().drop_front(isDirect ? 0 : 1) << ')'; + p << " to "; + p.printSuccessorAndUseList(op.getOperation(), 0); + p << " unwind "; + p.printSuccessorAndUseList(op.getOperation(), 1); + + p.printOptionalAttrDict(op.getAttrs(), {"callee"}); + + SmallVector resultTypes(op.getResultTypes()); + SmallVector argTypes( + llvm::drop_begin(op.getOperandTypes(), isDirect ? 0 : 1)); + + p << " : " << FunctionType::get(argTypes, resultTypes, op.getContext()); +} + +// ::= `llvm.invoke` (function-id | ssa-use) `(` ssa-use-list `)` +// `to` bb-id (`[` ssa-use-and-type-list `]`)? +// `unwind` bb-id (`[` ssa-use-and-type-list `]`)? +// attribute-dict? `:` function-type +static ParseResult parseInvokeOp(OpAsmParser &parser, OperationState &result) { + SmallVector operands; + FunctionType type; + SymbolRefAttr funcAttr; + llvm::SMLoc trailingTypeLoc; + Block *normalDest, *unwindDest; + SmallVector normalOperands, unwindOperands; + + // Parse an operand list that will, in practice, contain 0 or 1 operand. In + // case of an indirect call, there will be 1 operand before `(`. In case of a + // direct call, there will be no operands and the parser will stop at the + // function identifier without complaining. + if (parser.parseOperandList(operands)) + return failure(); + bool isDirect = operands.empty(); + + // Optionally parse a function identifier. + if (isDirect && parser.parseAttribute(funcAttr, "callee", result.attributes)) + return failure(); + + if (parser.parseOperandList(operands, OpAsmParser::Delimiter::Paren) || + parser.parseKeyword("to") || + parser.parseSuccessorAndUseList(normalDest, normalOperands) || + parser.parseKeyword("unwind") || + parser.parseSuccessorAndUseList(unwindDest, unwindOperands) || + parser.parseOptionalAttrDict(result.attributes) || parser.parseColon() || + parser.getCurrentLocation(&trailingTypeLoc) || parser.parseType(type)) + return failure(); + + auto funcType = type.dyn_cast(); + if (!funcType) + return parser.emitError(trailingTypeLoc, "expected function type"); + if (isDirect) { + // Make sure types match. + if (parser.resolveOperands(operands, funcType.getInputs(), + parser.getNameLoc(), result.operands)) + return failure(); + result.addTypes(funcType.getResults()); + } else { + // Construct the LLVM IR Dialect function type that the first operand + // should match. + if (funcType.getNumResults() > 1) + return parser.emitError(trailingTypeLoc, + "expected function with 0 or 1 result"); + + Builder &builder = parser.getBuilder(); + auto *llvmDialect = + builder.getContext()->getRegisteredDialect(); + LLVM::LLVMType llvmResultType; + if (funcType.getNumResults() == 0) { + llvmResultType = LLVM::LLVMType::getVoidTy(llvmDialect); + } else { + llvmResultType = funcType.getResult(0).dyn_cast(); + if (!llvmResultType) + return parser.emitError(trailingTypeLoc, + "expected result to have LLVM type"); + } + + SmallVector argTypes; + argTypes.reserve(funcType.getNumInputs()); + for (int i = 0, e = funcType.getNumInputs(); i < e; ++i) { + auto argType = funcType.getInput(i).dyn_cast(); + if (!argType) + return parser.emitError(trailingTypeLoc, + "expected LLVM types as inputs"); + argTypes.push_back(argType); + } + auto llvmFuncType = LLVM::LLVMType::getFunctionTy(llvmResultType, argTypes, + /*isVarArg=*/false); + auto wrappedFuncType = llvmFuncType.getPointerTo(); + + auto funcArguments = + ArrayRef(operands).drop_front(); + + // Make sure that the first operand (indirect callee) matches the wrapped + // LLVM IR function type, and that the types of the other call operands + // match the types of the function arguments. + if (parser.resolveOperand(operands[0], wrappedFuncType, result.operands) || + parser.resolveOperands(funcArguments, funcType.getInputs(), + parser.getNameLoc(), result.operands)) + return failure(); + + result.addTypes(llvmResultType); + } + result.addSuccessor(normalDest, normalOperands); + result.addSuccessor(unwindDest, unwindOperands); + return success(); +} + +//===----------------------------------------------------------------------===// +// Printing/parsing for LLVM::LandingpadOp. +//===----------------------------------------------------------------------===// + +static void printLandingpadOp(OpAsmPrinter &p, LandingpadOp &op) { + p << op.getOperationName() << (op.cleanup() ? " cleanup " : " "); + + // Clauses + for (auto it : op.getOperands()) { + // Similar to llvm - if clause is an array type then it is filter + // clause else catch clause + bool isArrayTy = it.getType().cast().isArrayTy(); + p << '(' << (isArrayTy ? "filter " : "catch ") << it << " : " + << it.getType() << ") "; + } + + p.printOptionalAttrDict(op.getAttrs(), {"cleanup"}); + + p << ": " << op.getType(); +} + +// ::= `llvm.landingpad` `cleanup`? +// ((`catch` | `filter`) operand-type ssa-use)* attribute-dict? +static ParseResult parseLandingpadOp(OpAsmParser &parser, + OperationState &result) { + // Check for cleanup + UnitAttr ua; + parser.parseAttribute(ua, "cleanup", result.attributes); + + // Parse clauses with types + while ((parser.parseOptionalLParen() || true) && + (!parser.parseOptionalKeyword("filter") || + !parser.parseOptionalKeyword("catch"))) { + OpAsmParser::OperandType operand; + Type ty; + if (parser.parseOperand(operand) || parser.parseColon() || + parser.parseType(ty) || + parser.resolveOperand(operand, ty, result.operands)) + return failure(); + parser.parseOptionalRParen(); + } + + Type type; + llvm::SMLoc typeLocation; + parser.getCurrentLocation(&typeLocation); + if (parser.parseColon() || parser.parseType(type)) + return parser.emitError(typeLocation, "invalid type"); + + result.addTypes(type); + return success(); +} + //===----------------------------------------------------------------------===// // Printing/parsing for LLVM::CallOp. //===----------------------------------------------------------------------===// Index: mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp =================================================================== --- mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -76,7 +76,7 @@ /// `br` branches to `target`. Return the block arguments to attach to the /// generated branch op. These should be in the same order as the PHIs in /// `target`. - SmallVector processBranchArgs(llvm::BranchInst *br, + SmallVector processBranchArgs(llvm::Instruction *br, llvm::BasicBlock *target); /// Return `value` as an attribute to attach to a GlobalOp. Attribute getConstantAsAttr(llvm::Constant *value); @@ -269,16 +269,21 @@ } Value Importer::processConstant(llvm::Constant *c) { + OpBuilder bEntry(currentEntryBlock, currentEntryBlock->begin()); if (Attribute attr = getConstantAsAttr(c)) { // These constants can be represented as attributes. - OpBuilder b(currentEntryBlock, currentEntryBlock->begin()); - return instMap[c] = b.create(unknownLoc, - processType(c->getType()), attr); + return instMap[c] = bEntry.create( + unknownLoc, processType(c->getType()), attr); } if (auto *cn = dyn_cast(c)) { - OpBuilder b(currentEntryBlock, currentEntryBlock->begin()); return instMap[c] = - b.create(unknownLoc, processType(cn->getType())); + bEntry.create(unknownLoc, processType(cn->getType())); + } + if (auto *GV = dyn_cast(c)) { + auto i = + bEntry.create(UnknownLoc::get(context), processGlobal(GV), + ArrayRef()); + return i; } if (auto *ce = dyn_cast(c)) { llvm::Instruction *i = ce->getAsInstruction(); @@ -311,11 +316,6 @@ return unknownInstMap[value]->getResult(0); } - if (auto *GV = dyn_cast(value)) { - return b.create(UnknownLoc::get(context), processGlobal(GV), - ArrayRef()); - } - // Note, constant global variables are both GlobalVariables and Constants, // so we handle GlobalVariables first above. if (auto *c = dyn_cast(value)) @@ -406,7 +406,7 @@ // `br` branches to `target`. Return the branch arguments to `br`, in the // same order of the PHIs in `target`. -SmallVector Importer::processBranchArgs(llvm::BranchInst *br, +SmallVector Importer::processBranchArgs(llvm::Instruction *br, llvm::BasicBlock *target) { SmallVector v; for (auto inst = target->begin(); isa(inst); ++inst) { @@ -519,6 +519,49 @@ v = op->getResult(0); return success(); } + case llvm::Instruction::LandingPad: { + llvm::LandingPadInst *lpi = cast(inst); + SmallVector ops; + + for (unsigned i = 0; i < lpi->getNumClauses(); i++) { + ops.push_back(processConstant(lpi->getClause(i))); + } + + b.create(loc, processType(lpi->getType()), lpi->isCleanup(), + ops); + return success(); + } + case llvm::Instruction::Invoke: { + llvm::InvokeInst *ii = cast(inst); + + SmallVector tys; + if (!ii->getType()->isVoidTy()) + tys.push_back(processType(inst->getType())); + + SmallVector ops; + ops.reserve(inst->getNumOperands() + 1); + for (auto &op : ii->arg_operands()) + ops.push_back(processValue(op.get())); + + Operation *op; + if (llvm::Function *callee = ii->getCalledFunction()) { + op = b.create(loc, tys, b.getSymbolRefAttr(callee->getName()), + ops, blocks[ii->getNormalDest()], + processBranchArgs(ii, ii->getNormalDest()), + blocks[ii->getUnwindDest()], + processBranchArgs(ii, ii->getUnwindDest())); + } else { + ops.insert(ops.begin(), processValue(ii->getCalledValue())); + op = b.create(loc, tys, ops, blocks[ii->getNormalDest()], + processBranchArgs(ii, ii->getNormalDest()), + blocks[ii->getUnwindDest()], + processBranchArgs(ii, ii->getUnwindDest())); + } + + if (!ii->getType()->isVoidTy()) + v = op->getResult(0); + return success(); + } case llvm::Instruction::GetElementPtr: { // FIXME: Support inbounds GEPs. llvm::GetElementPtrInst *gep = cast(inst); Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp =================================================================== --- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -201,6 +201,35 @@ return success(result->getType()->isVoidTy()); } + if (auto invOp = dyn_cast(opInst)) { + auto operands = lookupValues(opInst.getOperands()); + ArrayRef operandsRef(operands); + if (auto attr = opInst.getAttrOfType("callee")) + builder.CreateInvoke(functionMapping.lookup(attr.getValue()), + blockMapping[invOp.getSuccessor(0)], + blockMapping[invOp.getSuccessor(1)], operandsRef); + else + builder.CreateInvoke( + operandsRef.front(), blockMapping[invOp.getSuccessor(0)], + blockMapping[invOp.getSuccessor(1)], operandsRef.drop_front()); + return success(); + } + + if (auto lpOp = dyn_cast(opInst)) { + llvm::Type *ty = lpOp.getType().dyn_cast().getUnderlyingType(); + llvm::LandingPadInst *lpi = + builder.CreateLandingPad(ty, lpOp.getNumOperands()); + + // Add clauses + for (auto operand : lookupValues(lpOp.getOperands())) { + if (auto constOper = dyn_cast(operand)) + lpi->addClause(constOper); + else + return emitError(opInst.getLoc(), "constant clauses expected"); + } + return success(); + } + // Emit branches. We need to look up the remapped blocks and ignore the block // arguments that were transformed into PHI nodes. if (auto brOp = dyn_cast(opInst)) { Index: mlir/test/Dialect/LLVMIR/roundtrip.mlir =================================================================== --- mlir/test/Dialect/LLVMIR/roundtrip.mlir +++ mlir/test/Dialect/LLVMIR/roundtrip.mlir @@ -218,3 +218,53 @@ %1 = llvm.mlir.null : !llvm<"{void(i32, void()*)*, i64}*"> llvm.return } + +llvm.mlir.global external constant @_ZTIi() : !llvm<"i8*"> +llvm.func @bar(!llvm<"i8*">, !llvm<"i8*">, !llvm<"i8*">) +llvm.func @__gxx_personality_v0(...) -> !llvm.i32 + +// CHECK-LABEL: @invokeLandingpad +llvm.func @invokeLandingpad() -> !llvm.i32 { +// CHECK-NEXT: %[[a0:[0-9]+]] = llvm.mlir.constant(0 : i32) : !llvm.i32 +// CHECK-NEXT: %{{[0-9]+}} = llvm.mlir.constant(3 : i32) : !llvm.i32 +// CHECK-NEXT: %[[a2:[0-9]+]] = llvm.mlir.constant("\01") : !llvm<"[1 x i8]"> +// CHECK-NEXT: %[[a3:[0-9]+]] = llvm.mlir.null : !llvm<"i8**"> +// CHECK-NEXT: %[[a4:[0-9]+]] = llvm.mlir.null : !llvm<"i8*"> +// CHECK-NEXT: %[[a5:[0-9]+]] = llvm.mlir.addressof @_ZTIi : !llvm<"i8**"> +// CHECK-NEXT: %[[a6:[0-9]+]] = llvm.bitcast %[[a5]] : !llvm<"i8**"> to !llvm<"i8*"> +// CHECK-NEXT: %[[a7:[0-9]+]] = llvm.mlir.constant(1 : i32) : !llvm.i32 +// CHECK-NEXT: %[[a8:[0-9]+]] = llvm.alloca %[[a7]] x !llvm.i8 : (!llvm.i32) -> !llvm<"i8*"> +// CHECK-NEXT: %{{[0-9]+}} = llvm.invoke @foo(%[[a7]]) to ^bb2 unwind ^bb1 : (!llvm.i32) -> !llvm<"{ i32, double, i32 }"> + %0 = llvm.mlir.constant(0 : i32) : !llvm.i32 + %1 = llvm.mlir.constant(3 : i32) : !llvm.i32 + %2 = llvm.mlir.constant("\01") : !llvm<"[1 x i8]"> + %3 = llvm.mlir.null : !llvm<"i8**"> + %4 = llvm.mlir.null : !llvm<"i8*"> + %5 = llvm.mlir.addressof @_ZTIi : !llvm<"i8**"> + %6 = llvm.bitcast %5 : !llvm<"i8**"> to !llvm<"i8*"> + %7 = llvm.mlir.constant(1 : i32) : !llvm.i32 + %8 = llvm.alloca %7 x !llvm.i8 : (!llvm.i32) -> !llvm<"i8*"> + %9 = llvm.invoke @foo(%7) to ^bb2 unwind ^bb1 : (!llvm.i32) -> !llvm<"{ i32, double, i32 }"> + +// CHECK-NEXT: ^bb1: +// CHECK-NEXT: %{{[0-9]+}} = llvm.landingpad (catch %[[a3]] : !llvm<"i8**">) (catch %[[a6]] : !llvm<"i8*">) (filter %[[a2]] : !llvm<"[1 x i8]">) : !llvm<"{ i8*, i32 }"> +// CHECK-NEXT: llvm.br ^bb3 +^bb1: + %10 = llvm.landingpad (catch %3 : !llvm<"i8**">) (catch %6 : !llvm<"i8*">) (filter %2 : !llvm<"[1 x i8]">) : !llvm<"{ i8*, i32 }"> + llvm.br ^bb3 + +// CHECK-NEXT: ^bb2: +// CHECK-NEXT: llvm.return %[[a7]] : !llvm.i32 +^bb2: + llvm.return %7 : !llvm.i32 + +// CHECK-NEXT: ^bb3: +// CHECK-NEXT: llvm.invoke @bar(%[[a8]], %[[a6]], %[[a4]]) to ^bb2 unwind ^bb1 : (!llvm<"i8*">, !llvm<"i8*">, !llvm<"i8*">) -> () +^bb3: + llvm.invoke @bar(%8, %6, %4) to ^bb2 unwind ^bb1 : (!llvm<"i8*">, !llvm<"i8*">, !llvm<"i8*">) -> () + +// CHECK-NEXT: ^bb4: +// CHECK-NEXT: llvm.return %[[a0]] : !llvm.i32 +^bb4: + llvm.return %0 : !llvm.i32 +} Index: mlir/test/Target/import.ll =================================================================== --- mlir/test/Target/import.ll +++ mlir/test/Target/import.ll @@ -62,11 +62,12 @@ entry: ; CHECK: %{{[0-9]+}} = llvm.inttoptr %arg0 : !llvm.i64 to !llvm<"i64*"> %aa = inttoptr i64 %a to i64* -; CHECK: %[[addrof:[0-9]+]] = llvm.mlir.addressof @g2 : !llvm<"double*"> -; CHECK: %{{[0-9]+}} = llvm.ptrtoint %[[addrof]] : !llvm<"double*"> to !llvm.i64 +; %[[addrof:[0-9]+]] = llvm.mlir.addressof @g2 : !llvm<"double*"> +; %[[addrof2:[0-9]+]] = llvm.mlir.addressof @g2 : !llvm<"double*"> +; %{{[0-9]+}} = llvm.inttoptr %arg0 : !llvm.i64 to !llvm<"i64*"> +; %{{[0-9]+}} = llvm.ptrtoint %[[addrof2]] : !llvm<"double*"> to !llvm.i64 +; %{{[0-9]+}} = llvm.getelementptr %[[addrof]][%3] : (!llvm<"double*">, !llvm.i32) -> !llvm<"double*"> %bb = ptrtoint double* @g2 to i64 -; CHECK-DAG: %[[addrof2:[0-9]+]] = llvm.mlir.addressof @g2 : !llvm<"double*"> -; CHECK: %{{[0-9]+}} = llvm.getelementptr %[[addrof2]][%[[c2]]] : (!llvm<"double*">, !llvm.i32) -> !llvm<"double*"> %cc = getelementptr double, double* @g2, i32 2 ; CHECK: %[[b:[0-9]+]] = llvm.trunc %arg0 : !llvm.i64 to !llvm.i32 %b = trunc i64 %a to i32 @@ -245,3 +246,39 @@ %3 = call i32 %2() ret i32 %3 } + +@_ZTIi = external dso_local constant i8* +@_ZTIii= external dso_local constant i8** +declare void @foo(i8*) +declare i8* @bar(i8*) +declare i32 @__gxx_personality_v0(...) + +; CHECK-LABEL: @invokeLandingpad +define i32 @invokeLandingpad() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { + ; CHECK: %[[a1:[0-9]+]] = llvm.bitcast %{{[0-9]+}} : !llvm<"i8***"> to !llvm<"i8*"> + ; CHECK: %[[a3:[0-9]+]] = llvm.alloca %{{[0-9]+}} x !llvm.i8 : (!llvm.i32) -> !llvm<"i8*"> + %1 = alloca i8 + ; CHECK: llvm.invoke @foo(%[[a3]]) to ^bb2 unwind ^bb1 : (!llvm<"i8*">) -> () + invoke void @foo(i8* %1) to label %4 unwind label %2 + +; CHECK: ^bb1: + ; CHECK: %{{[0-9]+}} = llvm.landingpad (catch %{{[0-9]+}} : !llvm<"i8**">) (catch %[[a1]] : !llvm<"i8*">) (filter %{{[0-9]+}} : !llvm<"[1 x i8]">) : !llvm<"{ i8*, i32 }"> + %3 = landingpad { i8*, i32 } catch i8** @_ZTIi catch i8* bitcast (i8*** @_ZTIii to i8*) + ; FIXME: Change filter to a constant array once they are handled. + ; Currently, even though it parses this, LLVM module is broken + filter [1 x i8] [i8 1] + ; CHECK: llvm.br ^bb3 + br label %5 + +; CHECK: ^bb2: + ; CHECK: llvm.return %{{[0-9]+}} : !llvm.i32 + ret i32 1 + +; CHECK: ^bb3: + ; CHECK: %{{[0-9]+}} = llvm.invoke @bar(%[[a3]]) to ^bb2 unwind ^bb1 : (!llvm<"i8*">) -> !llvm<"i8*"> + %6 = invoke i8* @bar(i8* %1) to label %4 unwind label %2 + +; CHECK: ^bb4: + ; CHECK: llvm.return %{{[0-9]+}} : !llvm.i32 + ret i32 0 +} Index: mlir/test/Target/llvmir.mlir =================================================================== --- mlir/test/Target/llvmir.mlir +++ mlir/test/Target/llvmir.mlir @@ -1067,3 +1067,44 @@ // CHECK: ret i32* null llvm.return %0 : !llvm<"i32*"> } + +llvm.mlir.global external constant @_ZTIi() : !llvm<"i8*"> +llvm.func @foo(!llvm<"i8*">) +llvm.func @bar(!llvm<"i8*">) -> !llvm<"i8*"> +llvm.func @__gxx_personality_v0(...) -> !llvm.i32 + +// CHECK-LABEL: @invokeLandingpad +llvm.func @invokeLandingpad() -> !llvm.i32 { +// CHECK: %[[a1:[0-9]+]] = alloca i8 + %0 = llvm.mlir.constant(0 : i32) : !llvm.i32 + %1 = llvm.mlir.constant("\01") : !llvm<"[1 x i8]"> + %2 = llvm.mlir.addressof @_ZTIi : !llvm<"i8**"> + %3 = llvm.bitcast %2 : !llvm<"i8**"> to !llvm<"i8*"> + %4 = llvm.mlir.null : !llvm<"i8**"> + %5 = llvm.mlir.constant(1 : i32) : !llvm.i32 + %6 = llvm.alloca %5 x !llvm.i8 : (!llvm.i32) -> !llvm<"i8*"> +// CHECK: invoke void @foo(i8* %[[a1]]) +// CHECK-NEXT: to label %[[normal:[0-9]+]] unwind label %[[unwind:[0-9]+]] + llvm.invoke @foo(%6) to ^bb2 unwind ^bb1 : (!llvm<"i8*">) -> () + +// CHECK: [[unwind]]: +^bb1: +// CHECK: %{{[0-9]+}} = landingpad { i8*, i32 } +// CHECK-NEXT: catch i8** null +// CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*) +// CHECK-NEXT: filter [1 x i8] c"\01" + %7 = llvm.landingpad (catch %4 : !llvm<"i8**">) (catch %3 : !llvm<"i8*">) (filter %1 : !llvm<"[1 x i8]">) : !llvm<"{ i8*, i32 }"> +// CHECK: br label %[[final:[0-9]+]] + llvm.br ^bb3 + +// CHECK: [[normal]]: +// CHECK-NEXT: ret i32 1 +^bb2: // 2 preds: ^bb0, ^bb3 + llvm.return %5 : !llvm.i32 + +// CHECK: [[final]]: +// CHECK-NEXT: %{{[0-9]+}} = invoke i8* @bar(i8* %[[a1]]) +// CHECK-NEXT: to label %[[normal]] unwind label %[[unwind]] +^bb3: // pred: ^bb1 + %8 = llvm.invoke @bar(%6) to ^bb2 unwind ^bb1 : (!llvm<"i8*">) -> !llvm<"i8*"> +}