[PATCH] D109660: [SystemZ] Recognize .machine directive in parser.
Jonas Paulsson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 12 08:22:01 PDT 2021
jonpa created this revision.
jonpa added a reviewer: uweigand.
Herald added a subscriber: hiraditya.
jonpa requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The .machine directive can be used in assembly files to specify the ISA for the instructions following it.
Does such a directive need to be output again from the parser in case output is back into textual form (filetype=asm)? This is currently not done by the patch - I see that these are dropped after running GAS | objdump... (object format). I guess in that case either MCTargetStreamer is needed, or possibly some RawText emission..?
https://reviews.llvm.org/D109660
Files:
llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
llvm/test/MC/SystemZ/machine-directive.s
Index: llvm/test/MC/SystemZ/machine-directive.s
===================================================================
--- /dev/null
+++ llvm/test/MC/SystemZ/machine-directive.s
@@ -0,0 +1,17 @@
+# RUN: not llvm-mc -triple=s390x-linux-gnu %s --filetype=asm 2>&1 | FileCheck %s
+
+# CHECK: error: instruction requires: vector
+# CHECK: vgbm %v0, 1
+# CHECK: ^
+
+# CHECK-NOT: error:
+# CHECK: vgbm %v0, 0
+# CHECK: vgbm %v0, 3
+
+.machine z13
+vgbm %v0, 0
+.machine zEC12
+vgbm %v0, 1
+.machine z13
+vgbm %v0, 3
+
Index: llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
===================================================================
--- llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
+++ llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
@@ -420,6 +420,7 @@
bool parseAddressRegister(Register &Reg);
bool ParseDirectiveInsn(SMLoc L);
+ bool ParseDirectiveMachine(SMLoc L);
OperandMatchResultTy parseAddress(OperandVector &Operands,
MemoryKind MemKind,
@@ -1210,6 +1211,8 @@
if (IDVal == ".insn")
return ParseDirectiveInsn(DirectiveID.getLoc());
+ if (IDVal == ".machine")
+ return ParseDirectiveMachine(DirectiveID.getLoc());
return true;
}
@@ -1322,6 +1325,26 @@
return false;
}
+/// ParseDirectiveMachine
+/// ::= .machine [ mcpu ]
+bool SystemZAsmParser::ParseDirectiveMachine(SMLoc L) {
+ MCAsmParser &Parser = getParser();
+ if (Parser.getTok().isNot(AsmToken::Identifier) &&
+ Parser.getTok().isNot(AsmToken::String))
+ return Error(L, "unexpected token in '.machine' directive");
+
+ StringRef CPU = Parser.getTok().getIdentifier();
+ Parser.Lex();
+ if (parseToken(AsmToken::EndOfStatement))
+ return addErrorSuffix(" in '.machine' directive");
+
+ MCSubtargetInfo &STI = copySTI();
+ STI.setDefaultFeatures(CPU, /*TuneCPU*/ CPU, "");
+ setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
+
+ return false;
+}
+
bool SystemZAsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
SMLoc &EndLoc, bool RestoreOnFailure) {
Register Reg;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109660.372124.patch
Type: text/x-patch
Size: 2135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210912/4b0c19bb/attachment.bin>
More information about the llvm-commits
mailing list