16 #include "llvm/Support/SourceMgr.h"
17 #include "llvm/Support/raw_ostream.h"
25 std::vector<llvm::LineEditor::Completion>
31 const std::string &binding) {
32 auto fileLoc = op->getLoc()->findInstanceOf<FileLineColLoc>();
34 qs.
getBufferId(), fileLoc.getLine(), fileLoc.getColumn());
36 "\"" + binding +
"\" binds here");
43 llvm::StringRef functionName) {
48 std::vector<Operation *> slice;
49 std::vector<Value> values;
50 std::vector<Type> outputTypes;
52 for (
auto *op : ops) {
54 if (!isa<func::ReturnOp>(op))
58 outputTypes.insert(outputTypes.end(), op->getResults().getTypes().begin(),
59 op->getResults().getTypes().end());
62 values.insert(values.end(), op->getOperands().begin(),
63 op->getOperands().end());
67 FunctionType funcType =
69 auto loc = builder.getUnknownLoc();
70 func::FuncOp funcOp = func::FuncOp::create(loc, functionName, funcType);
72 builder.setInsertionPointToEnd(funcOp.addEntryBlock());
77 mapper.
map(arg.value(), funcOp.getArgument(arg.index()));
80 std::vector<Operation *> clonedOps;
81 std::vector<Value> clonedVals;
84 clonedOps.emplace_back(builder.clone(*slicedOp, mapper));
85 clonedVals.insert(clonedVals.end(), clonedOp->
result_begin(),
89 builder.
create<func::ReturnOp>(loc, clonedVals);
92 size_t currentIndex = 0;
93 while (currentIndex < funcOp.getNumArguments()) {
94 if (funcOp.getArgument(currentIndex).use_empty())
95 funcOp.eraseArgument(currentIndex);
118 os <<
"Available commands:\n\n"
119 " match MATCHER, m MATCHER "
120 "Match the mlir against the given matcher.\n"
122 "Terminates the query session.\n\n";
136 std::vector<Operation *> matches =
145 os <<
"\n" << *
function <<
"\n\n";
152 os <<
"Match #" << ++matchCount <<
":\n\n";
156 os << matchCount << (matchCount == 1 ?
" match.\n\n" :
" matches.\n\n");
This is a utility class for mapping one set of IR entities to another.
void map(Value from, Value to)
Inserts a new mapping for 'from' to 'to'.
MLIRContext is the top-level object for a collection of MLIR operations.
void loadDialect()
Load a dialect in the context.
This class helps build Operations.
Operation is the basic unit of execution within MLIR.
result_iterator result_begin()
MLIRContext * getContext()
Return the context this operation is associated with.
static Operation * create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, NamedAttrList &&attributes, OpaqueProperties properties, BlockRange successors, unsigned numRegions)
Create a new Operation with the specific fields.
result_iterator result_end()
This class provides an abstraction over the various different ranges of value types.
This class provides an abstraction over the different types of ranges over Values.
static QueryRef parse(llvm::StringRef line, const QuerySession &qs)
static std::vector< llvm::LineEditor::Completion > complete(llvm::StringRef line, size_t pos, const QuerySession &qs)
llvm::SourceMgr & getSourceManager() const
StringRef getFunctionName() const
bool hasFunctionName() const
static std::vector< Operation * > getMatches(Operation *root, DynMatcher matcher)
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
QueryRef parse(llvm::StringRef line, const QuerySession &qs)
static Operation * extractFunction(std::vector< Operation * > &ops, MLIRContext *context, llvm::StringRef functionName)
llvm::IntrusiveRefCntPtr< Query > QueryRef
std::vector< llvm::LineEditor::Completion > complete(llvm::StringRef line, size_t pos, const QuerySession &qs)
static void printMatch(llvm::raw_ostream &os, QuerySession &qs, Operation *op, const std::string &binding)
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
This class represents an efficient way to signal success or failure.
mlir::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const override
mlir::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const override
mlir::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const override
const matcher::DynMatcher matcher
mlir::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const override
mlir::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const override