37void LLLexer::Error(LocTy ErrorLoc,
const Twine &
Msg,
38 LLLexer::ErrorPriority Priority) {
39 if (Priority < ErrorInfo.Priority)
42 ErrorInfo.Priority = Priority;
57uint64_t LLLexer::atoull(
const char *Buffer,
const char *
End) {
59 for (; Buffer !=
End; Buffer++) {
60 uint64_t OldRes = Result;
62 Result += *Buffer-
'0';
63 if (Result < OldRes) {
64 LexError(
"constant bigger than 64 bits detected");
71uint64_t LLLexer::HexIntToVal(
const char *Buffer,
const char *
End) {
73 for (; Buffer !=
End; ++Buffer) {
78 if (Result < OldRes) {
79 LexError(
"constant bigger than 64 bits detected");
86void LLLexer::HexToIntPair(
const char *Buffer,
const char *
End,
89 if (
End - Buffer >= 16) {
90 for (
int i = 0; i < 16; i++, Buffer++) {
97 for (
int i = 0; i < 16 && Buffer !=
End; i++, Buffer++) {
102 LexError(
"constant bigger than 128 bits detected");
107void LLLexer::FP80HexToIntPair(
const char *Buffer,
const char *
End,
110 for (
int i=0; i<4 && Buffer !=
End; i++, Buffer++) {
116 for (
int i = 0; i < 16 && Buffer !=
End; i++, Buffer++) {
121 LexError(
"constant bigger than 128 bits detected");
127 if (Str.empty())
return;
129 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
131 for (
char *BIn = Buffer; BIn != EndBuffer; ) {
132 if (BIn[0] ==
'\\') {
133 if (BIn < EndBuffer-1 && BIn[1] ==
'\\') {
136 }
else if (BIn < EndBuffer-2 &&
137 isxdigit(
static_cast<unsigned char>(BIn[1])) &&
138 isxdigit(
static_cast<unsigned char>(BIn[2]))) {
149 Str.resize(BOut-Buffer);
154 return isalnum(
static_cast<unsigned char>(
C)) ||
C ==
'-' ||
C ==
'$' ||
155 C ==
'.' ||
C ==
'_';
161 if (CurPtr[0] ==
':')
return CurPtr+1;
173 : CurBuf(StartBuf), ErrorInfo(Err), SM(SM), Context(
C) {
174 CurPtr = CurBuf.begin();
177int LLLexer::getNextChar() {
178 char CurChar = *CurPtr++;
180 default:
return (
unsigned char)CurChar;
184 if (CurPtr-1 != CurBuf.
end())
199 int CurChar = getNextChar();
203 if (isalpha(
static_cast<unsigned char>(CurChar)) || CurChar ==
'_')
204 return LexIdentifier();
214 case '+':
return LexPositive();
215 case '@':
return LexAt();
216 case '$':
return LexDollar();
217 case '%':
return LexPercent();
218 case '"':
return LexQuote();
222 StrVal.assign(TokStart, CurPtr-1);
225 if (CurPtr[0] ==
'.' && CurPtr[1] ==
'.') {
233 case '!':
return LexExclaim();
238 case '#':
return LexHash();
239 case '0':
case '1':
case '2':
case '3':
case '4':
240 case '5':
case '6':
case '7':
case '8':
case '9':
242 return LexDigitOrNegative();
256 if (getNextChar() !=
'*')
265void LLLexer::SkipLineComment() {
267 if (CurPtr[0] ==
'\n' || CurPtr[0] ==
'\r' || getNextChar() == EOF)
274bool LLLexer::SkipCComment() {
276 int CurChar = getNextChar();
279 LexError(
"unterminated comment");
283 CurChar = getNextChar();
286 if (CurChar == EOF) {
287 LexError(
"unterminated comment");
305 StrVal.assign(TokStart, CurPtr - 1);
310 if (CurPtr[0] ==
'"') {
314 int CurChar = getNextChar();
316 if (CurChar == EOF) {
317 LexError(
"end of file in COMDAT variable name");
320 if (CurChar ==
'"') {
321 StrVal.assign(TokStart + 2, CurPtr - 1);
323 if (StringRef(StrVal).
contains(0)) {
324 LexError(
"NUL character is not allowed in names");
341 const char *
Start = CurPtr;
343 int CurChar = getNextChar();
345 if (CurChar == EOF) {
346 LexError(
"end of file in string constant");
349 if (CurChar ==
'"') {
350 StrVal.assign(Start, CurPtr-1);
358bool LLLexer::ReadVarName() {
359 const char *NameStart = CurPtr;
360 if (isalpha(
static_cast<unsigned char>(CurPtr[0])) ||
361 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
362 CurPtr[0] ==
'.' || CurPtr[0] ==
'_') {
364 while (isalnum(
static_cast<unsigned char>(CurPtr[0])) ||
365 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
366 CurPtr[0] ==
'.' || CurPtr[0] ==
'_')
369 StrVal.assign(NameStart, CurPtr);
378 if (!isdigit(
static_cast<unsigned char>(CurPtr[0])))
381 for (++CurPtr; isdigit(
static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
384 uint64_t Val = atoull(TokStart + 1, CurPtr);
385 if ((
unsigned)Val != Val)
386 LexError(
"invalid value number (too large)");
387 UIntVal = unsigned(Val);
393 if (CurPtr[0] ==
'"') {
397 int CurChar = getNextChar();
399 if (CurChar == EOF) {
400 LexError(
"end of file in global variable name");
403 if (CurChar ==
'"') {
404 StrVal.assign(TokStart+2, CurPtr-1);
406 if (StringRef(StrVal).
contains(0)) {
407 LexError(
"NUL character is not allowed in names");
420 return LexUIntID(
VarID);
439 if (CurPtr[0] ==
':') {
441 if (StringRef(StrVal).
contains(0)) {
442 LexError(
"NUL character is not allowed in names");
457 if (isalpha(
static_cast<unsigned char>(CurPtr[0])) ||
458 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
459 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\') {
461 while (isalnum(
static_cast<unsigned char>(CurPtr[0])) ||
462 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
463 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\')
466 StrVal.assign(TokStart+1, CurPtr);
485 if (isdigit(
static_cast<unsigned char>(CurPtr[0])))
499 const char *StartChar = CurPtr;
500 const char IntOrByteIdentifier = CurPtr[-1];
501 const char *IntOrByteEnd =
502 (IntOrByteIdentifier ==
'i' || IntOrByteIdentifier ==
'b') ?
nullptr
504 const char *KeywordEnd =
nullptr;
509 if (!IntOrByteEnd && !isdigit(
static_cast<unsigned char>(*CurPtr)))
510 IntOrByteEnd = CurPtr;
511 if (!KeywordEnd && !isalnum(
static_cast<unsigned char>(*CurPtr)) &&
518 if (!IgnoreColonInIdentifiers && *CurPtr ==
':') {
519 StrVal.assign(StartChar-1, CurPtr++);
526 IntOrByteEnd = CurPtr;
527 if (IntOrByteEnd != StartChar) {
528 CurPtr = IntOrByteEnd;
529 uint64_t NumBits = atoull(StartChar, CurPtr);
532 LexError(
"bitwidth for integer or byte type out of range");
535 if (IntOrByteIdentifier ==
'i')
544 if (!KeywordEnd) KeywordEnd = CurPtr;
547 StringRef
Keyword(StartChar, CurPtr - StartChar);
549#define KEYWORD(STR) \
551 if (Keyword == #STR) \
552 return lltok::kw_##STR; \
579 KEYWORD(externally_initialized);
647 KEYWORD(no_sanitize_hwaddress);
648 KEYWORD(sanitize_address_dyninit);
662 KEYWORD(aarch64_sve_vector_pcs);
663 KEYWORD(aarch64_sme_preservemost_from_x0);
664 KEYWORD(aarch64_sme_preservemost_from_x1);
665 KEYWORD(aarch64_sme_preservemost_from_x2);
696 KEYWORD(amdgpu_cs_chain_preserve);
699 KEYWORD(amdgpu_gfx_whole_wave);
702 KEYWORD(wasm_emscripten_invokecc);
706 KEYWORD(cheriot_compartmentcallcc);
707 KEYWORD(cheriot_compartmentcalleecc);
708 KEYWORD(cheriot_librarycallcc);
717#define GET_ATTR_NAMES
718#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
719 KEYWORD(DISPLAY_NAME);
720#include "llvm/IR/Attributes.inc"
733 KEYWORD(inaccessiblemem_or_argmemonly);
861 KEYWORD(typeCheckedLoadVCalls);
862 KEYWORD(typeTestAssumeConstVCalls);
863 KEYWORD(typeCheckedLoadConstVCalls);
868 KEYWORD(typeidCompatibleVTable);
909#define TYPEKEYWORD(STR, LLVMTY) \
911 if (Keyword == STR) { \
913 return lltok::Type; \
934#define INSTKEYWORD(STR, Enum) \
936 if (Keyword == #STR) { \
937 UIntVal = Instruction::Enum; \
938 return lltok::kw_##STR; \
1005#define DWKEYWORD(TYPE, TOKEN) \
1007 if (Keyword.starts_with("DW_" #TYPE "_")) { \
1008 StrVal.assign(Keyword.begin(), Keyword.end()); \
1009 return lltok::TOKEN; \
1016 DWKEYWORD(LLVM_LANG_DIALECT, DwarfLangDialect);
1022 DWKEYWORD(APPLE_ENUM_KIND, DwarfEnumKind);
1027#define DBGRECORDTYPEKEYWORD(STR) \
1029 if (Keyword == "dbg_" #STR) { \
1031 return lltok::DbgRecordType; \
1040#undef DBGRECORDTYPEKEYWORD
1042 if (
Keyword.starts_with(
"DIFlag")) {
1047 if (
Keyword.starts_with(
"DISPFlag")) {
1052 if (
Keyword.starts_with(
"CSK_")) {
1057 if (Keyword ==
"NoDebug" || Keyword ==
"FullDebug" ||
1058 Keyword ==
"LineTablesOnly" || Keyword ==
"DebugDirectivesOnly") {
1063 if (Keyword ==
"GNU" || Keyword ==
"Apple" || Keyword ==
"None" ||
1064 Keyword ==
"Default") {
1069 if (Keyword ==
"Binary" || Keyword ==
"Decimal" || Keyword ==
"Rational") {
1077 if ((TokStart[0] ==
'u' || TokStart[0] ==
's' || TokStart[0] ==
'f') &&
1078 TokStart[1] ==
'0' && TokStart[2] ==
'x' &&
1079 isxdigit(
static_cast<unsigned char>(TokStart[3]))) {
1080 bool IsFloatConst = TokStart[0] ==
'f';
1081 size_t Len = CurPtr - TokStart - 3;
1083 StringRef HexStr(TokStart + 3, Len);
1084 if (!
all_of(HexStr, isxdigit)) {
1086 CurPtr = TokStart + 3;
1089 APInt Tmp(Bits, HexStr, 16);
1090 uint32_t ActiveBits = Tmp.getActiveBits();
1091 if (!IsFloatConst && ActiveBits > 0 && ActiveBits < Bits)
1092 Tmp = Tmp.trunc(ActiveBits);
1093 APSIntVal =
APSInt(Tmp, TokStart[0] !=
's');
1098 if (TokStart[0] ==
'c' && TokStart[1] ==
'c') {
1099 CurPtr = TokStart+2;
1104 CurPtr = TokStart+1;
1118 CurPtr = TokStart + 2;
1121 if ((CurPtr[0] >=
'K' && CurPtr[0] <=
'M') || CurPtr[0] ==
'H' ||
1128 if (!isxdigit(
static_cast<unsigned char>(CurPtr[0]))) {
1130 CurPtr = TokStart+1;
1134 while (isxdigit(
static_cast<unsigned char>(CurPtr[0])))
1137 if (*CurPtr ==
'.') {
1139 return LexFloatStr();
1147 APInt(64, HexIntToVal(TokStart + 2, CurPtr)));
1157 FP80HexToIntPair(TokStart + 3, CurPtr, Pair);
1158 APSIntVal = APInt(80, Pair);
1162 HexToIntPair(TokStart + 3, CurPtr, Pair);
1163 APSIntVal = APInt(128, Pair);
1167 HexToIntPair(TokStart + 3, CurPtr, Pair);
1168 APSIntVal = APInt(128, Pair);
1171 uint64_t Val = HexIntToVal(TokStart + 3, CurPtr);
1173 LexError(
"hexadecimal constant too large for half (16-bit)");
1176 APSIntVal = APInt(16, Val);
1181 uint64_t Val = HexIntToVal(TokStart + 3, CurPtr);
1183 LexError(
"hexadecimal constant too large for bfloat (16-bit)");
1186 APSIntVal = APInt(16, Val);
1204 if (!isdigit(
static_cast<unsigned char>(TokStart[0])) &&
1205 !isdigit(
static_cast<unsigned char>(CurPtr[0]))) {
1208 StrVal.assign(TokStart,
End-1);
1215 return LexFloatStr();
1221 for (; isdigit(
static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
1225 if (isdigit(TokStart[0]) && CurPtr[0] ==
':') {
1226 uint64_t Val = atoull(TokStart, CurPtr);
1228 if ((
unsigned)Val != Val)
1229 LexError(
"invalid value number (too large)");
1230 UIntVal = unsigned(Val);
1237 StrVal.assign(TokStart,
End-1);
1245 if (CurPtr[0] !=
'.') {
1246 if (TokStart[0] ==
'0' && TokStart[1] ==
'x')
1248 if (TokStart[0] ==
'-' && TokStart[1] ==
'0' && TokStart[2] ==
'x')
1249 return LexFloatStr();
1251 APSIntVal =
APSInt(StringRef(TokStart, CurPtr - TokStart));
1258 while (isdigit(
static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1260 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
1261 if (isdigit(
static_cast<unsigned char>(CurPtr[1])) ||
1262 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
1263 isdigit(
static_cast<unsigned char>(CurPtr[2])))) {
1265 while (isdigit(
static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1269 StrVal.assign(TokStart, CurPtr - TokStart);
1279 if (!isdigit(
static_cast<unsigned char>(CurPtr[0])))
1280 return LexFloatStr();
1283 for (++CurPtr; isdigit(
static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
1288 if (CurPtr[0] ==
'x')
1289 return LexFloatStr();
1292 if (CurPtr[0] !=
'.') {
1293 CurPtr = TokStart + 1;
1300 while (isdigit(
static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1302 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
1303 if (isdigit(
static_cast<unsigned char>(CurPtr[1])) ||
1304 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
1305 isdigit(
static_cast<unsigned char>(CurPtr[2])))) {
1307 while (isdigit(
static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1311 StrVal.assign(TokStart, CurPtr - TokStart);
1325 if (*CurPtr ==
'-' || *CurPtr ==
'+')
1328 if (*CurPtr !=
'0') {
1330 const char *LabelStart = CurPtr;
1333 StringRef
Label(LabelStart, CurPtr - LabelStart);
1336 if (Label ==
"inf") {
1338 StrVal.assign(TokStart, CurPtr - TokStart);
1344 if (Label ==
"qnan") {
1345 StrVal = *TokStart ==
'-' ?
"-nan(0)" :
"nan(0)";
1350 if ((Label ==
"nan" || Label ==
"snan") && *CurPtr ==
'(') {
1351 const char *Payload = ++CurPtr;
1352 while (*CurPtr && *CurPtr !=
')')
1356 if (*CurPtr++ !=
')') {
1357 CurPtr = TokStart + 1;
1358 LexError(
"unclosed nan literal");
1362 StringRef PayloadStr(Payload, CurPtr - Payload);
1364 if (PayloadStr.consume_front(
"0x") && PayloadStr.getAsInteger(16, Val)) {
1365 StrVal.assign(TokStart, CurPtr - TokStart);
1368 if (StrVal[0] ==
'+')
1375 LexError(
"bad payload format for nan literal");
1376 CurPtr = TokStart + 1;
1381 if (*CurPtr++ !=
'x') {
1383 CurPtr = TokStart + 1;
1387 if (!isxdigit(
static_cast<unsigned char>(CurPtr[0]))) {
1389 CurPtr = TokStart + 1;
1393 while (isxdigit(
static_cast<unsigned char>(CurPtr[0])))
1396 if (*CurPtr !=
'.') {
1398 CurPtr = TokStart + 1;
1403 while (isxdigit(
static_cast<unsigned char>(CurPtr[0])))
1406 if (*CurPtr !=
'p' && *CurPtr !=
'P') {
1408 CurPtr = TokStart + 1;
1413 if (*CurPtr ==
'+' || *CurPtr ==
'-')
1415 while (isdigit(
static_cast<unsigned char>(CurPtr[0])))
1418 StrVal.assign(TokStart, CurPtr - TokStart);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Mark last scratch load
AMDGPU Register Bank Select
This file implements a class to represent arbitrary precision integral constant values and operations...
static void cleanup(BlockFrequencyInfoImplBase &BFI)
Clear all memory not needed downstream.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static void UnEscapeLexed(std::string &Str)
static const char * isLabelTail(const char *CurPtr)
isLabelTail - Return true if this pointer points to a valid end of a label.
#define DBGRECORDTYPEKEYWORD(STR)
static bool isLabelChar(char C)
isLabelChar - Return true for [-a-zA-Z$._0-9].
#define TYPEKEYWORD(STR, LLVMTY)
#define DWKEYWORD(TYPE, TOKEN)
#define INSTKEYWORD(STR, Enum)
static constexpr auto TAG
dot regions Print regions of function to dot true view regions View regions of function(with no function bodies)"
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
static uint64_t allOnes(unsigned int Count)
static const fltSemantics & IEEEdouble()
static LLVM_ABI ByteType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing a ByteType.
Lightweight error class with error context and mandatory checking.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
@ MIN_INT_BITS
Minimum number of bits that can be specified.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
LLVM_ABI void Warning(LocTy WarningLoc, const Twine &Msg) const
LLVM_ABI LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &, LLVMContext &C)
This is an important class for using LLVM in a threaded context.
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
static LLVM_ABI Type * getLabelTy(LLVMContext &C)
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
static LLVM_ABI Type * getX86_FP80Ty(LLVMContext &C)
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
std::tuple< const DIScope *, const DIScope *, const DILocalVariable * > VarID
A unique key that represents a debug variable.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
constexpr NextUseDistance min(NextUseDistance A, NextUseDistance B)
constexpr std::invoke_result_t< FnT, ArgsT... > invoke(FnT &&Fn, ArgsT &&...Args)
C++20 constexpr invoke.
static void assign(DXContainerYAML::SourceInfo::SectionHeader &Dst, const dxbc::SourceInfo::SectionHeader &Src)
LLVM_ABI FPClassTest fneg(FPClassTest Mask)
Return the test mask which returns true if the value's sign bit is flipped.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
constexpr NextUseDistance max(NextUseDistance A, NextUseDistance B)
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ FSub
Subtraction of floats.
@ Xor
Bitwise or logical XOR of integers.
@ And
Bitwise or logical AND of integers.
@ Sub
Subtraction of integers.
auto partition(R &&Range, UnaryPredicate P)
Provide wrappers to std::partition which take ranges instead of having to pass begin/end explicitly.
@ End
Run the machine verifier once, at the end of the pipeline.
LLVM_ABI Error write(DWPWriter &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue, raw_pwrite_stream *OS=nullptr)