llvm.org GIT mirror llvm / b15c258
[MIRParser] Parse lane masks for register live-ins Differential Revision: https://reviews.llvm.org/D25530 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284052 91177308-0d34-0410-b5e6-96231b3b80d8 Krzysztof Parzyszek 4 years ago
5 changed file(s) with 87 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
423423 return C == 'H' || C == 'K' || C == 'L' || C == 'M';
424424 }
425425
426 static Cursor maybeLexHexFloatingPointLiteral(Cursor C, MIToken &Token) {
427 if (C.peek() != '0' || C.peek(1) != 'x')
428 return None;
429 Cursor Range = C;
430 C.advance(2); // Skip '0x'
431 if (isValidHexFloatingPointPrefix(C.peek()))
432 C.advance();
433 while (isxdigit(C.peek()))
434 C.advance();
435 Token.reset(MIToken::FloatingPointLiteral, Range.upto(C));
436 return C;
437 }
438
439426 static Cursor lexFloatingPointLiteral(Cursor Range, Cursor C, MIToken &Token) {
440427 C.advance();
441428 // Skip over [0-9]*([eE][-+]?[0-9]+)?
449436 C.advance();
450437 }
451438 Token.reset(MIToken::FloatingPointLiteral, Range.upto(C));
439 return C;
440 }
441
442 static Cursor maybeLexHexadecimalLiteral(Cursor C, MIToken &Token) {
443 if (C.peek() != '0' || (C.peek(1) != 'x' && C.peek(1) != 'X'))
444 return None;
445 Cursor Range = C;
446 C.advance(2);
447 unsigned PrefLen = 2;
448 if (isValidHexFloatingPointPrefix(C.peek())) {
449 C.advance();
450 PrefLen++;
451 }
452 while (isxdigit(C.peek()))
453 C.advance();
454 StringRef StrVal = Range.upto(C);
455 if (StrVal.size() <= PrefLen)
456 return None;
457 if (PrefLen == 2)
458 Token.reset(MIToken::HexLiteral, Range.upto(C));
459 else // It must be 3, which means that there was a floating-point prefix.
460 Token.reset(MIToken::FloatingPointLiteral, Range.upto(C));
452461 return C;
453462 }
454463
608617 return R.remaining();
609618 if (Cursor R = maybeLexExternalSymbol(C, Token, ErrorCallback))
610619 return R.remaining();
611 if (Cursor R = maybeLexHexFloatingPointLiteral(C, Token))
620 if (Cursor R = maybeLexHexadecimalLiteral(C, Token))
612621 return R.remaining();
613622 if (Cursor R = maybeLexNumericalLiteral(C, Token))
614623 return R.remaining();
117117 // Other tokens
118118 IntegerLiteral,
119119 FloatingPointLiteral,
120 HexLiteral,
120121 VirtualRegister,
121122 ConstantPoolItem,
122123 JumpTableIndex,
3535 #include "llvm/Target/TargetInstrInfo.h"
3636 #include "llvm/Target/TargetIntrinsicInfo.h"
3737 #include "llvm/Target/TargetSubtargetInfo.h"
38 #include
3839
3940 using namespace llvm;
4041
452453 unsigned Reg = 0;
453454 if (parseNamedRegister(Reg))
454455 return true;
455 MBB.addLiveIn(Reg);
456456 lex();
457 LaneBitmask Mask = ~LaneBitmask(0);
458 if (consumeIfPresent(MIToken::colon)) {
459 // Parse lane mask.
460 if (Token.isNot(MIToken::IntegerLiteral) &&
461 Token.isNot(MIToken::HexLiteral))
462 return error("expected a lane mask");
463 static_assert(sizeof(LaneBitmask) == sizeof(unsigned), "");
464 if (getUnsigned(Mask))
465 return error("invalid lane mask value");
466 lex();
467 }
468 MBB.addLiveIn(Reg, Mask);
457469 } while (consumeIfPresent(MIToken::comma));
458470 return false;
459471 }
11061118 bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) {
11071119 auto Loc = Token.location();
11081120 lex();
1109 if (Token.isNot(MIToken::FloatingPointLiteral))
1121 if (Token.isNot(MIToken::FloatingPointLiteral) &&
1122 Token.isNot(MIToken::HexLiteral))
11101123 return error("expected a floating point literal");
11111124 const Constant *C = nullptr;
11121125 if (parseIRConstant(Loc, C))
11161129 }
11171130
11181131 bool MIParser::getUnsigned(unsigned &Result) {
1119 assert(Token.hasIntegerValue() && "Expected a token with an integer value");
1120 const uint64_t Limit = uint64_t(std::numeric_limits::max()) + 1;
1121 uint64_t Val64 = Token.integerValue().getLimitedValue(Limit);
1122 if (Val64 == Limit)
1123 return error("expected 32-bit integer (too large)");
1124 Result = Val64;
1125 return false;
1132 if (Token.hasIntegerValue()) {
1133 const uint64_t Limit = uint64_t(std::numeric_limits::max()) + 1;
1134 uint64_t Val64 = Token.integerValue().getLimitedValue(Limit);
1135 if (Val64 == Limit)
1136 return error("expected 32-bit integer (too large)");
1137 Result = Val64;
1138 return false;
1139 }
1140 if (Token.is(MIToken::HexLiteral)) {
1141 StringRef S = Token.range();
1142 assert(S[0] == '0' && tolower(S[1]) == 'x');
1143 // This could be a floating point literal with a special prefix.
1144 if (!isxdigit(S[2]))
1145 return true;
1146 StringRef V = S.substr(2);
1147 unsigned BW = std::min(V.size()*4, 32);
1148 APInt A(BW, V, 16);
1149 APInt Limit = APInt(BW, std::numeric_limits::max());
1150 if (A.ugt(Limit))
1151 return error("expected 32-bit integer (too large)");
1152 Result = A.getZExtValue();
1153 return false;
1154 }
1155 return true;
11261156 }
11271157
11281158 bool MIParser::parseMBBReference(MachineBasicBlock *&MBB) {
498498 First = false;
499499 printReg(LI.PhysReg, OS, TRI);
500500 if (LI.LaneMask != ~0u)
501 OS << ':' << PrintLaneMask(LI.LaneMask);
501 OS << ":0x" << PrintLaneMask(LI.LaneMask);
502502 }
503503 OS << "\n";
504504 HasLineAttributes = true;
0 # RUN: llc -march=hexagon -run-pass none -o - %s | FileCheck %s
1 # Check that the MIR parser can parse lane masks in block liveins.
2
3 # CHECK-LABEL: name: foo
4 # CHECK: bb.0:
5 # CHECK: liveins: %d0:0x00000002, %d1, %d2:0x00000010
6
7 --- |
8 define void @foo() {
9 ret void
10 }
11 ...
12
13 ---
14 name: foo
15 tracksRegLiveness: true
16
17 body: |
18 bb.0:
19 liveins: %d0:0x00002, %d1, %d2:16
20 A2_nop
21 ...
22