LLVM  14.0.0git
AsmPrinterInlineAsm.cpp
Go to the documentation of this file.
1 //===-- AsmPrinterInlineAsm.cpp - AsmPrinter Inline Asm Handling ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the inline assembler pieces of the AsmPrinter class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/ADT/SmallString.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/Twine.h"
22 #include "llvm/IR/Constants.h"
23 #include "llvm/IR/DataLayout.h"
24 #include "llvm/IR/DiagnosticInfo.h"
25 #include "llvm/IR/InlineAsm.h"
26 #include "llvm/IR/LLVMContext.h"
27 #include "llvm/IR/Module.h"
28 #include "llvm/MC/MCAsmInfo.h"
30 #include "llvm/MC/MCStreamer.h"
32 #include "llvm/MC/MCSymbol.h"
33 #include "llvm/MC/TargetRegistry.h"
36 #include "llvm/Support/SourceMgr.h"
39 using namespace llvm;
40 
41 #define DEBUG_TYPE "asm-printer"
42 
43 unsigned AsmPrinter::addInlineAsmDiagBuffer(StringRef AsmStr,
44  const MDNode *LocMDNode) const {
46  Context.initInlineSourceManager();
47  SourceMgr &SrcMgr = *Context.getInlineSourceManager();
48  std::vector<const MDNode *> &LocInfos = Context.getLocInfos();
49 
50  std::unique_ptr<MemoryBuffer> Buffer;
51  // The inline asm source manager will outlive AsmStr, so make a copy of the
52  // string for SourceMgr to own.
53  Buffer = MemoryBuffer::getMemBufferCopy(AsmStr, "<inline asm>");
54 
55  // Tell SrcMgr about this buffer, it takes ownership of the buffer.
56  unsigned BufNum = SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
57 
58  // Store LocMDNode in DiagInfo, using BufNum as an identifier.
59  if (LocMDNode) {
60  LocInfos.resize(BufNum);
61  LocInfos[BufNum - 1] = LocMDNode;
62  }
63 
64  return BufNum;
65 }
66 
67 
68 /// EmitInlineAsm - Emit a blob of inline asm to the output streamer.
69 void AsmPrinter::emitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
70  const MCTargetOptions &MCOptions,
71  const MDNode *LocMDNode,
72  InlineAsm::AsmDialect Dialect) const {
73  assert(!Str.empty() && "Can't emit empty inline asm block");
74 
75  // Remember if the buffer is nul terminated or not so we can avoid a copy.
76  bool isNullTerminated = Str.back() == 0;
77  if (isNullTerminated)
78  Str = Str.substr(0, Str.size()-1);
79 
80  // If the output streamer does not have mature MC support or the integrated
81  // assembler has been disabled or not required, just emit the blob textually.
82  // Otherwise parse the asm and emit it via MC support.
83  // This is useful in case the asm parser doesn't handle something but the
84  // system assembler does.
85  const MCAsmInfo *MCAI = TM.getMCAsmInfo();
86  assert(MCAI && "No MCAsmInfo");
87  if (!MCAI->useIntegratedAssembler() &&
89  !OutStreamer->isIntegratedAssemblerRequired()) {
91  OutStreamer->emitRawText(Str);
92  emitInlineAsmEnd(STI, nullptr);
93  return;
94  }
95 
96  unsigned BufNum = addInlineAsmDiagBuffer(Str, LocMDNode);
99 
100  std::unique_ptr<MCAsmParser> Parser(
102 
103  // Do not use assembler-level information for parsing inline assembly.
104  OutStreamer->setUseAssemblerInfoForParsing(false);
105 
106  // We create a new MCInstrInfo here since we might be at the module level
107  // and not have a MachineFunction to initialize the TargetInstrInfo from and
108  // we only need MCInstrInfo for asm parsing. We create one unconditionally
109  // because it's not subtarget dependent.
110  std::unique_ptr<MCInstrInfo> MII(TM.getTarget().createMCInstrInfo());
111  assert(MII && "Failed to create instruction info");
112  std::unique_ptr<MCTargetAsmParser> TAP(TM.getTarget().createMCAsmParser(
113  STI, *Parser, *MII, MCOptions));
114  if (!TAP)
115  report_fatal_error("Inline asm not supported by this streamer because"
116  " we don't have an asm parser for this target\n");
117  Parser->setAssemblerDialect(Dialect);
118  Parser->setTargetParser(*TAP.get());
119  // Enable lexing Masm binary and hex integer literals in intel inline
120  // assembly.
121  if (Dialect == InlineAsm::AD_Intel)
122  Parser->getLexer().setLexMasmIntegers(true);
123 
125  // Don't implicitly switch to the text section before the asm.
126  (void)Parser->Run(/*NoInitialTextSection*/ true,
127  /*NoFinalize*/ true);
128  emitInlineAsmEnd(STI, &TAP->getSTI());
129 }
130 
131 static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
132  MachineModuleInfo *MMI, AsmPrinter *AP,
133  uint64_t LocCookie, raw_ostream &OS) {
134  // Switch to the inline assembly variant.
135  OS << "\t.intel_syntax\n\t";
136 
137  const char *LastEmitted = AsmStr; // One past the last character emitted.
138  unsigned NumOperands = MI->getNumOperands();
139 
140  while (*LastEmitted) {
141  switch (*LastEmitted) {
142  default: {
143  // Not a special case, emit the string section literally.
144  const char *LiteralEnd = LastEmitted+1;
145  while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
146  *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
147  ++LiteralEnd;
148 
149  OS.write(LastEmitted, LiteralEnd-LastEmitted);
150  LastEmitted = LiteralEnd;
151  break;
152  }
153  case '\n':
154  ++LastEmitted; // Consume newline character.
155  OS << '\n'; // Indent code with newline.
156  break;
157  case '$': {
158  ++LastEmitted; // Consume '$' character.
159  bool Done = true;
160 
161  // Handle escapes.
162  switch (*LastEmitted) {
163  default: Done = false; break;
164  case '$':
165  ++LastEmitted; // Consume second '$' character.
166  break;
167  }
168  if (Done) break;
169 
170  bool HasCurlyBraces = false;
171  if (*LastEmitted == '{') { // ${variable}
172  ++LastEmitted; // Consume '{' character.
173  HasCurlyBraces = true;
174  }
175 
176  // If we have ${:foo}, then this is not a real operand reference, it is a
177  // "magic" string reference, just like in .td files. Arrange to call
178  // PrintSpecial.
179  if (HasCurlyBraces && LastEmitted[0] == ':') {
180  ++LastEmitted;
181  const char *StrStart = LastEmitted;
182  const char *StrEnd = strchr(StrStart, '}');
183  if (!StrEnd)
184  report_fatal_error("Unterminated ${:foo} operand in inline asm"
185  " string: '" + Twine(AsmStr) + "'");
186 
187  std::string Val(StrStart, StrEnd);
188  AP->PrintSpecial(MI, OS, Val.c_str());
189  LastEmitted = StrEnd+1;
190  break;
191  }
192 
193  const char *IDStart = LastEmitted;
194  const char *IDEnd = IDStart;
195  while (isDigit(*IDEnd))
196  ++IDEnd;
197 
198  unsigned Val;
199  if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
200  report_fatal_error("Bad $ operand number in inline asm string: '" +
201  Twine(AsmStr) + "'");
202  LastEmitted = IDEnd;
203 
204  if (Val >= NumOperands-1)
205  report_fatal_error("Invalid $ operand number in inline asm string: '" +
206  Twine(AsmStr) + "'");
207 
208  char Modifier[2] = { 0, 0 };
209 
210  if (HasCurlyBraces) {
211  // If we have curly braces, check for a modifier character. This
212  // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
213  if (*LastEmitted == ':') {
214  ++LastEmitted; // Consume ':' character.
215  if (*LastEmitted == 0)
216  report_fatal_error("Bad ${:} expression in inline asm string: '" +
217  Twine(AsmStr) + "'");
218 
219  Modifier[0] = *LastEmitted;
220  ++LastEmitted; // Consume modifier character.
221  }
222 
223  if (*LastEmitted != '}')
224  report_fatal_error("Bad ${} expression in inline asm string: '" +
225  Twine(AsmStr) + "'");
226  ++LastEmitted; // Consume '}' character.
227  }
228 
229  // Okay, we finally have a value number. Ask the target to print this
230  // operand!
231  unsigned OpNo = InlineAsm::MIOp_FirstOperand;
232 
233  bool Error = false;
234 
235  // Scan to find the machine operand number for the operand.
236  for (; Val; --Val) {
237  if (OpNo >= MI->getNumOperands()) break;
238  unsigned OpFlags = MI->getOperand(OpNo).getImm();
239  OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
240  }
241 
242  // We may have a location metadata attached to the end of the
243  // instruction, and at no point should see metadata at any
244  // other point while processing. It's an error if so.
245  if (OpNo >= MI->getNumOperands() ||
246  MI->getOperand(OpNo).isMetadata()) {
247  Error = true;
248  } else {
249  unsigned OpFlags = MI->getOperand(OpNo).getImm();
250  ++OpNo; // Skip over the ID number.
251 
252  if (InlineAsm::isMemKind(OpFlags)) {
254  MI, OpNo, Modifier[0] ? Modifier : nullptr, OS);
255  } else {
256  Error = AP->PrintAsmOperand(MI, OpNo,
257  Modifier[0] ? Modifier : nullptr, OS);
258  }
259  }
260  if (Error) {
261  std::string msg;
262  raw_string_ostream Msg(msg);
263  Msg << "invalid operand in inline asm: '" << AsmStr << "'";
264  MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
265  }
266  break;
267  }
268  }
269  }
270  OS << "\n\t.att_syntax\n" << (char)0; // null terminate string.
271 }
272 
273 static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
274  MachineModuleInfo *MMI, const MCAsmInfo *MAI,
275  AsmPrinter *AP, uint64_t LocCookie,
276  raw_ostream &OS) {
277  int CurVariant = -1; // The number of the {.|.|.} region we are in.
278  const char *LastEmitted = AsmStr; // One past the last character emitted.
279  unsigned NumOperands = MI->getNumOperands();
280  int AsmPrinterVariant = MAI->getAssemblerDialect();
281 
283  OS << '\t';
284 
285  while (*LastEmitted) {
286  switch (*LastEmitted) {
287  default: {
288  // Not a special case, emit the string section literally.
289  const char *LiteralEnd = LastEmitted+1;
290  while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
291  *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
292  ++LiteralEnd;
293  if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
294  OS.write(LastEmitted, LiteralEnd-LastEmitted);
295  LastEmitted = LiteralEnd;
296  break;
297  }
298  case '\n':
299  ++LastEmitted; // Consume newline character.
300  OS << '\n'; // Indent code with newline.
301  break;
302  case '$': {
303  ++LastEmitted; // Consume '$' character.
304  bool Done = true;
305 
306  // Handle escapes.
307  switch (*LastEmitted) {
308  default: Done = false; break;
309  case '$': // $$ -> $
310  if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
311  OS << '$';
312  ++LastEmitted; // Consume second '$' character.
313  break;
314  case '(': // $( -> same as GCC's { character.
315  ++LastEmitted; // Consume '(' character.
316  if (CurVariant != -1)
317  report_fatal_error("Nested variants found in inline asm string: '" +
318  Twine(AsmStr) + "'");
319  CurVariant = 0; // We're in the first variant now.
320  break;
321  case '|':
322  ++LastEmitted; // consume '|' character.
323  if (CurVariant == -1)
324  OS << '|'; // this is gcc's behavior for | outside a variant
325  else
326  ++CurVariant; // We're in the next variant.
327  break;
328  case ')': // $) -> same as GCC's } char.
329  ++LastEmitted; // consume ')' character.
330  if (CurVariant == -1)
331  OS << '}'; // this is gcc's behavior for } outside a variant
332  else
333  CurVariant = -1;
334  break;
335  }
336  if (Done) break;
337 
338  bool HasCurlyBraces = false;
339  if (*LastEmitted == '{') { // ${variable}
340  ++LastEmitted; // Consume '{' character.
341  HasCurlyBraces = true;
342  }
343 
344  // If we have ${:foo}, then this is not a real operand reference, it is a
345  // "magic" string reference, just like in .td files. Arrange to call
346  // PrintSpecial.
347  if (HasCurlyBraces && *LastEmitted == ':') {
348  ++LastEmitted;
349  const char *StrStart = LastEmitted;
350  const char *StrEnd = strchr(StrStart, '}');
351  if (!StrEnd)
352  report_fatal_error("Unterminated ${:foo} operand in inline asm"
353  " string: '" + Twine(AsmStr) + "'");
354 
355  std::string Val(StrStart, StrEnd);
356  AP->PrintSpecial(MI, OS, Val.c_str());
357  LastEmitted = StrEnd+1;
358  break;
359  }
360 
361  const char *IDStart = LastEmitted;
362  const char *IDEnd = IDStart;
363  while (isDigit(*IDEnd))
364  ++IDEnd;
365 
366  unsigned Val;
367  if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
368  report_fatal_error("Bad $ operand number in inline asm string: '" +
369  Twine(AsmStr) + "'");
370  LastEmitted = IDEnd;
371 
372  char Modifier[2] = { 0, 0 };
373 
374  if (HasCurlyBraces) {
375  // If we have curly braces, check for a modifier character. This
376  // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
377  if (*LastEmitted == ':') {
378  ++LastEmitted; // Consume ':' character.
379  if (*LastEmitted == 0)
380  report_fatal_error("Bad ${:} expression in inline asm string: '" +
381  Twine(AsmStr) + "'");
382 
383  Modifier[0] = *LastEmitted;
384  ++LastEmitted; // Consume modifier character.
385  }
386 
387  if (*LastEmitted != '}')
388  report_fatal_error("Bad ${} expression in inline asm string: '" +
389  Twine(AsmStr) + "'");
390  ++LastEmitted; // Consume '}' character.
391  }
392 
393  if (Val >= NumOperands-1)
394  report_fatal_error("Invalid $ operand number in inline asm string: '" +
395  Twine(AsmStr) + "'");
396 
397  // Okay, we finally have a value number. Ask the target to print this
398  // operand!
399  if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
400  unsigned OpNo = InlineAsm::MIOp_FirstOperand;
401 
402  bool Error = false;
403 
404  // Scan to find the machine operand number for the operand.
405  for (; Val; --Val) {
406  if (OpNo >= MI->getNumOperands()) break;
407  unsigned OpFlags = MI->getOperand(OpNo).getImm();
408  OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
409  }
410 
411  // We may have a location metadata attached to the end of the
412  // instruction, and at no point should see metadata at any
413  // other point while processing. It's an error if so.
414  if (OpNo >= MI->getNumOperands() ||
415  MI->getOperand(OpNo).isMetadata()) {
416  Error = true;
417  } else {
418  unsigned OpFlags = MI->getOperand(OpNo).getImm();
419  ++OpNo; // Skip over the ID number.
420 
421  // FIXME: Shouldn't arch-independent output template handling go into
422  // PrintAsmOperand?
423  // Labels are target independent.
424  if (MI->getOperand(OpNo).isBlockAddress()) {
425  const BlockAddress *BA = MI->getOperand(OpNo).getBlockAddress();
426  MCSymbol *Sym = AP->GetBlockAddressSymbol(BA);
427  Sym->print(OS, AP->MAI);
429  } else if (MI->getOperand(OpNo).isMBB()) {
430  const MCSymbol *Sym = MI->getOperand(OpNo).getMBB()->getSymbol();
431  Sym->print(OS, AP->MAI);
432  } else if (Modifier[0] == 'l') {
433  Error = true;
434  } else if (InlineAsm::isMemKind(OpFlags)) {
436  MI, OpNo, Modifier[0] ? Modifier : nullptr, OS);
437  } else {
438  Error = AP->PrintAsmOperand(MI, OpNo,
439  Modifier[0] ? Modifier : nullptr, OS);
440  }
441  }
442  if (Error) {
443  std::string msg;
444  raw_string_ostream Msg(msg);
445  Msg << "invalid operand in inline asm: '" << AsmStr << "'";
446  MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
447  }
448  }
449  break;
450  }
451  }
452  }
453  OS << '\n' << (char)0; // null terminate string.
454 }
455 
456 /// This method formats and emits the specified machine instruction that is an
457 /// inline asm.
458 void AsmPrinter::emitInlineAsm(const MachineInstr *MI) const {
459  assert(MI->isInlineAsm() && "printInlineAsm only works on inline asms");
460 
461  // Count the number of register definitions to find the asm string.
462  unsigned NumDefs = 0;
463  for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
464  ++NumDefs)
465  assert(NumDefs != MI->getNumOperands()-2 && "No asm string?");
466 
467  assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
468 
469  // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
470  const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
471 
472  // If this asmstr is empty, just print the #APP/#NOAPP markers.
473  // These are useful to see where empty asm's wound up.
474  if (AsmStr[0] == 0) {
475  OutStreamer->emitRawComment(MAI->getInlineAsmStart());
476  OutStreamer->emitRawComment(MAI->getInlineAsmEnd());
477  return;
478  }
479 
480  // Emit the #APP start marker. This has to happen even if verbose-asm isn't
481  // enabled, so we use emitRawComment.
482  OutStreamer->emitRawComment(MAI->getInlineAsmStart());
483 
484  // Get the !srcloc metadata node if we have it, and decode the loc cookie from
485  // it.
486  uint64_t LocCookie = 0;
487  const MDNode *LocMD = nullptr;
488  for (unsigned i = MI->getNumOperands(); i != 0; --i) {
489  if (MI->getOperand(i-1).isMetadata() &&
490  (LocMD = MI->getOperand(i-1).getMetadata()) &&
491  LocMD->getNumOperands() != 0) {
492  if (const ConstantInt *CI =
493  mdconst::dyn_extract<ConstantInt>(LocMD->getOperand(0))) {
494  LocCookie = CI->getZExtValue();
495  break;
496  }
497  }
498  }
499 
500  // Emit the inline asm to a temporary string so we can emit it through
501  // EmitInlineAsm.
502  SmallString<256> StringData;
503  raw_svector_ostream OS(StringData);
504 
505  AsmPrinter *AP = const_cast<AsmPrinter*>(this);
506  if (MI->getInlineAsmDialect() == InlineAsm::AD_ATT)
507  EmitGCCInlineAsmStr(AsmStr, MI, MMI, MAI, AP, LocCookie, OS);
508  else
509  EmitMSInlineAsmStr(AsmStr, MI, MMI, AP, LocCookie, OS);
510 
511  // Emit warnings if we use reserved registers on the clobber list, as
512  // that might lead to undefined behaviour.
513  SmallVector<Register, 8> RestrRegs;
515  // Start with the first operand descriptor, and iterate over them.
516  for (unsigned I = InlineAsm::MIOp_FirstOperand, NumOps = MI->getNumOperands();
517  I < NumOps; ++I) {
518  const MachineOperand &MO = MI->getOperand(I);
519  if (!MO.isImm())
520  continue;
521  unsigned Flags = MO.getImm();
523  Register Reg = MI->getOperand(I + 1).getReg();
524  if (!TRI->isAsmClobberable(*MF, Reg))
525  RestrRegs.push_back(Reg);
526  }
527  // Skip to one before the next operand descriptor, if it exists.
529  }
530 
531  if (!RestrRegs.empty()) {
532  std::string Msg = "inline asm clobber list contains reserved registers: ";
533  ListSeparator LS;
534  for (const Register &RR : RestrRegs) {
535  Msg += LS;
536  Msg += TRI->getName(RR);
537  }
538  const char *Note =
539  "Reserved registers on the clobber list may not be "
540  "preserved across the asm statement, and clobbering them may "
541  "lead to undefined behaviour.";
543  LocCookie, Msg, DiagnosticSeverity::DS_Warning));
546  }
547 
548  emitInlineAsm(OS.str(), getSubtargetInfo(), TM.Options.MCOptions, LocMD,
549  MI->getInlineAsmDialect());
550 
551  // Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't
552  // enabled, so we use emitRawComment.
553  OutStreamer->emitRawComment(MAI->getInlineAsmEnd());
554 }
555 
556 /// PrintSpecial - Print information related to the specified machine instr
557 /// that is independent of the operand, and may be independent of the instr
558 /// itself. This can be useful for portably encoding the comment character
559 /// or other bits of target-specific knowledge into the asmstrings. The
560 /// syntax used is ${:comment}. Targets can override this to add support
561 /// for their own strange codes.
563  const char *Code) const {
564  if (!strcmp(Code, "private")) {
565  const DataLayout &DL = MF->getDataLayout();
566  OS << DL.getPrivateGlobalPrefix();
567  } else if (!strcmp(Code, "comment")) {
568  OS << MAI->getCommentString();
569  } else if (!strcmp(Code, "uid")) {
570  // Comparing the address of MI isn't sufficient, because machineinstrs may
571  // be allocated to the same address across functions.
572 
573  // If this is a new LastFn instruction, bump the counter.
574  if (LastMI != MI || LastFn != getFunctionNumber()) {
575  ++Counter;
576  LastMI = MI;
577  LastFn = getFunctionNumber();
578  }
579  OS << Counter;
580  } else {
581  std::string msg;
582  raw_string_ostream Msg(msg);
583  Msg << "Unknown special formatter '" << Code
584  << "' for machine instr: " << *MI;
585  report_fatal_error(Twine(Msg.str()));
586  }
587 }
588 
590  assert(MO.isGlobal() && "caller should check MO.isGlobal");
592  printOffset(MO.getOffset(), OS);
593 }
594 
595 /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
596 /// instruction, using the specified assembler variant. Targets should
597 /// override this to format as appropriate for machine specific ExtraCodes
598 /// or when the arch-independent handling would be too complex otherwise.
599 bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
600  const char *ExtraCode, raw_ostream &O) {
601  // Does this asm operand have a single letter operand modifier?
602  if (ExtraCode && ExtraCode[0]) {
603  if (ExtraCode[1] != 0) return true; // Unknown modifier.
604 
605  // https://gcc.gnu.org/onlinedocs/gccint/Output-Template.html
606  const MachineOperand &MO = MI->getOperand(OpNo);
607  switch (ExtraCode[0]) {
608  default:
609  return true; // Unknown modifier.
610  case 'a': // Print as memory address.
611  if (MO.isReg()) {
612  PrintAsmMemoryOperand(MI, OpNo, nullptr, O);
613  return false;
614  }
615  LLVM_FALLTHROUGH; // GCC allows '%a' to behave like '%c' with immediates.
616  case 'c': // Substitute immediate value without immediate syntax
617  if (MO.isImm()) {
618  O << MO.getImm();
619  return false;
620  }
621  if (MO.isGlobal()) {
622  PrintSymbolOperand(MO, O);
623  return false;
624  }
625  return true;
626  case 'n': // Negate the immediate constant.
627  if (!MO.isImm())
628  return true;
629  O << -MO.getImm();
630  return false;
631  case 's': // The GCC deprecated s modifier
632  if (!MO.isImm())
633  return true;
634  O << ((32 - MO.getImm()) & 31);
635  return false;
636  }
637  }
638  return true;
639 }
640 
642  const char *ExtraCode, raw_ostream &O) {
643  // Target doesn't support this yet!
644  return true;
645 }
646 
648 
650  const MCSubtargetInfo *EndInfo) const {}
i
i
Definition: README.txt:29
MemoryBuffer.h
AsmPrinter.h
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MCAsmInfo::getCommentString
StringRef getCommentString() const
Definition: MCAsmInfo.h:641
llvm::LLVMContext::emitError
void emitError(uint64_t LocCookie, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
Definition: LLVMContext.cpp:251
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::MCRegisterInfo::getName
const char * getName(MCRegister RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register.
Definition: MCRegisterInfo.h:485
llvm::InlineAsm::AsmDialect
AsmDialect
Definition: InlineAsm.h:33
llvm::AsmPrinter::printOffset
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
Definition: AsmPrinter.cpp:3095
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCAsmInfo::getEmitGNUAsmStartIndentationMarker
bool getEmitGNUAsmStartIndentationMarker() const
Definition: MCAsmInfo.h:646
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::MachineModuleInfo::getContext
const MCContext & getContext() const
Definition: MachineModuleInfo.h:167
llvm::MCAsmInfo::useIntegratedAssembler
bool useIntegratedAssembler() const
Return true if assembly (inline or otherwise) should be parsed.
Definition: MCAsmInfo.h:814
llvm::MachineOperand::getGlobal
const GlobalValue * getGlobal() const
Definition: MachineOperand.h:563
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::MCAsmInfo::parseInlineAsmUsingAsmParser
bool parseInlineAsmUsingAsmParser() const
Return true if target want to use AsmParser to parse inlineasm.
Definition: MCAsmInfo.h:817
Note
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles Note
Definition: README.txt:239
llvm::AsmPrinter::emitInlineAsmEnd
virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, const MCSubtargetInfo *EndInfo) const
Let the target do anything it needs to do after emitting inlineasm.
Definition: AsmPrinterInlineAsm.cpp:649
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:625
llvm::InlineAsm::AD_ATT
@ AD_ATT
Definition: InlineAsm.h:34
llvm::AsmPrinter::MAI
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:88
llvm::MCAsmInfo::getInlineAsmStart
const char * getInlineAsmStart() const
Definition: MCAsmInfo.h:667
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
InlineAsm.h
ErrorHandling.h
llvm::TargetRegisterInfo::isAsmClobberable
virtual bool isAsmClobberable(const MachineFunction &MF, MCRegister PhysReg) const
Returns false if we can't guarantee that Physreg, specified as an IR asm clobber constraint,...
Definition: TargetRegisterInfo.h:535
MachineBasicBlock.h
llvm::TargetSubtargetInfo::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Definition: TargetSubtargetInfo.h:124
llvm::MCTargetOptions::IASSearchPaths
std::vector< std::string > IASSearchPaths
Additional paths to search for .include directives when using the integrated assembler.
Definition: MCTargetOptions.h:71
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:233
llvm::AsmPrinter::PrintSymbolOperand
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
Definition: AsmPrinterInlineAsm.cpp:589
Module.h
TargetInstrInfo.h
llvm::MCAsmInfo::getAssemblerDialect
unsigned getAssemblerDialect() const
Definition: MCAsmInfo.h:672
llvm::MachineOperand::getOffset
int64_t getOffset() const
Return the offset from the symbol in this operand.
Definition: MachineOperand.h:600
llvm::InlineAsm::Kind_Clobber
@ Kind_Clobber
Definition: InlineAsm.h:236
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1567
MCTargetAsmParser.h
llvm::Target::createMCInstrInfo
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
Definition: TargetRegistry.h:404
llvm::MDNode::getNumOperands
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1143
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::MachineBasicBlock::getSymbol
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Definition: MachineBasicBlock.cpp:60
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
TargetMachine.h
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
Constants.h
SmallString.h
llvm::MachineOperand::getImm
int64_t getImm() const
Definition: MachineOperand.h:537
llvm::DS_Warning
@ DS_Warning
Definition: DiagnosticInfo.h:47
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:97
llvm::AsmPrinter::PrintAsmMemoryOperand
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
Definition: AsmPrinterInlineAsm.cpp:641
Twine.h
llvm::SrcMgr
SourceMgr SrcMgr
Definition: Error.cpp:24
MCSymbol.h
llvm::TargetOptions::MCOptions
MCTargetOptions MCOptions
Machine level options.
Definition: TargetOptions.h:420
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
MCSubtargetInfo.h
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:78
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition: raw_ostream.cpp:220
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCContext::registerInlineAsmLabel
void registerInlineAsmLabel(MCSymbol *Sym)
registerInlineAsmLabel - Records that the name is a label referenced in inline assembly.
Definition: MCContext.cpp:357
EmitGCCInlineAsmStr
static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, const MCAsmInfo *MAI, AsmPrinter *AP, uint64_t LocCookie, raw_ostream &OS)
Definition: AsmPrinterInlineAsm.cpp:273
llvm::MCAsmInfo::getInlineAsmEnd
const char * getInlineAsmEnd() const
Definition: MCAsmInfo.h:668
llvm::AsmPrinter::PrintSpecial
virtual void PrintSpecial(const MachineInstr *MI, raw_ostream &OS, const char *Code) const
Print information related to the specified machine instr that is independent of the operand,...
Definition: AsmPrinterInlineAsm.cpp:562
llvm::MCSymbol::print
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:59
llvm::InlineAsm::getKind
static unsigned getKind(unsigned Flags)
Definition: InlineAsm.h:328
SourceMgr.h
llvm::InlineAsm::isMemKind
static bool isMemKind(unsigned Flag)
Definition: InlineAsm.h:280
llvm::SmallString< 256 >
llvm::Target::createMCAsmParser
MCTargetAsmParser * createMCAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser, const MCInstrInfo &MII, const MCTargetOptions &Options) const
createMCAsmParser - Create a target specific assembly parser.
Definition: TargetRegistry.h:475
llvm::DiagnosticInfoInlineAsm
Diagnostic information for inline asm reporting.
Definition: DiagnosticInfo.h:133
llvm::MDNode::getOperand
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1137
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:630
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:197
llvm::MachineOperand::isReg
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Definition: MachineOperand.h:321
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
uint64_t
llvm::AsmPrinter::GetBlockAddressSymbol
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
Definition: AsmPrinter.cpp:3116
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::AsmPrinter::getSymbolPreferLocal
MCSymbol * getSymbolPreferLocal(const GlobalValue &GV) const
Similar to getSymbol() but preferred for references.
Definition: AsmPrinter.cpp:490
llvm::MCContext::getInlineSourceManager
SourceMgr * getInlineSourceManager()
Definition: MCContext.h:413
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::TargetMachine::Options
TargetOptions Options
Definition: TargetMachine.h:120
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::InlineAsm::MIOp_FirstOperand
@ MIOp_FirstOperand
Definition: InlineAsm.h:220
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:100
llvm::AsmPrinter::OutContext
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:92
MachineModuleInfo.h
llvm::MDNode
Metadata node.
Definition: Metadata.h:906
llvm::MCTargetOptions
Definition: MCTargetOptions.h:36
isReg
static bool isReg(const MCInst &MI, unsigned OpNo)
Definition: MipsInstPrinter.cpp:31
llvm::BlockAddress
The address of a basic block.
Definition: Constants.h:848
llvm::TargetMachine::getMCAsmInfo
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
Definition: TargetMachine.h:207
isDigit
static bool isDigit(const char C)
Definition: RustDemangle.cpp:206
MCAsmInfo.h
llvm::InlineAsm::AD_Intel
@ AD_Intel
Definition: InlineAsm.h:35
DataLayout.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::SourceMgr
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:31
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:286
llvm::SourceMgr::setIncludeDirs
void setIncludeDirs(const std::vector< std::string > &Dirs)
Definition: SourceMgr.h:103
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::AsmPrinter::MMI
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:103
llvm::LLVMContext::diagnose
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Definition: LLVMContext.cpp:228
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::AsmPrinter::getSubtargetInfo
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:238
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::AsmPrinter::emitInlineAsmStart
virtual void emitInlineAsmStart() const
Let the target do anything it needs to do before emitting inlineasm.
Definition: AsmPrinterInlineAsm.cpp:647
llvm::AArch64CC::LS
@ LS
Definition: AArch64BaseInfo.h:264
llvm::Module::getContext
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:261
DiagnosticInfo.h
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
llvm::SourceMgr::AddNewSourceBuffer
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition: SourceMgr.h:141
llvm::MachineOperand::isImm
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
Definition: MachineOperand.h:323
llvm::AsmPrinter::TM
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:85
SmallVector.h
llvm::InlineAsm::getNumOperandRegisters
static unsigned getNumOperandRegisters(unsigned Flag)
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag.
Definition: InlineAsm.h:339
MCStreamer.h
llvm::MachineFunction::getDataLayout
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Definition: MachineFunction.cpp:261
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:658
llvm::createMCAsmParser
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance for parsing assembly similar to gas syntax.
Definition: AsmParser.cpp:6408
EmitMSInlineAsmStr
static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, AsmPrinter *AP, uint64_t LocCookie, raw_ostream &OS)
Definition: AsmPrinterInlineAsm.cpp:131
LLVMContext.h
llvm::TargetMachine::getTarget
const Target & getTarget() const
Definition: TargetMachine.h:126
raw_ostream.h
MachineFunction.h
llvm::MemoryBuffer::getMemBufferCopy
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
Definition: MemoryBuffer.cpp:136
TargetRegistry.h
llvm::raw_string_ostream::str
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
Definition: raw_ostream.h:643
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::AsmPrinter::getFunctionNumber
unsigned getFunctionNumber() const
Return a unique ID for the current function.
Definition: AsmPrinter.cpp:220
llvm::MachineModuleInfo::getModule
const Module * getModule() const
Definition: MachineModuleInfo.h:174
TargetRegisterInfo.h
llvm::AsmPrinter::PrintAsmOperand
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
Definition: AsmPrinterInlineAsm.cpp:599
llvm::MachineOperand::isGlobal
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Definition: MachineOperand.h:339
llvm::DS_Note
@ DS_Note
Definition: DiagnosticInfo.h:51