1//===- llvm/CodeGen/GlobalMerge.h -------------------------------*- 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_CODEGEN_GLOBALMERGE_H
10#define LLVM_CODEGEN_GLOBALMERGE_H
11
12#include "llvm/IR/PassManager.h"
13
14namespace llvm {
15
16class TargetMachine;
17
18struct GlobalMergeOptions {
19 // FIXME: Infer the maximum possible offset depending on the actual users
20 // (these max offsets are different for the users inside Thumb or ARM
21 // functions), see the code that passes in the offset in the ARM backend
22 // for more information.
23 unsigned MaxOffset = 0;
24 bool GroupByUse = true;
25 bool IgnoreSingleUse = true;
26 bool MergeConst = false;
27 /// Whether we should merge global variables that have external linkage.
28 bool MergeExternal = true;
29 /// Whether we should try to optimize for size only.
30 /// Currently, this applies a dead simple heuristic: only consider globals
31 /// used in minsize functions for merging.
32 /// FIXME: This could learn about optsize, and be used in the cost model.
33 bool SizeOnly = false;
34};
35
36// FIXME: This pass must run before AsmPrinterPass::doInitialization!
37class GlobalMergePass : public PassInfoMixin<GlobalMergePass> {
38 const TargetMachine *TM;
39 GlobalMergeOptions Options;
40
41public:
42 GlobalMergePass(const TargetMachine *TM, GlobalMergeOptions Options)
43 : TM(TM), Options(Options) {}
44
45 PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
46};
47
48} // namespace llvm
49
50#endif // LLVM_CODEGEN_GLOBALMERGE_H
51

source code of llvm/include/llvm/CodeGen/GlobalMerge.h