@@ -27,6 +27,64 @@ namespace ROCDL {
2727// / 5. Returns an empty string.
2828StringRef getROCMPath ();
2929
30+ // / Helper class for specifying the AMD GCN device libraries required for
31+ // / compilation.
32+ class AMDGCNLibraryList {
33+ public:
34+ typedef enum : uint32_t {
35+ None = 0 ,
36+ Ockl = 1 ,
37+ Ocml = 2 ,
38+ OpenCL = 4 ,
39+ Hip = 8 ,
40+ LastLib = Hip,
41+ All = (LastLib << 1 ) - 1
42+ } Library;
43+
44+ explicit AMDGCNLibraryList (uint32_t libs = All) : libList(All & libs) {}
45+
46+ // / Return a list with no libraries.
47+ static AMDGCNLibraryList getEmpty () { return AMDGCNLibraryList (None); }
48+
49+ // / Return the libraries needed for compiling code with OpenCL calls.
50+ static AMDGCNLibraryList getOpenCL () {
51+ return AMDGCNLibraryList (Ockl | Ocml | OpenCL);
52+ }
53+
54+ // / Returns true if the list is empty.
55+ bool isEmpty () const { return libList == None; }
56+
57+ // / Adds a library to the list.
58+ AMDGCNLibraryList addLibrary (Library lib) {
59+ libList = libList | lib;
60+ return *this ;
61+ }
62+
63+ // / Adds all the libraries in `list` to the library list.
64+ AMDGCNLibraryList addList (AMDGCNLibraryList list) {
65+ libList = libList | list.libList ;
66+ return *this ;
67+ }
68+
69+ // / Removes a library from the list.
70+ AMDGCNLibraryList removeLibrary (Library lib) {
71+ libList = libList & ~lib;
72+ return *this ;
73+ }
74+
75+ // / Returns true if `lib` is in the list of libraries.
76+ bool requiresLibrary (Library lib) const { return (libList & lib) != None; }
77+
78+ // / Returns true if `libList` contains all the libraries in `libs`.
79+ bool containLibraries (uint32_t libs) const {
80+ return (libList & libs) != None;
81+ }
82+
83+ private:
84+ // / Library list.
85+ uint32_t libList;
86+ };
87+
3088// / Base class for all ROCDL serializations from GPU modules into binary
3189// / strings. By default this class serializes into LLVM bitcode.
3290class SerializeGPUModuleBase : public LLVM ::ModuleToObject {
@@ -49,8 +107,8 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
49107 // / Returns the bitcode files to be loaded.
50108 ArrayRef<std::string> getFileList () const ;
51109
52- // / Appends standard ROCm device libraries like `ocml.bc`, `ockl.bc`, etc .
53- LogicalResult appendStandardLibs ();
110+ // / Appends standard ROCm device Library to `fileList` .
111+ LogicalResult appendStandardLibs (AMDGCNLibraryList libs );
54112
55113 // / Loads the bitcode files in `fileList`.
56114 virtual std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
@@ -63,15 +121,20 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
63121 LogicalResult handleBitcodeFile (llvm::Module &module ) override ;
64122
65123protected:
66- // / Appends the paths of common ROCm device libraries to `libs`.
67- LogicalResult getCommonBitcodeLibs (llvm::SmallVector<std::string> &libs,
68- SmallVector<char , 256 > &libPath,
69- StringRef isaVersion);
70-
71124 // / Adds `oclc` control variables to the LLVM module.
72- void addControlVariables (llvm::Module &module , bool wave64, bool daz,
73- bool finiteOnly, bool unsafeMath, bool fastMath,
74- bool correctSqrt, StringRef abiVer);
125+ void addControlVariables (llvm::Module &module , AMDGCNLibraryList libs,
126+ bool wave64, bool daz, bool finiteOnly,
127+ bool unsafeMath, bool fastMath, bool correctSqrt,
128+ StringRef abiVer);
129+
130+ // / Compiles assembly to a binary.
131+ virtual std::optional<SmallVector<char , 0 >>
132+ compileToBinary (const std::string &serializedISA);
133+
134+ // / Default implementation of `ModuleToObject::moduleToObject`.
135+ std::optional<SmallVector<char , 0 >>
136+ moduleToObjectImpl (const gpu::TargetOptions &targetOptions,
137+ llvm::Module &llvmModule);
75138
76139 // / Returns the assembled ISA.
77140 std::optional<SmallVector<char , 0 >> assembleIsa (StringRef isa);
@@ -84,6 +147,9 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
84147
85148 // / List of LLVM bitcode files to link to.
86149 SmallVector<std::string> fileList;
150+
151+ // / AMD GCN libraries to use when linking, the default is using all.
152+ AMDGCNLibraryList deviceLibs = AMDGCNLibraryList::getEmpty();
87153};
88154} // namespace ROCDL
89155} // namespace mlir
0 commit comments