llvm.org GIT mirror llvm / a943056
[AsmPrinter] refactor to remove remove AsmVariant. NFC Summary: The InlineAsm::AsmDialect is only required for X86; no architecture makes use of it and as such it gets passed around between arch-specific and general code while being unused for all architectures but X86. Since the AsmDialect is queried from a MachineInstr, which we also pass around, remove the additional AsmDialect parameter and query for it deep in the X86AsmPrinter only when needed/as late as possible. This refactor should help later planned refactors to AsmPrinter, as this difference in the X86AsmPrinter makes it harder to make AsmPrinter more generic. Reviewers: craig.topper Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines Tags: #llvm Differential Revision: https://reviews.llvm.org/D60488 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358101 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Desaulniers 1 year, 7 months ago
27 changed file(s) with 105 addition(s) and 182 deletion(s). Raw diff Collapse all Expand all
593593 /// specified assembler variant. Targets should override this to format as
594594 /// appropriate. This method can return true if the operand is erroneous.
595595 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
596 unsigned AsmVariant, const char *ExtraCode,
597 raw_ostream &OS);
596 const char *ExtraCode, raw_ostream &OS);
598597
599598 /// Print the specified operand of MI, an INLINEASM instruction, using the
600599 /// specified assembler variant as an address. Targets should override this to
601600 /// format as appropriate. This method can return true if the operand is
602601 /// erroneous.
603602 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
604 unsigned AsmVariant, const char *ExtraCode,
605 raw_ostream &OS);
603 const char *ExtraCode, raw_ostream &OS);
606604
607605 /// Let the target do anything it needs to do before emitting inlineasm.
608606 /// \p StartInfo - the subtarget info before parsing inline asm
168168 }
169169
170170 static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
171 MachineModuleInfo *MMI, int InlineAsmVariant,
172 AsmPrinter *AP, unsigned LocCookie,
173 raw_ostream &OS) {
171 MachineModuleInfo *MMI, AsmPrinter *AP,
172 unsigned LocCookie, raw_ostream &OS) {
174173 // Switch to the inline assembly variant.
175174 OS << "\t.intel_syntax\n\t";
176175
262261 ++OpNo; // Skip over the ID number.
263262
264263 if (InlineAsm::isMemKind(OpFlags)) {
265 Error = AP->PrintAsmMemoryOperand(MI, OpNo, InlineAsmVariant,
266 /*Modifier*/ nullptr, OS);
264 Error = AP->PrintAsmMemoryOperand(MI, OpNo, /*Modifier*/ nullptr, OS);
267265 } else {
268 Error = AP->PrintAsmOperand(MI, OpNo, InlineAsmVariant,
269 /*Modifier*/ nullptr, OS);
266 Error = AP->PrintAsmOperand(MI, OpNo, /*Modifier*/ nullptr, OS);
270267 }
271268 }
272269 if (Error) {
283280 }
284281
285282 static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
286 MachineModuleInfo *MMI, int InlineAsmVariant,
287 int AsmPrinterVariant, AsmPrinter *AP,
288 unsigned LocCookie, raw_ostream &OS) {
283 MachineModuleInfo *MMI, int AsmPrinterVariant,
284 AsmPrinter *AP, unsigned LocCookie,
285 raw_ostream &OS) {
289286 int CurVariant = -1; // The number of the {.|.|.} region we are in.
290287 const char *LastEmitted = AsmStr; // One past the last character emitted.
291288 unsigned NumOperands = MI->getNumOperands();
440437 }
441438 } else {
442439 if (InlineAsm::isMemKind(OpFlags)) {
443 Error = AP->PrintAsmMemoryOperand(MI, OpNo, InlineAsmVariant,
444 Modifier[0] ? Modifier : nullptr,
445 OS);
440 Error = AP->PrintAsmMemoryOperand(
441 MI, OpNo, Modifier[0] ? Modifier : nullptr, OS);
446442 } else {
447 Error = AP->PrintAsmOperand(MI, OpNo, InlineAsmVariant,
443 Error = AP->PrintAsmOperand(MI, OpNo,
448444 Modifier[0] ? Modifier : nullptr, OS);
449445 }
450446 }
514510
515511 // The variant of the current asmprinter.
516512 int AsmPrinterVariant = MAI->getAssemblerDialect();
517 InlineAsm::AsmDialect InlineAsmVariant = MI->getInlineAsmDialect();
518513 AsmPrinter *AP = const_cast(this);
519 if (InlineAsmVariant == InlineAsm::AD_ATT)
520 EmitGCCInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AsmPrinterVariant,
521 AP, LocCookie, OS);
514 if (MI->getInlineAsmDialect() == InlineAsm::AD_ATT)
515 EmitGCCInlineAsmStr(AsmStr, MI, MMI, AsmPrinterVariant, AP, LocCookie, OS);
522516 else
523 EmitMSInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AP, LocCookie, OS);
517 EmitMSInlineAsmStr(AsmStr, MI, MMI, AP, LocCookie, OS);
524518
525519 // Emit warnings if we use reserved registers on the clobber list, as
526520 // that might give surprising results.
606600 /// instruction, using the specified assembler variant. Targets should
607601 /// override this to format as appropriate.
608602 bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
609 unsigned AsmVariant, const char *ExtraCode,
610 raw_ostream &O) {
603 const char *ExtraCode, raw_ostream &O) {
611604 // Does this asm operand have a single letter operand modifier?
612605 if (ExtraCode && ExtraCode[0]) {
613606 if (ExtraCode[1] != 0) return true; // Unknown modifier.
637630 }
638631
639632 bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
640 unsigned AsmVariant,
641633 const char *ExtraCode, raw_ostream &O) {
642634 // Target doesn't support this yet!
643635 return true;
152152 raw_ostream &O);
153153
154154 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
155 unsigned AsmVariant, const char *ExtraCode,
156 raw_ostream &O) override;
155 const char *ExtraCode, raw_ostream &O) override;
157156 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
158 unsigned AsmVariant, const char *ExtraCode,
159 raw_ostream &O) override;
157 const char *ExtraCode, raw_ostream &O) override;
160158
161159 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
162160
490488 }
491489
492490 bool AArch64AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
493 unsigned AsmVariant,
494491 const char *ExtraCode, raw_ostream &O) {
495492 const MachineOperand &MO = MI->getOperand(OpNum);
496493
497494 // First try the generic code, which knows about modifiers like 'c' and 'n'.
498 if (!AsmPrinter::PrintAsmOperand(MI, OpNum, AsmVariant, ExtraCode, O))
495 if (!AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O))
499496 return false;
500497
501498 // Does this asm operand have a single letter operand modifier?
507504 default:
508505 return true; // Unknown modifier.
509506 case 'a': // Print 'a' modifier
510 PrintAsmMemoryOperand(MI, OpNum, AsmVariant, ExtraCode, O);
507 PrintAsmMemoryOperand(MI, OpNum, ExtraCode, O);
511508 return false;
512509 case 'w': // Print W register
513510 case 'x': // Print X register
574571
575572 bool AArch64AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
576573 unsigned OpNum,
577 unsigned AsmVariant,
578574 const char *ExtraCode,
579575 raw_ostream &O) {
580576 if (ExtraCode && ExtraCode[0] && ExtraCode[0] != 'a')
11211121 }
11221122
11231123 bool AMDGPUAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
1124 unsigned AsmVariant,
11251124 const char *ExtraCode, raw_ostream &O) {
11261125 // First try the generic code, which knows about modifiers like 'c' and 'n'.
1127 if (!AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O))
1126 if (!AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O))
11281127 return false;
11291128
11301129 if (ExtraCode && ExtraCode[0]) {
133133 const MachineBasicBlock *MBB) const override;
134134
135135 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
136 unsigned AsmVariant, const char *ExtraCode,
137 raw_ostream &O) override;
136 const char *ExtraCode, raw_ostream &O) override;
138137
139138 protected:
140139 mutable std::vector DisasmLines, HexLines;
254254 }
255255
256256 bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
257 unsigned AsmVariant, const char *ExtraCode,
258 raw_ostream &O) {
257 const char *ExtraCode, raw_ostream &O) {
259258 // Does this asm operand have a single letter operand modifier?
260259 if (ExtraCode && ExtraCode[0]) {
261260 if (ExtraCode[1] != 0) return true; // Unknown modifier.
263262 switch (ExtraCode[0]) {
264263 default:
265264 // See if this is a generic print operand
266 return AsmPrinter::PrintAsmOperand(MI, OpNum, AsmVariant, ExtraCode, O);
265 return AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O);
267266 case 'a': // Print as a memory address.
268267 if (MI->getOperand(OpNum).isReg()) {
269268 O << "["
442441 }
443442
444443 bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
445 unsigned OpNum, unsigned AsmVariant,
446 const char *ExtraCode,
444 unsigned OpNum, const char *ExtraCode,
447445 raw_ostream &O) {
448446 // Does this asm operand have a single letter operand modifier?
449447 if (ExtraCode && ExtraCode[0]) {
7575 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
7676
7777 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
78 unsigned AsmVariant, const char *ExtraCode,
79 raw_ostream &O) override;
78 const char *ExtraCode, raw_ostream &O) override;
8079 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
81 unsigned AsmVariant, const char *ExtraCode,
82 raw_ostream &O) override;
80 const char *ExtraCode, raw_ostream &O) override;
8381
8482 void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
8583 const MCSubtargetInfo *EndInfo) const override;
4545 const char *Modifier = 0);
4646
4747 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
48 unsigned AsmVariant, const char *ExtraCode,
49 raw_ostream &O) override;
48 const char *ExtraCode, raw_ostream &O) override;
5049
5150 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
52 unsigned AsmVariant, const char *ExtraCode,
53 raw_ostream &O) override;
51 const char *ExtraCode, raw_ostream &O) override;
5452
5553 void EmitInstruction(const MachineInstr *MI) override;
5654
8482 }
8583
8684 bool AVRAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
87 unsigned AsmVariant, const char *ExtraCode,
88 raw_ostream &O) {
85 const char *ExtraCode, raw_ostream &O) {
8986 // Default asm printer can only deal with some extra codes,
9087 // so try it first.
91 bool Error = AsmPrinter::PrintAsmOperand(MI, OpNum, AsmVariant, ExtraCode, O);
88 bool Error = AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O);
9289
9390 if (Error && ExtraCode && ExtraCode[0]) {
9491 if (ExtraCode[1] != 0)
136133 }
137134
138135 bool AVRAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
139 unsigned OpNum, unsigned AsmVariant,
140 const char *ExtraCode,
136 unsigned OpNum, const char *ExtraCode,
141137 raw_ostream &O) {
142138 if (ExtraCode && ExtraCode[0]) {
143139 llvm_unreachable("This branch is not implemented yet");
4242 bool doInitialization(Module &M) override;
4343 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
4444 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
45 unsigned AsmVariant, const char *ExtraCode,
46 raw_ostream &O) override;
45 const char *ExtraCode, raw_ostream &O) override;
4746 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
48 unsigned AsmVariant, const char *ExtraCode,
49 raw_ostream &O) override;
47 const char *ExtraCode, raw_ostream &O) override;
5048
5149 void EmitInstruction(const MachineInstr *MI) override;
5250 };
103101 }
104102
105103 bool BPFAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
106 unsigned /*AsmVariant*/,
107104 const char *ExtraCode, raw_ostream &O) {
108105 if (ExtraCode && ExtraCode[0])
109106 return true; // BPF does not have special modifiers
113110 }
114111
115112 bool BPFAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
116 unsigned OpNum, unsigned AsmVariant,
117 const char *ExtraCode,
113 unsigned OpNum, const char *ExtraCode,
118114 raw_ostream &O) {
119115 assert(OpNum + 1 < MI->getNumOperands() && "Insufficient operands");
120116 const MachineOperand &BaseMO = MI->getOperand(OpNum);
112112
113113 /// PrintAsmOperand - Print out an operand for an inline asm expression.
114114 bool HexagonAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
115 unsigned AsmVariant,
116115 const char *ExtraCode,
117116 raw_ostream &OS) {
118117 // Does this asm operand have a single letter operand modifier?
123122 switch (ExtraCode[0]) {
124123 default:
125124 // See if this is a generic print operand
126 return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS);
125 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS);
127126 case 'c': // Don't print "$" before a global var name or constant.
128127 // Hexagon never has a prefix.
129128 printOperand(MI, OpNo, OS);
159158
160159 bool HexagonAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
161160 unsigned OpNo,
162 unsigned AsmVariant,
163161 const char *ExtraCode,
164162 raw_ostream &O) {
165163 if (ExtraCode && ExtraCode[0])
5151
5252 void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O);
5353 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
54 unsigned AsmVariant, const char *ExtraCode,
55 raw_ostream &OS) override;
54 const char *ExtraCode, raw_ostream &OS) override;
5655 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
57 unsigned AsmVariant, const char *ExtraCode,
58 raw_ostream &OS) override;
56 const char *ExtraCode, raw_ostream &OS) override;
5957 };
6058
6159 } // end namespace llvm
4747
4848 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
4949 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
50 unsigned AsmVariant, const char *ExtraCode,
51 raw_ostream &O) override;
50 const char *ExtraCode, raw_ostream &O) override;
5251 void EmitInstruction(const MachineInstr *MI) override;
5352 bool isBlockOnlyReachableByFallthrough(
5453 const MachineBasicBlock *MBB) const override;
107106
108107 // PrintAsmOperand - Print out an operand for an inline asm expression.
109108 bool LanaiAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
110 unsigned /*AsmVariant*/,
111109 const char *ExtraCode, raw_ostream &O) {
112110 // Does this asm operand have a single letter operand modifier?
113111 if (ExtraCode && ExtraCode[0]) {
5151 void printSrcMemOperand(const MachineInstr *MI, int OpNum,
5252 raw_ostream &O);
5353 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
54 unsigned AsmVariant, const char *ExtraCode,
55 raw_ostream &O) override;
56 bool PrintAsmMemoryOperand(const MachineInstr *MI,
57 unsigned OpNo, unsigned AsmVariant,
54 const char *ExtraCode, raw_ostream &O) override;
55 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
5856 const char *ExtraCode, raw_ostream &O) override;
5957 void EmitInstruction(const MachineInstr *MI) override;
6058
127125 /// PrintAsmOperand - Print out an operand for an inline asm expression.
128126 ///
129127 bool MSP430AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
130 unsigned AsmVariant,
131128 const char *ExtraCode, raw_ostream &O) {
132129 // Does this asm operand have a single letter operand modifier?
133130 if (ExtraCode && ExtraCode[0])
138135 }
139136
140137 bool MSP430AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
141 unsigned OpNo, unsigned AsmVariant,
138 unsigned OpNo,
142139 const char *ExtraCode,
143140 raw_ostream &O) {
144141 if (ExtraCode && ExtraCode[0]) {
509509
510510 // Print out an operand for an inline asm expression.
511511 bool MipsAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
512 unsigned AsmVariant, const char *ExtraCode,
513 raw_ostream &O) {
512 const char *ExtraCode, raw_ostream &O) {
514513 // Does this asm operand have a single letter operand modifier?
515514 if (ExtraCode && ExtraCode[0]) {
516515 if (ExtraCode[1] != 0) return true; // Unknown modifier.
519518 switch (ExtraCode[0]) {
520519 default:
521520 // See if this is a generic print operand
522 return AsmPrinter::PrintAsmOperand(MI,OpNum,AsmVariant,ExtraCode,O);
521 return AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O);
523522 case 'X': // hex const int
524523 if ((MO.getType()) != MachineOperand::MO_Immediate)
525524 return true;
615614 }
616615
617616 bool MipsAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
618 unsigned OpNum, unsigned AsmVariant,
617 unsigned OpNum,
619618 const char *ExtraCode,
620619 raw_ostream &O) {
621620 assert(OpNum + 1 < MI->getNumOperands() && "Insufficient operands");
144144 bool isBlockOnlyReachableByFallthrough(
145145 const MachineBasicBlock* MBB) const override;
146146 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
147 unsigned AsmVariant, const char *ExtraCode,
148 raw_ostream &O) override;
147 const char *ExtraCode, raw_ostream &O) override;
149148 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
150 unsigned AsmVariant, const char *ExtraCode,
151 raw_ostream &O) override;
149 const char *ExtraCode, raw_ostream &O) override;
152150 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
153151 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
154152 void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O);
22022202 /// PrintAsmOperand - Print out an operand for an inline asm expression.
22032203 ///
22042204 bool NVPTXAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
2205 unsigned AsmVariant,
22062205 const char *ExtraCode, raw_ostream &O) {
22072206 if (ExtraCode && ExtraCode[0]) {
22082207 if (ExtraCode[1] != 0)
22112210 switch (ExtraCode[0]) {
22122211 default:
22132212 // See if this is a generic print operand
2214 return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
2213 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O);
22152214 case 'r':
22162215 break;
22172216 }
22222221 return false;
22232222 }
22242223
2225 bool NVPTXAsmPrinter::PrintAsmMemoryOperand(
2226 const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant,
2227 const char *ExtraCode, raw_ostream &O) {
2224 bool NVPTXAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
2225 unsigned OpNo,
2226 const char *ExtraCode,
2227 raw_ostream &O) {
22282228 if (ExtraCode && ExtraCode[0])
22292229 return true; // Unknown modifier
22302230
229229 void printReturnValStr(const Function *, raw_ostream &O);
230230 void printReturnValStr(const MachineFunction &MF, raw_ostream &O);
231231 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
232 unsigned AsmVariant, const char *ExtraCode,
233 raw_ostream &) override;
232 const char *ExtraCode, raw_ostream &) override;
234233 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
235234 const char *Modifier = nullptr);
236235 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
237 unsigned AsmVariant, const char *ExtraCode,
238 raw_ostream &) override;
236 const char *ExtraCode, raw_ostream &) override;
239237
240238 const MCExpr *lowerConstantForGV(const Constant *CV, bool ProcessingGeneric);
241239 void printMCExpr(const MCExpr &Expr, raw_ostream &OS);
101101 void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O);
102102
103103 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
104 unsigned AsmVariant, const char *ExtraCode,
105 raw_ostream &O) override;
104 const char *ExtraCode, raw_ostream &O) override;
106105 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
107 unsigned AsmVariant, const char *ExtraCode,
108 raw_ostream &O) override;
106 const char *ExtraCode, raw_ostream &O) override;
109107
110108 void EmitEndOfAsmFile(Module &M) override;
111109
223221 /// PrintAsmOperand - Print out an operand for an inline asm expression.
224222 ///
225223 bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
226 unsigned AsmVariant,
227224 const char *ExtraCode, raw_ostream &O) {
228225 // Does this asm operand have a single letter operand modifier?
229226 if (ExtraCode && ExtraCode[0]) {
232229 switch (ExtraCode[0]) {
233230 default:
234231 // See if this is a generic print operand
235 return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
232 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O);
236233 case 'c': // Don't print "$" before a global var name or constant.
237234 break; // PPC never has a prefix.
238235 case 'L': // Write second word of DImode reference.
276273 // assembler operand.
277274
278275 bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
279 unsigned AsmVariant,
280276 const char *ExtraCode,
281277 raw_ostream &O) {
282278 if (ExtraCode && ExtraCode[0]) {
4141 void EmitInstruction(const MachineInstr *MI) override;
4242
4343 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
44 unsigned AsmVariant, const char *ExtraCode,
45 raw_ostream &OS) override;
44 const char *ExtraCode, raw_ostream &OS) override;
4645 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
47 unsigned AsmVariant, const char *ExtraCode,
48 raw_ostream &OS) override;
46 const char *ExtraCode, raw_ostream &OS) override;
4947
5048 void EmitToStreamer(MCStreamer &S, const MCInst &Inst);
5149 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
8280 }
8381
8482 bool RISCVAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
85 unsigned AsmVariant,
8683 const char *ExtraCode, raw_ostream &OS) {
87 if (AsmVariant != 0)
88 report_fatal_error("There are no defined alternate asm variants");
89
9084 // First try the generic code, which knows about modifiers like 'c' and 'n'.
91 if (!AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS))
85 if (!AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS))
9286 return false;
9387
9488 if (!ExtraCode) {
109103 }
110104
111105 bool RISCVAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
112 unsigned OpNo, unsigned AsmVariant,
106 unsigned OpNo,
113107 const char *ExtraCode,
114108 raw_ostream &OS) {
115 if (AsmVariant != 0)
116 report_fatal_error("There are no defined alternate asm variants");
117
118109 if (!ExtraCode) {
119110 const MachineOperand &MO = MI->getOperand(OpNo);
120111 // For now, we only support register memory operands in registers and
126117 return false;
127118 }
128119
129 return AsmPrinter::PrintAsmMemoryOperand(MI, OpNo, AsmVariant, ExtraCode, OS);
120 return AsmPrinter::PrintAsmMemoryOperand(MI, OpNo, ExtraCode, OS);
130121 }
131122
132123 // Force static initialization.
5858 }
5959
6060 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
61 unsigned AsmVariant, const char *ExtraCode,
62 raw_ostream &O) override;
61 const char *ExtraCode, raw_ostream &O) override;
6362 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
64 unsigned AsmVariant, const char *ExtraCode,
65 raw_ostream &O) override;
63 const char *ExtraCode, raw_ostream &O) override;
6664
6765 void LowerGETPCXAndEmitMCInsts(const MachineInstr *MI,
6866 const MCSubtargetInfo &STI);
404402 /// PrintAsmOperand - Print out an operand for an inline asm expression.
405403 ///
406404 bool SparcAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
407 unsigned AsmVariant,
408405 const char *ExtraCode,
409406 raw_ostream &O) {
410407 if (ExtraCode && ExtraCode[0]) {
413410 switch (ExtraCode[0]) {
414411 default:
415412 // See if this is a generic print operand
416 return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
413 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O);
417414 case 'f':
418415 case 'r':
419416 break;
426423 }
427424
428425 bool SparcAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
429 unsigned OpNo, unsigned AsmVariant,
426 unsigned OpNo,
430427 const char *ExtraCode,
431428 raw_ostream &O) {
432429 if (ExtraCode && ExtraCode[0])
616616 OutStreamer->EmitValue(Expr, Size);
617617 }
618618
619 bool SystemZAsmPrinter::PrintAsmOperand(const MachineInstr *MI,
620 unsigned OpNo,
621 unsigned AsmVariant,
619 bool SystemZAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
622620 const char *ExtraCode,
623621 raw_ostream &OS) {
624622 if (ExtraCode && *ExtraCode == 'n') {
635633
636634 bool SystemZAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
637635 unsigned OpNo,
638 unsigned AsmVariant,
639636 const char *ExtraCode,
640637 raw_ostream &OS) {
641638 SystemZInstPrinter::printAddress(MI->getOperand(OpNo).getReg(),
3535 void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
3636 void EmitEndOfAsmFile(Module &M) override;
3737 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
38 unsigned AsmVariant, const char *ExtraCode,
39 raw_ostream &OS) override;
38 const char *ExtraCode, raw_ostream &OS) override;
4039 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
41 unsigned AsmVariant, const char *ExtraCode,
42 raw_ostream &OS) override;
40 const char *ExtraCode, raw_ostream &OS) override;
4341
4442 bool doInitialization(Module &M) override {
4543 SM.reset();
386386 }
387387
388388 bool WebAssemblyAsmPrinter::PrintAsmOperand(const MachineInstr *MI,
389 unsigned OpNo, unsigned AsmVariant,
389 unsigned OpNo,
390390 const char *ExtraCode,
391391 raw_ostream &OS) {
392 if (AsmVariant != 0)
393 report_fatal_error("There are no defined alternate asm variants");
394
395392 // First try the generic code, which knows about modifiers like 'c' and 'n'.
396 if (!AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS))
393 if (!AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS))
397394 return false;
398395
399396 if (!ExtraCode) {
429426
430427 bool WebAssemblyAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
431428 unsigned OpNo,
432 unsigned AsmVariant,
433429 const char *ExtraCode,
434430 raw_ostream &OS) {
435 if (AsmVariant != 0)
436 report_fatal_error("There are no defined alternate asm variants");
437
438431 // The current approach to inline asm is that "r" constraints are expressed
439432 // as local indices, rather than values on the operand stack. This simplifies
440433 // using "r" as it eliminates the need to push and pop the values in a
441434 // particular order, however it also makes it impossible to have an "m"
442435 // constraint. So we don't support it.
443436
444 return AsmPrinter::PrintAsmMemoryOperand(MI, OpNo, AsmVariant, ExtraCode, OS);
437 return AsmPrinter::PrintAsmMemoryOperand(MI, OpNo, ExtraCode, OS);
445438 }
446439
447440 // Force static initialization.
6464 void EmitFunctionBodyStart() override;
6565 void EmitInstruction(const MachineInstr *MI) override;
6666 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
67 unsigned AsmVariant, const char *ExtraCode,
68 raw_ostream &OS) override;
67 const char *ExtraCode, raw_ostream &OS) override;
6968 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
70 unsigned AsmVariant, const char *ExtraCode,
71 raw_ostream &OS) override;
69 const char *ExtraCode, raw_ostream &OS) override;
7270
7371 MVT getRegType(unsigned RegNo) const;
7472 std::string regToString(const MachineOperand &MO);
2222 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
2323 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
2424 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/InlineAsm.h"
2526 #include "llvm/IR/Mangler.h"
2627 #include "llvm/IR/Module.h"
2728 #include "llvm/IR/Type.h"
199200
200201 static void printOperand(X86AsmPrinter &P, const MachineInstr *MI,
201202 unsigned OpNo, raw_ostream &O,
202 const char *Modifier = nullptr, unsigned AsmVariant = 0);
203 const char *Modifier = nullptr);
203204
204205 /// printPCRelImm - This is used to print an immediate value that ends up
205206 /// being encoded as a pc-relative value. These print slightly differently, for
223224 }
224225
225226 static void printOperand(X86AsmPrinter &P, const MachineInstr *MI,
226 unsigned OpNo, raw_ostream &O, const char *Modifier,
227 unsigned AsmVariant) {
227 unsigned OpNo, raw_ostream &O, const char *Modifier) {
228228 const MachineOperand &MO = MI->getOperand(OpNo);
229 const bool IsATT = MI->getInlineAsmDialect() == InlineAsm::AD_ATT;
229230 switch (MO.getType()) {
230231 default: llvm_unreachable("unknown operand type!");
231232 case MachineOperand::MO_Register: {
232 // FIXME: Enumerating AsmVariant, so we can remove magic number.
233 if (AsmVariant == 0) O << '%';
233 if (IsATT)
234 O << '%';
234235 unsigned Reg = MO.getReg();
235236 if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
236237 unsigned Size = (strcmp(Modifier+6,"64") == 0) ? 64 :
243244 }
244245
245246 case MachineOperand::MO_Immediate:
246 if (AsmVariant == 0) O << '$';
247 if (IsATT)
248 O << '$';
247249 O << MO.getImm();
248250 return;
249251
250252 case MachineOperand::MO_GlobalAddress: {
251 if (AsmVariant == 0) O << '$';
253 if (IsATT)
254 O << '$';
252255 printSymbolOperand(P, MO, O);
253256 break;
254257 }
326329
327330 static void printIntelMemReference(X86AsmPrinter &P, const MachineInstr *MI,
328331 unsigned Op, raw_ostream &O,
329 const char *Modifier = nullptr,
330 unsigned AsmVariant = 1) {
332 const char *Modifier = nullptr) {
331333 const MachineOperand &BaseReg = MI->getOperand(Op+X86::AddrBaseReg);
332334 unsigned ScaleVal = MI->getOperand(Op+X86::AddrScaleAmt).getImm();
333335 const MachineOperand &IndexReg = MI->getOperand(Op+X86::AddrIndexReg);
336338
337339 // If this has a segment register, print it.
338340 if (SegReg.getReg()) {
339 printOperand(P, MI, Op+X86::AddrSegmentReg, O, Modifier, AsmVariant);
341 printOperand(P, MI, Op + X86::AddrSegmentReg, O, Modifier);
340342 O << ':';
341343 }
342344
344346
345347 bool NeedPlus = false;
346348 if (BaseReg.getReg()) {
347 printOperand(P, MI, Op+X86::AddrBaseReg, O, Modifier, AsmVariant);
349 printOperand(P, MI, Op + X86::AddrBaseReg, O, Modifier);
348350 NeedPlus = true;
349351 }
350352
352354 if (NeedPlus) O << " + ";
353355 if (ScaleVal != 1)
354356 O << ScaleVal << '*';
355 printOperand(P, MI, Op+X86::AddrIndexReg, O, Modifier, AsmVariant);
357 printOperand(P, MI, Op + X86::AddrIndexReg, O, Modifier);
356358 NeedPlus = true;
357359 }
358360
359361 if (!DispSpec.isImm()) {
360362 if (NeedPlus) O << " + ";
361 printOperand(P, MI, Op+X86::AddrDisp, O, Modifier, AsmVariant);
363 printOperand(P, MI, Op + X86::AddrDisp, O, Modifier);
362364 } else {
363365 int64_t DispVal = DispSpec.getImm();
364366 if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) {
421423 /// PrintAsmOperand - Print out an operand for an inline asm expression.
422424 ///
423425 bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
424 unsigned AsmVariant,
425426 const char *ExtraCode, raw_ostream &O) {
426427 // Does this asm operand have a single letter operand modifier?
427428 if (ExtraCode && ExtraCode[0]) {
432433 switch (ExtraCode[0]) {
433434 default:
434435 // See if this is a generic print operand
435 return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
436 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O);
436437 case 'a': // This is an address. Currently only 'i' and 'r' are expected.
437438 switch (MO.getType()) {
438439 default:
508509 }
509510 }
510511
511 printOperand(*this, MI, OpNo, O, /*Modifier*/ nullptr, AsmVariant);
512 printOperand(*this, MI, OpNo, O, /*Modifier*/ nullptr);
512513 return false;
513514 }
514515
515 bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
516 unsigned OpNo, unsigned AsmVariant,
516 bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
517517 const char *ExtraCode,
518518 raw_ostream &O) {
519 if (AsmVariant) {
519 if (MI->getInlineAsmDialect() == InlineAsm::AD_Intel) {
520520 printIntelMemReference(*this, MI, OpNo, O);
521521 return false;
522522 }
122122 }
123123
124124 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
125 unsigned AsmVariant, const char *ExtraCode,
126 raw_ostream &OS) override;
125 const char *ExtraCode, raw_ostream &OS) override;
127126 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
128 unsigned AsmVariant, const char *ExtraCode,
129 raw_ostream &OS) override;
127 const char *ExtraCode, raw_ostream &OS) override;
130128
131129 bool doInitialization(Module &M) override {
132130 SMShadowTracker.reset(0);
6565 }
6666 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
6767 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
68 unsigned AsmVariant, const char *ExtraCode,
69 raw_ostream &O) override;
68 const char *ExtraCode, raw_ostream &O) override;
7069 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
71 unsigned AsmVariant, const char *ExtraCode,
72 raw_ostream &O) override;
70 const char *ExtraCode, raw_ostream &O) override;
7371
7472 void emitArrayBound(MCSymbol *Sym, const GlobalVariable *GV);
7573 void EmitGlobalVariable(const GlobalVariable *GV) override;
231229 /// PrintAsmOperand - Print out an operand for an inline asm expression.
232230 ///
233231 bool XCoreAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
234 unsigned AsmVariant,const char *ExtraCode,
235 raw_ostream &O) {
232 const char *ExtraCode, raw_ostream &O) {
236233 // Print the operand if there is no operand modifier.
237234 if (!ExtraCode || !ExtraCode[0]) {
238235 printOperand(MI, OpNo, O);
240237 }
241238
242239 // Otherwise fallback on the default implementation.
243 return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
244 }
245
246 bool XCoreAsmPrinter::
247 PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
248 unsigned AsmVariant, const char *ExtraCode,
249 raw_ostream &O) {
240 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O);
241 }
242
243 bool XCoreAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
244 unsigned OpNum,
245 const char *ExtraCode,
246 raw_ostream &O) {
250247 if (ExtraCode && ExtraCode[0]) {
251248 return true; // Unknown modifier.
252249 }