|
33 | 33 | #include "llvm/Support/Casting.h" |
34 | 34 | #include "llvm/Support/ErrorHandling.h" |
35 | 35 | #include "llvm/Support/SMLoc.h" |
| 36 | +#include "llvm/TargetParser/SubtargetFeature.h" |
36 | 37 | #include <algorithm> |
37 | 38 | #include <cassert> |
38 | 39 | #include <cstddef> |
@@ -410,6 +411,12 @@ class SystemZAsmParser : public MCTargetAsmParser { |
410 | 411 |
|
411 | 412 | private: |
412 | 413 | MCAsmParser &Parser; |
| 414 | + |
| 415 | + // A vector to contain the stack of FeatureBitsets created by `.machine push`. |
| 416 | + // `.machine pop` pops the top of the stack and uses `setAvailableFeatures` to |
| 417 | + // apply the result. |
| 418 | + SmallVector<FeatureBitset> MachineStack; |
| 419 | + |
413 | 420 | enum RegisterGroup { |
414 | 421 | RegGR, |
415 | 422 | RegFP, |
@@ -494,9 +501,8 @@ class SystemZAsmParser : public MCTargetAsmParser { |
494 | 501 |
|
495 | 502 | public: |
496 | 503 | SystemZAsmParser(const MCSubtargetInfo &sti, MCAsmParser &parser, |
497 | | - const MCInstrInfo &MII, |
498 | | - const MCTargetOptions &Options) |
499 | | - : MCTargetAsmParser(Options, sti, MII), Parser(parser) { |
| 504 | + const MCInstrInfo &MII, const MCTargetOptions &Options) |
| 505 | + : MCTargetAsmParser(Options, sti, MII), Parser(parser) { |
500 | 506 | MCAsmParserExtension::Initialize(Parser); |
501 | 507 |
|
502 | 508 | // Alias the .word directive to .short. |
@@ -1382,16 +1388,32 @@ bool SystemZAsmParser::parseDirectiveMachine(SMLoc L) { |
1382 | 1388 | Parser.getTok().isNot(AsmToken::String)) |
1383 | 1389 | return TokError("unexpected token in '.machine' directive"); |
1384 | 1390 |
|
1385 | | - StringRef CPU = Parser.getTok().getIdentifier(); |
| 1391 | + StringRef Id = Parser.getTok().getIdentifier(); |
| 1392 | + SMLoc IdLoc = Parser.getTok().getLoc(); |
| 1393 | + |
1386 | 1394 | Parser.Lex(); |
1387 | 1395 | if (parseEOL()) |
1388 | 1396 | return true; |
1389 | 1397 |
|
1390 | | - MCSubtargetInfo &STI = copySTI(); |
1391 | | - STI.setDefaultFeatures(CPU, /*TuneCPU*/ CPU, ""); |
1392 | | - setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); |
1393 | | - |
1394 | | - getTargetStreamer().emitMachine(CPU); |
| 1398 | + // Parse push and pop directives first |
| 1399 | + if (Id == "push") { |
| 1400 | + // Push the Current FeatureBitSet onto the stack. |
| 1401 | + MachineStack.push_back(getAvailableFeatures()); |
| 1402 | + } else if (Id == "pop") { |
| 1403 | + // If the stack is not empty pop the topmost FeatureBitset and use it. |
| 1404 | + if (MachineStack.empty()) |
| 1405 | + return Error(IdLoc, |
| 1406 | + "pop without corresponding push in '.machine' directive"); |
| 1407 | + setAvailableFeatures(MachineStack.back()); |
| 1408 | + MachineStack.pop_back(); |
| 1409 | + } else { |
| 1410 | + // Try to interpret the Identifier as a CPU spec and derive the |
| 1411 | + // FeatureBitset from that. |
| 1412 | + MCSubtargetInfo &STI = copySTI(); |
| 1413 | + STI.setDefaultFeatures(Id, /*TuneCPU*/ Id, ""); |
| 1414 | + setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); |
| 1415 | + } |
| 1416 | + getTargetStreamer().emitMachine(Id); |
1395 | 1417 |
|
1396 | 1418 | return false; |
1397 | 1419 | } |
|
0 commit comments