LLVM 19.0.0git
GlobalStatus.h
Go to the documentation of this file.
1//===- GlobalStatus.h - Compute status info for globals ---------*- 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#ifndef LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
10#define LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
11
14
15namespace llvm {
16
17class Constant;
18class Function;
19class Value;
20
21/// It is safe to destroy a constant iff it is only used by constants itself.
22/// Note that constants cannot be cyclic, so this test is pretty easy to
23/// implement recursively.
24///
25bool isSafeToDestroyConstant(const Constant *C);
26
27/// As we analyze each global, keep track of some information about it. If we
28/// find out that the address of the global is taken, none of this info will be
29/// accurate.
31 /// True if the global's address is used in a comparison.
32 bool IsCompared = false;
33
34 /// True if the global is ever loaded. If the global isn't ever loaded it
35 /// can be deleted.
36 bool IsLoaded = false;
37
38 /// Number of stores to the global.
39 unsigned NumStores = 0;
40
41 /// Keep track of what stores to the global look like.
43 /// There is no store to this global. It can thus be marked constant.
45
46 /// This global is stored to, but the only thing stored is the constant it
47 /// was initialized with. This is only tracked for scalar globals.
49
50 /// This global is stored to, but only its initializer and one other value
51 /// is ever stored to it. If this global isStoredOnce, we track the value
52 /// stored to it via StoredOnceStore below. This is only tracked for scalar
53 /// globals.
55
56 /// This global is stored to by multiple values or something else that we
57 /// cannot track.
58 Stored
60
61 /// If only one value (besides the initializer constant) is ever stored to
62 /// this global, keep track of what value it is via the store instruction.
63 const StoreInst *StoredOnceStore = nullptr;
64
65 /// If only one value (besides the initializer constant) is ever stored to
66 /// this global return the stored value.
70 : nullptr;
71 }
72
73 /// These start out null/false. When the first accessing function is noticed,
74 /// it is recorded. When a second different accessing function is noticed,
75 /// HasMultipleAccessingFunctions is set to true.
76 const Function *AccessingFunction = nullptr;
78
79 /// Set to the strongest atomic ordering requirement.
81
83
84 /// Look at all uses of the global and fill in the GlobalStatus structure. If
85 /// the global has its address taken, return true to indicate we can't do
86 /// anything with it.
87 static bool analyzeGlobal(const Value *V, GlobalStatus &GS);
88};
89
90} // end namespace llvm
91
92#endif // LLVM_TRANSFORMS_UTILS_GLOBALSTATUS_H
Atomic ordering constants.
An instruction for storing to memory.
Definition: Instructions.h:317
Value * getOperand(unsigned i) const
Definition: User.h:169
LLVM Value Representation.
Definition: Value.h:74
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool isSafeToDestroyConstant(const Constant *C)
It is safe to destroy a constant iff it is only used by constants itself.
AtomicOrdering
Atomic ordering for LLVM's memory model.
As we analyze each global, keep track of some information about it.
Definition: GlobalStatus.h:30
bool IsLoaded
True if the global is ever loaded.
Definition: GlobalStatus.h:36
AtomicOrdering Ordering
Set to the strongest atomic ordering requirement.
Definition: GlobalStatus.h:80
bool HasMultipleAccessingFunctions
Definition: GlobalStatus.h:77
unsigned NumStores
Number of stores to the global.
Definition: GlobalStatus.h:39
const StoreInst * StoredOnceStore
If only one value (besides the initializer constant) is ever stored to this global,...
Definition: GlobalStatus.h:63
bool IsCompared
True if the global's address is used in a comparison.
Definition: GlobalStatus.h:32
Value * getStoredOnceValue() const
If only one value (besides the initializer constant) is ever stored to this global return the stored ...
Definition: GlobalStatus.h:67
const Function * AccessingFunction
These start out null/false.
Definition: GlobalStatus.h:76
StoredType
Keep track of what stores to the global look like.
Definition: GlobalStatus.h:42
@ Stored
This global is stored to by multiple values or something else that we cannot track.
Definition: GlobalStatus.h:58
@ InitializerStored
This global is stored to, but the only thing stored is the constant it was initialized with.
Definition: GlobalStatus.h:48
@ NotStored
There is no store to this global. It can thus be marked constant.
Definition: GlobalStatus.h:44
@ StoredOnce
This global is stored to, but only its initializer and one other value is ever stored to it.
Definition: GlobalStatus.h:54
static bool analyzeGlobal(const Value *V, GlobalStatus &GS)
Look at all uses of the global and fill in the GlobalStatus structure.