OffloadBundler.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- OffloadBundler.h - File Bundling and Unbundling ----------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. ///
  14. /// \file
  15. /// This file defines an offload bundling API that bundles different files
  16. /// that relate with the same source code but different targets into a single
  17. /// one. Also the implements the opposite functionality, i.e. unbundle files
  18. /// previous created by this API.
  19. ///
  20. //===----------------------------------------------------------------------===//
  21. #ifndef LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
  22. #define LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
  23. #include "llvm/ADT/Triple.h"
  24. #include "llvm/Support/Error.h"
  25. #include <string>
  26. #include <vector>
  27. namespace clang {
  28. class OffloadBundlerConfig {
  29. public:
  30. bool AllowNoHost = false;
  31. bool AllowMissingBundles = false;
  32. bool CheckInputArchive = false;
  33. bool PrintExternalCommands = false;
  34. bool HipOpenmpCompatible = false;
  35. unsigned BundleAlignment = 1;
  36. unsigned HostInputIndex = ~0u;
  37. std::string FilesType;
  38. std::string ObjcopyPath;
  39. // TODO: Convert these to llvm::SmallVector
  40. std::vector<std::string> TargetNames;
  41. std::vector<std::string> InputFileNames;
  42. std::vector<std::string> OutputFileNames;
  43. };
  44. class OffloadBundler {
  45. public:
  46. const OffloadBundlerConfig &BundlerConfig;
  47. // TODO: Add error checking from ClangOffloadBundler.cpp
  48. OffloadBundler(const OffloadBundlerConfig &BC) : BundlerConfig(BC) {}
  49. // List bundle IDs. Return true if an error was found.
  50. static llvm::Error
  51. ListBundleIDsInFile(llvm::StringRef InputFileName,
  52. const OffloadBundlerConfig &BundlerConfig);
  53. llvm::Error BundleFiles();
  54. llvm::Error UnbundleFiles();
  55. llvm::Error UnbundleArchive();
  56. };
  57. /// Obtain the offload kind, real machine triple, and an optional GPUArch
  58. /// out of the target information specified by the user.
  59. /// Bundle Entry ID (or, Offload Target String) has following components:
  60. /// * Offload Kind - Host, OpenMP, or HIP
  61. /// * Triple - Standard LLVM Triple
  62. /// * TargetID (Optional) - target ID, like gfx906:xnack+ or sm_30
  63. struct OffloadTargetInfo {
  64. llvm::StringRef OffloadKind;
  65. llvm::Triple Triple;
  66. llvm::StringRef TargetID;
  67. const OffloadBundlerConfig &BundlerConfig;
  68. OffloadTargetInfo(const llvm::StringRef Target,
  69. const OffloadBundlerConfig &BC);
  70. bool hasHostKind() const;
  71. bool isOffloadKindValid() const;
  72. bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const;
  73. bool isTripleValid() const;
  74. bool operator==(const OffloadTargetInfo &Target) const;
  75. std::string str() const;
  76. };
  77. } // namespace clang
  78. #endif // LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
  79. #ifdef __GNUC__
  80. #pragma GCC diagnostic pop
  81. #endif