[DFAJumpThreading] Remove incoming StartBlock from all phis when unfolding select...
[llvm-project.git] / clang / lib / Analysis / FlowSensitive / Value.cpp
blobb069c1cd3da1171c4c108d6104099aabd4842e9b
1 //===-- Value.cpp -----------------------------------------------*- C++ -*-===//
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 // This file defines support functions for the `Value` type.
11 //===----------------------------------------------------------------------===//
13 #include "clang/Analysis/FlowSensitive/Value.h"
14 #include "clang/Analysis/FlowSensitive/DebugSupport.h"
15 #include "llvm/Support/Casting.h"
17 namespace clang {
18 namespace dataflow {
20 static bool areEquivalentIndirectionValues(const Value &Val1,
21 const Value &Val2) {
22 if (auto *IndVal1 = dyn_cast<PointerValue>(&Val1)) {
23 auto *IndVal2 = cast<PointerValue>(&Val2);
24 return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc();
26 return false;
29 bool areEquivalentValues(const Value &Val1, const Value &Val2) {
30 return &Val1 == &Val2 || (Val1.getKind() == Val2.getKind() &&
31 (isa<TopBoolValue>(&Val1) ||
32 areEquivalentIndirectionValues(Val1, Val2)));
35 raw_ostream &operator<<(raw_ostream &OS, const Value &Val) {
36 switch (Val.getKind()) {
37 case Value::Kind::Pointer: {
38 const auto *PV = dyn_cast<PointerValue>(&Val);
39 return OS << "Pointer(" << &PV->getPointeeLoc() << ")";
41 // FIXME: support remaining cases.
42 default:
43 return OS << debugString(Val.getKind());
47 } // namespace dataflow
48 } // namespace clang