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