xref: /freebsd-src/contrib/llvm-project/llvm/lib/Support/PGOOptions.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
106c3fb27SDimitry Andric //===------ PGOOptions.cpp -- PGO option tunables --------------*- C++ -*--===//
206c3fb27SDimitry Andric //
306c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
406c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
506c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
606c3fb27SDimitry Andric //
706c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
806c3fb27SDimitry Andric 
906c3fb27SDimitry Andric #include "llvm/Support/PGOOptions.h"
1006c3fb27SDimitry Andric #include "llvm/Support/VirtualFileSystem.h"
1106c3fb27SDimitry Andric 
1206c3fb27SDimitry Andric using namespace llvm;
1306c3fb27SDimitry Andric 
1406c3fb27SDimitry Andric PGOOptions::PGOOptions(std::string ProfileFile, std::string CSProfileGenFile,
1506c3fb27SDimitry Andric                        std::string ProfileRemappingFile,
1606c3fb27SDimitry Andric                        std::string MemoryProfile,
1706c3fb27SDimitry Andric                        IntrusiveRefCntPtr<vfs::FileSystem> FS, PGOAction Action,
1806c3fb27SDimitry Andric                        CSPGOAction CSAction, bool DebugInfoForProfiling,
19*5f757f3fSDimitry Andric                        bool PseudoProbeForProfiling, bool AtomicCounterUpdate)
2006c3fb27SDimitry Andric     : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
2106c3fb27SDimitry Andric       ProfileRemappingFile(ProfileRemappingFile), MemoryProfile(MemoryProfile),
2206c3fb27SDimitry Andric       Action(Action), CSAction(CSAction),
2306c3fb27SDimitry Andric       DebugInfoForProfiling(DebugInfoForProfiling ||
2406c3fb27SDimitry Andric                             (Action == SampleUse && !PseudoProbeForProfiling)),
25*5f757f3fSDimitry Andric       PseudoProbeForProfiling(PseudoProbeForProfiling),
26*5f757f3fSDimitry Andric       AtomicCounterUpdate(AtomicCounterUpdate), FS(std::move(FS)) {
2706c3fb27SDimitry Andric   // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
2806c3fb27SDimitry Andric   // callback with IRUse action without ProfileFile.
2906c3fb27SDimitry Andric 
3006c3fb27SDimitry Andric   // If there is a CSAction, PGOAction cannot be IRInstr or SampleUse.
3106c3fb27SDimitry Andric   assert(this->CSAction == NoCSAction ||
3206c3fb27SDimitry Andric          (this->Action != IRInstr && this->Action != SampleUse));
3306c3fb27SDimitry Andric 
3406c3fb27SDimitry Andric   // For CSIRInstr, CSProfileGenFile also needs to be nonempty.
3506c3fb27SDimitry Andric   assert(this->CSAction != CSIRInstr || !this->CSProfileGenFile.empty());
3606c3fb27SDimitry Andric 
3706c3fb27SDimitry Andric   // If CSAction is CSIRUse, PGOAction needs to be IRUse as they share
3806c3fb27SDimitry Andric   // a profile.
3906c3fb27SDimitry Andric   assert(this->CSAction != CSIRUse || this->Action == IRUse);
4006c3fb27SDimitry Andric 
4106c3fb27SDimitry Andric   // Cannot optimize with MemProf profile during IR instrumentation.
4206c3fb27SDimitry Andric   assert(this->MemoryProfile.empty() || this->Action != PGOOptions::IRInstr);
4306c3fb27SDimitry Andric 
4406c3fb27SDimitry Andric   // If neither Action nor CSAction nor MemoryProfile are set,
4506c3fb27SDimitry Andric   // DebugInfoForProfiling or PseudoProbeForProfiling needs to be true.
4606c3fb27SDimitry Andric   assert(this->Action != NoAction || this->CSAction != NoCSAction ||
4706c3fb27SDimitry Andric          !this->MemoryProfile.empty() || this->DebugInfoForProfiling ||
4806c3fb27SDimitry Andric          this->PseudoProbeForProfiling);
4906c3fb27SDimitry Andric 
5006c3fb27SDimitry Andric   // If we need to use the profile, the VFS cannot be nullptr.
5106c3fb27SDimitry Andric   assert(this->FS || !(this->Action == IRUse || this->CSAction == CSIRUse ||
5206c3fb27SDimitry Andric                        !this->MemoryProfile.empty()));
5306c3fb27SDimitry Andric }
5406c3fb27SDimitry Andric 
5506c3fb27SDimitry Andric PGOOptions::PGOOptions(const PGOOptions &) = default;
5606c3fb27SDimitry Andric 
5706c3fb27SDimitry Andric PGOOptions &PGOOptions::operator=(const PGOOptions &O) = default;
5806c3fb27SDimitry Andric 
5906c3fb27SDimitry Andric PGOOptions::~PGOOptions() = default;
60