29 llvm::SmallDenseMap<Block *, SmallVector<int, 4>> successorPositions;
30 for (
int i = 0, e = terminator->getNumSuccessors(); i < e; ++i) {
36 successorPositions[successor].
push_back(i);
45 OpBuilder builder(terminator->getContext());
46 for (
const auto &successor : successorPositions) {
48 for (
int position : llvm::drop_begin(successor.second, 1)) {
50 terminator->setSuccessor(dummyBlock, position);
52 dummyBlock->
addArgument(arg.getType(), arg.getLoc());
53 builder.create<LLVM::BrOp>(terminator->getLoc(),
62 for (
Block &block : llvm::make_early_inc_range(region)) {
70 struct LegalizeForExportPass
71 :
public LLVMLegalizeForExportBase<LegalizeForExportPass> {
72 void runOnOperation()
override {
79 return std::make_unique<LegalizeForExportPass>();
TODO: Remove this file when SCCP and integer range analysis have been ported to the new framework...
Block * getSuccessor(unsigned i)
This class contains a list of basic blocks and a link to the parent operation it is attached to...
Operation is a basic unit of execution within MLIR.
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
static void ensureDistinctSuccessors(Block &bb)
If the given block has the same successor with different arguments, introduce dummy successor blocks ...
Block represents an ordered list of Operations.
bool mightHaveTrait()
Returns true if the operation might have the provided trait.
This class provides the API for ops that are known to be terminators.
Region * getParent() const
Provide a 'getParent' method for ilist_node_with_parent methods.
std::enable_if< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT >::type walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one)...
std::unique_ptr< Pass > createLegalizeForExportPass()
Creates a pass that legalizes the LLVM dialect operations so that they can be translated to LLVM IR...
unsigned getNumArguments()
BlockArgListType getArguments()
This class represents an argument of a Block.
Operation * getTerminator()
Get the terminator operation of this block.
void push_back(Operation *op)
void ensureDistinctSuccessors(Operation *op)
Make argument-taking successors of each block distinct.
BlockArgument addArgument(Type type, Location loc)
Add one value to the argument list.
This class helps build Operations.