| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #ifndef LLVM_CLANG_DRIVER_COMPILATION_H |
| 10 | #define LLVM_CLANG_DRIVER_COMPILATION_H |
| 11 | |
| 12 | #include "clang/Basic/LLVM.h" |
| 13 | #include "clang/Driver/Action.h" |
| 14 | #include "clang/Driver/Job.h" |
| 15 | #include "clang/Driver/Util.h" |
| 16 | #include "llvm/ADT/ArrayRef.h" |
| 17 | #include "llvm/ADT/DenseMap.h" |
| 18 | #include "llvm/ADT/Optional.h" |
| 19 | #include "llvm/ADT/StringRef.h" |
| 20 | #include "llvm/Option/Option.h" |
| 21 | #include <cassert> |
| 22 | #include <iterator> |
| 23 | #include <map> |
| 24 | #include <memory> |
| 25 | #include <utility> |
| 26 | #include <vector> |
| 27 | |
| 28 | namespace llvm { |
| 29 | namespace opt { |
| 30 | |
| 31 | class DerivedArgList; |
| 32 | class InputArgList; |
| 33 | |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | namespace clang { |
| 38 | namespace driver { |
| 39 | |
| 40 | class Driver; |
| 41 | class ToolChain; |
| 42 | |
| 43 | |
| 44 | |
| 45 | class Compilation { |
| 46 | |
| 47 | const Driver &TheDriver; |
| 48 | |
| 49 | |
| 50 | const ToolChain &DefaultToolChain; |
| 51 | |
| 52 | |
| 53 | |
| 54 | unsigned ActiveOffloadMask = 0; |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | std::multimap<Action::OffloadKind, const ToolChain *> |
| 61 | OrderedOffloadingToolchains; |
| 62 | |
| 63 | |
| 64 | llvm::opt::InputArgList *Args; |
| 65 | |
| 66 | |
| 67 | |
| 68 | llvm::opt::DerivedArgList *TranslatedArgs; |
| 69 | |
| 70 | |
| 71 | |
| 72 | std::vector<std::unique_ptr<Action>> AllActions; |
| 73 | |
| 74 | |
| 75 | |
| 76 | ActionList Actions; |
| 77 | |
| 78 | |
| 79 | JobList Jobs; |
| 80 | |
| 81 | |
| 82 | |
| 83 | struct TCArgsKey final { |
| 84 | const ToolChain *TC = nullptr; |
| 85 | StringRef BoundArch; |
| 86 | Action::OffloadKind DeviceOffloadKind = Action::OFK_None; |
| 87 | |
| 88 | TCArgsKey(const ToolChain *TC, StringRef BoundArch, |
| 89 | Action::OffloadKind DeviceOffloadKind) |
| 90 | : TC(TC), BoundArch(BoundArch), DeviceOffloadKind(DeviceOffloadKind) {} |
| 91 | |
| 92 | bool operator<(const TCArgsKey &K) const { |
| 93 | if (TC < K.TC) |
| 94 | return true; |
| 95 | else if (TC == K.TC && BoundArch < K.BoundArch) |
| 96 | return true; |
| 97 | else if (TC == K.TC && BoundArch == K.BoundArch && |
| 98 | DeviceOffloadKind < K.DeviceOffloadKind) |
| 99 | return true; |
| 100 | return false; |
| 101 | } |
| 102 | }; |
| 103 | std::map<TCArgsKey, llvm::opt::DerivedArgList *> TCArgs; |
| 104 | |
| 105 | |
| 106 | llvm::opt::ArgStringList TempFiles; |
| 107 | |
| 108 | |
| 109 | ArgStringMap ResultFiles; |
| 110 | |
| 111 | |
| 112 | |
| 113 | ArgStringMap FailureResultFiles; |
| 114 | |
| 115 | |
| 116 | std::vector<Optional<StringRef>> Redirects; |
| 117 | |
| 118 | |
| 119 | bool ForDiagnostics = false; |
| 120 | |
| 121 | |
| 122 | bool ContainsError; |
| 123 | |
| 124 | |
| 125 | bool ForceKeepTempFiles = false; |
| 126 | |
| 127 | public: |
| 128 | Compilation(const Driver &D, const ToolChain &DefaultToolChain, |
| 129 | llvm::opt::InputArgList *Args, |
| 130 | llvm::opt::DerivedArgList *TranslatedArgs, bool ContainsError); |
| 131 | ~Compilation(); |
| 132 | |
| 133 | const Driver &getDriver() const { return TheDriver; } |
| 134 | |
| 135 | const ToolChain &getDefaultToolChain() const { return DefaultToolChain; } |
| 136 | |
| 137 | unsigned isOffloadingHostKind(Action::OffloadKind Kind) const { |
| 138 | return ActiveOffloadMask & Kind; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | using const_offload_toolchains_iterator = |
| 143 | const std::multimap<Action::OffloadKind, |
| 144 | const ToolChain *>::const_iterator; |
| 145 | using const_offload_toolchains_range = |
| 146 | std::pair<const_offload_toolchains_iterator, |
| 147 | const_offload_toolchains_iterator>; |
| 148 | |
| 149 | template <Action::OffloadKind Kind> |
| 150 | const_offload_toolchains_range getOffloadToolChains() const { |
| 151 | return OrderedOffloadingToolchains.equal_range(Kind); |
| 152 | } |
| 153 | |
| 154 | |
| 155 | template <Action::OffloadKind Kind> bool hasOffloadToolChain() const { |
| 156 | return OrderedOffloadingToolchains.find(Kind) != |
| 157 | OrderedOffloadingToolchains.end(); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | |
| 162 | template <Action::OffloadKind Kind> |
| 163 | const ToolChain *getSingleOffloadToolChain() const { |
| 164 | auto TCs = getOffloadToolChains<Kind>(); |
| 165 | |
| 166 | (0) . __assert_fail ("TCs.first != TCs.second && \"No tool chains of the selected kind exist!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Compilation.h", 167, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(TCs.first != TCs.second && |
| 167 | (0) . __assert_fail ("TCs.first != TCs.second && \"No tool chains of the selected kind exist!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Compilation.h", 167, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "No tool chains of the selected kind exist!"); |
| 168 | (0) . __assert_fail ("std..next(TCs.first) == TCs.second && \"More than one tool chain of the this kind exist.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Compilation.h", 169, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(std::next(TCs.first) == TCs.second && |
| 169 | (0) . __assert_fail ("std..next(TCs.first) == TCs.second && \"More than one tool chain of the this kind exist.\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Compilation.h", 169, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "More than one tool chain of the this kind exist."); |
| 170 | return TCs.first->second; |
| 171 | } |
| 172 | |
| 173 | void addOffloadDeviceToolChain(const ToolChain *DeviceToolChain, |
| 174 | Action::OffloadKind OffloadKind) { |
| 175 | (0) . __assert_fail ("OffloadKind != Action..OFK_Host && OffloadKind != Action..OFK_None && \"This is not a device tool chain!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Compilation.h", 176, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(OffloadKind != Action::OFK_Host && OffloadKind != Action::OFK_None && |
| 176 | (0) . __assert_fail ("OffloadKind != Action..OFK_Host && OffloadKind != Action..OFK_None && \"This is not a device tool chain!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Driver/Compilation.h", 176, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "This is not a device tool chain!"); |
| 177 | |
| 178 | |
| 179 | ActiveOffloadMask |= OffloadKind; |
| 180 | OrderedOffloadingToolchains.insert( |
| 181 | std::make_pair(OffloadKind, DeviceToolChain)); |
| 182 | } |
| 183 | |
| 184 | const llvm::opt::InputArgList &getInputArgs() const { return *Args; } |
| 185 | |
| 186 | const llvm::opt::DerivedArgList &getArgs() const { return *TranslatedArgs; } |
| 187 | |
| 188 | llvm::opt::DerivedArgList &getArgs() { return *TranslatedArgs; } |
| 189 | |
| 190 | ActionList &getActions() { return Actions; } |
| 191 | const ActionList &getActions() const { return Actions; } |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | template <typename T, typename... Args> T *MakeAction(Args &&... Arg) { |
| 197 | T *RawPtr = new T(std::forward<Args>(Arg)...); |
| 198 | AllActions.push_back(std::unique_ptr<Action>(RawPtr)); |
| 199 | return RawPtr; |
| 200 | } |
| 201 | |
| 202 | JobList &getJobs() { return Jobs; } |
| 203 | const JobList &getJobs() const { return Jobs; } |
| 204 | |
| 205 | void addCommand(std::unique_ptr<Command> C) { Jobs.addJob(std::move(C)); } |
| 206 | |
| 207 | const llvm::opt::ArgStringList &getTempFiles() const { return TempFiles; } |
| 208 | |
| 209 | const ArgStringMap &getResultFiles() const { return ResultFiles; } |
| 210 | |
| 211 | const ArgStringMap &getFailureResultFiles() const { |
| 212 | return FailureResultFiles; |
| 213 | } |
| 214 | |
| 215 | |
| 216 | StringRef getSysRoot() const; |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | const llvm::opt::DerivedArgList & |
| 227 | getArgsForToolChain(const ToolChain *TC, StringRef BoundArch, |
| 228 | Action::OffloadKind DeviceOffloadKind); |
| 229 | |
| 230 | |
| 231 | |
| 232 | const char *addTempFile(const char *Name) { |
| 233 | TempFiles.push_back(Name); |
| 234 | return Name; |
| 235 | } |
| 236 | |
| 237 | |
| 238 | |
| 239 | const char *addResultFile(const char *Name, const JobAction *JA) { |
| 240 | ResultFiles[JA] = Name; |
| 241 | return Name; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | |
| 246 | const char *addFailureResultFile(const char *Name, const JobAction *JA) { |
| 247 | FailureResultFiles[JA] = Name; |
| 248 | return Name; |
| 249 | } |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | bool CleanupFile(const char *File, bool IssueErrors = false) const; |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | bool CleanupFileList(const llvm::opt::ArgStringList &Files, |
| 262 | bool IssueErrors = false) const; |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | bool CleanupFileMap(const ArgStringMap &Files, |
| 271 | const JobAction *JA, |
| 272 | bool IssueErrors = false) const; |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | int ExecuteCommand(const Command &C, const Command *&FailingCommand) const; |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | void ExecuteJobs( |
| 286 | const JobList &Jobs, |
| 287 | SmallVectorImpl<std::pair<int, const Command *>> &FailingCommands) const; |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | void initCompilationForDiagnostics(); |
| 293 | |
| 294 | |
| 295 | bool isForDiagnostics() const { return ForDiagnostics; } |
| 296 | |
| 297 | |
| 298 | bool containsError() const { return ContainsError; } |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | void Redirect(ArrayRef<Optional<StringRef>> Redirects); |
| 306 | }; |
| 307 | |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | #endif |
| 312 | |