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