[llvm] r223147 - Introduce CPUStringIsValid() into MCSubtargetInfo and use it for ARM .cpu parsing.
Roman Divacky
rdivacky at freebsd.org
Tue Dec 2 12:03:23 PST 2014
Author: rdivacky
Date: Tue Dec 2 14:03:22 2014
New Revision: 223147
URL: http://llvm.org/viewvc/llvm-project?rev=223147&view=rev
Log:
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.
Added:
llvm/trunk/test/MC/ARM/cpu-test.s
Modified:
llvm/trunk/include/llvm/MC/MCSubtargetInfo.h
llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
Modified: llvm/trunk/include/llvm/MC/MCSubtargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSubtargetInfo.h?rev=223147&r1=223146&r2=223147&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSubtargetInfo.h (original)
+++ llvm/trunk/include/llvm/MC/MCSubtargetInfo.h Tue Dec 2 14:03:22 2014
@@ -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
Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=223147&r1=223146&r2=223147&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Tue Dec 2 14:03:22 2014
@@ -9083,6 +9083,17 @@ bool ARMAsmParser::parseDirectiveEabiAtt
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;
}
Added: llvm/trunk/test/MC/ARM/cpu-test.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/cpu-test.s?rev=223147&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/cpu-test.s (added)
+++ llvm/trunk/test/MC/ARM/cpu-test.s Tue Dec 2 14:03:22 2014
@@ -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
More information about the llvm-commits
mailing list