LCOV - code coverage report
Current view: top level - lib/Target/AMDGPU/MCTargetDesc - AMDGPUCodeObjectMetadata.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 19 19 100.0 %
Date: 2017-05-20 02:07:48 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===--- AMDGPUCodeObjectMetadata.h -----------------------------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : /// \file
      11             : /// \brief AMDGPU Code Object Metadata definitions and in-memory
      12             : /// representations.
      13             : ///
      14             : //
      15             : //===----------------------------------------------------------------------===//
      16             : 
      17             : #ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUCODEOBJECTMETADATA_H
      18             : #define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUCODEOBJECTMETADATA_H
      19             : 
      20             : #include <cstdint>
      21             : #include <string>
      22             : #include <system_error>
      23             : #include <vector>
      24             : 
      25             : namespace llvm {
      26             : namespace AMDGPU {
      27             : 
      28             : //===----------------------------------------------------------------------===//
      29             : // Code Object Metadata.
      30             : //===----------------------------------------------------------------------===//
      31             : namespace CodeObject {
      32             : 
      33             : /// \brief Code object metadata major version.
      34             : constexpr uint32_t MetadataVersionMajor = 1;
      35             : /// \brief Code object metadata minor version.
      36             : constexpr uint32_t MetadataVersionMinor = 0;
      37             : 
      38             : /// \brief Code object metadata beginning assembler directive.
      39             : constexpr char MetadataAssemblerDirectiveBegin[] =
      40             :     ".amdgpu_code_object_metadata";
      41             : /// \brief Code object metadata ending assembler directive.
      42             : constexpr char MetadataAssemblerDirectiveEnd[] =
      43             :     ".end_amdgpu_code_object_metadata";
      44             : 
      45             : /// \brief Access qualifiers.
      46             : enum class AccessQualifier : uint8_t {
      47             :   Default   = 0,
      48             :   ReadOnly  = 1,
      49             :   WriteOnly = 2,
      50             :   ReadWrite = 3,
      51             :   Unknown   = 0xff
      52             : };
      53             : 
      54             : /// \brief Address space qualifiers.
      55             : enum class AddressSpaceQualifier : uint8_t {
      56             :   Private  = 0,
      57             :   Global   = 1,
      58             :   Constant = 2,
      59             :   Local    = 3,
      60             :   Generic  = 4,
      61             :   Region   = 5,
      62             :   Unknown  = 0xff
      63             : };
      64             : 
      65             : /// \brief Value kinds.
      66             : enum class ValueKind : uint8_t {
      67             :   ByValue                = 0,
      68             :   GlobalBuffer           = 1,
      69             :   DynamicSharedPointer   = 2,
      70             :   Sampler                = 3,
      71             :   Image                  = 4,
      72             :   Pipe                   = 5,
      73             :   Queue                  = 6,
      74             :   HiddenGlobalOffsetX    = 7,
      75             :   HiddenGlobalOffsetY    = 8,
      76             :   HiddenGlobalOffsetZ    = 9,
      77             :   HiddenNone             = 10,
      78             :   HiddenPrintfBuffer     = 11,
      79             :   HiddenDefaultQueue     = 12,
      80             :   HiddenCompletionAction = 13,
      81             :   Unknown                = 0xff
      82             : };
      83             : 
      84             : /// \brief Value types.
      85             : enum class ValueType : uint8_t {
      86             :   Struct  = 0,
      87             :   I8      = 1,
      88             :   U8      = 2,
      89             :   I16     = 3,
      90             :   U16     = 4,
      91             :   F16     = 5,
      92             :   I32     = 6,
      93             :   U32     = 7,
      94             :   F32     = 8,
      95             :   I64     = 9,
      96             :   U64     = 10,
      97             :   F64     = 11,
      98             :   Unknown = 0xff
      99             : };
     100             : 
     101             : //===----------------------------------------------------------------------===//
     102             : // Kernel Metadata.
     103             : //===----------------------------------------------------------------------===//
     104             : namespace Kernel {
     105             : 
     106             : //===----------------------------------------------------------------------===//
     107             : // Kernel Attributes Metadata.
     108             : //===----------------------------------------------------------------------===//
     109             : namespace Attrs {
     110             : 
     111             : namespace Key {
     112             : /// \brief Key for Kernel::Attr::Metadata::mReqdWorkGroupSize.
     113             : constexpr char ReqdWorkGroupSize[] = "ReqdWorkGroupSize";
     114             : /// \brief Key for Kernel::Attr::Metadata::mWorkGroupSizeHint.
     115             : constexpr char WorkGroupSizeHint[] = "WorkGroupSizeHint";
     116             : /// \brief Key for Kernel::Attr::Metadata::mVecTypeHint.
     117             : constexpr char VecTypeHint[] = "VecTypeHint";
     118             : } // end namespace Key
     119             : 
     120             : /// \brief In-memory representation of kernel attributes metadata.
     121       44534 : struct Metadata final {
     122             :   /// \brief 'reqd_work_group_size' attribute. Optional.
     123             :   std::vector<uint32_t> mReqdWorkGroupSize = std::vector<uint32_t>();
     124             :   /// \brief 'work_group_size_hint' attribute. Optional.
     125             :   std::vector<uint32_t> mWorkGroupSizeHint = std::vector<uint32_t>();
     126             :   /// \brief 'vec_type_hint' attribute. Optional.
     127             :   std::string mVecTypeHint = std::string();
     128             : 
     129             :   /// \brief Default constructor.
     130        5656 :   Metadata() = default;
     131             : 
     132             :   /// \returns True if kernel attributes metadata is empty, false otherwise.
     133             :   bool empty() const {
     134       12054 :     return mReqdWorkGroupSize.empty() &&
     135       12003 :            mWorkGroupSizeHint.empty() &&
     136        7952 :            mVecTypeHint.empty();
     137             :   }
     138             : 
     139             :   /// \returns True if kernel attributes metadata is not empty, false otherwise.
     140             :   bool notEmpty() const {
     141             :     return !empty();
     142             :   }
     143             : };
     144             : 
     145             : } // end namespace Attrs
     146             : 
     147             : //===----------------------------------------------------------------------===//
     148             : // Kernel Argument Metadata.
     149             : //===----------------------------------------------------------------------===//
     150             : namespace Arg {
     151             : 
     152             : namespace Key {
     153             : /// \brief Key for Kernel::Arg::Metadata::mSize.
     154             : constexpr char Size[] = "Size";
     155             : /// \brief Key for Kernel::Arg::Metadata::mAlign.
     156             : constexpr char Align[] = "Align";
     157             : /// \brief Key for Kernel::Arg::Metadata::mValueKind.
     158             : constexpr char ValueKind[] = "ValueKind";
     159             : /// \brief Key for Kernel::Arg::Metadata::mValueType.
     160             : constexpr char ValueType[] = "ValueType";
     161             : /// \brief Key for Kernel::Arg::Metadata::mPointeeAlign.
     162             : constexpr char PointeeAlign[] = "PointeeAlign";
     163             : /// \brief Key for Kernel::Arg::Metadata::mAccQual.
     164             : constexpr char AccQual[] = "AccQual";
     165             : /// \brief Key for Kernel::Arg::Metadata::mAddrSpaceQual.
     166             : constexpr char AddrSpaceQual[] = "AddrSpaceQual";
     167             : /// \brief Key for Kernel::Arg::Metadata::mIsConst.
     168             : constexpr char IsConst[] = "IsConst";
     169             : /// \brief Key for Kernel::Arg::Metadata::mIsPipe.
     170             : constexpr char IsPipe[] = "IsPipe";
     171             : /// \brief Key for Kernel::Arg::Metadata::mIsRestrict.
     172             : constexpr char IsRestrict[] = "IsRestrict";
     173             : /// \brief Key for Kernel::Arg::Metadata::mIsVolatile.
     174             : constexpr char IsVolatile[] = "IsVolatile";
     175             : /// \brief Key for Kernel::Arg::Metadata::mName.
     176             : constexpr char Name[] = "Name";
     177             : /// \brief Key for Kernel::Arg::Metadata::mTypeName.
     178             : constexpr char TypeName[] = "TypeName";
     179             : } // end namespace Key
     180             : 
     181             : /// \brief In-memory representation of kernel argument metadata.
     182       90330 : struct Metadata final {
     183             :   /// \brief Size in bytes. Required.
     184             :   uint32_t mSize = 0;
     185             :   /// \brief Alignment in bytes. Required.
     186             :   uint32_t mAlign = 0;
     187             :   /// \brief Value kind. Required.
     188             :   ValueKind mValueKind = ValueKind::Unknown;
     189             :   /// \brief Value type. Required.
     190             :   ValueType mValueType = ValueType::Unknown;
     191             :   /// \brief Pointee alignment in bytes. Optional.
     192             :   uint32_t mPointeeAlign = 0;
     193             :   /// \brief Access qualifier. Optional.
     194             :   AccessQualifier mAccQual = AccessQualifier::Unknown;
     195             :   /// \brief Address space qualifier. Optional.
     196             :   AddressSpaceQualifier mAddrSpaceQual = AddressSpaceQualifier::Unknown;
     197             :   /// \brief True if 'const' qualifier is specified. Optional.
     198             :   bool mIsConst = false;
     199             :   /// \brief True if 'pipe' qualifier is specified. Optional.
     200             :   bool mIsPipe = false;
     201             :   /// \brief True if 'restrict' qualifier is specified. Optional.
     202             :   bool mIsRestrict = false;
     203             :   /// \brief True if 'volatile' qualifier is specified. Optional.
     204             :   bool mIsVolatile = false;
     205             :   /// \brief Name. Optional.
     206             :   std::string mName = std::string();
     207             :   /// \brief Type name. Optional.
     208             :   std::string mTypeName = std::string();
     209             : 
     210             :   /// \brief Default constructor.
     211       11568 :   Metadata() = default;
     212             : };
     213             : 
     214             : } // end namespace Arg
     215             : 
     216             : //===----------------------------------------------------------------------===//
     217             : // Kernel Code Properties Metadata.
     218             : //===----------------------------------------------------------------------===//
     219             : namespace CodeProps {
     220             : 
     221             : namespace Key {
     222             : /// \brief Key for Kernel::CodeProps::Metadata::mKernargSegmentSize.
     223             : constexpr char KernargSegmentSize[] = "KernargSegmentSize";
     224             : /// \brief Key for Kernel::CodeProps::Metadata::mWorkgroupGroupSegmentSize.
     225             : constexpr char WorkgroupGroupSegmentSize[] = "WorkgroupGroupSegmentSize";
     226             : /// \brief Key for Kernel::CodeProps::Metadata::mWorkitemPrivateSegmentSize.
     227             : constexpr char WorkitemPrivateSegmentSize[] = "WorkitemPrivateSegmentSize";
     228             : /// \brief Key for Kernel::CodeProps::Metadata::mWavefrontNumSGPRs.
     229             : constexpr char WavefrontNumSGPRs[] = "WavefrontNumSGPRs";
     230             : /// \brief Key for Kernel::CodeProps::Metadata::mWorkitemNumVGPRs.
     231             : constexpr char WorkitemNumVGPRs[] = "WorkitemNumVGPRs";
     232             : /// \brief Key for Kernel::CodeProps::Metadata::mKernargSegmentAlign.
     233             : constexpr char KernargSegmentAlign[] = "KernargSegmentAlign";
     234             : /// \brief Key for Kernel::CodeProps::Metadata::mGroupSegmentAlign.
     235             : constexpr char GroupSegmentAlign[] = "GroupSegmentAlign";
     236             : /// \brief Key for Kernel::CodeProps::Metadata::mPrivateSegmentAlign.
     237             : constexpr char PrivateSegmentAlign[] = "PrivateSegmentAlign";
     238             : /// \brief Key for Kernel::CodeProps::Metadata::mWavefrontSize.
     239             : constexpr char WavefrontSize[] = "WavefrontSize";
     240             : } // end namespace Key
     241             : 
     242             : /// \brief In-memory representation of kernel code properties metadata.
     243             : struct Metadata final {
     244             :   /// \brief Size in bytes of the kernarg segment memory. Kernarg segment memory
     245             :   /// holds the values of the arguments to the kernel. Optional.
     246             :   uint64_t mKernargSegmentSize = 0;
     247             :   /// \brief Size in bytes of the group segment memory required by a workgroup.
     248             :   /// This value does not include any dynamically allocated group segment memory
     249             :   /// that may be added when the kernel is dispatched. Optional.
     250             :   uint32_t mWorkgroupGroupSegmentSize = 0;
     251             :   /// \brief Size in bytes of the private segment memory required by a workitem.
     252             :   /// Private segment memory includes arg, spill and private segments. Optional.
     253             :   uint32_t mWorkitemPrivateSegmentSize = 0;
     254             :   /// \brief Total number of SGPRs used by a wavefront. Optional.
     255             :   uint16_t mWavefrontNumSGPRs = 0;
     256             :   /// \brief Total number of VGPRs used by a workitem. Optional.
     257             :   uint16_t mWorkitemNumVGPRs = 0;
     258             :   /// \brief Maximum byte alignment of variables used by the kernel in the
     259             :   /// kernarg memory segment. Expressed as a power of two. Optional.
     260             :   uint8_t mKernargSegmentAlign = 0;
     261             :   /// \brief Maximum byte alignment of variables used by the kernel in the
     262             :   /// group memory segment. Expressed as a power of two. Optional.
     263             :   uint8_t mGroupSegmentAlign = 0;
     264             :   /// \brief Maximum byte alignment of variables used by the kernel in the
     265             :   /// private memory segment. Expressed as a power of two. Optional.
     266             :   uint8_t mPrivateSegmentAlign = 0;
     267             :   /// \brief Wavefront size. Expressed as a power of two. Optional.
     268             :   uint8_t mWavefrontSize = 0;
     269             : 
     270             :   /// \brief Default constructor.
     271        1414 :   Metadata() = default;
     272             : 
     273             :   /// \returns True if kernel code properties metadata is empty, false
     274             :   /// otherwise.
     275             :   bool empty() const {
     276        4027 :     return !notEmpty();
     277             :   }
     278             : 
     279             :   /// \returns True if kernel code properties metadata is not empty, false
     280             :   /// otherwise.
     281             :   bool notEmpty() const {
     282        4540 :     return mKernargSegmentSize || mWorkgroupGroupSegmentSize ||
     283             :            mWorkitemPrivateSegmentSize || mWavefrontNumSGPRs ||
     284             :            mWorkitemNumVGPRs || mKernargSegmentAlign || mGroupSegmentAlign ||
     285        4510 :            mPrivateSegmentAlign || mWavefrontSize;
     286             :   }
     287             : };
     288             : 
     289             : } // end namespace CodeProps
     290             : 
     291             : //===----------------------------------------------------------------------===//
     292             : // Kernel Debug Properties Metadata.
     293             : //===----------------------------------------------------------------------===//
     294             : namespace DebugProps {
     295             : 
     296             : namespace Key {
     297             : /// \brief Key for Kernel::DebugProps::Metadata::mDebuggerABIVersion.
     298             : constexpr char DebuggerABIVersion[] = "DebuggerABIVersion";
     299             : /// \brief Key for Kernel::DebugProps::Metadata::mReservedNumVGPRs.
     300             : constexpr char ReservedNumVGPRs[] = "ReservedNumVGPRs";
     301             : /// \brief Key for Kernel::DebugProps::Metadata::mReservedFirstVGPR.
     302             : constexpr char ReservedFirstVGPR[] = "ReservedFirstVGPR";
     303             : /// \brief Key for Kernel::DebugProps::Metadata::mPrivateSegmentBufferSGPR.
     304             : constexpr char PrivateSegmentBufferSGPR[] = "PrivateSegmentBufferSGPR";
     305             : /// \brief Key for
     306             : ///     Kernel::DebugProps::Metadata::mWavefrontPrivateSegmentOffsetSGPR.
     307             : constexpr char WavefrontPrivateSegmentOffsetSGPR[] =
     308             :     "WavefrontPrivateSegmentOffsetSGPR";
     309             : } // end namespace Key
     310             : 
     311             : /// \brief In-memory representation of kernel debug properties metadata.
     312       22267 : struct Metadata final {
     313             :   /// \brief Debugger ABI version. Optional.
     314             :   std::vector<uint32_t> mDebuggerABIVersion = std::vector<uint32_t>();
     315             :   /// \brief Consecutive number of VGPRs reserved for debugger use. Must be 0 if
     316             :   /// mDebuggerABIVersion is not set. Optional.
     317             :   uint16_t mReservedNumVGPRs = 0;
     318             :   /// \brief First fixed VGPR reserved. Must be uint16_t(-1) if
     319             :   /// mDebuggerABIVersion is not set or mReservedFirstVGPR is 0. Optional.
     320             :   uint16_t mReservedFirstVGPR = uint16_t(-1);
     321             :   /// \brief Fixed SGPR of the first of 4 SGPRs used to hold the scratch V# used
     322             :   /// for the entire kernel execution. Must be uint16_t(-1) if
     323             :   /// mDebuggerABIVersion is not set or SGPR not used or not known. Optional.
     324             :   uint16_t mPrivateSegmentBufferSGPR = uint16_t(-1);
     325             :   /// \brief Fixed SGPR used to hold the wave scratch offset for the entire
     326             :   /// kernel execution. Must be uint16_t(-1) if mDebuggerABIVersion is not set
     327             :   /// or SGPR is not used or not known. Optional.
     328             :   uint16_t mWavefrontPrivateSegmentOffsetSGPR = uint16_t(-1);
     329             : 
     330             :   /// \brief Default constructor.
     331        2828 :   Metadata() = default;
     332             : 
     333             :   /// \returns True if kernel debug properties metadata is empty, false
     334             :   /// otherwise.
     335             :   bool empty() const {
     336        4027 :     return !notEmpty();
     337             :   }
     338             : 
     339             :   /// \returns True if kernel debug properties metadata is not empty, false
     340             :   /// otherwise.
     341             :   bool notEmpty() const {
     342        8054 :     return !mDebuggerABIVersion.empty();
     343             :   }
     344             : };
     345             : 
     346             : } // end namespace DebugProps
     347             : 
     348             : namespace Key {
     349             : /// \brief Key for Kernel::Metadata::mName.
     350             : constexpr char Name[] = "Name";
     351             : /// \brief Key for Kernel::Metadata::mLanguage.
     352             : constexpr char Language[] = "Language";
     353             : /// \brief Key for Kernel::Metadata::mLanguageVersion.
     354             : constexpr char LanguageVersion[] = "LanguageVersion";
     355             : /// \brief Key for Kernel::Metadata::mAttrs.
     356             : constexpr char Attrs[] = "Attrs";
     357             : /// \brief Key for Kernel::Metadata::mArgs.
     358             : constexpr char Args[] = "Args";
     359             : /// \brief Key for Kernel::Metadata::mCodeProps.
     360             : constexpr char CodeProps[] = "CodeProps";
     361             : /// \brief Key for Kernel::Metadata::mDebugProps.
     362             : constexpr char DebugProps[] = "DebugProps";
     363             : } // end namespace Key
     364             : 
     365             : /// \brief In-memory representation of kernel metadata.
     366       62487 : struct Metadata final {
     367             :   /// \brief Name. Required.
     368             :   std::string mName = std::string();
     369             :   /// \brief Language. Optional.
     370             :   std::string mLanguage = std::string();
     371             :   /// \brief Language version. Optional.
     372             :   std::vector<uint32_t> mLanguageVersion = std::vector<uint32_t>();
     373             :   /// \brief Attributes metadata. Optional.
     374             :   Attrs::Metadata mAttrs = Attrs::Metadata();
     375             :   /// \brief Arguments metadata. Optional.
     376             :   std::vector<Arg::Metadata> mArgs = std::vector<Arg::Metadata>();
     377             :   /// \brief Code properties metadata. Optional.
     378             :   CodeProps::Metadata mCodeProps = CodeProps::Metadata();
     379             :   /// \brief Debug properties metadata. Optional.
     380             :   DebugProps::Metadata mDebugProps = DebugProps::Metadata();
     381             : 
     382             :   /// \brief Default constructor.
     383        8484 :   Metadata() = default;
     384             : };
     385             : 
     386             : } // end namespace Kernel
     387             : 
     388             : namespace Key {
     389             : /// \brief Key for CodeObject::Metadata::mVersion.
     390             : constexpr char Version[] = "Version";
     391             : /// \brief Key for CodeObject::Metadata::mPrintf.
     392             : constexpr char Printf[] = "Printf";
     393             : /// \brief Key for CodeObject::Metadata::mKernels.
     394             : constexpr char Kernels[] = "Kernels";
     395             : } // end namespace Key
     396             : 
     397             : /// \brief In-memory representation of code object metadata.
     398        4426 : struct Metadata final {
     399             :   /// \brief Code object metadata version. Required.
     400             :   std::vector<uint32_t> mVersion = std::vector<uint32_t>();
     401             :   /// \brief Printf metadata. Optional.
     402             :   std::vector<std::string> mPrintf = std::vector<std::string>();
     403             :   /// \brief Kernels metadata. Optional.
     404             :   std::vector<Kernel::Metadata> mKernels = std::vector<Kernel::Metadata>();
     405             : 
     406             :   /// \brief Default constructor.
     407        6500 :   Metadata() = default;
     408             : 
     409             :   /// \brief Converts \p YamlString to \p CodeObjectMetadata.
     410             :   static std::error_code fromYamlString(std::string YamlString,
     411             :                                         Metadata &CodeObjectMetadata);
     412             : 
     413             :   /// \brief Converts \p CodeObjectMetadata to \p YamlString.
     414             :   static std::error_code toYamlString(Metadata CodeObjectMetadata,
     415             :                                       std::string &YamlString);
     416             : };
     417             : 
     418             : } // end namespace CodeObject
     419             : } // end namespace AMDGPU
     420             : } // end namespace llvm
     421             : 
     422             : #endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUCODEOBJECTMETADATA_H

Generated by: LCOV version 1.13