LLVM  14.0.0git
AMDKernelCodeTUtils.cpp
Go to the documentation of this file.
1 //===- AMDKernelCodeTUtils.cpp --------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file - utility functions to parse/print amd_kernel_code_t structure
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "AMDKernelCodeTUtils.h"
14 #include "AMDKernelCodeT.h"
15 #include "SIDefines.h"
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/ADT/StringRef.h"
22 
23 using namespace llvm;
24 
26  static StringRef const Table[] = {
27  "", // not found placeholder
28 #define RECORD(name, altName, print, parse) #name
29 #include "AMDKernelCodeTInfo.h"
30 #undef RECORD
31  };
32  return makeArrayRef(Table);
33 }
34 
36  static StringRef const Table[] = {
37  "", // not found placeholder
38 #define RECORD(name, altName, print, parse) #altName
39 #include "AMDKernelCodeTInfo.h"
40 #undef RECORD
41  };
42  return makeArrayRef(Table);
43 }
44 
46  const ArrayRef<StringRef> &altNames) {
47  StringMap<int> map;
48  assert(names.size() == altNames.size());
49  for (unsigned i = 0; i < names.size(); ++i) {
50  map.insert(std::make_pair(names[i], i));
51  map.insert(std::make_pair(altNames[i], i));
52  }
53  return map;
54 }
55 
57  static const auto map = createIndexMap(get_amd_kernel_code_t_FldNames(),
59  return map.lookup(name) - 1; // returns -1 if not found
60 }
61 
64 }
65 
66 // Field printing
67 
69  return OS << Name << " = ";
70 }
71 
72 template <typename T, T amd_kernel_code_t::*ptr>
74  raw_ostream &OS) {
75  printName(OS, Name) << (int)(C.*ptr);
76 }
77 
78 template <typename T, T amd_kernel_code_t::*ptr, int shift, int width = 1>
80  raw_ostream &OS) {
81  const auto Mask = (static_cast<T>(1) << width) - 1;
82  printName(OS, Name) << (int)((c.*ptr >> shift) & Mask);
83 }
84 
85 using PrintFx = void(*)(StringRef, const amd_kernel_code_t &, raw_ostream &);
86 
88  static const PrintFx Table[] = {
89 #define RECORD(name, altName, print, parse) print
90 #include "AMDKernelCodeTInfo.h"
91 #undef RECORD
92  };
93  return makeArrayRef(Table);
94 }
95 
97  int FldIndex,
98  raw_ostream &OS) {
99  auto Printer = getPrinterTable()[FldIndex];
100  if (Printer)
101  Printer(get_amd_kernel_code_t_FieldName(FldIndex), C, OS);
102 }
103 
105  raw_ostream &OS,
106  const char *tab) {
107  const int Size = getPrinterTable().size();
108  for (int i = 0; i < Size; ++i) {
109  OS << tab;
110  printAmdKernelCodeField(*C, i, OS);
111  OS << '\n';
112  }
113 }
114 
115 // Field parsing
116 
117 static bool expectAbsExpression(MCAsmParser &MCParser, int64_t &Value, raw_ostream& Err) {
118 
119  if (MCParser.getLexer().isNot(AsmToken::Equal)) {
120  Err << "expected '='";
121  return false;
122  }
123  MCParser.getLexer().Lex();
124 
125  if (MCParser.parseAbsoluteExpression(Value)) {
126  Err << "integer absolute expression expected";
127  return false;
128  }
129  return true;
130 }
131 
132 template <typename T, T amd_kernel_code_t::*ptr>
133 static bool parseField(amd_kernel_code_t &C, MCAsmParser &MCParser,
134  raw_ostream &Err) {
135  int64_t Value = 0;
136  if (!expectAbsExpression(MCParser, Value, Err))
137  return false;
138  C.*ptr = (T)Value;
139  return true;
140 }
141 
142 template <typename T, T amd_kernel_code_t::*ptr, int shift, int width = 1>
144  raw_ostream &Err) {
145  int64_t Value = 0;
146  if (!expectAbsExpression(MCParser, Value, Err))
147  return false;
148  const uint64_t Mask = ((UINT64_C(1) << width) - 1) << shift;
149  C.*ptr &= (T)~Mask;
150  C.*ptr |= (T)((Value << shift) & Mask);
151  return true;
152 }
153 
154 using ParseFx = bool(*)(amd_kernel_code_t &, MCAsmParser &MCParser,
155  raw_ostream &Err);
156 
158  static const ParseFx Table[] = {
159 #define RECORD(name, altName, print, parse) parse
160 #include "AMDKernelCodeTInfo.h"
161 #undef RECORD
162  };
163  return makeArrayRef(Table);
164 }
165 
167  MCAsmParser &MCParser,
169  raw_ostream &Err) {
170  const int Idx = get_amd_kernel_code_t_FieldIndex(ID);
171  if (Idx < 0) {
172  Err << "unexpected amd_kernel_code_t field name " << ID;
173  return false;
174  }
175  auto Parser = getParserTable()[Idx];
176  return Parser ? Parser(C, MCParser, Err) : false;
177 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
getParserTable
static ArrayRef< ParseFx > getParserTable()
Definition: AMDKernelCodeTUtils.cpp:157
i
i
Definition: README.txt:29
llvm::MCAsmParser
Generic assembler parser interface, for use by target specific assembly parsers.
Definition: MCAsmParser.h:124
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
PrintFx
void(*)(StringRef, const amd_kernel_code_t &, raw_ostream &) PrintFx
Definition: AMDKernelCodeTUtils.cpp:85
T
StringRef.h
llvm::dumpAmdKernelCode
void dumpAmdKernelCode(const amd_kernel_code_t *C, raw_ostream &OS, const char *tab)
Definition: AMDKernelCodeTUtils.cpp:104
parseBitField
static bool parseBitField(amd_kernel_code_t &C, MCAsmParser &MCParser, raw_ostream &Err)
Definition: AMDKernelCodeTUtils.cpp:143
llvm::MCAsmLexer::Lex
const AsmToken & Lex()
Consume the next token from the input stream and return it.
Definition: MCAsmLexer.h:81
MCAsmParser.h
llvm::BitmaskEnumDetail::Mask
std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::MCAsmParser::parseAbsoluteExpression
virtual bool parseAbsoluteExpression(int64_t &Res)=0
Parse an expression which must evaluate to an absolute value.
get_amd_kernel_code_t_FldNames
static ArrayRef< StringRef > get_amd_kernel_code_t_FldNames()
Definition: AMDKernelCodeTUtils.cpp:25
Printer
print alias Alias Set Printer
Definition: AliasSetTracker.cpp:762
printName
static raw_ostream & printName(raw_ostream &OS, StringRef Name)
Definition: AMDKernelCodeTUtils.cpp:68
ParseFx
bool(*)(amd_kernel_code_t &, MCAsmParser &MCParser, raw_ostream &Err) ParseFx
Definition: AMDKernelCodeTUtils.cpp:155
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
int
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
Definition: README.txt:536
llvm::StringMap::insert
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:274
createIndexMap
static StringMap< int > createIndexMap(const ArrayRef< StringRef > &names, const ArrayRef< StringRef > &altNames)
Definition: AMDKernelCodeTUtils.cpp:45
getPrinterTable
static ArrayRef< PrintFx > getPrinterTable()
Definition: AMDKernelCodeTUtils.cpp:87
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
StringMap.h
c
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int c
Definition: README.txt:418
llvm::StringMap< int >
llvm::AsmToken::Equal
@ Equal
Definition: MCAsmMacro.h:49
MCAsmLexer.h
index
splat index
Definition: README_ALTIVEC.txt:181
uint64_t
printBitField
static void printBitField(StringRef Name, const amd_kernel_code_t &c, raw_ostream &OS)
Definition: AMDKernelCodeTUtils.cpp:79
ArrayRef.h
AMDKernelCodeTUtils.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
printField
static void printField(StringRef Name, const amd_kernel_code_t &C, raw_ostream &OS)
Definition: AMDKernelCodeTUtils.cpp:73
amd_kernel_code_t
AMD Kernel Code Object (amd_kernel_code_t).
Definition: AMDKernelCodeT.h:526
get_amd_kernel_code_t_FldAltNames
static ArrayRef< StringRef > get_amd_kernel_code_t_FldAltNames()
Definition: AMDKernelCodeTUtils.cpp:35
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:78
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::printAmdKernelCodeField
void printAmdKernelCodeField(const amd_kernel_code_t &C, int FldIndex, raw_ostream &OS)
Definition: AMDKernelCodeTUtils.cpp:96
SIDefines.h
llvm::MCAsmLexer::isNot
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
Definition: MCAsmLexer.h:146
expectAbsExpression
static bool expectAbsExpression(MCAsmParser &MCParser, int64_t &Value, raw_ostream &Err)
Definition: AMDKernelCodeTUtils.cpp:117
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::MCAsmParser::getLexer
virtual MCAsmLexer & getLexer()=0
AMDKernelCodeT.h
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
parseField
static bool parseField(amd_kernel_code_t &C, MCAsmParser &MCParser, raw_ostream &Err)
Definition: AMDKernelCodeTUtils.cpp:133
shift
http eax xorl edx cl sete al setne dl sall eax sall edx But that requires good bit subreg support this might be better It s an extra shift
Definition: README.txt:30
get_amd_kernel_code_t_FieldName
static StringRef get_amd_kernel_code_t_FieldName(int index)
Definition: AMDKernelCodeTUtils.cpp:62
raw_ostream.h
get_amd_kernel_code_t_FieldIndex
static int get_amd_kernel_code_t_FieldIndex(StringRef name)
Definition: AMDKernelCodeTUtils.cpp:56
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::parseAmdKernelCodeField
bool parseAmdKernelCodeField(StringRef ID, MCAsmParser &Parser, amd_kernel_code_t &C, raw_ostream &Err)
Definition: AMDKernelCodeTUtils.cpp:166
AMDKernelCodeTInfo.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37