Skip to content

[SPARC][IAS] Add named prefetch tag constants #94249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class SparcAsmParser : public MCTargetAsmParser {

ParseStatus parseASITag(OperandVector &Operands);

ParseStatus parsePrefetchTag(OperandVector &Operands);

template <TailRelocKind Kind>
ParseStatus parseTailRelocSym(OperandVector &Operands);

Expand Down Expand Up @@ -209,7 +211,8 @@ class SparcOperand : public MCParsedAsmOperand {
k_Immediate,
k_MemoryReg,
k_MemoryImm,
k_ASITag
k_ASITag,
k_PrefetchTag,
} Kind;

SMLoc StartLoc, EndLoc;
Expand Down Expand Up @@ -240,6 +243,7 @@ class SparcOperand : public MCParsedAsmOperand {
struct ImmOp Imm;
struct MemOp Mem;
unsigned ASI;
unsigned Prefetch;
};

public:
Expand All @@ -253,6 +257,7 @@ class SparcOperand : public MCParsedAsmOperand {
bool isMEMri() const { return Kind == k_MemoryImm; }
bool isMembarTag() const { return Kind == k_Immediate; }
bool isASITag() const { return Kind == k_ASITag; }
bool isPrefetchTag() const { return Kind == k_PrefetchTag; }
bool isTailRelocSym() const { return Kind == k_Immediate; }

bool isCallTarget() const {
Expand Down Expand Up @@ -337,6 +342,11 @@ class SparcOperand : public MCParsedAsmOperand {
return ASI;
}

unsigned getPrefetchTag() const {
assert((Kind == k_PrefetchTag) && "Invalid access!");
return Prefetch;
}

/// getStartLoc - Get the location of the first token of this operand.
SMLoc getStartLoc() const override {
return StartLoc;
Expand All @@ -360,6 +370,9 @@ class SparcOperand : public MCParsedAsmOperand {
case k_ASITag:
OS << "ASI tag: " << getASITag() << "\n";
break;
case k_PrefetchTag:
OS << "Prefetch tag: " << getPrefetchTag() << "\n";
break;
}
}

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

void addPrefetchTagOperands(MCInst &Inst, unsigned N) const {
assert(N == 1 && "Invalid number of operands!");
Inst.addOperand(MCOperand::createImm(getPrefetchTag()));
}

void addMembarTagOperands(MCInst &Inst, unsigned N) const {
assert(N == 1 && "Invalid number of operands!");
const MCExpr *Expr = getImm();
Expand Down Expand Up @@ -469,6 +487,15 @@ class SparcOperand : public MCParsedAsmOperand {
return Op;
}

static std::unique_ptr<SparcOperand> CreatePrefetchTag(unsigned Val, SMLoc S,
SMLoc E) {
auto Op = std::make_unique<SparcOperand>(k_PrefetchTag);
Op->Prefetch = Val;
Op->StartLoc = S;
Op->EndLoc = E;
return Op;
}

static bool MorphToIntPairReg(SparcOperand &Op) {
unsigned Reg = Op.getReg();
assert(Op.Reg.Kind == rk_IntReg);
Expand Down Expand Up @@ -1088,6 +1115,44 @@ ParseStatus SparcAsmParser::parseASITag(OperandVector &Operands) {
return ParseStatus::Success;
}

ParseStatus SparcAsmParser::parsePrefetchTag(OperandVector &Operands) {
SMLoc S = Parser.getTok().getLoc();
SMLoc E = Parser.getTok().getEndLoc();
int64_t PrefetchVal = 0;

switch (getLexer().getKind()) {
case AsmToken::LParen:
case AsmToken::Integer:
case AsmToken::Identifier:
case AsmToken::Plus:
case AsmToken::Minus:
case AsmToken::Tilde:
if (getParser().parseAbsoluteExpression(PrefetchVal) ||
!isUInt<5>(PrefetchVal))
return Error(S, "invalid prefetch number, must be between 0 and 31");
break;
case AsmToken::Hash: {
SMLoc TagStart = getLexer().peekTok(false).getLoc();
Parser.Lex(); // Eat the '#'.
const StringRef PrefetchName = Parser.getTok().getString();
const SparcPrefetchTag::PrefetchTag *PrefetchTag =
SparcPrefetchTag::lookupPrefetchTagByName(PrefetchName);
Parser.Lex(); // Eat the identifier token.

if (!PrefetchTag)
return Error(TagStart, "unknown prefetch tag");

PrefetchVal = PrefetchTag->Encoding;
break;
}
default:
return ParseStatus::NoMatch;
}

Operands.push_back(SparcOperand::CreatePrefetchTag(PrefetchVal, S, E));
return ParseStatus::Success;
}

ParseStatus SparcAsmParser::parseCallTarget(OperandVector &Operands) {
SMLoc S = Parser.getTok().getLoc();
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,14 @@ void SparcInstPrinter::printASITag(const MCInst *MI, int opNum,
else
O << Imm;
}

void SparcInstPrinter::printPrefetchTag(const MCInst *MI, int opNum,
const MCSubtargetInfo &STI,
raw_ostream &O) {
unsigned Imm = MI->getOperand(opNum).getImm();
auto PrefetchTag = SparcPrefetchTag::lookupPrefetchTagByEncoding(Imm);
if (PrefetchTag)
O << '#' << PrefetchTag->Name;
else
O << Imm;
}
2 changes: 2 additions & 0 deletions llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class SparcInstPrinter : public MCInstPrinter {
raw_ostream &O);
void printASITag(const MCInst *MI, int opNum, const MCSubtargetInfo &STI,
raw_ostream &O);
void printPrefetchTag(const MCInst *MI, int opNum, const MCSubtargetInfo &STI,
raw_ostream &O);
};
} // end namespace llvm

Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ namespace SparcASITag {
#define GET_ASITagsList_IMPL
#include "SparcGenSearchableTables.inc"
} // end namespace SparcASITag

namespace SparcPrefetchTag {
#define GET_PrefetchTagsList_IMPL
#include "SparcGenSearchableTables.inc"
} // end namespace SparcPrefetchTag
} // end namespace llvm

using namespace llvm;
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Target/Sparc/MCTargetDesc/SparcMCTargetDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ struct ASITag {
#define GET_ASITagsList_DECL
#include "SparcGenSearchableTables.inc"
} // end namespace SparcASITag

// Defines symbolic names for Sparc v9 prefetch tag names.
namespace SparcPrefetchTag {
struct PrefetchTag {
const char *Name;
unsigned Encoding;
};

#define GET_PrefetchTagsList_DECL
#include "SparcGenSearchableTables.inc"
} // end namespace SparcPrefetchTag
} // End llvm namespace

// Defines symbolic names for Sparc registers. This defines a mapping from
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/Sparc/Sparc.td
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//

include "llvm/Target/Target.td"
include "llvm/TableGen/SearchableTable.td"

//===----------------------------------------------------------------------===//
// SPARC Subtarget features.
Expand Down Expand Up @@ -91,6 +92,7 @@ foreach i = 0 ... 5 in
//===----------------------------------------------------------------------===//

include "SparcASITags.td"
include "SparcPrefetchTags.td"
include "SparcRegisterInfo.td"
include "SparcCallingConv.td"
include "SparcSchedule.td"
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/Sparc/SparcASITags.td
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
//
//===----------------------------------------------------------------------===//

include "llvm/TableGen/SearchableTable.td"

class ASITag<string name, string alt_name, bits<8> op> {
string Name = name;
// A maximum of one alias is supported right now.
Expand Down
14 changes: 12 additions & 2 deletions llvm/lib/Target/Sparc/SparcInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ def ASITag : Operand<i32> {
let ParserMatchClass = SparcASITagAsmOperand;
}

def SparcPrefetchTagAsmOperand : AsmOperandClass {
let Name = "PrefetchTag";
let ParserMethod = "parsePrefetchTag";
}

def PrefetchTag : Operand<i32> {
let PrintMethod = "printPrefetchTag";
let ParserMatchClass = SparcPrefetchTagAsmOperand;
}

// Branch targets have OtherVT type.
def brtarget : Operand<OtherVT> {
let EncoderMethod = "getBranchTargetOpValue";
Expand Down Expand Up @@ -1767,10 +1777,10 @@ let Predicates = [HasV9], rs1 = 0, rs2 = 0 in {
// Section A.42 - Prefetch Data
let Predicates = [HasV9] in {
def PREFETCHr : F3_1<3, 0b101101,
(outs), (ins (MEMrr $rs1, $rs2):$addr, shift_imm5:$rd),
(outs), (ins (MEMrr $rs1, $rs2):$addr, PrefetchTag:$rd),
"prefetch [$addr], $rd", []>;
def PREFETCHi : F3_2<3, 0b101101,
(outs), (ins (MEMri $rs1, $simm13):$addr, shift_imm5:$rd),
(outs), (ins (MEMri $rs1, $simm13):$addr, PrefetchTag:$rd),
"prefetch [$addr], $rd", []>;
}

Expand Down
41 changes: 41 additions & 0 deletions llvm/lib/Target/Sparc/SparcPrefetchTags.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===- SparcPrefetchTags.td --------------------------------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the symbolic operands permitted for various kinds of
// SPARCv9 prefetches.
//
//===----------------------------------------------------------------------===//

class PrefetchTag<string name, bits<8> op> {
string Name = name;
bits<8> Encoding = op;
}

def PrefetchTagsList : GenericTable {
let FilterClass = "PrefetchTag";
let Fields = ["Name", "Encoding"];

let PrimaryKey = [ "Encoding" ];
let PrimaryKeyName = "lookupPrefetchTagByEncoding";
}

def lookupPrefetchTagByName : SearchIndex {
let Table = PrefetchTagsList;
let Key = [ "Name" ];
}

def : PrefetchTag<"n_reads", 0x0>;
def : PrefetchTag<"one_read", 0x1>;
def : PrefetchTag<"n_writes", 0x2>;
def : PrefetchTag<"one_write", 0x3>;
def : PrefetchTag<"page", 0x4>;
def : PrefetchTag<"unified", 0x11>;
def : PrefetchTag<"n_reads_strong", 0x14>;
def : PrefetchTag<"one_read_strong", 0x15>;
def : PrefetchTag<"n_writes_strong", 0x16>;
def : PrefetchTag<"one_write_strong", 0x17>;
62 changes: 58 additions & 4 deletions llvm/test/MC/Disassembler/Sparc/sparc-v9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,65 @@
# CHECK: membar #LoadLoad | #StoreLoad | #LoadStore | #StoreStore | #Lookaside | #MemIssue | #Sync
0x81 0x43 0xe0 0x7f

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

# CHECK: prefetch [%i1+%i2], 1
0xc3,0x6e,0x40,0x1a
# CHECK: prefetch [%i1+3968], #one_read
0xc3 0x6e 0x6f 0x80

# CHECK: prefetch [%i1+3968], #n_writes
0xc5 0x6e 0x6f 0x80

# CHECK: prefetch [%i1+3968], #one_write
0xc7 0x6e 0x6f 0x80

# CHECK: prefetch [%i1+3968], #page
0xc9 0x6e 0x6f 0x80

# CHECK: prefetch [%i1+3968], #unified
0xe3 0x6e 0x6f 0x80

# CHECK: prefetch [%i1+3968], #n_reads_strong
0xe9 0x6e 0x6f 0x80

# CHECK: prefetch [%i1+3968], #one_read_strong
0xeb 0x6e 0x6f 0x80

# CHECK: prefetch [%i1+3968], #n_writes_strong
0xed 0x6e 0x6f 0x80

# CHECK: prefetch [%i1+3968], #one_write_strong
0xef 0x6e 0x6f 0x80

# CHECK: prefetch [%i1+%i2], #n_reads
0xc1 0x6e 0x40 0x1a

# CHECK: prefetch [%i1+%i2], #one_read
0xc3 0x6e 0x40 0x1a

# CHECK: prefetch [%i1+%i2], #n_writes
0xc5 0x6e 0x40 0x1a

# CHECK: prefetch [%i1+%i2], #one_write
0xc7 0x6e 0x40 0x1a

# CHECK: prefetch [%i1+%i2], #page
0xc9 0x6e 0x40 0x1a

# CHECK: prefetch [%i1+%i2], #unified
0xe3 0x6e 0x40 0x1a

# CHECK: prefetch [%i1+%i2], #n_reads_strong
0xe9 0x6e 0x40 0x1a

# CHECK: prefetch [%i1+%i2], #one_read_strong
0xeb 0x6e 0x40 0x1a

# CHECK: prefetch [%i1+%i2], #n_writes_strong
0xed 0x6e 0x40 0x1a

# CHECK: prefetch [%i1+%i2], #one_write_strong
0xef 0x6e 0x40 0x1a

# CHECK: done
0x81,0xf0,0x00,0x00
Expand Down
Loading
Loading