Enzyme main
Loading...
Searching...
No Matches
PrintBaseObject.cpp
Go to the documentation of this file.
1//===- PrintBaseObject.cpp - Print base objects for tests ----------------===//
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#include "Interfaces/Utils.h"
10#include "Passes/PassDetails.h"
11#include "Passes/Passes.h"
12
13#include "mlir/IR/AsmState.h"
14#include "mlir/IR/SymbolTable.h"
15#include "mlir/Interfaces/FunctionInterfaces.h"
16
17using namespace mlir;
18using namespace mlir::enzyme;
19
20namespace mlir {
21namespace enzyme {
22#define GEN_PASS_DEF_PRINTBASEOBJECTPASS
23#include "Passes/Passes.h.inc"
24} // namespace enzyme
25} // namespace mlir
26
27namespace {
28struct PrintBaseObjectPass
29 : public enzyme::impl::PrintBaseObjectPassBase<PrintBaseObjectPass> {
30 using PrintBaseObjectPassBase::PrintBaseObjectPassBase;
31
32 void runOnOperation() override {
33 getOperation()->walk([&](FunctionOpInterface function) {
34 AsmState state(function);
35 function.walk([&](Operation *op) {
36 if (!op->hasTrait<OpTrait::ReturnLike>() ||
37 op->getParentOp() != function.getOperation())
38 return;
39 for (auto [index, value] : llvm::enumerate(op->getOperands())) {
40 auto &os = llvm::outs();
41 os << '@' << SymbolTable::getSymbolName(function).getValue()
42 << " return " << index << ": ";
43 value.printAsOperand(os, state);
44 os << " -> ";
45 oputils::getBaseObject(value, offsetAllowed)
46 .printAsOperand(os, state);
47 os << '\n';
48 }
49 });
50 });
51 }
52};
53} // namespace
Value getBaseObject(Value v, bool offsetAllowed)
Definition Utils.cpp:123