1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#pragma once
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//===- GlobalStatus.h - Compute status info for globals ---------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
#define LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
#include "llvm/Support/AtomicOrdering.h"
namespace llvm {
class Constant;
class Function;
class Value;
/// It is safe to destroy a constant iff it is only used by constants itself.
/// Note that constants cannot be cyclic, so this test is pretty easy to
/// implement recursively.
///
bool isSafeToDestroyConstant(const Constant *C);
/// As we analyze each global, keep track of some information about it. If we
/// find out that the address of the global is taken, none of this info will be
/// accurate.
struct GlobalStatus {
/// True if the global's address is used in a comparison.
bool IsCompared = false;
/// True if the global is ever loaded. If the global isn't ever loaded it
/// can be deleted.
bool IsLoaded = false;
/// Keep track of what stores to the global look like.
enum StoredType {
/// There is no store to this global. It can thus be marked constant.
NotStored,
/// This global is stored to, but the only thing stored is the constant it
/// was initialized with. This is only tracked for scalar globals.
InitializerStored,
/// This global is stored to, but only its initializer and one other value
/// is ever stored to it. If this global isStoredOnce, we track the value
/// stored to it in StoredOnceValue below. This is only tracked for scalar
/// globals.
StoredOnce,
/// This global is stored to by multiple values or something else that we
/// cannot track.
Stored
} StoredType = NotStored;
/// If only one value (besides the initializer constant) is ever stored to
/// this global, keep track of what value it is.
Value *StoredOnceValue = nullptr;
/// These start out null/false. When the first accessing function is noticed,
/// it is recorded. When a second different accessing function is noticed,
/// HasMultipleAccessingFunctions is set to true.
const Function *AccessingFunction = nullptr;
bool HasMultipleAccessingFunctions = false;
/// Set to true if this global has a user that is not an instruction (e.g. a
/// constant expr or GV initializer).
bool HasNonInstructionUser = false;
/// Set to the strongest atomic ordering requirement.
AtomicOrdering Ordering = AtomicOrdering::NotAtomic;
GlobalStatus();
/// Look at all uses of the global and fill in the GlobalStatus structure. If
/// the global has its address taken, return true to indicate we can't do
/// anything with it.
static bool analyzeGlobal(const Value *V, GlobalStatus &GS);
};
} // end namespace llvm
#endif // LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
|