31 using namespace ::AMDGPU::RuntimeMD;
35 cl::desc(
"Dump AMDGPU runtime metadata"));
39 cl::desc(
"Check AMDGPU runtime metadata YAML parser"));
51 static void mapping(
IO &YamlIO, KernelArg::Metadata &
A) {
66 static const bool flow =
true;
70 static void mapping(
IO &YamlIO, Kernel::Metadata &K) {
83 static const bool flow =
true;
87 static void mapping(
IO &YamlIO, Program::Metadata &Prog) {
92 static const bool flow =
true;
101 std::vector<uint32_t> V;
202 KernelArg::Metadata Arg;
207 if (
auto PT = dyn_cast<PointerType>(T)) {
208 auto ET = PT->getElementType();
214 Arg.TypeName = TypeName;
221 TypeQual.split(SplitQ,
" ", -1,
false );
225 .Case(
"volatile", &Arg.IsVolatile)
226 .
Case(
"restrict", &Arg.IsRestrict)
227 .
Case(
"const", &Arg.IsConst)
228 .
Case(
"pipe", &Arg.IsPipe)
241 if (!AccQual.empty()) {
250 if (
auto *PT = dyn_cast<PointerType>(T)) {
252 PT->getAddressSpace()));
264 if (
auto MD = M.getNamedMetadata(
"opencl.ocl.version")) {
265 if (MD->getNumOperands() != 0) {
266 auto Node = MD->getOperand(0);
267 if (Node->getNumOperands() > 1) {
268 Kernel.Language =
"OpenCL C";
269 uint16_t Major = mdconst::extract<ConstantInt>(Node->getOperand(0))
271 uint16_t Minor = mdconst::extract<ConstantInt>(Node->getOperand(1))
273 Kernel.LanguageVersion.push_back(Major);
274 Kernel.LanguageVersion.push_back(Minor);
280 for (
auto &Arg : F.
args()) {
281 unsigned I = Arg.getArgNo();
282 Type *
T = Arg.getType();
284 "kernel_arg_type")->
getOperand(I))->getString();
286 "kernel_arg_base_type")->
getOperand(I))->getString();
288 if (
auto ArgNameMD = F.
getMetadata(
"kernel_arg_name"))
289 ArgName = cast<MDString>(ArgNameMD->getOperand(I))->getString();
291 "kernel_arg_type_qual")->
getOperand(I))->getString();
293 "kernel_arg_access_qual")->
getOperand(I))->getString();
300 .
Cases(
"image1d_t",
"image1d_array_t",
"image1d_buffer_t",
302 .
Cases(
"image2d_depth_t",
"image2d_array_depth_t",
303 "image2d_msaa_t",
"image2d_array_msaa_t",
305 .
Cases(
"image2d_array_msaa_depth_t",
"image3d_t",
313 BaseTypeName, TypeName, ArgName, TypeQual, AccQual));
334 if (
auto RWGS = F.
getMetadata(
"reqd_work_group_size"))
337 if (
auto WGSH = F.
getMetadata(
"work_group_size_hint"))
342 VTH->getOperand(0))->
getType(), mdconst::extract<ConstantInt>(
343 VTH->getOperand(1))->getZExtValue());
348 Program::Metadata::Metadata(
const std::string &YAML) {
353 std::string Program::Metadata::toYAML(
void) {
367 auto P = Program::Metadata::fromYAML(YAML);
369 llvm::errs() <<
"AMDGPU runtime metadata parser test "
370 << (YAML == S ?
"passes" :
"fails") <<
".\n";
372 llvm::errs() <<
"First output: " << YAML <<
'\n'
373 <<
"Second output: " << S <<
'\n';
378 Program::Metadata Prog;
384 for (
unsigned I = 0;
I < MD->getNumOperands(); ++
I) {
385 auto Node = MD->getOperand(
I);
386 if (Node->getNumOperands() > 0)
387 Prog.PrintfInfo.push_back(cast<MDString>(Node->getOperand(0))
394 if (!
F.getMetadata(
"kernel_arg_type"))
399 auto YAML = Prog.toYAML();
402 llvm::errs() <<
"AMDGPU runtime metadata:\n" << YAML <<
'\n';
static KernelArg::ValueType getRuntimeMDValueType(Type *Ty, StringRef TypeName)
A parsed version of the target data layout string in and methods for querying it. ...
Tracking metadata reference owned by Metadata.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void mapOptional(const char *Key, T &Val)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
A Module instance is used to store all the information related to an LLVM module. ...
2: 32-bit floating point type
unsigned getNumOperands() const
Return number of MDNode operands.
const char ArgIsVolatile[]
#define LLVM_YAML_IS_SEQUENCE_VECTOR(_type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence...
1: 16-bit floating point type
static IntegerType * getInt64Ty(LLVMContext &C)
Address space for local memory.
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
const char WorkGroupSizeHint[]
Type * getPointerElementType() const
StringRef getName() const
Return a constant reference to the value's name.
const uint8_t INVALID_ADDR_QUAL
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const char ReqdWorkGroupSize[]
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
Type * getVectorElementType() const
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
TypeID getTypeID() const
Return the type id for the type.
Type * getElementType() const
const uint8_t INVALID_ACC_QUAL
Address space for region memory.
11: Arbitrary bit width integers
A switch()-like statement whose cases are string literals.
iterator_range< iterator > functions()
The instances of the Type class are immutable: once they are created, they are never changed...
Address space for constant memory (VTX2)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const char ArgValueType[]
const unsigned char MDRevision
const uint32_t INVALID_KERNEL_INDEX
unsigned getIntegerBitWidth() const
Address space for flat memory.
The Output class is used to generate a yaml document from in-memory structs and vectors.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
static Kernel::Metadata getRuntimeMDForKernel(const Function &F)
const char ArgPointeeAlign[]
const char NoPartialWorkGroups[]
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
const MDOperand & getOperand(unsigned I) const
static void checkRuntimeMDYAMLString(const std::string &YAML)
This is the shared class of boolean and integer constants.
16: SIMD 'packed' format, or other vector type
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
const char ArgIsRestrict[]
Module.h This file contains the declarations for the Module class.
static KernelArg::AddressSpaceQualifer getRuntimeAddrSpace(AMDGPUAS::AddressSpaces A)
Class to represent vector types.
const unsigned char MDVersion
static KernelArg::Metadata getRuntimeMDForKernelArg(const DataLayout &DL, Type *T, KernelArg::Kind Kind, StringRef BaseTypeName="", StringRef TypeName="", StringRef ArgName="", StringRef TypeQual="", StringRef AccQual="")
unsigned getVectorNumElements() const
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Cases(const char(&S0)[N0], const char(&S1)[N1], const T &Value)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
std::string getRuntimeMDYAMLString(Module &M)
static std::string getOCLTypeName(Type *Ty, bool Signed)
static cl::opt< bool > CheckRuntimeMDParser("amdgpu-check-rtmd-parser", cl::Hidden, cl::desc("Check AMDGPU runtime metadata YAML parser"))
static std::vector< uint32_t > getThreeInt32(MDNode *Node)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const char LanguageVersion[]
op_range operands() const
3: 64-bit floating point type
#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(_type)
Utility for declaring that a std::vector of a particular type should be considered a YAML flow sequen...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Module * getParent()
Get the module that this global value is contained inside of...
StringRef - Represent a constant reference to a string, i.e.
void mapRequired(const char *Key, T &Val)
static cl::opt< bool > DumpRuntimeMD("amdgpu-dump-rtmd", cl::desc("Dump AMDGPU runtime metadata"))
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
iterator_range< arg_iterator > args()
Address space for global memory (RAT0, VTX0).