xref: /freebsd/contrib/llvm-project/llvm/include/llvm/CodeGen/GlobalMerge.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
17a6dacacSDimitry Andric //===- llvm/CodeGen/GlobalMerge.h -------------------------------*- C++ -*-===//
27a6dacacSDimitry Andric //
37a6dacacSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47a6dacacSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
57a6dacacSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67a6dacacSDimitry Andric //
77a6dacacSDimitry Andric //===----------------------------------------------------------------------===//
87a6dacacSDimitry Andric 
97a6dacacSDimitry Andric #ifndef LLVM_CODEGEN_GLOBALMERGE_H
107a6dacacSDimitry Andric #define LLVM_CODEGEN_GLOBALMERGE_H
117a6dacacSDimitry Andric 
127a6dacacSDimitry Andric #include "llvm/IR/PassManager.h"
137a6dacacSDimitry Andric 
147a6dacacSDimitry Andric namespace llvm {
157a6dacacSDimitry Andric 
167a6dacacSDimitry Andric class TargetMachine;
177a6dacacSDimitry Andric 
187a6dacacSDimitry Andric struct GlobalMergeOptions {
197a6dacacSDimitry Andric   // FIXME: Infer the maximum possible offset depending on the actual users
207a6dacacSDimitry Andric   // (these max offsets are different for the users inside Thumb or ARM
217a6dacacSDimitry Andric   // functions), see the code that passes in the offset in the ARM backend
227a6dacacSDimitry Andric   // for more information.
237a6dacacSDimitry Andric   unsigned MaxOffset = 0;
24*0fca6ea1SDimitry Andric   // The minimum size in bytes of each global that should considered in merging.
25*0fca6ea1SDimitry Andric   unsigned MinSize = 0;
267a6dacacSDimitry Andric   bool GroupByUse = true;
277a6dacacSDimitry Andric   bool IgnoreSingleUse = true;
287a6dacacSDimitry Andric   bool MergeConst = false;
297a6dacacSDimitry Andric   /// Whether we should merge global variables that have external linkage.
307a6dacacSDimitry Andric   bool MergeExternal = true;
317a6dacacSDimitry Andric   /// Whether we should try to optimize for size only.
327a6dacacSDimitry Andric   /// Currently, this applies a dead simple heuristic: only consider globals
337a6dacacSDimitry Andric   /// used in minsize functions for merging.
347a6dacacSDimitry Andric   /// FIXME: This could learn about optsize, and be used in the cost model.
357a6dacacSDimitry Andric   bool SizeOnly = false;
367a6dacacSDimitry Andric };
377a6dacacSDimitry Andric 
387a6dacacSDimitry Andric // FIXME: This pass must run before AsmPrinterPass::doInitialization!
397a6dacacSDimitry Andric class GlobalMergePass : public PassInfoMixin<GlobalMergePass> {
407a6dacacSDimitry Andric   const TargetMachine *TM;
417a6dacacSDimitry Andric   GlobalMergeOptions Options;
427a6dacacSDimitry Andric 
437a6dacacSDimitry Andric public:
GlobalMergePass(const TargetMachine * TM,GlobalMergeOptions Options)447a6dacacSDimitry Andric   GlobalMergePass(const TargetMachine *TM, GlobalMergeOptions Options)
457a6dacacSDimitry Andric       : TM(TM), Options(Options) {}
467a6dacacSDimitry Andric 
477a6dacacSDimitry Andric   PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
487a6dacacSDimitry Andric };
497a6dacacSDimitry Andric 
507a6dacacSDimitry Andric } // namespace llvm
517a6dacacSDimitry Andric 
527a6dacacSDimitry Andric #endif // LLVM_CODEGEN_GLOBALMERGE_H
53