|
| 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 | + |
| 46 | +namespace llvm { |
| 47 | +class raw_ostream; |
| 48 | +} |
| 49 | + |
| 50 | +namespace COMGR { |
| 51 | +class CachedCommandAdaptor { |
| 52 | +public: |
| 53 | + using ActionClass = clang::driver::Action::ActionClass; |
| 54 | + using HashAlgorithm = llvm::SHA256; |
| 55 | + using Identifier = llvm::SmallString<64>; |
| 56 | + |
| 57 | + llvm::Expected<Identifier> getIdentifier() const; |
| 58 | + |
| 59 | + virtual bool canCache() const = 0; |
| 60 | + virtual llvm::Error writeExecuteOutput(llvm::StringRef CachedBuffer) = 0; |
| 61 | + virtual llvm::Expected<llvm::StringRef> readExecuteOutput() = 0; |
| 62 | + virtual amd_comgr_status_t execute(llvm::raw_ostream &LogS) = 0; |
| 63 | + |
| 64 | + virtual ~CachedCommandAdaptor() = default; |
| 65 | + |
| 66 | + // helper to work around the comgr-xxxxx string appearing in files |
| 67 | + static void addFileContents(HashAlgorithm &H, llvm::StringRef Buf); |
| 68 | + static void addString(HashAlgorithm &H, llvm::StringRef S); |
| 69 | + static std::optional<size_t> searchComgrTmpModel(llvm::StringRef S); |
| 70 | + |
| 71 | +protected: |
| 72 | + virtual ActionClass getClass() const = 0; |
| 73 | + virtual void addOptionsIdentifier(HashAlgorithm &) const = 0; |
| 74 | + virtual llvm::Error addInputIdentifier(HashAlgorithm &) const = 0; |
| 75 | +}; |
| 76 | +} // namespace COMGR |
| 77 | + |
| 78 | +#endif |
0 commit comments