1//===- InliningUtils.cpp ---- Misc utilities for inlining -----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements miscellaneous inlining utilities.
10//
11//===----------------------------------------------------------------------===//
12
13#include "mlir/Transforms/InliningUtils.h"
14
15#include "mlir/IR/Builders.h"
16#include "mlir/IR/BuiltinOps.h"
17#include "mlir/IR/IRMapping.h"
18#include "mlir/IR/Operation.h"
19#include "mlir/Interfaces/CallInterfaces.h"
20#include "llvm/Support/Debug.h"
21#include "llvm/Support/DebugLog.h"
22#include "llvm/Support/raw_ostream.h"
23#include <optional>
24
25#define DEBUG_TYPE "inlining"
26
27using namespace mlir;
28
29/// Combine `callee` location with `caller` location to create a stack that
30/// represents the call chain.
31/// If `callee` location is a `CallSiteLoc`, indicating an existing stack of
32/// locations, the `caller` location is appended to the end of it, extending
33/// the chain.
34/// Otherwise, a single `CallSiteLoc` is created, representing a direct call
35/// from `caller` to `callee`.
36static LocationAttr stackLocations(Location callee, Location caller) {
37 Location lastCallee = callee;
38 SmallVector<CallSiteLoc> calleeInliningStack;
39 while (auto nextCallSite = dyn_cast<CallSiteLoc>(Val&: lastCallee)) {
40 calleeInliningStack.push_back(Elt: nextCallSite);
41 lastCallee = nextCallSite.getCaller();
42 }
43
44 CallSiteLoc firstCallSite = CallSiteLoc::get(callee: lastCallee, caller);
45 for (CallSiteLoc currentCallSite : reverse(C&: calleeInliningStack))
46 firstCallSite =
47 CallSiteLoc::get(callee: currentCallSite.getCallee(), caller: firstCallSite);
48
49 return firstCallSite;
50}
51
52/// Remap all locations reachable from the inlined blocks with CallSiteLoc
53/// locations with the provided caller location.
54static void
55remapInlinedLocations(iterator_range<Region::iterator> inlinedBlocks,
56 Location callerLoc) {
57 DenseMap<Location, LocationAttr> mappedLocations;
58 auto remapLoc = [&](Location loc) {
59 auto [it, inserted] = mappedLocations.try_emplace(Key: loc);
60 // Only query the attribute uniquer once per callsite attribute.
61 if (inserted) {
62 LocationAttr newLoc = stackLocations(callee: loc, caller: callerLoc);
63 it->getSecond() = newLoc;
64 }
65 return it->second;
66 };
67
68 AttrTypeReplacer attrReplacer;
69 attrReplacer.addReplacement(
70 callback: [&](LocationAttr loc) -> std::pair<LocationAttr, WalkResult> {
71 return {remapLoc(loc), WalkResult::skip()};
72 });
73
74 for (Block &block : inlinedBlocks) {
75 for (BlockArgument &arg : block.getArguments())
76 if (LocationAttr newLoc = remapLoc(arg.getLoc()))
77 arg.setLoc(newLoc);
78
79 for (Operation &op : block)
80 attrReplacer.recursivelyReplaceElementsIn(op: &op, /*replaceAttrs=*/false,
81 /*replaceLocs=*/true);
82 }
83}
84
85static void remapInlinedOperands(iterator_range<Region::iterator> inlinedBlocks,
86 IRMapping &mapper) {
87 auto remapOperands = [&](Operation *op) {
88 for (auto &operand : op->getOpOperands())
89 if (auto mappedOp = mapper.lookupOrNull(from: operand.get()))
90 operand.set(mappedOp);
91 };
92 for (auto &block : inlinedBlocks)
93 block.walk(callback&: remapOperands);
94}
95
96//===----------------------------------------------------------------------===//
97// InlinerInterface
98//===----------------------------------------------------------------------===//
99
100bool InlinerInterface::isLegalToInline(Operation *call, Operation *callable,
101 bool wouldBeCloned) const {
102 if (auto *handler = getInterfaceFor(obj: call))
103 return handler->isLegalToInline(call, callable, wouldBeCloned);
104 return false;
105}
106
107bool InlinerInterface::isLegalToInline(Region *dest, Region *src,
108 bool wouldBeCloned,
109 IRMapping &valueMapping) const {
110 if (auto *handler = getInterfaceFor(obj: dest->getParentOp()))
111 return handler->isLegalToInline(dest, src, wouldBeCloned, valueMapping);
112 return false;
113}
114
115bool InlinerInterface::isLegalToInline(Operation *op, Region *dest,
116 bool wouldBeCloned,
117 IRMapping &valueMapping) const {
118 if (auto *handler = getInterfaceFor(obj: op))
119 return handler->isLegalToInline(op, dest, wouldBeCloned, valueMapping);
120 return false;
121}
122
123bool InlinerInterface::shouldAnalyzeRecursively(Operation *op) const {
124 auto *handler = getInterfaceFor(obj: op);
125 return handler ? handler->shouldAnalyzeRecursively(op) : true;
126}
127
128/// Handle the given inlined terminator by replacing it with a new operation
129/// as necessary.
130void InlinerInterface::handleTerminator(Operation *op, Block *newDest) const {
131 auto *handler = getInterfaceFor(obj: op);
132 assert(handler && "expected valid dialect handler");
133 handler->handleTerminator(op, newDest);
134}
135
136/// Handle the given inlined terminator by replacing it with a new operation
137/// as necessary.
138void InlinerInterface::handleTerminator(Operation *op,
139 ValueRange valuesToRepl) const {
140 auto *handler = getInterfaceFor(obj: op);
141 assert(handler && "expected valid dialect handler");
142 handler->handleTerminator(op, valuesToReplace: valuesToRepl);
143}
144
145/// Returns true if the inliner can use the fast path for the given inlined
146/// block. Only called when exactly one block was inlined.
147bool InlinerInterface::allowSingleBlockOptimization(Block *inlinedBlock) const {
148 auto *handler = getInterfaceFor(obj: inlinedBlock->getParentOp());
149 assert(handler && "expected valid dialect handler");
150 return handler->allowSingleBlockOptimization(inlinedBlock);
151}
152
153Value InlinerInterface::handleArgument(OpBuilder &builder, Operation *call,
154 Operation *callable, Value argument,
155 DictionaryAttr argumentAttrs) const {
156 auto *handler = getInterfaceFor(obj: callable);
157 assert(handler && "expected valid dialect handler");
158 return handler->handleArgument(builder, call, callable, argument,
159 argumentAttrs);
160}
161
162Value InlinerInterface::handleResult(OpBuilder &builder, Operation *call,
163 Operation *callable, Value result,
164 DictionaryAttr resultAttrs) const {
165 auto *handler = getInterfaceFor(obj: callable);
166 assert(handler && "expected valid dialect handler");
167 return handler->handleResult(builder, call, callable, result, resultAttrs);
168}
169
170void InlinerInterface::processInlinedCallBlocks(
171 Operation *call, iterator_range<Region::iterator> inlinedBlocks) const {
172 auto *handler = getInterfaceFor(obj: call);
173 assert(handler && "expected valid dialect handler");
174 handler->processInlinedCallBlocks(call, inlinedBlocks);
175}
176
177/// Utility to check that all of the operations within 'src' can be inlined.
178static bool isLegalToInline(InlinerInterface &interface, Region *src,
179 Region *insertRegion, bool shouldCloneInlinedRegion,
180 IRMapping &valueMapping) {
181 for (auto &block : *src) {
182 for (auto &op : block) {
183 // UnrealizedConversionCastOp is inlineable but cannot implement the
184 // inliner interface due to layering constraints.
185 if (isa<UnrealizedConversionCastOp>(Val: op))
186 continue;
187
188 // Check this operation.
189 if (!interface.isLegalToInline(op: &op, dest: insertRegion,
190 wouldBeCloned: shouldCloneInlinedRegion, valueMapping)) {
191 LDBG() << "* Illegal to inline because of op: "
192 << OpWithFlags(&op, OpPrintingFlags().skipRegions());
193 return false;
194 }
195 // Check any nested regions.
196 if (interface.shouldAnalyzeRecursively(op: &op) &&
197 llvm::any_of(Range: op.getRegions(), P: [&](Region &region) {
198 return !isLegalToInline(interface, src: &region, insertRegion,
199 shouldCloneInlinedRegion, valueMapping);
200 }))
201 return false;
202 }
203 }
204 return true;
205}
206
207//===----------------------------------------------------------------------===//
208// Inline Methods
209//===----------------------------------------------------------------------===//
210
211static void handleArgumentImpl(InlinerInterface &interface, OpBuilder &builder,
212 CallOpInterface call,
213 CallableOpInterface callable,
214 IRMapping &mapper) {
215 // Unpack the argument attributes if there are any.
216 SmallVector<DictionaryAttr> argAttrs(
217 callable.getCallableRegion()->getNumArguments(),
218 builder.getDictionaryAttr(value: {}));
219 if (ArrayAttr arrayAttr = callable.getArgAttrsAttr()) {
220 assert(arrayAttr.size() == argAttrs.size());
221 for (auto [idx, attr] : llvm::enumerate(First&: arrayAttr))
222 argAttrs[idx] = cast<DictionaryAttr>(Val: attr);
223 }
224
225 // Run the argument attribute handler for the given argument and attribute.
226 for (auto [blockArg, argAttr] :
227 llvm::zip(t: callable.getCallableRegion()->getArguments(), u&: argAttrs)) {
228 Value newArgument = interface.handleArgument(
229 builder, call, callable, argument: mapper.lookup(from: blockArg), argumentAttrs: argAttr);
230 assert(newArgument.getType() == mapper.lookup(blockArg).getType() &&
231 "expected the argument type to not change");
232
233 // Update the mapping to point the new argument returned by the handler.
234 mapper.map(from: blockArg, to: newArgument);
235 }
236}
237
238static void handleResultImpl(InlinerInterface &interface, OpBuilder &builder,
239 CallOpInterface call, CallableOpInterface callable,
240 ValueRange results) {
241 // Unpack the result attributes if there are any.
242 SmallVector<DictionaryAttr> resAttrs(results.size(),
243 builder.getDictionaryAttr(value: {}));
244 if (ArrayAttr arrayAttr = callable.getResAttrsAttr()) {
245 assert(arrayAttr.size() == resAttrs.size());
246 for (auto [idx, attr] : llvm::enumerate(First&: arrayAttr))
247 resAttrs[idx] = cast<DictionaryAttr>(Val: attr);
248 }
249
250 // Run the result attribute handler for the given result and attribute.
251 for (auto [result, resAttr] : llvm::zip(t&: results, u&: resAttrs)) {
252 // Store the original result users before running the handler.
253 DenseSet<Operation *> resultUsers(llvm::from_range, result.getUsers());
254
255 Value newResult =
256 interface.handleResult(builder, call, callable, result, resultAttrs: resAttr);
257 assert(newResult.getType() == result.getType() &&
258 "expected the result type to not change");
259
260 // Replace the result uses except for the ones introduce by the handler.
261 result.replaceUsesWithIf(newValue: newResult, shouldReplace: [&](OpOperand &operand) {
262 return resultUsers.count(V: operand.getOwner());
263 });
264 }
265}
266
267static LogicalResult inlineRegionImpl(
268 InlinerInterface &interface,
269 function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
270 Region *src, Block *inlineBlock, Block::iterator inlinePoint,
271 IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes,
272 std::optional<Location> inlineLoc, bool shouldCloneInlinedRegion,
273 CallOpInterface call = {}) {
274 assert(resultsToReplace.size() == regionResultTypes.size());
275 // We expect the region to have at least one block.
276 if (src->empty())
277 return failure();
278
279 // Check that all of the region arguments have been mapped.
280 auto *srcEntryBlock = &src->front();
281 if (llvm::any_of(Range: srcEntryBlock->getArguments(),
282 P: [&](BlockArgument arg) { return !mapper.contains(from: arg); }))
283 return failure();
284
285 // Check that the operations within the source region are valid to inline.
286 Region *insertRegion = inlineBlock->getParent();
287 if (!interface.isLegalToInline(dest: insertRegion, src, wouldBeCloned: shouldCloneInlinedRegion,
288 valueMapping&: mapper) ||
289 !isLegalToInline(interface, src, insertRegion, shouldCloneInlinedRegion,
290 valueMapping&: mapper))
291 return failure();
292
293 // Run the argument attribute handler before inlining the callable region.
294 OpBuilder builder(inlineBlock, inlinePoint);
295 auto callable = dyn_cast<CallableOpInterface>(Val: src->getParentOp());
296 if (call && callable)
297 handleArgumentImpl(interface, builder, call, callable, mapper);
298
299 // Clone the callee's source into the caller.
300 Block *postInsertBlock = inlineBlock->splitBlock(splitBefore: inlinePoint);
301 cloneCallback(builder, src, inlineBlock, postInsertBlock, mapper,
302 shouldCloneInlinedRegion);
303
304 // Get the range of newly inserted blocks.
305 auto newBlocks = llvm::make_range(x: std::next(x: inlineBlock->getIterator()),
306 y: postInsertBlock->getIterator());
307 Block *firstNewBlock = &*newBlocks.begin();
308
309 // Remap the locations of the inlined operations if a valid source location
310 // was provided.
311 if (inlineLoc && !llvm::isa<UnknownLoc>(Val: *inlineLoc))
312 remapInlinedLocations(inlinedBlocks: newBlocks, callerLoc: *inlineLoc);
313
314 // If the blocks were moved in-place, make sure to remap any necessary
315 // operands.
316 if (!shouldCloneInlinedRegion)
317 remapInlinedOperands(inlinedBlocks: newBlocks, mapper);
318
319 // Process the newly inlined blocks.
320 if (call)
321 interface.processInlinedCallBlocks(call, inlinedBlocks: newBlocks);
322 interface.processInlinedBlocks(inlinedBlocks: newBlocks);
323
324 // Handle the case where only a single block was inlined.
325 if (llvm::hasSingleElement(C&: newBlocks) &&
326 interface.allowSingleBlockOptimization(inlinedBlock: firstNewBlock)) {
327 // Run the result attribute handler on the terminator operands.
328 Operation *firstBlockTerminator = firstNewBlock->getTerminator();
329 builder.setInsertionPoint(firstBlockTerminator);
330 if (call && callable)
331 handleResultImpl(interface, builder, call, callable,
332 results: firstBlockTerminator->getOperands());
333
334 // Have the interface handle the terminator of this block.
335 interface.handleTerminator(op: firstBlockTerminator, valuesToRepl: resultsToReplace);
336 firstBlockTerminator->erase();
337
338 // Merge the post insert block into the cloned entry block.
339 firstNewBlock->getOperations().splice(where: firstNewBlock->end(),
340 L2&: postInsertBlock->getOperations());
341 postInsertBlock->erase();
342 } else {
343 // Otherwise, there were multiple blocks inlined. Add arguments to the post
344 // insertion block to represent the results to replace.
345 for (const auto &resultToRepl : llvm::enumerate(First&: resultsToReplace)) {
346 resultToRepl.value().replaceAllUsesWith(
347 newValue: postInsertBlock->addArgument(type: regionResultTypes[resultToRepl.index()],
348 loc: resultToRepl.value().getLoc()));
349 }
350
351 // Run the result attribute handler on the post insertion block arguments.
352 builder.setInsertionPointToStart(postInsertBlock);
353 if (call && callable)
354 handleResultImpl(interface, builder, call, callable,
355 results: postInsertBlock->getArguments());
356
357 /// Handle the terminators for each of the new blocks.
358 for (auto &newBlock : newBlocks)
359 interface.handleTerminator(op: newBlock.getTerminator(), newDest: postInsertBlock);
360 }
361
362 // Splice the instructions of the inlined entry block into the insert block.
363 inlineBlock->getOperations().splice(where: inlineBlock->end(),
364 L2&: firstNewBlock->getOperations());
365 firstNewBlock->erase();
366 return success();
367}
368
369static LogicalResult inlineRegionImpl(
370 InlinerInterface &interface,
371 function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
372 Region *src, Block *inlineBlock, Block::iterator inlinePoint,
373 ValueRange inlinedOperands, ValueRange resultsToReplace,
374 std::optional<Location> inlineLoc, bool shouldCloneInlinedRegion,
375 CallOpInterface call = {}) {
376 // We expect the region to have at least one block.
377 if (src->empty())
378 return failure();
379
380 auto *entryBlock = &src->front();
381 if (inlinedOperands.size() != entryBlock->getNumArguments())
382 return failure();
383
384 // Map the provided call operands to the arguments of the region.
385 IRMapping mapper;
386 for (unsigned i = 0, e = inlinedOperands.size(); i != e; ++i) {
387 // Verify that the types of the provided values match the function argument
388 // types.
389 BlockArgument regionArg = entryBlock->getArgument(i);
390 if (inlinedOperands[i].getType() != regionArg.getType())
391 return failure();
392 mapper.map(from: regionArg, to: inlinedOperands[i]);
393 }
394
395 // Call into the main region inliner function.
396 return inlineRegionImpl(interface, cloneCallback, src, inlineBlock,
397 inlinePoint, mapper, resultsToReplace,
398 regionResultTypes: resultsToReplace.getTypes(), inlineLoc,
399 shouldCloneInlinedRegion, call);
400}
401
402LogicalResult mlir::inlineRegion(
403 InlinerInterface &interface,
404 function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
405 Region *src, Operation *inlinePoint, IRMapping &mapper,
406 ValueRange resultsToReplace, TypeRange regionResultTypes,
407 std::optional<Location> inlineLoc, bool shouldCloneInlinedRegion) {
408 return inlineRegion(interface, cloneCallback, src, inlineBlock: inlinePoint->getBlock(),
409 inlinePoint: ++inlinePoint->getIterator(), mapper, resultsToReplace,
410 regionResultTypes, inlineLoc, shouldCloneInlinedRegion);
411}
412
413LogicalResult mlir::inlineRegion(
414 InlinerInterface &interface,
415 function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
416 Region *src, Block *inlineBlock, Block::iterator inlinePoint,
417 IRMapping &mapper, ValueRange resultsToReplace, TypeRange regionResultTypes,
418 std::optional<Location> inlineLoc, bool shouldCloneInlinedRegion) {
419 return inlineRegionImpl(
420 interface, cloneCallback, src, inlineBlock, inlinePoint, mapper,
421 resultsToReplace, regionResultTypes, inlineLoc, shouldCloneInlinedRegion);
422}
423
424LogicalResult mlir::inlineRegion(
425 InlinerInterface &interface,
426 function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
427 Region *src, Operation *inlinePoint, ValueRange inlinedOperands,
428 ValueRange resultsToReplace, std::optional<Location> inlineLoc,
429 bool shouldCloneInlinedRegion) {
430 return inlineRegion(interface, cloneCallback, src, inlineBlock: inlinePoint->getBlock(),
431 inlinePoint: ++inlinePoint->getIterator(), inlinedOperands,
432 resultsToReplace, inlineLoc, shouldCloneInlinedRegion);
433}
434
435LogicalResult mlir::inlineRegion(
436 InlinerInterface &interface,
437 function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
438 Region *src, Block *inlineBlock, Block::iterator inlinePoint,
439 ValueRange inlinedOperands, ValueRange resultsToReplace,
440 std::optional<Location> inlineLoc, bool shouldCloneInlinedRegion) {
441 return inlineRegionImpl(interface, cloneCallback, src, inlineBlock,
442 inlinePoint, inlinedOperands, resultsToReplace,
443 inlineLoc, shouldCloneInlinedRegion);
444}
445
446/// Utility function used to generate a cast operation from the given interface,
447/// or return nullptr if a cast could not be generated.
448static Value materializeConversion(const DialectInlinerInterface *interface,
449 SmallVectorImpl<Operation *> &castOps,
450 OpBuilder &castBuilder, Value arg, Type type,
451 Location conversionLoc) {
452 if (!interface)
453 return nullptr;
454
455 // Check to see if the interface for the call can materialize a conversion.
456 Operation *castOp = interface->materializeCallConversion(builder&: castBuilder, input: arg,
457 resultType: type, conversionLoc);
458 if (!castOp)
459 return nullptr;
460 castOps.push_back(Elt: castOp);
461
462 // Ensure that the generated cast is correct.
463 assert(castOp->getNumOperands() == 1 && castOp->getOperand(0) == arg &&
464 castOp->getNumResults() == 1 && *castOp->result_type_begin() == type);
465 return castOp->getResult(idx: 0);
466}
467
468/// This function inlines a given region, 'src', of a callable operation,
469/// 'callable', into the location defined by the given call operation. This
470/// function returns failure if inlining is not possible, success otherwise. On
471/// failure, no changes are made to the module. 'shouldCloneInlinedRegion'
472/// corresponds to whether the source region should be cloned into the 'call' or
473/// spliced directly.
474LogicalResult mlir::inlineCall(
475 InlinerInterface &interface,
476 function_ref<InlinerInterface::CloneCallbackSigTy> cloneCallback,
477 CallOpInterface call, CallableOpInterface callable, Region *src,
478 bool shouldCloneInlinedRegion) {
479 // We expect the region to have at least one block.
480 if (src->empty())
481 return failure();
482 auto *entryBlock = &src->front();
483 ArrayRef<Type> callableResultTypes = callable.getResultTypes();
484
485 // Inlining replaces the call with the body of the callee, so the call must
486 // not have any results that are produced by the call operation itself: there
487 // would be nothing left to compute them.
488 if (call.getForwardedResults().size() != call->getNumResults())
489 return failure();
490
491 // Make sure that the number of arguments and results matchup between the call
492 // and the region.
493 SmallVector<Value, 8> callOperands(call.getArgOperands());
494 SmallVector<Value, 8> callResults(call.getForwardedResults());
495 if (callOperands.size() != entryBlock->getNumArguments() ||
496 callResults.size() != callableResultTypes.size())
497 return failure();
498
499 // A set of cast operations generated to matchup the signature of the region
500 // with the signature of the call.
501 SmallVector<Operation *, 4> castOps;
502 castOps.reserve(N: callOperands.size() + callResults.size());
503
504 // Functor used to cleanup generated state on failure.
505 auto cleanupState = [&] {
506 for (auto *op : castOps) {
507 op->getResult(idx: 0).replaceAllUsesWith(newValue: op->getOperand(idx: 0));
508 op->erase();
509 }
510 return failure();
511 };
512
513 // Builder used for any conversion operations that need to be materialized.
514 OpBuilder castBuilder(call);
515 Location castLoc = call.getLoc();
516 const auto *callInterface = interface.getInterfaceFor(obj: call->getDialect());
517
518 // Map the provided call operands to the arguments of the region.
519 IRMapping mapper;
520 for (unsigned i = 0, e = callOperands.size(); i != e; ++i) {
521 BlockArgument regionArg = entryBlock->getArgument(i);
522 Value operand = callOperands[i];
523
524 // If the call operand doesn't match the expected region argument, try to
525 // generate a cast.
526 Type regionArgType = regionArg.getType();
527 if (operand.getType() != regionArgType) {
528 if (!(operand = materializeConversion(interface: callInterface, castOps, castBuilder,
529 arg: operand, type: regionArgType, conversionLoc: castLoc)))
530 return cleanupState();
531 }
532 mapper.map(from: regionArg, to: operand);
533 }
534
535 // Ensure that the resultant values of the call match the callable.
536 castBuilder.setInsertionPointAfter(call);
537 for (unsigned i = 0, e = callResults.size(); i != e; ++i) {
538 Value callResult = callResults[i];
539 if (callResult.getType() == callableResultTypes[i])
540 continue;
541
542 // Generate a conversion that will produce the original type, so that the IR
543 // is still valid after the original call gets replaced.
544 Value castResult =
545 materializeConversion(interface: callInterface, castOps, castBuilder, arg: callResult,
546 type: callResult.getType(), conversionLoc: castLoc);
547 if (!castResult)
548 return cleanupState();
549 callResult.replaceAllUsesWith(newValue: castResult);
550 castResult.getDefiningOp()->replaceUsesOfWith(from: castResult, to: callResult);
551 }
552
553 // Check that it is legal to inline the callable into the call.
554 if (!interface.isLegalToInline(call, callable, wouldBeCloned: shouldCloneInlinedRegion))
555 return cleanupState();
556
557 // Attempt to inline the call.
558 if (failed(Result: inlineRegionImpl(interface, cloneCallback, src, inlineBlock: call->getBlock(),
559 inlinePoint: ++call->getIterator(), mapper, resultsToReplace: callResults,
560 regionResultTypes: callableResultTypes, inlineLoc: call.getLoc(),
561 shouldCloneInlinedRegion, call)))
562 return cleanupState();
563 return success();
564}
565