1 Pull in r223147, r223255 and r223390 from upstream llvm trunk (by Roman
4 Introduce CPUStringIsValid() into MCSubtargetInfo and use it for ARM
7 Previously .cpu directive in ARM assembler didnt switch to the new
8 CPU and therefore acted as a nop. This implemented real action for
9 .cpu and eg. allows to assembler FreeBSD kernel with -integrated-as.
11 Change the name to be in style.
13 Add a FIXME as requested by Renato Golin.
15 Introduced here: http://svnweb.freebsd.org/changeset/base/275654
17 Index: include/llvm/MC/MCSubtargetInfo.h
18 ===================================================================
19 --- include/llvm/MC/MCSubtargetInfo.h
20 +++ include/llvm/MC/MCSubtargetInfo.h
21 @@ -132,6 +132,15 @@ class MCSubtargetInfo {
23 /// Initialize an InstrItineraryData instance.
24 void initInstrItins(InstrItineraryData &InstrItins) const;
26 + /// Check whether the CPU string is valid.
27 + bool isCPUStringValid(StringRef CPU) {
28 + auto Found = std::find_if(ProcDesc.begin(), ProcDesc.end(),
29 + [=](const SubtargetFeatureKV &KV) {
30 + return CPU == KV.Key;
32 + return Found != ProcDesc.end();
36 } // End llvm namespace
37 Index: lib/Target/ARM/AsmParser/ARMAsmParser.cpp
38 ===================================================================
39 --- lib/Target/ARM/AsmParser/ARMAsmParser.cpp
40 +++ lib/Target/ARM/AsmParser/ARMAsmParser.cpp
41 @@ -8618,6 +8618,20 @@ bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L)
42 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
43 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
44 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
46 + if (!STI.isCPUStringValid(CPU)) {
47 + Error(L, "Unknown CPU name");
51 + // FIXME: This switches the CPU features globally, therefore it might
52 + // happen that code you would not expect to assemble will. For details
53 + // see: http://llvm.org/bugs/show_bug.cgi?id=20757
54 + STI.InitMCProcessorInfo(CPU, "");
55 + STI.InitCPUSchedModel(CPU);
56 + unsigned FB = ComputeAvailableFeatures(STI.getFeatureBits());
57 + setAvailableFeatures(FB);
62 Index: test/MC/ARM/cpu-test.s
63 ===================================================================
64 --- test/MC/ARM/cpu-test.s
65 +++ test/MC/ARM/cpu-test.s
67 +// RUN: not llvm-mc -o - -triple arm-gnueabi-freebsd11.0 < %s > %t 2> %t2
68 +// RUN: FileCheck %s < %t
69 +// RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t2
71 +// CHECK: .cpu cortex-a8
76 +// CHECK-ERROR: error: instruction requires: data-barriers
78 +// CHECK-ERROR: error: Unknown CPU name