Skip to content

Commit 8314da0

Browse files
committed
[COMGR][Cache] Add CachedCommand minimal implementation
This object wraps an llvm::driver::Command into something that can be cached by Comgr's cache. co-authored by anjenner and jmmartinez Change-Id: I0ef7dded51681be2cdb95b1734595b4d08023488
1 parent 4d49464 commit 8314da0

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed

amd/comgr/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ option(COMGR_BUILD_SHARED_LIBS "Build the shared library"
7171
${build_shared_libs_default})
7272

7373
set(SOURCES
74+
src/comgr-cache-command.cpp
7475
src/comgr-compiler.cpp
7576
src/comgr.cpp
7677
src/comgr-device-libs.cpp

amd/comgr/src/comgr-cache-command.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "comgr-cache-command.h"
2+
3+
namespace COMGR {
4+
using namespace llvm;
5+
using namespace clang;
6+
7+
CachedCommand::CachedCommand(driver::Command &Command,
8+
DiagnosticOptions &DiagOpts,
9+
llvm::vfs::FileSystem &VFS,
10+
ExecuteFnTy &&ExecuteImpl)
11+
: Command(Command), DiagOpts(DiagOpts), VFS(VFS),
12+
ExecuteImpl(std::move(ExecuteImpl)) {}
13+
14+
amd_comgr_status_t CachedCommand::execute(llvm::raw_ostream &LogS) {
15+
return ExecuteImpl(Command, LogS, DiagOpts, VFS);
16+
}
17+
} // namespace COMGR

amd/comgr/src/comgr-cache-command.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*******************************************************************************
2+
*
3+
* University of Illinois/NCSA
4+
* Open Source License
5+
*
6+
* Copyright (c) 2018 Advanced Micro Devices, Inc. All Rights Reserved.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* with the Software without restriction, including without limitation the
11+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12+
* sell copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* * Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimers.
17+
*
18+
* * Redistributions in binary form must reproduce the above copyright
19+
* notice, this list of conditions and the following disclaimers in the
20+
* documentation and/or other materials provided with the distribution.
21+
*
22+
* * Neither the names of Advanced Micro Devices, Inc. nor the names of its
23+
* contributors may be used to endorse or promote products derived from
24+
* this Software without specific prior written permission.
25+
*
26+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
32+
* THE SOFTWARE.
33+
*
34+
******************************************************************************/
35+
36+
#ifndef COMGR_CACHE_COMMAND_H
37+
#define COMGR_CACHE_COMMAND_H
38+
39+
#include "amd_comgr.h"
40+
41+
#include <clang/Driver/Action.h>
42+
#include <llvm/Support/Error.h>
43+
#include <llvm/Support/MemoryBuffer.h>
44+
#include <llvm/Support/SHA256.h>
45+
#include <llvm/Support/VirtualFileSystem.h>
46+
47+
namespace clang {
48+
class DiagnosticOptions;
49+
namespace driver {
50+
class Command;
51+
} // namespace driver
52+
} // namespace clang
53+
54+
namespace llvm {
55+
class raw_ostream;
56+
}
57+
58+
namespace COMGR {
59+
class CachedCommandAdaptor {
60+
public:
61+
virtual amd_comgr_status_t execute(llvm::raw_ostream &LogS) = 0;
62+
63+
virtual ~CachedCommandAdaptor() = default;
64+
};
65+
66+
class CachedCommand final : public CachedCommandAdaptor {
67+
public:
68+
using ExecuteFnTy = std::function<amd_comgr_status_t(
69+
clang::driver::Command &, llvm::raw_ostream &, clang::DiagnosticOptions &,
70+
llvm::vfs::FileSystem &)>;
71+
72+
private:
73+
clang::driver::Command &Command;
74+
clang::DiagnosticOptions &DiagOpts;
75+
llvm::vfs::FileSystem &VFS;
76+
ExecuteFnTy ExecuteImpl;
77+
78+
public:
79+
CachedCommand(clang::driver::Command &Command,
80+
clang::DiagnosticOptions &DiagOpts, llvm::vfs::FileSystem &VFS,
81+
ExecuteFnTy &&ExecuteImpl);
82+
83+
amd_comgr_status_t execute(llvm::raw_ostream &LogS) override;
84+
85+
~CachedCommand() override = default;
86+
};
87+
} // namespace COMGR
88+
89+
#endif

amd/comgr/src/comgr-compiler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
******************************************************************************/
3838

3939
#include "comgr-compiler.h"
40+
#include "comgr-cache-command.h"
4041
#include "comgr-device-libs.h"
4142
#include "comgr-diagnostic-handler.h"
4243
#include "comgr-env.h"
@@ -772,7 +773,8 @@ AMDGPUCompiler::executeInProcessDriver(ArrayRef<const char *> Args) {
772773
}
773774

774775
for (auto &Job : C->getJobs()) {
775-
if (auto Status = executeCommand(Job, LogS, *DiagOpts, *VFS)) {
776+
CachedCommand C(Job, *DiagOpts, *VFS, executeCommand);
777+
if (auto Status = C.execute(LogS)) {
776778
return Status;
777779
}
778780
}

0 commit comments

Comments
 (0)