/src/llvm-project/llvm/lib/Analysis/ValueLatticeUtils.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- ValueLatticeUtils.cpp - Utils for solving lattices ------*- 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 implements common functions useful for performing data-flow |
10 | | // analyses that propagate values across function boundaries. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "llvm/Analysis/ValueLatticeUtils.h" |
15 | | #include "llvm/IR/GlobalVariable.h" |
16 | | #include "llvm/IR/Instructions.h" |
17 | | using namespace llvm; |
18 | | |
19 | 0 | bool llvm::canTrackArgumentsInterprocedurally(Function *F) { |
20 | 0 | return F->hasLocalLinkage() && !F->hasAddressTaken(); |
21 | 0 | } |
22 | | |
23 | 0 | bool llvm::canTrackReturnsInterprocedurally(Function *F) { |
24 | 0 | return F->hasExactDefinition() && !F->hasFnAttribute(Attribute::Naked); |
25 | 0 | } |
26 | | |
27 | 0 | bool llvm::canTrackGlobalVariableInterprocedurally(GlobalVariable *GV) { |
28 | 0 | if (GV->isConstant() || !GV->hasLocalLinkage() || |
29 | 0 | !GV->hasDefinitiveInitializer()) |
30 | 0 | return false; |
31 | 0 | return all_of(GV->users(), [&](User *U) { |
32 | | // Currently all users of a global variable have to be non-volatile loads |
33 | | // or stores of the global type, and the global cannot be stored itself. |
34 | 0 | if (auto *Store = dyn_cast<StoreInst>(U)) |
35 | 0 | return Store->getValueOperand() != GV && !Store->isVolatile() && |
36 | 0 | Store->getValueOperand()->getType() == GV->getValueType(); |
37 | 0 | if (auto *Load = dyn_cast<LoadInst>(U)) |
38 | 0 | return !Load->isVolatile() && Load->getType() == GV->getValueType(); |
39 | | |
40 | 0 | return false; |
41 | 0 | }); |
42 | 0 | } |