LLVM  8.0.0svn
AsmPrinterInlineAsm.cpp
Go to the documentation of this file.
1 //===-- AsmPrinterInlineAsm.cpp - AsmPrinter Inline Asm Handling ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the inline assembler pieces of the AsmPrinter class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/ADT/Twine.h"
23 #include "llvm/IR/Constants.h"
24 #include "llvm/IR/DataLayout.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"
35 #include "llvm/Support/SourceMgr.h"
39 using namespace llvm;
40 
41 #define DEBUG_TYPE "asm-printer"
42 
43 /// srcMgrDiagHandler - This callback is invoked when the SourceMgr for an
44 /// inline asm has an error in it. diagInfo is a pointer to the SrcMgrDiagInfo
45 /// struct above.
46 static void srcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) {
47  AsmPrinter::SrcMgrDiagInfo *DiagInfo =
48  static_cast<AsmPrinter::SrcMgrDiagInfo *>(diagInfo);
49  assert(DiagInfo && "Diagnostic context not passed down?");
50 
51  // Look up a LocInfo for the buffer this diagnostic is coming from.
52  unsigned BufNum = DiagInfo->SrcMgr.FindBufferContainingLoc(Diag.getLoc());
53  const MDNode *LocInfo = nullptr;
54  if (BufNum > 0 && BufNum <= DiagInfo->LocInfos.size())
55  LocInfo = DiagInfo->LocInfos[BufNum-1];
56 
57  // If the inline asm had metadata associated with it, pull out a location
58  // cookie corresponding to which line the error occurred on.
59  unsigned LocCookie = 0;
60  if (LocInfo) {
61  unsigned ErrorLine = Diag.getLineNo()-1;
62  if (ErrorLine >= LocInfo->getNumOperands())
63  ErrorLine = 0;
64 
65  if (LocInfo->getNumOperands() != 0)
66  if (const ConstantInt *CI =
67  mdconst::dyn_extract<ConstantInt>(LocInfo->getOperand(ErrorLine)))
68  LocCookie = CI->getZExtValue();
69  }
70 
71  DiagInfo->DiagHandler(Diag, DiagInfo->DiagContext, LocCookie);
72 }
73 
74 /// EmitInlineAsm - Emit a blob of inline asm to the output streamer.
75 void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
76  const MCTargetOptions &MCOptions,
77  const MDNode *LocMDNode,
78  InlineAsm::AsmDialect Dialect) const {
79  assert(!Str.empty() && "Can't emit empty inline asm block");
80 
81  // Remember if the buffer is nul terminated or not so we can avoid a copy.
82  bool isNullTerminated = Str.back() == 0;
83  if (isNullTerminated)
84  Str = Str.substr(0, Str.size()-1);
85 
86  // If the output streamer does not have mature MC support or the integrated
87  // assembler has been disabled, just emit the blob textually.
88  // Otherwise parse the asm and emit it via MC support.
89  // This is useful in case the asm parser doesn't handle something but the
90  // system assembler does.
91  const MCAsmInfo *MCAI = TM.getMCAsmInfo();
92  assert(MCAI && "No MCAsmInfo");
93  if (!MCAI->useIntegratedAssembler() &&
94  !OutStreamer->isIntegratedAssemblerRequired()) {
96  OutStreamer->EmitRawText(Str);
97  emitInlineAsmEnd(STI, nullptr);
98  return;
99  }
100 
101  if (!DiagInfo) {
102  DiagInfo = make_unique<SrcMgrDiagInfo>();
103 
105  Context.setInlineSourceManager(&DiagInfo->SrcMgr);
106 
107  LLVMContext &LLVMCtx = MMI->getModule()->getContext();
108  if (LLVMCtx.getInlineAsmDiagnosticHandler()) {
109  DiagInfo->DiagHandler = LLVMCtx.getInlineAsmDiagnosticHandler();
110  DiagInfo->DiagContext = LLVMCtx.getInlineAsmDiagnosticContext();
111  DiagInfo->SrcMgr.setDiagHandler(srcMgrDiagHandler, DiagInfo.get());
112  }
113  }
114 
115  SourceMgr &SrcMgr = DiagInfo->SrcMgr;
116  SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths);
117 
118  std::unique_ptr<MemoryBuffer> Buffer;
119  // The inline asm source manager will outlive Str, so make a copy of the
120  // string for SourceMgr to own.
121  Buffer = MemoryBuffer::getMemBufferCopy(Str, "<inline asm>");
122 
123  // Tell SrcMgr about this buffer, it takes ownership of the buffer.
124  unsigned BufNum = SrcMgr.AddNewSourceBuffer(std::move(Buffer), SMLoc());
125 
126  // Store LocMDNode in DiagInfo, using BufNum as an identifier.
127  if (LocMDNode) {
128  DiagInfo->LocInfos.resize(BufNum);
129  DiagInfo->LocInfos[BufNum-1] = LocMDNode;
130  }
131 
132  std::unique_ptr<MCAsmParser> Parser(
133  createMCAsmParser(SrcMgr, OutContext, *OutStreamer, *MAI, BufNum));
134 
135  // Do not use assembler-level information for parsing inline assembly.
136  OutStreamer->setUseAssemblerInfoForParsing(false);
137 
138  // We create a new MCInstrInfo here since we might be at the module level
139  // and not have a MachineFunction to initialize the TargetInstrInfo from and
140  // we only need MCInstrInfo for asm parsing. We create one unconditionally
141  // because it's not subtarget dependent.
142  std::unique_ptr<MCInstrInfo> MII(TM.getTarget().createMCInstrInfo());
143  std::unique_ptr<MCTargetAsmParser> TAP(TM.getTarget().createMCAsmParser(
144  STI, *Parser, *MII, MCOptions));
145  if (!TAP)
146  report_fatal_error("Inline asm not supported by this streamer because"
147  " we don't have an asm parser for this target\n");
148  Parser->setAssemblerDialect(Dialect);
149  Parser->setTargetParser(*TAP.get());
150  Parser->setEnablePrintSchedInfo(EnablePrintSchedInfo);
151  if (Dialect == InlineAsm::AD_Intel)
152  // We need this flag to be able to parse numbers like "0bH"
153  Parser->setParsingInlineAsm(true);
154  if (MF) {
156  TAP->SetFrameRegister(TRI->getFrameRegister(*MF));
157  }
158 
160  // Don't implicitly switch to the text section before the asm.
161  int Res = Parser->Run(/*NoInitialTextSection*/ true,
162  /*NoFinalize*/ true);
163  emitInlineAsmEnd(STI, &TAP->getSTI());
164 
165  if (Res && !DiagInfo->DiagHandler)
166  report_fatal_error("Error parsing inline asm\n");
167 }
168 
169 static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
170  MachineModuleInfo *MMI, int InlineAsmVariant,
171  AsmPrinter *AP, unsigned LocCookie,
172  raw_ostream &OS) {
173  // Switch to the inline assembly variant.
174  OS << "\t.intel_syntax\n\t";
175 
176  const char *LastEmitted = AsmStr; // One past the last character emitted.
177  unsigned NumOperands = MI->getNumOperands();
178 
179  while (*LastEmitted) {
180  switch (*LastEmitted) {
181  default: {
182  // Not a special case, emit the string section literally.
183  const char *LiteralEnd = LastEmitted+1;
184  while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
185  *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
186  ++LiteralEnd;
187 
188  OS.write(LastEmitted, LiteralEnd-LastEmitted);
189  LastEmitted = LiteralEnd;
190  break;
191  }
192  case '\n':
193  ++LastEmitted; // Consume newline character.
194  OS << '\n'; // Indent code with newline.
195  break;
196  case '$': {
197  ++LastEmitted; // Consume '$' character.
198  bool Done = true;
199 
200  // Handle escapes.
201  switch (*LastEmitted) {
202  default: Done = false; break;
203  case '$':
204  ++LastEmitted; // Consume second '$' character.
205  break;
206  }
207  if (Done) break;
208 
209  // If we have ${:foo}, then this is not a real operand reference, it is a
210  // "magic" string reference, just like in .td files. Arrange to call
211  // PrintSpecial.
212  if (LastEmitted[0] == '{' && LastEmitted[1] == ':') {
213  LastEmitted += 2;
214  const char *StrStart = LastEmitted;
215  const char *StrEnd = strchr(StrStart, '}');
216  if (!StrEnd)
217  report_fatal_error("Unterminated ${:foo} operand in inline asm"
218  " string: '" + Twine(AsmStr) + "'");
219 
220  std::string Val(StrStart, StrEnd);
221  AP->PrintSpecial(MI, OS, Val.c_str());
222  LastEmitted = StrEnd+1;
223  break;
224  }
225 
226  const char *IDStart = LastEmitted;
227  const char *IDEnd = IDStart;
228  while (*IDEnd >= '0' && *IDEnd <= '9') ++IDEnd;
229 
230  unsigned Val;
231  if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
232  report_fatal_error("Bad $ operand number in inline asm string: '" +
233  Twine(AsmStr) + "'");
234  LastEmitted = IDEnd;
235 
236  if (Val >= NumOperands-1)
237  report_fatal_error("Invalid $ operand number in inline asm string: '" +
238  Twine(AsmStr) + "'");
239 
240  // Okay, we finally have a value number. Ask the target to print this
241  // operand!
242  unsigned OpNo = InlineAsm::MIOp_FirstOperand;
243 
244  bool Error = false;
245 
246  // Scan to find the machine operand number for the operand.
247  for (; Val; --Val) {
248  if (OpNo >= MI->getNumOperands()) break;
249  unsigned OpFlags = MI->getOperand(OpNo).getImm();
250  OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
251  }
252 
253  // We may have a location metadata attached to the end of the
254  // instruction, and at no point should see metadata at any
255  // other point while processing. It's an error if so.
256  if (OpNo >= MI->getNumOperands() ||
257  MI->getOperand(OpNo).isMetadata()) {
258  Error = true;
259  } else {
260  unsigned OpFlags = MI->getOperand(OpNo).getImm();
261  ++OpNo; // Skip over the ID number.
262 
263  if (InlineAsm::isMemKind(OpFlags)) {
264  Error = AP->PrintAsmMemoryOperand(MI, OpNo, InlineAsmVariant,
265  /*Modifier*/ nullptr, OS);
266  } else {
267  Error = AP->PrintAsmOperand(MI, OpNo, InlineAsmVariant,
268  /*Modifier*/ nullptr, OS);
269  }
270  }
271  if (Error) {
272  std::string msg;
273  raw_string_ostream Msg(msg);
274  Msg << "invalid operand in inline asm: '" << AsmStr << "'";
275  MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
276  }
277  break;
278  }
279  }
280  }
281  OS << "\n\t.att_syntax\n" << (char)0; // null terminate string.
282 }
283 
284 static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI,
285  MachineModuleInfo *MMI, int InlineAsmVariant,
286  int AsmPrinterVariant, AsmPrinter *AP,
287  unsigned LocCookie, raw_ostream &OS) {
288  int CurVariant = -1; // The number of the {.|.|.} region we are in.
289  const char *LastEmitted = AsmStr; // One past the last character emitted.
290  unsigned NumOperands = MI->getNumOperands();
291 
292  OS << '\t';
293 
294  while (*LastEmitted) {
295  switch (*LastEmitted) {
296  default: {
297  // Not a special case, emit the string section literally.
298  const char *LiteralEnd = LastEmitted+1;
299  while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
300  *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
301  ++LiteralEnd;
302  if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
303  OS.write(LastEmitted, LiteralEnd-LastEmitted);
304  LastEmitted = LiteralEnd;
305  break;
306  }
307  case '\n':
308  ++LastEmitted; // Consume newline character.
309  OS << '\n'; // Indent code with newline.
310  break;
311  case '$': {
312  ++LastEmitted; // Consume '$' character.
313  bool Done = true;
314 
315  // Handle escapes.
316  switch (*LastEmitted) {
317  default: Done = false; break;
318  case '$': // $$ -> $
319  if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
320  OS << '$';
321  ++LastEmitted; // Consume second '$' character.
322  break;
323  case '(': // $( -> same as GCC's { character.
324  ++LastEmitted; // Consume '(' character.
325  if (CurVariant != -1)
326  report_fatal_error("Nested variants found in inline asm string: '" +
327  Twine(AsmStr) + "'");
328  CurVariant = 0; // We're in the first variant now.
329  break;
330  case '|':
331  ++LastEmitted; // consume '|' character.
332  if (CurVariant == -1)
333  OS << '|'; // this is gcc's behavior for | outside a variant
334  else
335  ++CurVariant; // We're in the next variant.
336  break;
337  case ')': // $) -> same as GCC's } char.
338  ++LastEmitted; // consume ')' character.
339  if (CurVariant == -1)
340  OS << '}'; // this is gcc's behavior for } outside a variant
341  else
342  CurVariant = -1;
343  break;
344  }
345  if (Done) break;
346 
347  bool HasCurlyBraces = false;
348  if (*LastEmitted == '{') { // ${variable}
349  ++LastEmitted; // Consume '{' character.
350  HasCurlyBraces = true;
351  }
352 
353  // If we have ${:foo}, then this is not a real operand reference, it is a
354  // "magic" string reference, just like in .td files. Arrange to call
355  // PrintSpecial.
356  if (HasCurlyBraces && *LastEmitted == ':') {
357  ++LastEmitted;
358  const char *StrStart = LastEmitted;
359  const char *StrEnd = strchr(StrStart, '}');
360  if (!StrEnd)
361  report_fatal_error("Unterminated ${:foo} operand in inline asm"
362  " string: '" + Twine(AsmStr) + "'");
363 
364  std::string Val(StrStart, StrEnd);
365  AP->PrintSpecial(MI, OS, Val.c_str());
366  LastEmitted = StrEnd+1;
367  break;
368  }
369 
370  const char *IDStart = LastEmitted;
371  const char *IDEnd = IDStart;
372  while (*IDEnd >= '0' && *IDEnd <= '9') ++IDEnd;
373 
374  unsigned Val;
375  if (StringRef(IDStart, IDEnd-IDStart).getAsInteger(10, Val))
376  report_fatal_error("Bad $ operand number in inline asm string: '" +
377  Twine(AsmStr) + "'");
378  LastEmitted = IDEnd;
379 
380  char Modifier[2] = { 0, 0 };
381 
382  if (HasCurlyBraces) {
383  // If we have curly braces, check for a modifier character. This
384  // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
385  if (*LastEmitted == ':') {
386  ++LastEmitted; // Consume ':' character.
387  if (*LastEmitted == 0)
388  report_fatal_error("Bad ${:} expression in inline asm string: '" +
389  Twine(AsmStr) + "'");
390 
391  Modifier[0] = *LastEmitted;
392  ++LastEmitted; // Consume modifier character.
393  }
394 
395  if (*LastEmitted != '}')
396  report_fatal_error("Bad ${} expression in inline asm string: '" +
397  Twine(AsmStr) + "'");
398  ++LastEmitted; // Consume '}' character.
399  }
400 
401  if (Val >= NumOperands-1)
402  report_fatal_error("Invalid $ operand number in inline asm string: '" +
403  Twine(AsmStr) + "'");
404 
405  // Okay, we finally have a value number. Ask the target to print this
406  // operand!
407  if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
408  unsigned OpNo = InlineAsm::MIOp_FirstOperand;
409 
410  bool Error = false;
411 
412  // Scan to find the machine operand number for the operand.
413  for (; Val; --Val) {
414  if (OpNo >= MI->getNumOperands()) break;
415  unsigned OpFlags = MI->getOperand(OpNo).getImm();
416  OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
417  }
418 
419  // We may have a location metadata attached to the end of the
420  // instruction, and at no point should see metadata at any
421  // other point while processing. It's an error if so.
422  if (OpNo >= MI->getNumOperands() ||
423  MI->getOperand(OpNo).isMetadata()) {
424  Error = true;
425  } else {
426  unsigned OpFlags = MI->getOperand(OpNo).getImm();
427  ++OpNo; // Skip over the ID number.
428 
429  if (Modifier[0] == 'l') { // Labels are target independent.
430  // FIXME: What if the operand isn't an MBB, report error?
431  const MCSymbol *Sym = MI->getOperand(OpNo).getMBB()->getSymbol();
432  Sym->print(OS, AP->MAI);
433  } else {
434  if (InlineAsm::isMemKind(OpFlags)) {
435  Error = AP->PrintAsmMemoryOperand(MI, OpNo, InlineAsmVariant,
436  Modifier[0] ? Modifier : nullptr,
437  OS);
438  } else {
439  Error = AP->PrintAsmOperand(MI, OpNo, InlineAsmVariant,
440  Modifier[0] ? Modifier : nullptr, OS);
441  }
442  }
443  }
444  if (Error) {
445  std::string msg;
446  raw_string_ostream Msg(msg);
447  Msg << "invalid operand in inline asm: '" << AsmStr << "'";
448  MMI->getModule()->getContext().emitError(LocCookie, Msg.str());
449  }
450  }
451  break;
452  }
453  }
454  }
455  OS << '\n' << (char)0; // null terminate string.
456 }
457 
458 /// EmitInlineAsm - This method formats and emits the specified machine
459 /// instruction that is an inline asm.
460 void AsmPrinter::EmitInlineAsm(const MachineInstr *MI) const {
461  assert(MI->isInlineAsm() && "printInlineAsm only works on inline asms");
462 
463  // Count the number of register definitions to find the asm string.
464  unsigned NumDefs = 0;
465  for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
466  ++NumDefs)
467  assert(NumDefs != MI->getNumOperands()-2 && "No asm string?");
468 
469  assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
470 
471  // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
472  const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
473 
474  // If this asmstr is empty, just print the #APP/#NOAPP markers.
475  // These are useful to see where empty asm's wound up.
476  if (AsmStr[0] == 0) {
477  OutStreamer->emitRawComment(MAI->getInlineAsmStart());
478  OutStreamer->emitRawComment(MAI->getInlineAsmEnd());
479  return;
480  }
481 
482  // Emit the #APP start marker. This has to happen even if verbose-asm isn't
483  // enabled, so we use emitRawComment.
484  OutStreamer->emitRawComment(MAI->getInlineAsmStart());
485 
486  // Get the !srcloc metadata node if we have it, and decode the loc cookie from
487  // it.
488  unsigned LocCookie = 0;
489  const MDNode *LocMD = nullptr;
490  for (unsigned i = MI->getNumOperands(); i != 0; --i) {
491  if (MI->getOperand(i-1).isMetadata() &&
492  (LocMD = MI->getOperand(i-1).getMetadata()) &&
493  LocMD->getNumOperands() != 0) {
494  if (const ConstantInt *CI =
495  mdconst::dyn_extract<ConstantInt>(LocMD->getOperand(0))) {
496  LocCookie = CI->getZExtValue();
497  break;
498  }
499  }
500  }
501 
502  // Emit the inline asm to a temporary string so we can emit it through
503  // EmitInlineAsm.
504  SmallString<256> StringData;
505  raw_svector_ostream OS(StringData);
506 
507  // The variant of the current asmprinter.
508  int AsmPrinterVariant = MAI->getAssemblerDialect();
509  InlineAsm::AsmDialect InlineAsmVariant = MI->getInlineAsmDialect();
510  AsmPrinter *AP = const_cast<AsmPrinter*>(this);
511  if (InlineAsmVariant == InlineAsm::AD_ATT)
512  EmitGCCInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AsmPrinterVariant,
513  AP, LocCookie, OS);
514  else
515  EmitMSInlineAsmStr(AsmStr, MI, MMI, InlineAsmVariant, AP, LocCookie, OS);
516 
517  // Reset SanitizeAddress based on the function's attribute.
518  MCTargetOptions MCOptions = TM.Options.MCOptions;
519  MCOptions.SanitizeAddress =
520  MF->getFunction().hasFnAttribute(Attribute::SanitizeAddress);
521 
522  EmitInlineAsm(OS.str(), getSubtargetInfo(), MCOptions, LocMD,
523  MI->getInlineAsmDialect());
524 
525  // Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't
526  // enabled, so we use emitRawComment.
527  OutStreamer->emitRawComment(MAI->getInlineAsmEnd());
528 }
529 
530 
531 /// PrintSpecial - Print information related to the specified machine instr
532 /// that is independent of the operand, and may be independent of the instr
533 /// itself. This can be useful for portably encoding the comment character
534 /// or other bits of target-specific knowledge into the asmstrings. The
535 /// syntax used is ${:comment}. Targets can override this to add support
536 /// for their own strange codes.
538  const char *Code) const {
539  if (!strcmp(Code, "private")) {
540  const DataLayout &DL = MF->getDataLayout();
541  OS << DL.getPrivateGlobalPrefix();
542  } else if (!strcmp(Code, "comment")) {
543  OS << MAI->getCommentString();
544  } else if (!strcmp(Code, "uid")) {
545  // Comparing the address of MI isn't sufficient, because machineinstrs may
546  // be allocated to the same address across functions.
547 
548  // If this is a new LastFn instruction, bump the counter.
549  if (LastMI != MI || LastFn != getFunctionNumber()) {
550  ++Counter;
551  LastMI = MI;
552  LastFn = getFunctionNumber();
553  }
554  OS << Counter;
555  } else {
556  std::string msg;
557  raw_string_ostream Msg(msg);
558  Msg << "Unknown special formatter '" << Code
559  << "' for machine instr: " << *MI;
560  report_fatal_error(Msg.str());
561  }
562 }
563 
564 /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
565 /// instruction, using the specified assembler variant. Targets should
566 /// override this to format as appropriate.
567 bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
568  unsigned AsmVariant, const char *ExtraCode,
569  raw_ostream &O) {
570  // Does this asm operand have a single letter operand modifier?
571  if (ExtraCode && ExtraCode[0]) {
572  if (ExtraCode[1] != 0) return true; // Unknown modifier.
573 
574  const MachineOperand &MO = MI->getOperand(OpNo);
575  switch (ExtraCode[0]) {
576  default:
577  return true; // Unknown modifier.
578  case 'c': // Substitute immediate value without immediate syntax
580  return true;
581  O << MO.getImm();
582  return false;
583  case 'n': // Negate the immediate constant.
585  return true;
586  O << -MO.getImm();
587  return false;
588  case 's': // The GCC deprecated s modifier
590  return true;
591  O << ((32 - MO.getImm()) & 31);
592  return false;
593  }
594  }
595  return true;
596 }
597 
598 bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
599  unsigned AsmVariant,
600  const char *ExtraCode, raw_ostream &O) {
601  // Target doesn't support this yet!
602  return true;
603 }
604 
606 
608  const MCSubtargetInfo *EndInfo) const {}
virtual void emitInlineAsmStart() const
Let the target do anything it needs to do before emitting inlineasm.
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
const char * getInlineAsmStart() const
Definition: MCAsmInfo.h:504
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
Definition: SourceMgr.cpp:61
LLVMContext & Context
MachineBasicBlock * getMBB() const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
MCTargetOptions MCOptions
Machine level options.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:119
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
SMLoc getLoc() const
Definition: SourceMgr.h:286
StringRef getPrivateGlobalPrefix() const
Definition: DataLayout.h:294
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
std::vector< std::string > IASSearchPaths
Additional paths to search for .include directives when using the integrated assembler.
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:88
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
bool EnablePrintSchedInfo
Enable print [latency:throughput] in output.
Definition: AsmPrinter.h:125
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:223
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
SourceMgr SrcMgr
Definition: Error.cpp:24
bool SanitizeAddress
Enables AddressSanitizer instrumentation at machine level.
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
bool isInlineAsm() const
Definition: MachineInstr.h:867
void * getInlineAsmDiagnosticContext() const
getInlineAsmDiagnosticContext - Return the diagnostic context set by setInlineAsmDiagnosticHandler.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:307
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:504
bool isMetadata() const
isMetadata - Tests if this is a MO_Metadata operand.
unsigned const TargetRegisterInfo * TRI
Metadata node.
Definition: Metadata.h:862
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:96
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1067
const char * getInlineAsmEnd() const
Definition: MCAsmInfo.h:505
LLVMContext::InlineAsmDiagHandlerTy DiagHandler
Definition: AsmPrinter.h:163
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance.
Definition: AsmParser.cpp:5899
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:314
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:242
int getLineNo() const
Definition: SourceMgr.h:288
const char * getSymbolName() const
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
Context object for machine code objects.
Definition: MCContext.h:63
void emitError(unsigned LocCookie, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
const MCContext & getContext() const
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition: SourceMgr.h:152
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:598
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:99
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
void setInlineSourceManager(SourceMgr *SM)
Definition: MCContext.h:291
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:84
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
unsigned getAssemblerDialect() const
Definition: MCAsmInfo.h:509
This file contains the declarations for the subclasses of Constant, which represent the different fla...
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:81
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
static unsigned getNumOperandRegisters(unsigned Flag)
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag...
Definition: InlineAsm.h:336
StringRef getCommentString() const
Definition: MCAsmInfo.h:486
static void srcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo)
srcMgrDiagHandler - This callback is invoked when the SourceMgr for an inline asm has an error in it...
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:42
const Target & getTarget() const
static bool isMemKind(unsigned Flag)
Definition: InlineAsm.h:277
MCTargetAsmParser * createMCAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser, const MCInstrInfo &MII, const MCTargetOptions &Options) const
createMCAsmParser - Create a target specific assembly parser.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVM_NODISCARD char back() const
back - Get the last character in the string.
Definition: StringRef.h:149
std::string & str()
Flushes the stream contents to the target string and returns the string&#39;s reference.
Definition: raw_ostream.h:493
raw_ostream & write(unsigned char C)
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:497
unsigned getFunctionNumber() const
Return a unique ID for the current function.
Definition: AsmPrinter.cpp:205
InlineAsm::AsmDialect getInlineAsmDialect() const
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
MachineOperand class - Representation of each machine instruction operand.
Module.h This file contains the declarations for the Module class.
virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, const MCSubtargetInfo *EndInfo) const
Let the target do anything it needs to do after emitting inlineasm.
StringRef str()
Return a StringRef for the vector contents.
Definition: raw_ostream.h:529
int64_t getImm() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
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...
bool useIntegratedAssembler() const
Return true if assembly (inline or otherwise) should be parsed.
Definition: MCAsmInfo.h:610
Representation of each machine instruction.
Definition: MachineInstr.h:60
TargetOptions Options
Definition: TargetMachine.h:98
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Generic base class for all target subtargets.
InlineAsmDiagHandlerTy getInlineAsmDiagnosticHandler() const
getInlineAsmDiagnosticHandler - Return the diagnostic handler set by setInlineAsmDiagnosticHandler.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
const Module * getModule() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:477
static void EmitGCCInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, int InlineAsmVariant, int AsmPrinterVariant, AsmPrinter *AP, unsigned LocCookie, raw_ostream &OS)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
void setIncludeDirs(const std::vector< std::string > &Dirs)
Definition: SourceMgr.h:112
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static void EmitMSInlineAsmStr(const char *AsmStr, const MachineInstr *MI, MachineModuleInfo *MMI, int InlineAsmVariant, AsmPrinter *AP, unsigned LocCookie, raw_ostream &OS)
std::vector< const MDNode * > LocInfos
Definition: AsmPrinter.h:162
Represents a location in source code.
Definition: SMLoc.h:24
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1073
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:316
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
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...
const MDNode * getMetadata() const
This class contains meta information specific to a module.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:260
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:60