@@ -27,6 +27,62 @@ 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) == lib; }
77+
78+ // / Returns true if `libList` contains any of the libraries in `libs`.
79+ bool requiresAnyOf (uint32_t libs) const { return (libList & libs) != None; }
80+
81+ private:
82+ // / Library list.
83+ uint32_t libList;
84+ };
85+
3086// / Base class for all ROCDL serializations from GPU modules into binary
3187// / strings. By default this class serializes into LLVM bitcode.
3288class SerializeGPUModuleBase : public LLVM ::ModuleToObject {
@@ -49,8 +105,8 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
49105 // / Returns the bitcode files to be loaded.
50106 ArrayRef<std::string> getFileList () const ;
51107
52- // / Appends standard ROCm device libraries like `ocml.bc`, `ockl.bc`, etc .
53- LogicalResult appendStandardLibs ();
108+ // / Appends standard ROCm device libraries to `fileList` .
109+ LogicalResult appendStandardLibs (AMDGCNLibraryList libs );
54110
55111 // / Loads the bitcode files in `fileList`.
56112 virtual std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
@@ -63,15 +119,20 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
63119 LogicalResult handleBitcodeFile (llvm::Module &module ) override ;
64120
65121protected:
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-
71122 // / 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);
123+ void addControlVariables (llvm::Module &module , AMDGCNLibraryList libs,
124+ bool wave64, bool daz, bool finiteOnly,
125+ bool unsafeMath, bool fastMath, bool correctSqrt,
126+ StringRef abiVer);
127+
128+ // / Compiles assembly to a binary.
129+ virtual std::optional<SmallVector<char , 0 >>
130+ compileToBinary (const std::string &serializedISA);
131+
132+ // / Default implementation of `ModuleToObject::moduleToObject`.
133+ std::optional<SmallVector<char , 0 >>
134+ moduleToObjectImpl (const gpu::TargetOptions &targetOptions,
135+ llvm::Module &llvmModule);
75136
76137 // / Returns the assembled ISA.
77138 std::optional<SmallVector<char , 0 >> assembleIsa (StringRef isa);
@@ -84,6 +145,9 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
84145
85146 // / List of LLVM bitcode files to link to.
86147 SmallVector<std::string> fileList;
148+
149+ // / AMD GCN libraries to use when linking, the default is using all.
150+ AMDGCNLibraryList deviceLibs = AMDGCNLibraryList::getEmpty();
87151};
88152} // namespace ROCDL
89153} // namespace mlir
0 commit comments