1516e3017SSteven Wu //===------ PGOOptions.cpp -- PGO option tunables --------------*- C++ -*--===//
2516e3017SSteven Wu //
3516e3017SSteven Wu // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4516e3017SSteven Wu // See https://llvm.org/LICENSE.txt for license information.
5516e3017SSteven Wu // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6516e3017SSteven Wu //
7516e3017SSteven Wu //===----------------------------------------------------------------------===//
8516e3017SSteven Wu
9516e3017SSteven Wu #include "llvm/Support/PGOOptions.h"
10516e3017SSteven Wu #include "llvm/Support/VirtualFileSystem.h"
11516e3017SSteven Wu
12516e3017SSteven Wu using namespace llvm;
13516e3017SSteven Wu
PGOOptions(std::string ProfileFile,std::string CSProfileGenFile,std::string ProfileRemappingFile,std::string MemoryProfile,IntrusiveRefCntPtr<vfs::FileSystem> FS,PGOAction Action,CSPGOAction CSAction,ColdFuncOpt ColdType,bool DebugInfoForProfiling,bool PseudoProbeForProfiling,bool AtomicCounterUpdate)14516e3017SSteven Wu PGOOptions::PGOOptions(std::string ProfileFile, std::string CSProfileGenFile,
15516e3017SSteven Wu std::string ProfileRemappingFile,
16546ec641STeresa Johnson std::string MemoryProfile,
17516e3017SSteven Wu IntrusiveRefCntPtr<vfs::FileSystem> FS, PGOAction Action,
18*93cdd1b5SArthur Eubanks CSPGOAction CSAction, ColdFuncOpt ColdType,
19*93cdd1b5SArthur Eubanks bool DebugInfoForProfiling, bool PseudoProbeForProfiling,
20*93cdd1b5SArthur Eubanks bool AtomicCounterUpdate)
21516e3017SSteven Wu : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
22546ec641STeresa Johnson ProfileRemappingFile(ProfileRemappingFile), MemoryProfile(MemoryProfile),
23*93cdd1b5SArthur Eubanks Action(Action), CSAction(CSAction), ColdOptType(ColdType),
24516e3017SSteven Wu DebugInfoForProfiling(DebugInfoForProfiling ||
25516e3017SSteven Wu (Action == SampleUse && !PseudoProbeForProfiling)),
26611ce241SQiongsi Wu PseudoProbeForProfiling(PseudoProbeForProfiling),
27611ce241SQiongsi Wu AtomicCounterUpdate(AtomicCounterUpdate), FS(std::move(FS)) {
28516e3017SSteven Wu // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
29516e3017SSteven Wu // callback with IRUse action without ProfileFile.
30516e3017SSteven Wu
31516e3017SSteven Wu // If there is a CSAction, PGOAction cannot be IRInstr or SampleUse.
32516e3017SSteven Wu assert(this->CSAction == NoCSAction ||
33516e3017SSteven Wu (this->Action != IRInstr && this->Action != SampleUse));
34516e3017SSteven Wu
35516e3017SSteven Wu // For CSIRInstr, CSProfileGenFile also needs to be nonempty.
36516e3017SSteven Wu assert(this->CSAction != CSIRInstr || !this->CSProfileGenFile.empty());
37516e3017SSteven Wu
38516e3017SSteven Wu // If CSAction is CSIRUse, PGOAction needs to be IRUse as they share
39516e3017SSteven Wu // a profile.
40516e3017SSteven Wu assert(this->CSAction != CSIRUse || this->Action == IRUse);
41516e3017SSteven Wu
42546ec641STeresa Johnson // Cannot optimize with MemProf profile during IR instrumentation.
43546ec641STeresa Johnson assert(this->MemoryProfile.empty() || this->Action != PGOOptions::IRInstr);
44546ec641STeresa Johnson
45546ec641STeresa Johnson // If neither Action nor CSAction nor MemoryProfile are set,
46546ec641STeresa Johnson // DebugInfoForProfiling or PseudoProbeForProfiling needs to be true.
47516e3017SSteven Wu assert(this->Action != NoAction || this->CSAction != NoCSAction ||
48546ec641STeresa Johnson !this->MemoryProfile.empty() || this->DebugInfoForProfiling ||
49546ec641STeresa Johnson this->PseudoProbeForProfiling);
50516e3017SSteven Wu
51516e3017SSteven Wu // If we need to use the profile, the VFS cannot be nullptr.
52546ec641STeresa Johnson assert(this->FS || !(this->Action == IRUse || this->CSAction == CSIRUse ||
53546ec641STeresa Johnson !this->MemoryProfile.empty()));
54516e3017SSteven Wu }
55516e3017SSteven Wu
56516e3017SSteven Wu PGOOptions::PGOOptions(const PGOOptions &) = default;
57516e3017SSteven Wu
58516e3017SSteven Wu PGOOptions &PGOOptions::operator=(const PGOOptions &O) = default;
59516e3017SSteven Wu
60516e3017SSteven Wu PGOOptions::~PGOOptions() = default;
61