Matthew Simpson | 2284937 | 2017-10-13 17:53:44 +0000 | [diff] [blame] | 1 | //===-- ValueLatticeUtils.cpp - Utils for solving lattices ------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Matthew Simpson | 2284937 | 2017-10-13 17:53:44 +0000 | [diff] [blame] | 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 | bool llvm::canTrackArgumentsInterprocedurally(Function *F) { |
| 20 | return F->hasLocalLinkage() && !F->hasAddressTaken(); |
| 21 | } |
| 22 | |
| 23 | bool llvm::canTrackReturnsInterprocedurally(Function *F) { |
| 24 | return F->hasExactDefinition() && !F->hasFnAttribute(Attribute::Naked); |
| 25 | } |
| 26 | |
| 27 | bool llvm::canTrackGlobalVariableInterprocedurally(GlobalVariable *GV) { |
| 28 | if (GV->isConstant() || !GV->hasLocalLinkage() || |
| 29 | !GV->hasDefinitiveInitializer()) |
| 30 | return false; |
Florian Hahn | 0b72b9d | 2020-07-09 18:31:23 +0100 | [diff] [blame] | 31 | return all_of(GV->users(), [&](User *U) { |
| 32 | // Currently all users of a global variable have to be none-volatile loads |
| 33 | // or stores and the global cannot be stored itself. |
| 34 | if (auto *Store = dyn_cast<StoreInst>(U)) |
| 35 | return Store->getValueOperand() != GV && !Store->isVolatile(); |
| 36 | if (auto *Load = dyn_cast<LoadInst>(U)) |
| 37 | return !Load->isVolatile(); |
| 38 | |
Matthew Simpson | 2284937 | 2017-10-13 17:53:44 +0000 | [diff] [blame] | 39 | return false; |
| 40 | }); |
| 41 | } |