Skip to content

Commit a2b48fb

Browse files
nvjleLucasSte
authored andcommitted
[SOL] Remove now obsolete old syntax bits. (#72)
Patch #54 originally reworked the SBF textual assembly syntax to match the rbpf-style syntax. In order to allow some soak-time, the above patch temporarily supported both the old and new syntax (selectable on the command line or via bespoke assembler directives). A little over a year has passed since then, and all is well with the new syntax, testing, and so forth. The current patch now removes all existing remnants of the old syntax-- including some of the target-independent changes made in the original patch to support both (e.g., a minor TableGen change for variants, some additional command line selector flags, etc). All related unit tests have been updated accordingly.
1 parent 868bbfd commit a2b48fb

24 files changed

+407
-1181
lines changed

llvm/lib/Target/SBF/AsmParser/SBFAsmParser.cpp

+2-190
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ class SBFAsmParser : public MCTargetAsmParser {
3333

3434
SMLoc getLoc() const { return getParser().getTok().getLoc(); }
3535

36-
bool isNewSyntax() {
37-
return getParser().getAssemblerDialect() == 0;
38-
}
39-
40-
bool PreMatchCheck(OperandVector &Operands);
41-
4236
bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
4337
OperandVector &Operands, MCStreamer &Out,
4438
uint64_t &ErrorInfo,
@@ -52,25 +46,14 @@ class SBFAsmParser : public MCTargetAsmParser {
5246
bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5347
SMLoc NameLoc, OperandVector &Operands) override;
5448

55-
bool parseOldInstruction(ParseInstructionInfo &Info, StringRef Name,
56-
SMLoc NameLoc, OperandVector &Operands);
57-
5849
bool ParseDirective(AsmToken DirectiveID) override;
5950

60-
// "=" is used as assignment operator for assembly statement, so can't be used
61-
// for symbol assignment (old syntax only).
62-
bool equalIsAsmAssignment() override { return isNewSyntax(); }
63-
// "*" is used for dereferencing memory that it will be the start of
64-
// statement (old syntax only).
65-
bool starIsStartOfStatement() override { return !isNewSyntax(); }
66-
6751
#define GET_ASSEMBLER_HEADER
6852
#include "SBFGenAsmMatcher.inc"
6953

7054
bool parseOperand(OperandVector &Operands, StringRef Mnemonic);
7155
OperandMatchResultTy parseImmediate(OperandVector &Operands);
7256
OperandMatchResultTy parseRegister(OperandVector &Operands);
73-
OperandMatchResultTy parseOperandAsOperator(OperandVector &Operands);
7457
OperandMatchResultTy parseMemOperand(OperandVector &Operands);
7558

7659
public:
@@ -280,45 +263,14 @@ struct SBFOperand : public MCParsedAsmOperand {
280263
#define GET_MATCHER_IMPLEMENTATION
281264
#include "SBFGenAsmMatcher.inc"
282265

283-
bool SBFAsmParser::PreMatchCheck(OperandVector &Operands) {
284-
285-
// These checks not needed for the new syntax.
286-
if (isNewSyntax())
287-
return false;
288-
289-
if (Operands.size() == 4) {
290-
// check "reg1 = -reg2" and "reg1 = be16/be32/be64/le16/le32/le64 reg2",
291-
// reg1 must be the same as reg2
292-
SBFOperand &Op0 = (SBFOperand &)*Operands[0];
293-
SBFOperand &Op1 = (SBFOperand &)*Operands[1];
294-
SBFOperand &Op2 = (SBFOperand &)*Operands[2];
295-
SBFOperand &Op3 = (SBFOperand &)*Operands[3];
296-
if (Op0.isReg() && Op1.isToken() && Op2.isToken() && Op3.isReg()
297-
&& Op1.getToken() == "="
298-
&& (Op2.getToken() == "-" || Op2.getToken() == "be16"
299-
|| Op2.getToken() == "be32" || Op2.getToken() == "be64"
300-
|| Op2.getToken() == "le16" || Op2.getToken() == "le32"
301-
|| Op2.getToken() == "le64")
302-
&& Op0.getReg() != Op3.getReg())
303-
return true;
304-
}
305-
306-
return false;
307-
}
308-
309266
bool SBFAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
310267
OperandVector &Operands,
311268
MCStreamer &Out, uint64_t &ErrorInfo,
312269
bool MatchingInlineAsm) {
313270
MCInst Inst;
314271
SMLoc ErrorLoc;
315272

316-
if (PreMatchCheck(Operands))
317-
return Error(IDLoc, "additional inst constraint not met");
318-
319-
unsigned Dialect = getParser().getAssemblerDialect();
320-
switch (MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm,
321-
Dialect)) {
273+
switch (MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
322274
default:
323275
break;
324276
case Match_Success:
@@ -372,75 +324,6 @@ OperandMatchResultTy SBFAsmParser::tryParseRegister(MCRegister &Reg,
372324
return MatchOperand_NoMatch;
373325
}
374326

375-
OperandMatchResultTy
376-
SBFAsmParser::parseOperandAsOperator(OperandVector &Operands) {
377-
if (isNewSyntax())
378-
llvm_unreachable("parseOperandAsOperator called for new syntax");
379-
380-
SMLoc S = getLoc();
381-
382-
if (getLexer().getKind() == AsmToken::Identifier) {
383-
StringRef Name = getLexer().getTok().getIdentifier();
384-
385-
if (SBFOperand::isValidIdInMiddle(Name)) {
386-
getLexer().Lex();
387-
Operands.push_back(SBFOperand::createToken(Name, S));
388-
return MatchOperand_Success;
389-
}
390-
391-
return MatchOperand_NoMatch;
392-
}
393-
394-
switch (getLexer().getKind()) {
395-
case AsmToken::Minus:
396-
case AsmToken::Plus: {
397-
if (getLexer().peekTok().is(AsmToken::Integer))
398-
return MatchOperand_NoMatch;
399-
[[fallthrough]];
400-
}
401-
402-
case AsmToken::Equal:
403-
case AsmToken::Greater:
404-
case AsmToken::Less:
405-
case AsmToken::Pipe:
406-
case AsmToken::Star:
407-
case AsmToken::LParen:
408-
case AsmToken::RParen:
409-
case AsmToken::LBrac:
410-
case AsmToken::RBrac:
411-
case AsmToken::Slash:
412-
case AsmToken::Amp:
413-
case AsmToken::Percent:
414-
case AsmToken::Caret: {
415-
StringRef Name = getLexer().getTok().getString();
416-
getLexer().Lex();
417-
Operands.push_back(SBFOperand::createToken(Name, S));
418-
419-
return MatchOperand_Success;
420-
}
421-
422-
case AsmToken::EqualEqual:
423-
case AsmToken::ExclaimEqual:
424-
case AsmToken::GreaterEqual:
425-
case AsmToken::GreaterGreater:
426-
case AsmToken::LessEqual:
427-
case AsmToken::LessLess: {
428-
Operands.push_back(SBFOperand::createToken(
429-
getLexer().getTok().getString().substr(0, 1), S));
430-
Operands.push_back(SBFOperand::createToken(
431-
getLexer().getTok().getString().substr(1, 1), S));
432-
getLexer().Lex();
433-
434-
return MatchOperand_Success;
435-
}
436-
437-
default:
438-
break;
439-
}
440-
441-
return MatchOperand_NoMatch;
442-
}
443-
444327
OperandMatchResultTy SBFAsmParser::parseRegister(OperandVector &Operands) {
445328
SMLoc S = getLoc();
446329
SMLoc E = SMLoc::getFromPointer(S.getPointer() - 1);
@@ -519,9 +402,6 @@ OperandMatchResultTy SBFAsmParser::parseMemOperand(OperandVector &Operands) {
519402
/// information, adding to Operands. If operand was parsed, returns false, else
520403
/// true.
521404
bool SBFAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
522-
if (!isNewSyntax())
523-
llvm_unreachable("parseOperand called for old syntax");
524-
525405
// Attempt to parse token as a register.
526406
if (parseRegister(Operands) == MatchOperand_Success)
527407
return false;
@@ -544,10 +424,6 @@ bool SBFAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
544424
/// Parse an SBF instruction.
545425
bool SBFAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
546426
SMLoc NameLoc, OperandVector &Operands) {
547-
if (!isNewSyntax()) {
548-
return parseOldInstruction(Info, Name, NameLoc, Operands);
549-
}
550-
551427
// First operand is token for instruction mnemonic.
552428
Operands.push_back(SBFOperand::createToken(Name, NameLoc));
553429

@@ -581,71 +457,7 @@ bool SBFAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
581457
return false;
582458
}
583459

584-
/// Parse an SBF instruction which is in SBF verifier format (old syntax).
585-
bool SBFAsmParser::parseOldInstruction(ParseInstructionInfo &Info,
586-
StringRef Name, SMLoc NameLoc,
587-
OperandVector &Operands) {
588-
if (isNewSyntax())
589-
llvm_unreachable("parseOldInstruction called for new syntax");
590-
591-
// The first operand could be either register or actually an operator.
592-
unsigned RegNo = MatchRegisterName(Name);
593-
594-
if (RegNo != 0) {
595-
SMLoc E = SMLoc::getFromPointer(NameLoc.getPointer() - 1);
596-
Operands.push_back(SBFOperand::createReg(RegNo, NameLoc, E));
597-
} else if (SBFOperand::isValidIdAtStart (Name))
598-
Operands.push_back(SBFOperand::createToken(Name, NameLoc));
599-
else
600-
return Error(NameLoc, "invalid register/token name");
601-
602-
while (!getLexer().is(AsmToken::EndOfStatement)) {
603-
// Attempt to parse token as operator
604-
if (parseOperandAsOperator(Operands) == MatchOperand_Success)
605-
continue;
606-
607-
// Attempt to parse token as register
608-
if (parseRegister(Operands) == MatchOperand_Success)
609-
continue;
610-
611-
// Attempt to parse token as an immediate
612-
if (parseImmediate(Operands) != MatchOperand_Success) {
613-
SMLoc Loc = getLexer().getLoc();
614-
return Error(Loc, "unexpected token");
615-
}
616-
}
617-
618-
if (getLexer().isNot(AsmToken::EndOfStatement)) {
619-
SMLoc Loc = getLexer().getLoc();
620-
621-
getParser().eatToEndOfStatement();
622-
623-
return Error(Loc, "unexpected token");
624-
}
625-
626-
// Consume the EndOfStatement.
627-
getParser().Lex();
628-
return false;
629-
}
630-
631-
bool SBFAsmParser::ParseDirective(AsmToken DirectiveID) {
632-
// This returns false if this function recognizes the directive
633-
// regardless of whether it is successfully handles or reports an
634-
// error. Otherwise it returns true to give the generic parser a
635-
// chance at recognizing it.
636-
StringRef IDVal = DirectiveID.getString();
637-
638-
if (IDVal == ".syntax_old") {
639-
getParser().setAssemblerDialect(1);
640-
return false;
641-
}
642-
if (IDVal == ".syntax_new") {
643-
getParser().setAssemblerDialect(0);
644-
return false;
645-
}
646-
647-
return true;
648-
}
460+
bool SBFAsmParser::ParseDirective(AsmToken DirectiveID) { return true; }
649461

650462
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSBFAsmParser() {
651463
RegisterMCAsmParser<SBFAsmParser> XX(getTheSBFXTarget());

llvm/lib/Target/SBF/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set(LLVM_TARGET_DEFINITIONS SBF.td)
44

55
tablegen(LLVM SBFGenAsmMatcher.inc -gen-asm-matcher)
66
tablegen(LLVM SBFGenAsmWriter.inc -gen-asm-writer)
7-
tablegen(LLVM SBFGenAsmWriter1.inc -gen-asm-writer -asmwriternum=1)
87
tablegen(LLVM SBFGenCallingConv.inc -gen-callingconv)
98
tablegen(LLVM SBFGenDAGISel.inc -gen-dag-isel)
109
tablegen(LLVM SBFGenDisassemblerTables.inc -gen-disassembler)

llvm/lib/Target/SBF/MCTargetDesc/SBFInstPrinter.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ using namespace llvm;
2525

2626
// Include the auto-generated portion of the assembly writer.
2727
#include "SBFGenAsmWriter.inc"
28-
#include "SBFGenAsmWriter1.inc"
2928

3029
void SBFInstPrinter::printInst(const MCInst *MI, uint64_t Address,
3130
StringRef Annot, const MCSubtargetInfo &STI,

llvm/lib/Target/SBF/MCTargetDesc/SBFInstPrinter.h

-20
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,6 @@ class SBFInstPrinter : public MCInstPrinter {
3636
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
3737
static const char *getRegisterName(MCRegister Reg);
3838
};
39-
class MachineInstr;
40-
41-
class SBFLegacyInstPrinter : public SBFInstPrinter {
42-
public:
43-
SBFLegacyInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
44-
const MCRegisterInfo &MRI)
45-
: SBFInstPrinter(MAI, MII, MRI) {}
46-
47-
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
48-
const MCSubtargetInfo &STI, raw_ostream &O) override {
49-
printInstruction(MI, Address, O);
50-
printAnnotation(O, Annot);
51-
}
52-
53-
// Autogenerated by tblgen.
54-
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
55-
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
56-
static const char *getRegisterName(MCRegister Reg);
57-
};
58-
5939
}
6040

6141
#endif

llvm/lib/Target/SBF/MCTargetDesc/SBFMCAsmInfo.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717

1818
using namespace llvm;
1919

20-
cl::opt<unsigned> SBFAsmWriterVariant(
21-
"sbf-output-asm-variant", cl::Hidden, cl::init(0),
22-
cl::desc("Choose output assembly variant (0 = sbf[default], 1 = legacy)"));
23-
2420
SBFMCAsmInfo::SBFMCAsmInfo(const Triple &TT, const MCTargetOptions &Options) {
25-
AssemblerDialect = SBFAsmWriterVariant;
21+
assert(AssemblerDialect == 0);
2622

2723
PrivateGlobalPrefix = ".L";
2824
WeakRefDirective = "\t.weak\t";

llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ static MCInstPrinter *createSBFMCInstPrinter(const Triple &T,
8080
const MCRegisterInfo &MRI) {
8181
if (SyntaxVariant == 0)
8282
return new SBFInstPrinter(MAI, MII, MRI);
83-
if (SyntaxVariant == 1)
84-
return new SBFLegacyInstPrinter(MAI, MII, MRI);
8583

8684
return nullptr;
8785
}

llvm/lib/Target/SBF/SBF.td

+3-18
Original file line numberDiff line numberDiff line change
@@ -58,40 +58,25 @@ def SBFAsmWriter : AsmWriter {
5858
bit isMCAsmWriter = 1;
5959
}
6060

61-
def LegacyAsmWriter : AsmWriter {
62-
let AsmWriterClassName = "LegacyInstPrinter";
63-
int Variant = 1;
64-
int isMCAsmWriter = 1;
65-
}
66-
6761
//===----------------------------------------------------------------------===//
6862
// Assembly parser
6963
//===----------------------------------------------------------------------===//
7064

71-
def SBFAsmParser : AsmParser {
72-
bit HasMnemonicFirst = 0;
73-
}
65+
def SBFAsmParser : AsmParser;
7466

7567
def SBFAsmParserVariant : AsmParserVariant {
7668
int Variant = 0;
7769
string Name = "sbf";
7870
string BreakCharacters = ".";
7971
}
8072

81-
def LegacyAsmParserVariant : AsmParserVariant {
82-
int Variant = 1;
83-
string Name = "legacy";
84-
string BreakCharacters = ".";
85-
string TokenizingCharacters = "#()[]=:.<>!+*/";
86-
}
87-
8873
//===----------------------------------------------------------------------===//
8974
// Target Declaration
9075
//===----------------------------------------------------------------------===//
9176

9277
def SBF : Target {
9378
let InstructionSet = SBFInstrInfo;
94-
let AssemblyWriters = [SBFAsmWriter, LegacyAsmWriter];
79+
let AssemblyWriters = [SBFAsmWriter];
9580
let AssemblyParsers = [SBFAsmParser];
96-
let AssemblyParserVariants = [SBFAsmParserVariant, LegacyAsmParserVariant];
81+
let AssemblyParserVariants = [SBFAsmParserVariant];
9782
}

llvm/lib/Target/SBF/SBFAsmPrinter.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ using namespace llvm;
3434

3535
#define DEBUG_TYPE "asm-printer"
3636

37-
extern cl::opt<unsigned> SBFAsmWriterVariant;
3837
static cl::opt<bool> SBFEnableBTFEmission(
3938
"sbf-enable-btf-emission", cl::Hidden, cl::init(false),
4039
cl::desc("Enable BTF debuginfo sections to be emitted"));
@@ -138,15 +137,11 @@ bool SBFAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
138137
if (ExtraCode)
139138
return true; // Unknown modifier.
140139

141-
if (SBFAsmWriterVariant == 1)
142-
O << "(";
143140
O << SBFInstPrinter::getRegisterName(BaseMO.getReg());
144141
if (Offset < 0)
145142
O << " - " << -Offset;
146143
else
147144
O << " + " << Offset;
148-
if (SBFAsmWriterVariant == 1)
149-
O << ")";
150145

151146
return false;
152147
}

0 commit comments

Comments
 (0)