[llvm] [SystemZ] Implement .machine (push|pop) directives (PR #137302)
Ulrich Weigand via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 28 04:26:32 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);
----------------
uweigand wrote:
Minor nit: looks like you do the same `emitMachine` call in all three branches, so it probably should be moved after the if.
https://github.com/llvm/llvm-project/pull/137302
More information about the llvm-commits
mailing list