[llvm] [SystemZ] Implement .machine (push|pop) directives (PR #137302)
Dominik Steenken via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 28 05:25:14 PDT 2025
================
@@ -1382,17 +1395,35 @@ bool SystemZAsmParser::parseDirectiveMachine(SMLoc L) {
Parser.getTok().isNot(AsmToken::String))
return TokError("unexpected token in '.machine' directive");
- StringRef CPU = Parser.getTok().getIdentifier();
+ StringRef Id = Parser.getTok().getIdentifier();
+
+ // Parse push and pop directives first
+ if (Id == "push") {
+ // Push the Current FeatureBitSet onto the stack.
+ MachineStack.push_back(CurrentFeatures);
+ getTargetStreamer().emitMachine("push");
+ } else if (Id == "pop") {
+ // If the Stack is not empty, pop the topmost FeatureBitset and use it.
+ if (MachineStack.empty())
+ return TokError("pop without corresponding push in '.machine' directive");
+ CurrentFeatures = MachineStack.back();
+ MachineStack.pop_back();
+ setAvailableFeatures(CurrentFeatures);
+ getTargetStreamer().emitMachine("pop");
+ } else {
+ // Try to interpret the Identifier as a CPU spec and derive the
+ // FeatureBitset from that.
+ MCSubtargetInfo &STI = copySTI();
+ STI.setDefaultFeatures(Id, /*TuneCPU*/ Id, "");
+ CurrentFeatures = STI.getFeatureBits();
+ setAvailableFeatures(ComputeAvailableFeatures(CurrentFeatures));
+ getTargetStreamer().emitMachine(Id);
+ }
+
Parser.Lex();
if (parseEOL())
return true;
----------------
dominik-steenken wrote:
Yes. This introduced a minor compilcation wherre i had to separate the reporting of the `TokError` from the existing `if` block, but i think it is now in the right place. Thanks for the feedback :)
https://github.com/llvm/llvm-project/pull/137302
More information about the llvm-commits
mailing list