Jlm
AliasAnalysis.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 
10 #include <jlm/rvsdg/lambda.hpp>
11 #include <jlm/rvsdg/Phi.hpp>
12 #include <jlm/rvsdg/theta.hpp>
13 
14 namespace jlm::llvm::aa
15 {
16 
18 
19 AliasAnalysis::~AliasAnalysis() noexcept = default;
20 
30 static bool
32  AliasAnalysis::AliasQueryResponse a,
33  AliasAnalysis::AliasQueryResponse b)
34 {
35  if (a == AliasAnalysis::NoAlias)
36  return b != AliasAnalysis::MustAlias;
37  if (a == AliasAnalysis::MayAlias)
38  return true;
39  if (a == AliasAnalysis::MustAlias)
40  return b != AliasAnalysis::NoAlias;
41  JLM_UNREACHABLE("Unknown alias response");
42 }
43 
45  std::shared_ptr<AliasAnalysis> first,
46  std::shared_ptr<AliasAnalysis> second)
47  : First_(std::move(first)),
48  Second_(std::move(second))
49 {}
50 
52 
53 AliasAnalysis::AliasQueryResponse
55  const rvsdg::Output & p1,
56  size_t s1,
57  const rvsdg::Output & p2,
58  size_t s2)
59 {
60  const auto firstResponse = First_->Query(p1, s1, p2, s2);
61  if (firstResponse == MayAlias)
62  return Second_->Query(p1, s1, p2, s2);
63 
64  // When building with asserts, always query the second analysis and double check
65  JLM_ASSERT(AreAliasResponsesCompatible(firstResponse, Second_->Query(p1, s1, p2, s2)));
66  return firstResponse;
67 }
68 
69 std::string
71 {
72  return util::strfmt("ChainedAA(", First_->ToString(), ",", Second_->ToString(), ")");
73 }
74 
75 bool
77 {
78  return IsOrContains<PointerType>(*value.Type());
79 }
80 
81 }
virtual ~AliasAnalysis() noexcept
std::shared_ptr< AliasAnalysis > First_
std::string ToString() const override
std::shared_ptr< AliasAnalysis > Second_
AliasQueryResponse Query(const rvsdg::Output &p1, size_t s1, const rvsdg::Output &p2, size_t s2) override
ChainedAliasAnalysis(std::shared_ptr< AliasAnalysis > first, std::shared_ptr< AliasAnalysis > second)
~ChainedAliasAnalysis() noexcept override
const std::shared_ptr< const rvsdg::Type > & Type() const noexcept
Definition: node.hpp:366
#define JLM_ASSERT(x)
Definition: common.hpp:16
#define JLM_UNREACHABLE(msg)
Definition: common.hpp:43
static bool AreAliasResponsesCompatible(AliasAnalysis::AliasQueryResponse a, AliasAnalysis::AliasQueryResponse b)
bool IsPointerCompatible(const rvsdg::Output &value)
static std::string strfmt(Args... args)
Definition: strfmt.hpp:35