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, 18*0fca6ea1SDimitry Andric CSPGOAction CSAction, ColdFuncOpt ColdType, 19*0fca6ea1SDimitry Andric bool DebugInfoForProfiling, bool PseudoProbeForProfiling, 20*0fca6ea1SDimitry Andric bool AtomicCounterUpdate) 2106c3fb27SDimitry Andric : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile), 2206c3fb27SDimitry Andric ProfileRemappingFile(ProfileRemappingFile), MemoryProfile(MemoryProfile), 23*0fca6ea1SDimitry Andric Action(Action), CSAction(CSAction), ColdOptType(ColdType), 2406c3fb27SDimitry Andric DebugInfoForProfiling(DebugInfoForProfiling || 2506c3fb27SDimitry Andric (Action == SampleUse && !PseudoProbeForProfiling)), 265f757f3fSDimitry Andric PseudoProbeForProfiling(PseudoProbeForProfiling), 275f757f3fSDimitry Andric AtomicCounterUpdate(AtomicCounterUpdate), FS(std::move(FS)) { 2806c3fb27SDimitry Andric // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can 2906c3fb27SDimitry Andric // callback with IRUse action without ProfileFile. 3006c3fb27SDimitry Andric 3106c3fb27SDimitry Andric // If there is a CSAction, PGOAction cannot be IRInstr or SampleUse. 3206c3fb27SDimitry Andric assert(this->CSAction == NoCSAction || 3306c3fb27SDimitry Andric (this->Action != IRInstr && this->Action != SampleUse)); 3406c3fb27SDimitry Andric 3506c3fb27SDimitry Andric // For CSIRInstr, CSProfileGenFile also needs to be nonempty. 3606c3fb27SDimitry Andric assert(this->CSAction != CSIRInstr || !this->CSProfileGenFile.empty()); 3706c3fb27SDimitry Andric 3806c3fb27SDimitry Andric // If CSAction is CSIRUse, PGOAction needs to be IRUse as they share 3906c3fb27SDimitry Andric // a profile. 4006c3fb27SDimitry Andric assert(this->CSAction != CSIRUse || this->Action == IRUse); 4106c3fb27SDimitry Andric 4206c3fb27SDimitry Andric // Cannot optimize with MemProf profile during IR instrumentation. 4306c3fb27SDimitry Andric assert(this->MemoryProfile.empty() || this->Action != PGOOptions::IRInstr); 4406c3fb27SDimitry Andric 4506c3fb27SDimitry Andric // If neither Action nor CSAction nor MemoryProfile are set, 4606c3fb27SDimitry Andric // DebugInfoForProfiling or PseudoProbeForProfiling needs to be true. 4706c3fb27SDimitry Andric assert(this->Action != NoAction || this->CSAction != NoCSAction || 4806c3fb27SDimitry Andric !this->MemoryProfile.empty() || this->DebugInfoForProfiling || 4906c3fb27SDimitry Andric this->PseudoProbeForProfiling); 5006c3fb27SDimitry Andric 5106c3fb27SDimitry Andric // If we need to use the profile, the VFS cannot be nullptr. 5206c3fb27SDimitry Andric assert(this->FS || !(this->Action == IRUse || this->CSAction == CSIRUse || 5306c3fb27SDimitry Andric !this->MemoryProfile.empty())); 5406c3fb27SDimitry Andric } 5506c3fb27SDimitry Andric 5606c3fb27SDimitry Andric PGOOptions::PGOOptions(const PGOOptions &) = default; 5706c3fb27SDimitry Andric 5806c3fb27SDimitry Andric PGOOptions &PGOOptions::operator=(const PGOOptions &O) = default; 5906c3fb27SDimitry Andric 6006c3fb27SDimitry Andric PGOOptions::~PGOOptions() = default; 61