Skip to content

Commit 2388129

Browse files
authored
[SPARC][IAS] Add named prefetch tag constants
This adds named tag constants (such as `#one_write` and `#one_read`) for the prefetch instruction. Reviewers: jrtc27, rorth, brad0, s-barannikov Reviewed By: s-barannikov Pull Request: #94249
1 parent cc19374 commit 2388129

File tree

11 files changed

+312
-13
lines changed

11 files changed

+312
-13
lines changed

llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class SparcAsmParser : public MCTargetAsmParser {
9191

9292
ParseStatus parseASITag(OperandVector &Operands);
9393

94+
ParseStatus parsePrefetchTag(OperandVector &Operands);
95+
9496
template <TailRelocKind Kind>
9597
ParseStatus parseTailRelocSym(OperandVector &Operands);
9698

@@ -209,7 +211,8 @@ class SparcOperand : public MCParsedAsmOperand {
209211
k_Immediate,
210212
k_MemoryReg,
211213
k_MemoryImm,
212-
k_ASITag
214+
k_ASITag,
215+
k_PrefetchTag,
213216
} Kind;
214217

215218
SMLoc StartLoc, EndLoc;
@@ -240,6 +243,7 @@ class SparcOperand : public MCParsedAsmOperand {
240243
struct ImmOp Imm;
241244
struct MemOp Mem;
242245
unsigned ASI;
246+
unsigned Prefetch;
243247
};
244248

245249
public:
@@ -253,6 +257,7 @@ class SparcOperand : public MCParsedAsmOperand {
253257
bool isMEMri() const { return Kind == k_MemoryImm; }
254258
bool isMembarTag() const { return Kind == k_Immediate; }
255259
bool isASITag() const { return Kind == k_ASITag; }
260+
bool isPrefetchTag() const { return Kind == k_PrefetchTag; }
256261
bool isTailRelocSym() const { return Kind == k_Immediate; }
257262

258263
bool isCallTarget() const {
@@ -337,6 +342,11 @@ class SparcOperand : public MCParsedAsmOperand {
337342
return ASI;
338343
}
339344

345+
unsigned getPrefetchTag() const {
346+
assert((Kind == k_PrefetchTag) && "Invalid access!");
347+
return Prefetch;
348+
}
349+
340350
/// getStartLoc - Get the location of the first token of this operand.
341351
SMLoc getStartLoc() const override {
342352
return StartLoc;
@@ -360,6 +370,9 @@ class SparcOperand : public MCParsedAsmOperand {
360370
case k_ASITag:
361371
OS << "ASI tag: " << getASITag() << "\n";
362372
break;
373+
case k_PrefetchTag:
374+
OS << "Prefetch tag: " << getPrefetchTag() << "\n";
375+
break;
363376
}
364377
}
365378

@@ -416,6 +429,11 @@ class SparcOperand : public MCParsedAsmOperand {
416429
Inst.addOperand(MCOperand::createImm(getASITag()));
417430
}
418431

432+
void addPrefetchTagOperands(MCInst &Inst, unsigned N) const {
433+
assert(N == 1 && "Invalid number of operands!");
434+
Inst.addOperand(MCOperand::createImm(getPrefetchTag()));
435+
}
436+
419437
void addMembarTagOperands(MCInst &Inst, unsigned N) const {
420438
assert(N == 1 && "Invalid number of operands!");
421439
const MCExpr *Expr = getImm();
@@ -469,6 +487,15 @@ class SparcOperand : public MCParsedAsmOperand {
469487
return Op;
470488
}
471489

490+
static std::unique_ptr<SparcOperand> CreatePrefetchTag(unsigned Val, SMLoc S,
491+
SMLoc E) {
492+
auto Op = std::make_unique<SparcOperand>(k_PrefetchTag);
493+
Op->Prefetch = Val;
494+
Op->StartLoc = S;
495+
Op->EndLoc = E;
496+
return Op;
497+
}
498+
472499
static bool MorphToIntPairReg(SparcOperand &Op) {
473500
unsigned Reg = Op.getReg();
474501
assert(Op.Reg.Kind == rk_IntReg);
@@ -1088,6 +1115,44 @@ ParseStatus SparcAsmParser::parseASITag(OperandVector &Operands) {
10881115
return ParseStatus::Success;
10891116
}
10901117

1118+
ParseStatus SparcAsmParser::parsePrefetchTag(OperandVector &Operands) {
1119+
SMLoc S = Parser.getTok().getLoc();
1120+
SMLoc E = Parser.getTok().getEndLoc();
1121+
int64_t PrefetchVal = 0;
1122+
1123+
switch (getLexer().getKind()) {
1124+
case AsmToken::LParen:
1125+
case AsmToken::Integer:
1126+
case AsmToken::Identifier:
1127+
case AsmToken::Plus:
1128+
case AsmToken::Minus:
1129+
case AsmToken::Tilde:
1130+
if (getParser().parseAbsoluteExpression(PrefetchVal) ||
1131+
!isUInt<5>(PrefetchVal))
1132+
return Error(S, "invalid prefetch number, must be between 0 and 31");
1133+
break;
1134+
case AsmToken::Hash: {
1135+
SMLoc TagStart = getLexer().peekTok(false).getLoc();
1136+
Parser.Lex(); // Eat the '#'.
1137+
const StringRef PrefetchName = Parser.getTok().getString();
1138+
const SparcPrefetchTag::PrefetchTag *PrefetchTag =
1139+
SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);
1140+
Parser.Lex(); // Eat the identifier token.
1141+
1142+
if (!PrefetchTag)
1143+
return Error(TagStart, "unknown prefetch tag");
1144+
1145+
PrefetchVal = PrefetchTag->Encoding;
1146+
break;
1147+
}
1148+
default:
1149+
return ParseStatus::NoMatch;
1150+
}
1151+
1152+
Operands.push_back(SparcOperand::CreatePrefetchTag(PrefetchVal, S, E));
1153+
return ParseStatus::Success;
1154+
}
1155+
10911156
ParseStatus SparcAsmParser::parseCallTarget(OperandVector &Operands) {
10921157
SMLoc S = Parser.getTok().getLoc();
10931158
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);

llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,14 @@ void SparcInstPrinter::printASITag(const MCInst *MI, int opNum,
253253
else
254254
O << Imm;
255255
}
256+
257+
void SparcInstPrinter::printPrefetchTag(const MCInst *MI, int opNum,
258+
const MCSubtargetInfo &STI,
259+
raw_ostream &O) {
260+
unsigned Imm = MI->getOperand(opNum).getImm();
261+
auto PrefetchTag = SparcPrefetchTag::lookupPrefetchTagByEncoding(Imm);
262+
if (PrefetchTag)
263+
O << '#' << PrefetchTag->Name;
264+
else
265+
O << Imm;
266+
}

llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class SparcInstPrinter : public MCInstPrinter {
5656
raw_ostream &O);
5757
void printASITag(const MCInst *MI, int opNum, const MCSubtargetInfo &STI,
5858
raw_ostream &O);
59+
void printPrefetchTag(const MCInst *MI, int opNum, const MCSubtargetInfo &STI,
60+
raw_ostream &O);
5961
};
6062
} // end namespace llvm
6163

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ namespace SparcASITag {
2626
#define GET_ASITagsList_IMPL
2727
#include "SparcGenSearchableTables.inc"
2828
} // end namespace SparcASITag
29+
30+
namespace SparcPrefetchTag {
31+
#define GET_PrefetchTagsList_IMPL
32+
#include "SparcGenSearchableTables.inc"
33+
} // end namespace SparcPrefetchTag
2934
} // end namespace llvm
3035

3136
using namespace llvm;

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ struct ASITag {
4848
#define GET_ASITagsList_DECL
4949
#include "SparcGenSearchableTables.inc"
5050
} // end namespace SparcASITag
51+
52+
// Defines symbolic names for Sparc v9 prefetch tag names.
53+
namespace SparcPrefetchTag {
54+
struct PrefetchTag {
55+
const char *Name;
56+
unsigned Encoding;
57+
};
58+
59+
#define GET_PrefetchTagsList_DECL
60+
#include "SparcGenSearchableTables.inc"
61+
} // end namespace SparcPrefetchTag
5162
} // End llvm namespace
5263

5364
// Defines symbolic names for Sparc registers. This defines a mapping from

llvm/lib/Target/Sparc/Sparc.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
include "llvm/Target/Target.td"
17+
include "llvm/TableGen/SearchableTable.td"
1718

1819
//===----------------------------------------------------------------------===//
1920
// SPARC Subtarget features.
@@ -91,6 +92,7 @@ foreach i = 0 ... 5 in
9192
//===----------------------------------------------------------------------===//
9293

9394
include "SparcASITags.td"
95+
include "SparcPrefetchTags.td"
9496
include "SparcRegisterInfo.td"
9597
include "SparcCallingConv.td"
9698
include "SparcSchedule.td"

llvm/lib/Target/Sparc/SparcASITags.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
include "llvm/TableGen/SearchableTable.td"
15-
1614
class ASITag<string name, string alt_name, bits<8> op> {
1715
string Name = name;
1816
// A maximum of one alias is supported right now.

llvm/lib/Target/Sparc/SparcInstrInfo.td

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ def ASITag : Operand<i32> {
197197
let ParserMatchClass = SparcASITagAsmOperand;
198198
}
199199

200+
def SparcPrefetchTagAsmOperand : AsmOperandClass {
201+
let Name = "PrefetchTag";
202+
let ParserMethod = "parsePrefetchTag";
203+
}
204+
205+
def PrefetchTag : Operand<i32> {
206+
let PrintMethod = "printPrefetchTag";
207+
let ParserMatchClass = SparcPrefetchTagAsmOperand;
208+
}
209+
200210
// Branch targets have OtherVT type.
201211
def brtarget : Operand<OtherVT> {
202212
let EncoderMethod = "getBranchTargetOpValue";
@@ -1767,10 +1777,10 @@ let Predicates = [HasV9], rs1 = 0, rs2 = 0 in {
17671777
// Section A.42 - Prefetch Data
17681778
let Predicates = [HasV9] in {
17691779
def PREFETCHr : F3_1<3, 0b101101,
1770-
(outs), (ins (MEMrr $rs1, $rs2):$addr, shift_imm5:$rd),
1780+
(outs), (ins (MEMrr $rs1, $rs2):$addr, PrefetchTag:$rd),
17711781
"prefetch [$addr], $rd", []>;
17721782
def PREFETCHi : F3_2<3, 0b101101,
1773-
(outs), (ins (MEMri $rs1, $simm13):$addr, shift_imm5:$rd),
1783+
(outs), (ins (MEMri $rs1, $simm13):$addr, PrefetchTag:$rd),
17741784
"prefetch [$addr], $rd", []>;
17751785
}
17761786

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===- SparcPrefetchTags.td --------------------------------*- tablegen -*-===//
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+
// This file defines the symbolic operands permitted for various kinds of
10+
// SPARCv9 prefetches.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
class PrefetchTag<string name, bits<8> op> {
15+
string Name = name;
16+
bits<8> Encoding = op;
17+
}
18+
19+
def PrefetchTagsList : GenericTable {
20+
let FilterClass = "PrefetchTag";
21+
let Fields = ["Name", "Encoding"];
22+
23+
let PrimaryKey = [ "Encoding" ];
24+
let PrimaryKeyName = "lookupPrefetchTagByEncoding";
25+
}
26+
27+
def lookupPrefetchTagByName : SearchIndex {
28+
let Table = PrefetchTagsList;
29+
let Key = [ "Name" ];
30+
}
31+
32+
def : PrefetchTag<"n_reads", 0x0>;
33+
def : PrefetchTag<"one_read", 0x1>;
34+
def : PrefetchTag<"n_writes", 0x2>;
35+
def : PrefetchTag<"one_write", 0x3>;
36+
def : PrefetchTag<"page", 0x4>;
37+
def : PrefetchTag<"unified", 0x11>;
38+
def : PrefetchTag<"n_reads_strong", 0x14>;
39+
def : PrefetchTag<"one_read_strong", 0x15>;
40+
def : PrefetchTag<"n_writes_strong", 0x16>;
41+
def : PrefetchTag<"one_write_strong", 0x17>;

llvm/test/MC/Disassembler/Sparc/sparc-v9.txt

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,65 @@
132132
# CHECK: membar #LoadLoad | #StoreLoad | #LoadStore | #StoreStore | #Lookaside | #MemIssue | #Sync
133133
0x81 0x43 0xe0 0x7f
134134

135-
# CHECK: prefetch [%i1+3968], 1
136-
0xc3,0x6e,0x6f,0x80
135+
# CHECK: prefetch [%i1+3968], #n_reads
136+
0xc1 0x6e 0x6f 0x80
137137

138-
# CHECK: prefetch [%i1+%i2], 1
139-
0xc3,0x6e,0x40,0x1a
138+
# CHECK: prefetch [%i1+3968], #one_read
139+
0xc3 0x6e 0x6f 0x80
140+
141+
# CHECK: prefetch [%i1+3968], #n_writes
142+
0xc5 0x6e 0x6f 0x80
143+
144+
# CHECK: prefetch [%i1+3968], #one_write
145+
0xc7 0x6e 0x6f 0x80
146+
147+
# CHECK: prefetch [%i1+3968], #page
148+
0xc9 0x6e 0x6f 0x80
149+
150+
# CHECK: prefetch [%i1+3968], #unified
151+
0xe3 0x6e 0x6f 0x80
152+
153+
# CHECK: prefetch [%i1+3968], #n_reads_strong
154+
0xe9 0x6e 0x6f 0x80
155+
156+
# CHECK: prefetch [%i1+3968], #one_read_strong
157+
0xeb 0x6e 0x6f 0x80
158+
159+
# CHECK: prefetch [%i1+3968], #n_writes_strong
160+
0xed 0x6e 0x6f 0x80
161+
162+
# CHECK: prefetch [%i1+3968], #one_write_strong
163+
0xef 0x6e 0x6f 0x80
164+
165+
# CHECK: prefetch [%i1+%i2], #n_reads
166+
0xc1 0x6e 0x40 0x1a
167+
168+
# CHECK: prefetch [%i1+%i2], #one_read
169+
0xc3 0x6e 0x40 0x1a
170+
171+
# CHECK: prefetch [%i1+%i2], #n_writes
172+
0xc5 0x6e 0x40 0x1a
173+
174+
# CHECK: prefetch [%i1+%i2], #one_write
175+
0xc7 0x6e 0x40 0x1a
176+
177+
# CHECK: prefetch [%i1+%i2], #page
178+
0xc9 0x6e 0x40 0x1a
179+
180+
# CHECK: prefetch [%i1+%i2], #unified
181+
0xe3 0x6e 0x40 0x1a
182+
183+
# CHECK: prefetch [%i1+%i2], #n_reads_strong
184+
0xe9 0x6e 0x40 0x1a
185+
186+
# CHECK: prefetch [%i1+%i2], #one_read_strong
187+
0xeb 0x6e 0x40 0x1a
188+
189+
# CHECK: prefetch [%i1+%i2], #n_writes_strong
190+
0xed 0x6e 0x40 0x1a
191+
192+
# CHECK: prefetch [%i1+%i2], #one_write_strong
193+
0xef 0x6e 0x40 0x1a
140194

141195
# CHECK: done
142196
0x81,0xf0,0x00,0x00

0 commit comments

Comments
 (0)