LLVM 19.0.0git
Go to the documentation of this file.
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
12#include "llvm/IR/PassManager.h"
15using namespace llvm;
19 if (F.isDeclaration())
20 return false;
21 // Respect existing attributes.
22 if (F.hasOptNone() || F.hasOptSize() || F.hasMinSize())
23 return false;
24 if (F.hasFnAttribute(Attribute::Cold))
25 return true;
26 if (!PSI.hasProfileSummary())
27 return false;
29 return PSI.isFunctionColdInCallGraph(&F, BFI);
39 bool MadeChange = false;
40 for (Function &F : M) {
41 if (!shouldRunOnFunction(F, PSI, FAM))
42 continue;
43 switch (ColdType) {
45 llvm_unreachable("bailed out for default above");
46 break;
48 F.addFnAttr(Attribute::OptimizeForSize);
49 break;
51 F.addFnAttr(Attribute::MinSize);
52 break;
54 // alwaysinline is incompatible with optnone.
55 if (F.hasFnAttribute(Attribute::AlwaysInline))
56 continue;
57 F.addFnAttr(Attribute::OptimizeNone);
58 F.addFnAttr(Attribute::NoInline);
59 break;
60 }
61 MadeChange = true;
62 }
63 return MadeChange ? PreservedAnalyses::none() : PreservedAnalyses::all();
#define F(x, y, z)
Definition: MD5.cpp:55
static bool shouldRunOnFunction(Function &F, ProfileSummaryInfo &PSI, FunctionAnalysisManager &FAM)
FunctionAnalysisManager FAM
This header defines various interfaces for pass management in LLVM.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:321
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:473
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:631
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
Analysis providing profile information.
bool hasProfileSummary() const
Returns true if profile summary is available.
bool isFunctionColdInCallGraph(const FuncT *F, BFIT &BFI) const
Returns true if F contains only cold code.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)