[llvm] d2c2248 - [X86] Parse and ignore .arch directives

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 30 08:38:35 PDT 2020


Author: Fangrui Song
Date: 2020-07-30T08:30:06-07:00
New Revision: d2c22487225b05159c1d7d0da7fac7cae3d2049b

URL: https://github.com/llvm/llvm-project/commit/d2c22487225b05159c1d7d0da7fac7cae3d2049b
DIFF: https://github.com/llvm/llvm-project/commit/d2c22487225b05159c1d7d0da7fac7cae3d2049b.diff

LOG: [X86] Parse and ignore .arch directives

We parse .arch so that some `.arch i386; .code32` code can assemble. It seems
that X86AsmParser does not do a good job tracking what features are needed to
assemble instructions. GNU as's x86 port supports a very wide range of .arch
operands. Ignore the operand for now.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D84900

Added: 
    llvm/test/MC/X86/directive-arch.s

Modified: 
    llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index a278c46aaf97..f52735068c8b 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -937,6 +937,7 @@ class X86AsmParser : public MCTargetAsmParser {
                           SMLoc End, unsigned Size, StringRef Identifier,
                           const InlineAsmIdentifierInfo &Info);
 
+  bool parseDirectiveArch();
   bool parseDirectiveEven(SMLoc L);
   bool ParseDirectiveCode(StringRef IDVal, SMLoc L);
 
@@ -3993,6 +3994,8 @@ bool X86AsmParser::OmitRegisterFromClobberLists(unsigned RegNo) {
 bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
   MCAsmParser &Parser = getParser();
   StringRef IDVal = DirectiveID.getIdentifier();
+  if (IDVal.startswith(".arch"))
+    return parseDirectiveArch();
   if (IDVal.startswith(".code"))
     return ParseDirectiveCode(IDVal, DirectiveID.getLoc());
   else if (IDVal.startswith(".att_syntax")) {
@@ -4047,6 +4050,12 @@ bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {
   return true;
 }
 
+bool X86AsmParser::parseDirectiveArch() {
+  // Ignore .arch for now.
+  getParser().parseStringToEndOfStatement();
+  return false;
+}
+
 /// parseDirectiveEven
 ///  ::= .even
 bool X86AsmParser::parseDirectiveEven(SMLoc L) {

diff  --git a/llvm/test/MC/X86/directive-arch.s b/llvm/test/MC/X86/directive-arch.s
new file mode 100644
index 000000000000..5f148a2ffb17
--- /dev/null
+++ b/llvm/test/MC/X86/directive-arch.s
@@ -0,0 +1,10 @@
+## We currently parse but ignore .arch directives.
+# RUN: llvm-mc -triple=x86_64 %s | FileCheck /dev/null --implicit-check-not=.arch
+
+.arch i286
+.arch generic32
+
+.arch .avx512vl
+.arch .noavx512bw
+.arch .nop
+.arch .sse4.2


        


More information about the llvm-commits mailing list