Jlm
Trace.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2025 HÃ¥vard Krogstie <krogstie.havard@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
8 #include <jlm/llvm/ir/Trace.hpp>
11 #include <jlm/rvsdg/Trace.hpp>
12 
13 namespace jlm::llvm
14 {
15 
17 
18 rvsdg::Output &
19 OutputTracer::traceStep(rvsdg::Output & output, bool mayLeaveRegion)
20 {
21  // FIXME: Needing to create a custom subclass of OutputTracer to make it handle a single LLVM
22  // specific operation is not great, as we now have multiple choices for traceOutput.
23  // It would be better to have a single tracing class that handles all operations,
24  // and somehow marking the IOBarrier with a "trait" that makes the output map to the input.
25 
26  auto & trace1 = rvsdg::OutputTracer::traceStep(output, mayLeaveRegion);
27 
28  if (const auto [node, ioBarrierOp] =
29  rvsdg::TryGetSimpleNodeAndOptionalOp<IOBarrierOperation>(trace1);
30  node && ioBarrierOp)
31  {
32  return *IOBarrierOperation::BarredInput(*node).origin();
33  }
34 
35  return trace1;
36 }
37 
40 {
41  OutputTracer tracer;
42  return tracer.trace(output);
43 }
44 
45 std::optional<int64_t>
47 {
48  const auto & normalized = llvm::traceOutput(output);
49 
50  if (const auto [_, constant] =
51  rvsdg::TryGetSimpleNodeAndOptionalOp<IntegerConstantOperation>(normalized);
52  constant)
53  {
54  const auto & rep = constant->Representation();
55  if (rep.is_known() && rep.nbits() <= 64)
56  return rep.to_int();
57  return std::nullopt;
58  }
59 
60  if (const auto [_, constant] =
61  rvsdg::TryGetSimpleNodeAndOptionalOp<rvsdg::BitConstantOperation>(normalized);
62  constant)
63  {
64  const auto & rep = constant->value();
65  if (rep.is_known() && rep.nbits() <= 64)
66  return rep.to_int();
67  return std::nullopt;
68  }
69 
70  return std::nullopt;
71 }
72 
73 }
static rvsdg::Input & BarredInput(const rvsdg::SimpleNode &node) noexcept
Definition: IOBarrier.hpp:70
rvsdg::Output & traceStep(rvsdg::Output &output, bool mayLeaveRegion) override
Definition: Trace.cpp:19
Output * origin() const noexcept
Definition: node.hpp:58
Output & trace(Output &output)
Definition: Trace.cpp:20
virtual Output & traceStep(Output &output, bool mayLeaveRegion)
Definition: Trace.cpp:124
Global memory state passed between functions.
rvsdg::Output & traceOutput(rvsdg::Output &output)
Definition: Trace.cpp:39
std::optional< int64_t > tryGetConstantSignedInteger(const rvsdg::Output &output)
Definition: Trace.cpp:46