-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[Offload] Add Offload API Sphinx documentation #147323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+305
−16
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_static/ | ||
_themes/ | ||
offload-api.rst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
if(LLVM_ENABLE_SPHINX) | ||
include(AddSphinxTarget) | ||
if(SPHINX_FOUND AND SPHINX_OUTPUT_HTML) | ||
# Generate offload-api.rst from OffloadAPI.td | ||
set(LLVM_TARGET_DEFINITIONS | ||
${OFFLOAD_SOURCE_DIR}/liboffload/API/OffloadAPI.td) | ||
tablegen(OFFLOAD source/offload-api.rst -gen-doc | ||
EXTRA_INCLUDES ${OFFLOAD_SOURCE_DIR}/liboffload/API) | ||
add_public_tablegen_target(OffloadDocsGenerate) | ||
|
||
# Due to Sphinx only allowing a single source direcotry and the fact we | ||
# only generate a single file, copy offload-api.rst to the source directory | ||
# to be included in the generated documentation. | ||
# Additionally, copy the llvm-theme into the Sphinx source directory. | ||
# A .gitignore file ensures the copied files will not be added to the | ||
# repository. | ||
add_custom_target(OffloadDocsCopy | ||
COMMAND ${CMAKE_COMMAND} -E copy | ||
${CMAKE_CURRENT_BINARY_DIR}/source/offload-api.rst | ||
${CMAKE_CURRENT_SOURCE_DIR}/offload-api.rst | ||
COMMAND ${CMAKE_COMMAND} -E copy | ||
${OFFLOAD_SOURCE_DIR}/../clang/www/favicon.ico | ||
${CMAKE_CURRENT_SOURCE_DIR}/_static/favicon.ico | ||
COMMAND ${CMAKE_COMMAND} -E copy | ||
${OFFLOAD_SOURCE_DIR}/../llvm/docs/_static/llvm.css | ||
${CMAKE_CURRENT_SOURCE_DIR}/_static/llvm.css | ||
COMMAND ${CMAKE_COMMAND} -E copy_directory | ||
${OFFLOAD_SOURCE_DIR}/../llvm/docs/_themes | ||
${CMAKE_CURRENT_SOURCE_DIR}/_themes | ||
) | ||
add_dependencies(OffloadDocsCopy OffloadDocsGenerate) | ||
|
||
# Generate the HTML documentation, the docs-offload-html target. | ||
add_sphinx_target(html offload) | ||
add_dependencies(docs-offload-html OffloadDocsCopy) | ||
endif() | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# For the full list of built-in configuration values, see the documentation: | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html | ||
|
||
# -- Project information ----------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information | ||
|
||
project = "Offload" | ||
copyright = "2025, LLVM project" | ||
author = "LLVM project" | ||
|
||
# -- General configuration --------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration | ||
|
||
extensions = [] | ||
|
||
templates_path = ["_templates"] | ||
exclude_patterns = [] | ||
|
||
# -- C domain configuration -------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#c-config | ||
|
||
c_maximum_signature_line_length = 60 | ||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output | ||
|
||
html_theme = "llvm-theme" | ||
html_theme_path = ["_themes"] | ||
html_static_path = ["_static"] | ||
html_favicon = "_static/favicon.ico" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.. Offload documentation master file, created by | ||
sphinx-quickstart on Fri Jul 4 14:59:13 2025. | ||
You can adapt this file completely to your liking, but it should at least | ||
contain the root `toctree` directive. | ||
RossBrunton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Welcome to Offload's documentation! | ||
=================================== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:caption: Contents: | ||
|
||
offload-api | ||
|
||
|
||
Indices and tables | ||
================== | ||
|
||
* :ref:`genindex` | ||
* :ref:`modindex` | ||
* :ref:`search` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
//===- offload-tblgen/DocGen.cpp - Tablegen backend for Offload header ----===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This is a Tablegen backend that produces the contents of the Offload API | ||
// specification. The generated reStructuredText is Sphinx compatible, see | ||
// https://www.sphinx-doc.org/en/master/usage/domains/c.html for further | ||
// details on the C language domain. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/Support/FormatVariadic.h" | ||
#include "llvm/TableGen/Record.h" | ||
#include "llvm/TableGen/TableGenBackend.h" | ||
|
||
#include "GenCommon.hpp" | ||
#include "RecordTypes.hpp" | ||
|
||
using namespace llvm; | ||
using namespace offload::tblgen; | ||
|
||
namespace { | ||
std::string makeFunctionSignature(StringRef RetTy, StringRef Name, | ||
ArrayRef<ParamRec> Params) { | ||
std::string S; | ||
raw_string_ostream OS{S}; | ||
OS << RetTy << " " << Name << "("; | ||
for (const ParamRec &Param : Params) { | ||
OS << Param.getType() << " " << Param.getName(); | ||
if (Param != Params.back()) { | ||
OS << ", "; | ||
} | ||
} | ||
OS << ")"; | ||
return S; | ||
} | ||
|
||
std::string makeDoubleBackticks(StringRef R) { | ||
std::string S; | ||
for (char C : R) { | ||
if (C == '`') { | ||
S.push_back('`'); | ||
} | ||
S.push_back(C); | ||
} | ||
return S; | ||
} | ||
|
||
void processMacro(const MacroRec &M, raw_ostream &OS) { | ||
OS << formatv(".. c:macro:: {0}\n\n", M.getNameWithArgs()); | ||
OS << " " << M.getDesc() << "\n\n"; | ||
} | ||
|
||
void processTypedef(const TypedefRec &T, raw_ostream &OS) { | ||
OS << formatv(".. c:type:: {0} {1}\n\n", T.getValue(), T.getName()); | ||
OS << " " << T.getDesc() << "\n\n"; | ||
} | ||
|
||
void processHandle(const HandleRec &H, raw_ostream &OS) { | ||
|
||
OS << formatv(".. c:type:: struct {0} *{1}\n\n", getHandleImplName(H), | ||
H.getName()); | ||
OS << " " << H.getDesc() << "\n\n"; | ||
} | ||
|
||
void processFptrTypedef(const FptrTypedefRec &F, raw_ostream &OS) { | ||
OS << ".. c:type:: " | ||
<< makeFunctionSignature(F.getReturn(), | ||
StringRef{formatv("(*{0})", F.getName())}, | ||
F.getParams()) | ||
<< "\n\n"; | ||
for (const ParamRec &P : F.getParams()) { | ||
OS << formatv(" :param {0}: {1}\n", P.getName(), P.getDesc()); | ||
} | ||
OS << "\n"; | ||
} | ||
|
||
void processEnum(const EnumRec &E, raw_ostream &OS) { | ||
OS << formatv(".. c:enum:: {0}\n\n", E.getName()); | ||
OS << " " << E.getDesc() << "\n\n"; | ||
for (const EnumValueRec Etor : E.getValues()) { | ||
OS << formatv(" .. c:enumerator:: {0}_{1}\n\n", E.getEnumValNamePrefix(), | ||
Etor.getName()); | ||
OS << " " << Etor.getDesc() << "\n\n"; | ||
} | ||
} | ||
|
||
void processStruct(const StructRec &S, raw_ostream &OS) { | ||
OS << formatv(".. c:struct:: {0}\n\n", S.getName()); | ||
OS << " " << S.getDesc() << "\n\n"; | ||
for (const StructMemberRec &M : S.getMembers()) { | ||
OS << formatv(" .. c:member:: {0} {1}\n\n", M.getType(), M.getName()); | ||
OS << " " << M.getDesc() << "\n\n"; | ||
} | ||
} | ||
|
||
void processFunction(const FunctionRec &F, raw_ostream &OS) { | ||
OS << ".. c:function:: " | ||
<< makeFunctionSignature({formatv("{0}_result_t", PrefixLower)}, | ||
F.getName(), F.getParams()) | ||
<< "\n\n"; | ||
|
||
OS << " " << F.getDesc() << "\n\n"; | ||
for (StringRef D : F.getDetails()) { | ||
OS << " " << D << "\n"; | ||
} | ||
if (!F.getDetails().empty()) { | ||
OS << "\n"; | ||
} | ||
|
||
for (const ParamRec &P : F.getParams()) { | ||
OS << formatv(" :param {0}: {1}\n", P.getName(), P.getDesc()); | ||
} | ||
|
||
for (const ReturnRec &R : F.getReturns()) { | ||
OS << formatv(" :retval {0}:\n", R.getValue()); | ||
for (StringRef C : R.getConditions()) { | ||
OS << " * "; | ||
if (C.starts_with("`") && C.ends_with("`")) { | ||
OS << ":c:expr:" << C; | ||
} else { | ||
OS << makeDoubleBackticks(C); | ||
} | ||
OS << "\n"; | ||
} | ||
} | ||
OS << "\n"; | ||
} | ||
} // namespace | ||
|
||
void EmitOffloadDoc(const RecordKeeper &Records, raw_ostream &OS) { | ||
OS << "Offload API\n"; | ||
OS << "===========\n\n"; | ||
|
||
ArrayRef<const Record *> Macros = Records.getAllDerivedDefinitions("Macro"); | ||
if (!Macros.empty()) { | ||
OS << "Macros\n"; | ||
OS << "------\n\n"; | ||
for (const Record *M : Macros) { | ||
processMacro(MacroRec{M}, OS); | ||
} | ||
} | ||
|
||
ArrayRef<const Record *> Handles = Records.getAllDerivedDefinitions("Handle"); | ||
ArrayRef<const Record *> Typedefs = | ||
Records.getAllDerivedDefinitions("Typedef"); | ||
ArrayRef<const Record *> FptrTypedefs = | ||
Records.getAllDerivedDefinitions("FptrTypedef"); | ||
if (!Handles.empty() || !Typedefs.empty() || !FptrTypedefs.empty()) { | ||
OS << "Type Definitions\n"; | ||
OS << "----------------\n\n"; | ||
for (const Record *H : Handles) { | ||
processHandle(HandleRec{H}, OS); | ||
} | ||
for (const Record *T : Typedefs) { | ||
processTypedef(TypedefRec{T}, OS); | ||
} | ||
for (const Record *F : FptrTypedefs) { | ||
processFptrTypedef(FptrTypedefRec{F}, OS); | ||
} | ||
} | ||
|
||
ArrayRef<const Record *> Enums = Records.getAllDerivedDefinitions("Enum"); | ||
OS << "Enums\n"; | ||
OS << "-----\n\n"; | ||
if (!Enums.empty()) { | ||
for (const Record *E : Enums) { | ||
processEnum(EnumRec{E}, OS); | ||
} | ||
} | ||
|
||
ArrayRef<const Record *> Structs = Records.getAllDerivedDefinitions("Struct"); | ||
if (!Structs.empty()) { | ||
OS << "Structs\n"; | ||
OS << "-------\n\n"; | ||
for (const Record *S : Structs) { | ||
processStruct(StructRec{S}, OS); | ||
} | ||
} | ||
|
||
ArrayRef<const Record *> Functions = | ||
Records.getAllDerivedDefinitions("Function"); | ||
if (!Functions.empty()) { | ||
OS << "Functions\n"; | ||
OS << "---------\n\n"; | ||
for (const Record *F : Functions) { | ||
processFunction(FunctionRec{F}, OS); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.