blob: 3f9287e26ce7e93dd1253c9bfeed5eefb2314672 [file] [log] [blame]
Matthew Simpson22849372017-10-13 17:53:44 +00001//===-- ValueLatticeUtils.cpp - Utils for solving lattices ------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Simpson22849372017-10-13 17:53:44 +00006//
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"
17using namespace llvm;
18
19bool llvm::canTrackArgumentsInterprocedurally(Function *F) {
20 return F->hasLocalLinkage() && !F->hasAddressTaken();
21}
22
23bool llvm::canTrackReturnsInterprocedurally(Function *F) {
24 return F->hasExactDefinition() && !F->hasFnAttribute(Attribute::Naked);
25}
26
27bool llvm::canTrackGlobalVariableInterprocedurally(GlobalVariable *GV) {
28 if (GV->isConstant() || !GV->hasLocalLinkage() ||
29 !GV->hasDefinitiveInitializer())
30 return false;
31 return !any_of(GV->users(), [&](User *U) {
32 if (auto *Store = dyn_cast<StoreInst>(U)) {
33 if (Store->getValueOperand() == GV || Store->isVolatile())
34 return true;
35 } else if (auto *Load = dyn_cast<LoadInst>(U)) {
36 if (Load->isVolatile())
37 return true;
38 } else {
39 return true;
40 }
41 return false;
42 });
43}