Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
PGOForceFunctionAttrs.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
12#include "llvm/IR/Module.h"
13#include "llvm/IR/PassManager.h"
15
16using namespace llvm;
17
20 if (F.isDeclaration())
21 return false;
22 // Respect existing attributes.
23 if (F.hasOptNone() || F.hasOptSize())
24 return false;
25 if (F.hasFnAttribute(Attribute::Cold))
26 return true;
27 if (!PSI.hasProfileSummary())
28 return false;
30 return PSI.isFunctionColdInCallGraph(&F, BFI);
31}
32
40 bool MadeChange = false;
41 for (Function &F : M) {
42 if (!shouldRunOnFunction(F, PSI, FAM))
43 continue;
44 switch (ColdType) {
46 llvm_unreachable("bailed out for default above");
47 break;
49 F.addFnAttr(Attribute::OptimizeForSize);
50 break;
52 F.addFnAttr(Attribute::MinSize);
53 break;
55 // alwaysinline is incompatible with optnone.
56 if (F.hasFnAttribute(Attribute::AlwaysInline))
57 continue;
58 F.addFnAttr(Attribute::OptimizeNone);
59 F.addFnAttr(Attribute::NoInline);
60 break;
61 }
62 MadeChange = true;
63 }
64 return MadeChange ? PreservedAnalyses::none() : PreservedAnalyses::all();
65}
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:55
static bool shouldRunOnFunction(Function &F, ProfileSummaryInfo &PSI, FunctionAnalysisManager &FAM)
FunctionAnalysisManager FAM
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
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.
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)