Skip to content

Commit 9c3ff12

Browse files
[NFC][Profile] Access profile through VirtualFileSystem
Make the access to profile data going through virtual file system so the inputs can be remapped. In the context of the caching, it can make sure we capture the inputs and provided an immutable input as profile data. Reviewed By: akyrtzi, benlangmuir Differential Revision: https://reviews.llvm.org/D139052
1 parent f35434f commit 9c3ff12

File tree

24 files changed

+154
-74
lines changed

24 files changed

+154
-74
lines changed

clang/include/clang/CodeGen/BackendUtil.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
namespace llvm {
1818
class BitcodeModule;
1919
template <typename T> class Expected;
20+
template <typename T> class IntrusiveRefCntPtr;
2021
class Module;
2122
class MemoryBufferRef;
23+
namespace vfs {
24+
class FileSystem;
25+
} // namespace vfs
2226
}
2327

2428
namespace clang {

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class EmitAssemblyHelper {
192192
const LangOptions &LOpts, Module *M,
193193
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
194194
: Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
195-
TargetOpts(TOpts), LangOpts(LOpts), TheModule(M), VFS(VFS),
195+
TargetOpts(TOpts), LangOpts(LOpts), TheModule(M), VFS(std::move(VFS)),
196196
CodeGenerationTime("codegen", "Code Generation Time"),
197197
TargetTriple(TheModule->getTargetTriple()) {}
198198

@@ -1201,9 +1201,8 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags,
12011201
const HeaderSearchOptions &HeaderOpts,
12021202
const CodeGenOptions &CGOpts,
12031203
const clang::TargetOptions &TOpts,
1204-
const LangOptions &LOpts,
1205-
StringRef TDesc, Module *M,
1206-
BackendAction Action,
1204+
const LangOptions &LOpts, StringRef TDesc,
1205+
Module *M, BackendAction Action,
12071206
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
12081207
std::unique_ptr<raw_pwrite_stream> OS) {
12091208

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ namespace clang {
147147

148148
public:
149149
BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags,
150-
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
150+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
151151
const HeaderSearchOptions &HeaderSearchOpts,
152152
const PreprocessorOptions &PPOpts,
153153
const CodeGenOptions &CodeGenOpts,
@@ -158,10 +158,10 @@ namespace clang {
158158
CoverageSourceInfo *CoverageInfo = nullptr)
159159
: Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
160160
CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
161-
AsmOutStream(std::move(OS)), Context(nullptr), FS(FS),
161+
AsmOutStream(std::move(OS)), Context(nullptr), FS(VFS),
162162
LLVMIRGeneration("irgen", "LLVM IR Generation Time"),
163163
LLVMIRGenerationRefCount(0),
164-
Gen(CreateLLVMCodeGen(Diags, InFile, FS, HeaderSearchOpts,
164+
Gen(CreateLLVMCodeGen(Diags, InFile, std::move(VFS), HeaderSearchOpts,
165165
PPOpts, CodeGenOpts, C, CoverageInfo)),
166166
LinkModules(std::move(LinkModules)) {
167167
TimerIsEnabled = CodeGenOpts.TimePasses;
@@ -173,7 +173,7 @@ namespace clang {
173173
// to use the clang diagnostic handler for IR input files. It avoids
174174
// initializing the OS field.
175175
BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags,
176-
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
176+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
177177
const HeaderSearchOptions &HeaderSearchOpts,
178178
const PreprocessorOptions &PPOpts,
179179
const CodeGenOptions &CodeGenOpts,
@@ -183,10 +183,10 @@ namespace clang {
183183
CoverageSourceInfo *CoverageInfo = nullptr)
184184
: Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
185185
CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
186-
Context(nullptr), FS(FS),
186+
Context(nullptr), FS(VFS),
187187
LLVMIRGeneration("irgen", "LLVM IR Generation Time"),
188188
LLVMIRGenerationRefCount(0),
189-
Gen(CreateLLVMCodeGen(Diags, "", FS, HeaderSearchOpts,
189+
Gen(CreateLLVMCodeGen(Diags, "", std::move(VFS), HeaderSearchOpts,
190190
PPOpts, CodeGenOpts, C, CoverageInfo)),
191191
LinkModules(std::move(LinkModules)), CurLinkModule(Module) {
192192
TimerIsEnabled = CodeGenOpts.TimePasses;
@@ -1212,10 +1212,10 @@ void CodeGenAction::ExecuteAction() {
12121212
std::unique_ptr<llvm::ToolOutputFile> OptRecordFile =
12131213
std::move(*OptRecordFileOrErr);
12141214

1215-
EmitBackendOutput(Diagnostics, CI.getHeaderSearchOpts(), CodeGenOpts,
1216-
TargetOpts, CI.getLangOpts(),
1217-
CI.getTarget().getDataLayoutString(), TheModule.get(), BA,
1218-
CI.getFileManager().getVirtualFileSystemPtr(), std::move(OS));
1215+
EmitBackendOutput(
1216+
Diagnostics, CI.getHeaderSearchOpts(), CodeGenOpts, TargetOpts,
1217+
CI.getLangOpts(), CI.getTarget().getDataLayoutString(), TheModule.get(),
1218+
BA, CI.getFileManager().getVirtualFileSystemPtr(), std::move(OS));
12191219
if (OptRecordFile)
12201220
OptRecordFile->keep();
12211221
}

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ CodeGenModule::CodeGenModule(ASTContext &C,
106106
const CodeGenOptions &CGO, llvm::Module &M,
107107
DiagnosticsEngine &diags,
108108
CoverageSourceInfo *CoverageInfo)
109-
: Context(C), LangOpts(C.getLangOpts()), FS(FS),
110-
HeaderSearchOpts(HSO), PreprocessorOpts(PPO), CodeGenOpts(CGO),
111-
TheModule(M), Diags(diags), Target(C.getTargetInfo()),
112-
ABI(createCXXABI(*this)), VMContext(M.getContext()), Types(*this),
113-
VTables(*this), SanitizerMD(new SanitizerMetadata(*this)) {
109+
: Context(C), LangOpts(C.getLangOpts()), FS(FS), HeaderSearchOpts(HSO),
110+
PreprocessorOpts(PPO), CodeGenOpts(CGO), TheModule(M), Diags(diags),
111+
Target(C.getTargetInfo()), ABI(createCXXABI(*this)),
112+
VMContext(M.getContext()), Types(*this), VTables(*this),
113+
SanitizerMD(new SanitizerMetadata(*this)) {
114114

115115
// Initialize the type cache.
116116
llvm::LLVMContext &LLVMContext = M.getContext();

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,8 +2153,8 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
21532153
Opts.OptimizationRemarkAnalysis.hasValidPattern();
21542154

21552155
bool UsingSampleProfile = !Opts.SampleProfileFile.empty();
2156-
bool UsingProfile = UsingSampleProfile ||
2157-
(Opts.getProfileUse() != CodeGenOptions::ProfileNone);
2156+
bool UsingProfile =
2157+
UsingSampleProfile || !Opts.ProfileInstrumentUsePath.empty();
21582158

21592159
if (Opts.DiagnosticsWithHotness && !UsingProfile &&
21602160
// An IR file will contain PGO as metadata

llvm/include/llvm/CodeGen/MIRSampleProfile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_CODEGEN_MIRSAMPLEPROFILE_H
1515
#define LLVM_CODEGEN_MIRSAMPLEPROFILE_H
1616

17+
#include "llvm/ADT/IntrusiveRefCntPtr.h"
1718
#include "llvm/ADT/StringRef.h"
1819
#include "llvm/CodeGen/MachineFunctionPass.h"
1920
#include "llvm/Support/Discriminator.h"
@@ -27,6 +28,10 @@ class MachineBlockFrequencyInfo;
2728
class MachineFunction;
2829
class Module;
2930

31+
namespace vfs {
32+
class FileSystem;
33+
} // namespace vfs
34+
3035
using namespace sampleprof;
3136

3237
class MIRProfileLoader;

llvm/include/llvm/Passes/PassBuilder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class StringRef;
3434
class AAManager;
3535
class TargetMachine;
3636
class ModuleSummaryIndex;
37+
template <typename T> class IntrusiveRefCntPtr;
38+
namespace vfs {
39+
class FileSystem;
40+
} // namespace vfs
3741

3842
/// Tunable parameters for passes in the default pipelines.
3943
class PipelineTuningOptions {

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ namespace llvm {
4444

4545
class IndexedInstrProfReader;
4646

47+
namespace vfs {
48+
class FileSystem;
49+
} // namespace vfs
50+
4751
namespace coverage {
4852

4953
class CoverageMappingReader;

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ namespace llvm {
4040

4141
class InstrProfReader;
4242

43+
namespace vfs {
44+
class FileSystem;
45+
} // namespace vfs
46+
4347
/// A file format agnostic iterator over profiling data.
4448
template <class record_type = NamedInstrProfRecord,
4549
class reader_type = InstrProfReader>

llvm/include/llvm/ProfileData/SampleProfReader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ namespace llvm {
252252
class raw_ostream;
253253
class Twine;
254254

255+
namespace vfs {
256+
class FileSystem;
257+
} // namespace vfs
258+
255259
namespace sampleprof {
256260

257261
class SampleProfileReader;

0 commit comments

Comments
 (0)