From 2664ea938ffdd15261876917640a5d70f1f30945 Mon Sep 17 00:00:00 2001 From: Roman Divacky Date: Tue, 2 Dec 2014 20:03:22 +0000 Subject: [PATCH] Introduce CPUStringIsValid() into MCSubtargetInfo and use it for ARM .cpu parsing. Previously .cpu directive in ARM assembler didnt switch to the new CPU and therefore acted as a nop. This implemented real action for .cpu and eg. allows to assembler FreeBSD kernel with -integrated-as. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223147 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCSubtargetInfo.h | 9 +++++++++ lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 11 +++++++++++ test/MC/ARM/cpu-test.s | 13 +++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 test/MC/ARM/cpu-test.s diff --git a/include/llvm/MC/MCSubtargetInfo.h b/include/llvm/MC/MCSubtargetInfo.h index 9d09bd8ed40..dba957018bf 100644 --- a/include/llvm/MC/MCSubtargetInfo.h +++ b/include/llvm/MC/MCSubtargetInfo.h @@ -136,6 +136,15 @@ public: /// Initialize an InstrItineraryData instance. void initInstrItins(InstrItineraryData &InstrItins) const; + + /// Check whether the CPU string is valid. + bool CPUStringIsValid(StringRef CPU) { + auto Found = std::find_if(ProcDesc.begin(), ProcDesc.end(), + [=](const SubtargetFeatureKV &KV) { + return CPU == KV.Key; + }); + return Found != ProcDesc.end(); + } }; } // End llvm namespace diff --git a/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index 5e91a199527..6e7a27ae03e 100644 --- a/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -9083,6 +9083,17 @@ bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) { bool ARMAsmParser::parseDirectiveCPU(SMLoc L) { StringRef CPU = getParser().parseStringToEndOfStatement().trim(); getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU); + + if (!STI.CPUStringIsValid(CPU)) { + Error(L, "Unknown CPU name"); + return false; + } + + STI.InitMCProcessorInfo(CPU, ""); + STI.InitCPUSchedModel(CPU); + unsigned FB = ComputeAvailableFeatures(STI.getFeatureBits()); + setAvailableFeatures(FB); + return false; } diff --git a/test/MC/ARM/cpu-test.s b/test/MC/ARM/cpu-test.s new file mode 100644 index 00000000000..766e454d080 --- /dev/null +++ b/test/MC/ARM/cpu-test.s @@ -0,0 +1,13 @@ +// RUN: not llvm-mc -o - -triple arm-gnueabi-freebsd11.0 < %s > %t 2> %t2 +// RUN: FileCheck %s < %t +// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t2 + +// CHECK: .cpu cortex-a8 +.cpu cortex-a8 +// CHECK: dsb sy +dsb +.cpu arm9 +// CHECK-ERROR: error: instruction requires: data-barriers +dsb +// CHECK-ERROR: error: Unknown CPU name +.cpu foobar -- 2.34.1