|
| 1 | +//===--- SILGenRequests.h - SILGen Requests ---------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// |
| 13 | +// This file defines SILGen requests. |
| 14 | +// |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | + |
| 17 | +#ifndef SWIFT_SILGEN_REQUESTS_H |
| 18 | +#define SWIFT_SILGEN_REQUESTS_H |
| 19 | + |
| 20 | +#include "swift/AST/ASTTypeIDs.h" |
| 21 | +#include "swift/AST/SimpleRequest.h" |
| 22 | + |
| 23 | +namespace swift { |
| 24 | + |
| 25 | +class FileUnit; |
| 26 | +class LangOptions; |
| 27 | +class ModuleDecl; |
| 28 | +class SILModule; |
| 29 | +class SILOptions; |
| 30 | +class SourceFile; |
| 31 | + |
| 32 | +namespace Lowering { |
| 33 | + class TypeConverter; |
| 34 | +} |
| 35 | + |
| 36 | +/// Report that a request of the given kind is being evaluated, so it |
| 37 | +/// can be recorded by the stats reporter. |
| 38 | +template<typename Request> |
| 39 | +void reportEvaluatedRequest(UnifiedStatsReporter &stats, |
| 40 | + const Request &request); |
| 41 | + |
| 42 | +struct SILGenDescriptor { |
| 43 | + llvm::PointerUnion<ModuleDecl *, FileUnit *> context; |
| 44 | + Lowering::TypeConverter &conv; |
| 45 | + const SILOptions &opts; |
| 46 | + |
| 47 | + friend llvm::hash_code hash_value(const SILGenDescriptor &owner) { |
| 48 | + return llvm::hash_combine(owner.context, (void *)&owner.conv, |
| 49 | + (void *)&owner.opts); |
| 50 | + } |
| 51 | + |
| 52 | + friend bool operator==(const SILGenDescriptor &lhs, |
| 53 | + const SILGenDescriptor &rhs) { |
| 54 | + return lhs.context == rhs.context && |
| 55 | + &lhs.conv == &rhs.conv && |
| 56 | + &lhs.opts == &rhs.opts; |
| 57 | + } |
| 58 | + |
| 59 | + friend bool operator!=(const SILGenDescriptor &lhs, |
| 60 | + const SILGenDescriptor &rhs) { |
| 61 | + return !(lhs == rhs); |
| 62 | + } |
| 63 | + |
| 64 | +public: |
| 65 | + static SILGenDescriptor forFile(FileUnit &sf, Lowering::TypeConverter &conv, |
| 66 | + const SILOptions &opts) { |
| 67 | + return SILGenDescriptor{&sf, conv, opts}; |
| 68 | + } |
| 69 | + |
| 70 | + static SILGenDescriptor forWholeModule(ModuleDecl *mod, |
| 71 | + Lowering::TypeConverter &conv, |
| 72 | + const SILOptions &opts) { |
| 73 | + return SILGenDescriptor{mod, conv, opts}; |
| 74 | + } |
| 75 | +}; |
| 76 | + |
| 77 | +class GenerateSILRequest : |
| 78 | + public SimpleRequest<GenerateSILRequest, |
| 79 | + SILModule *(SILGenDescriptor), |
| 80 | + CacheKind::Uncached> { |
| 81 | +public: |
| 82 | + using SimpleRequest::SimpleRequest; |
| 83 | + |
| 84 | +private: |
| 85 | + friend SimpleRequest; |
| 86 | + |
| 87 | + // Evaluation. |
| 88 | + llvm::Expected<SILModule *> |
| 89 | + evaluate(Evaluator &evaluator, SILGenDescriptor desc) const; |
| 90 | + |
| 91 | +public: |
| 92 | + bool isCached() const { return true; } |
| 93 | +}; |
| 94 | + |
| 95 | +void simple_display(llvm::raw_ostream &out, const SILGenDescriptor &d); |
| 96 | + |
| 97 | +SourceLoc extractNearestSourceLoc(const SILGenDescriptor &desc); |
| 98 | + |
| 99 | +/// The zone number for SILGen. |
| 100 | +#define SWIFT_TYPEID_ZONE SILGen |
| 101 | +#define SWIFT_TYPEID_HEADER "swift/AST/SILGenTypeIDZone.def" |
| 102 | +#include "swift/Basic/DefineTypeIDZone.h" |
| 103 | +#undef SWIFT_TYPEID_ZONE |
| 104 | +#undef SWIFT_TYPEID_HEADER |
| 105 | + |
| 106 | + // Set up reporting of evaluated requests. |
| 107 | +#define SWIFT_REQUEST(Zone, RequestType, Sig, Caching, LocOptions) \ |
| 108 | +template<> \ |
| 109 | +inline void reportEvaluatedRequest(UnifiedStatsReporter &stats, \ |
| 110 | + const RequestType &request) { \ |
| 111 | + ++stats.getFrontendCounters().RequestType; \ |
| 112 | +} |
| 113 | +#include "swift/AST/SILGenTypeIDZone.def" |
| 114 | +#undef SWIFT_REQUEST |
| 115 | + |
| 116 | +} // end namespace swift |
| 117 | + |
| 118 | +#endif // SWIFT_SILGEN_REQUESTS_H |
0 commit comments