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