LLVM 24.0.0git
RISCVAsmPrinter.cpp
Go to the documentation of this file.
1//===-- RISCVAsmPrinter.cpp - RISC-V LLVM assembly writer -----------------===//
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 contains a printer that converts from our internal representation
10// of machine-dependent LLVM code to the RISC-V assembly language.
11//
12//===----------------------------------------------------------------------===//
13
14#include "RISCVAsmPrinter.h"
21#include "RISCV.h"
24#include "RISCVRegisterInfo.h"
26#include "llvm/ADT/APInt.h"
27#include "llvm/ADT/ArrayRef.h"
28#include "llvm/ADT/Statistic.h"
36#include "llvm/IR/Module.h"
37#include "llvm/MC/MCAsmInfo.h"
38#include "llvm/MC/MCContext.h"
39#include "llvm/MC/MCInst.h"
43#include "llvm/MC/MCStreamer.h"
44#include "llvm/MC/MCSymbol.h"
51
52using namespace llvm;
53
54#define DEBUG_TYPE "asm-printer"
55
56STATISTIC(RISCVNumInstrsCompressed,
57 "Number of RISC-V Compressed instructions emitted");
58
59namespace {
60class RISCVAsmPrinter : public AsmPrinter {
61public:
62 static char ID;
63
64private:
65 const RISCVMCOptions &CLOpts;
66 const RISCVSubtarget *STI;
67
68public:
69 explicit RISCVAsmPrinter(TargetMachine &TM,
70 std::unique_ptr<MCStreamer> Streamer)
71 : AsmPrinter(TM, std::move(Streamer), ID),
72 CLOpts(RISCV_MC::getCLOpts(TM.Options.MCOptions)) {}
73
74 StringRef getPassName() const override { return "RISC-V Assembly Printer"; }
75
76 RISCVTargetStreamer &getTargetStreamer() const {
77 return static_cast<RISCVTargetStreamer &>(
78 *OutStreamer->getTargetStreamer());
79 }
80
81 void LowerSTACKMAP(MCStreamer &OutStreamer, StackMaps &SM,
82 const MachineInstr &MI);
83
84 void LowerPATCHPOINT(MCStreamer &OutStreamer, StackMaps &SM,
85 const MachineInstr &MI);
86
87 void LowerSTATEPOINT(MCStreamer &OutStreamer, StackMaps &SM,
88 const MachineInstr &MI);
89
90 bool runOnMachineFunction(MachineFunction &MF) override;
91
92 void emitInstruction(const MachineInstr *MI) override;
93
94 void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;
95
96 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
97 const char *ExtraCode, raw_ostream &OS) override;
98 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
99 const char *ExtraCode, raw_ostream &OS) override;
100
101 // Returns whether Inst is compressed.
102 bool EmitToStreamer(MCStreamer &S, const MCInst &Inst,
103 const MCSubtargetInfo &SubtargetInfo);
104 bool EmitToStreamer(MCStreamer &S, const MCInst &Inst) {
105 return EmitToStreamer(S, Inst, *STI);
106 }
107
108 bool lowerPseudoInstExpansion(const MachineInstr *MI, MCInst &Inst);
109
110 typedef std::tuple<unsigned, uint32_t> HwasanMemaccessTuple;
111 std::map<HwasanMemaccessTuple, MCSymbol *> HwasanMemaccessSymbols;
112 void LowerHWASAN_CHECK_MEMACCESS(const MachineInstr &MI);
113 void LowerKCFI_CHECK(const MachineInstr &MI);
114 void EmitHwasanMemaccessSymbols(Module &M);
115
116 // Wrapper needed for tblgenned pseudo lowering.
117 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
118
119 void emitStartOfAsmFile(Module &M) override;
120 void emitEndOfAsmFile(Module &M) override;
121
122 void emitFunctionEntryLabel() override;
123 bool emitTargetFeaturePush(const MCSubtargetInfo &STI) override;
124 void emitTargetFeaturePop(const MCSubtargetInfo &STI, bool DidPush) override;
125
126 void emitNoteGnuProperty(const Module &M);
127
128private:
129 void emitNTLHint(const MachineInstr *MI);
130
131 void emitLpadAlignedCall(const MachineInstr &MI);
132
133 // XRay Support
134 void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr *MI);
135 void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr *MI);
136 void LowerPATCHABLE_TAIL_CALL(const MachineInstr *MI);
137 void emitSled(const MachineInstr *MI, SledKind Kind);
138
139 void lowerToMCInst(const MachineInstr *MI, MCInst &OutMI);
140
141 MaybeAlign
142 getRequiredGlobalAlignmentGranule(const GlobalVariable &GV) override;
143};
144} // namespace
145
146void RISCVAsmPrinter::LowerSTACKMAP(MCStreamer &OutStreamer, StackMaps &SM,
147 const MachineInstr &MI) {
148 unsigned NOPBytes = STI->hasStdExtZca() ? 2 : 4;
149 unsigned NumNOPBytes = StackMapOpers(&MI).getNumPatchBytes();
150
151 auto &Ctx = OutStreamer.getContext();
152 MCSymbol *MILabel = Ctx.createTempSymbol();
153 OutStreamer.emitLabel(MILabel);
154
155 SM.recordStackMap(*MILabel, MI);
156 assert(NumNOPBytes % NOPBytes == 0 &&
157 "Invalid number of NOP bytes requested!");
158
159 // Scan ahead to trim the shadow.
160 const MachineBasicBlock &MBB = *MI.getParent();
162 ++MII;
163 while (NumNOPBytes > 0) {
164 if (MII != MBB.end() && MII->isDebugInstr()) {
165 ++MII;
166 continue;
167 }
168 if (MII == MBB.end() || MII->isCall() ||
169 MII->getOpcode() == TargetOpcode::PATCHPOINT ||
170 MII->getOpcode() == TargetOpcode::STACKMAP)
171 break;
172 ++MII;
173 NumNOPBytes -= NOPBytes;
174 }
175
176 // Emit nops.
177 emitNops(NumNOPBytes / NOPBytes);
178}
179
180// Lower a patchpoint of the form:
181// [<def>], <id>, <numBytes>, <target>, <numArgs>
182void RISCVAsmPrinter::LowerPATCHPOINT(MCStreamer &OutStreamer, StackMaps &SM,
183 const MachineInstr &MI) {
184 unsigned NOPBytes = STI->hasStdExtZca() ? 2 : 4;
185
186 auto &Ctx = OutStreamer.getContext();
187 MCSymbol *MILabel = Ctx.createTempSymbol();
188 OutStreamer.emitLabel(MILabel);
189 SM.recordPatchPoint(*MILabel, MI);
190
191 PatchPointOpers Opers(&MI);
192
193 const MachineOperand &CalleeMO = Opers.getCallTarget();
194 unsigned EncodedBytes = 0;
195
196 if (CalleeMO.isImm()) {
197 uint64_t CallTarget = CalleeMO.getImm();
198 if (CallTarget) {
199 assert((CallTarget & 0xFFFF'FFFF'FFFF) == CallTarget &&
200 "High 16 bits of call target should be zero.");
201 // Materialize the jump address:
203 RISCVMatInt::generateMCInstSeq(CallTarget, *STI, RISCV::X1, Seq);
204 for (MCInst &Inst : Seq) {
205 bool Compressed = EmitToStreamer(OutStreamer, Inst);
206 EncodedBytes += Compressed ? 2 : 4;
207 }
208 bool Compressed = EmitToStreamer(OutStreamer, MCInstBuilder(RISCV::JALR)
209 .addReg(RISCV::X1)
210 .addReg(RISCV::X1)
211 .addImm(0));
212 EncodedBytes += Compressed ? 2 : 4;
213 }
214 } else if (CalleeMO.isGlobal()) {
215 MCOperand CallTargetMCOp;
216 lowerOperand(CalleeMO, CallTargetMCOp);
217 EmitToStreamer(OutStreamer,
218 MCInstBuilder(RISCV::PseudoCALL).addOperand(CallTargetMCOp));
219 EncodedBytes += 8;
220 }
221
222 // Emit padding.
223 unsigned NumBytes = Opers.getNumPatchBytes();
224 assert(NumBytes >= EncodedBytes &&
225 "Patchpoint can't request size less than the length of a call.");
226 assert((NumBytes - EncodedBytes) % NOPBytes == 0 &&
227 "Invalid number of NOP bytes requested!");
228 emitNops((NumBytes - EncodedBytes) / NOPBytes);
229}
230
231void RISCVAsmPrinter::LowerSTATEPOINT(MCStreamer &OutStreamer, StackMaps &SM,
232 const MachineInstr &MI) {
233 unsigned NOPBytes = STI->hasStdExtZca() ? 2 : 4;
234
235 StatepointOpers SOpers(&MI);
236 if (unsigned PatchBytes = SOpers.getNumPatchBytes()) {
237 assert(PatchBytes % NOPBytes == 0 &&
238 "Invalid number of NOP bytes requested!");
239 emitNops(PatchBytes / NOPBytes);
240 } else {
241 // Lower call target and choose correct opcode
242 const MachineOperand &CallTarget = SOpers.getCallTarget();
243 MCOperand CallTargetMCOp;
244 switch (CallTarget.getType()) {
247 lowerOperand(CallTarget, CallTargetMCOp);
248 EmitToStreamer(
249 OutStreamer,
250 MCInstBuilder(RISCV::PseudoCALL).addOperand(CallTargetMCOp));
251 break;
253 CallTargetMCOp = MCOperand::createImm(CallTarget.getImm());
254 EmitToStreamer(OutStreamer, MCInstBuilder(RISCV::JAL)
255 .addReg(RISCV::X1)
256 .addOperand(CallTargetMCOp));
257 break;
259 CallTargetMCOp = MCOperand::createReg(CallTarget.getReg());
260 EmitToStreamer(OutStreamer, MCInstBuilder(RISCV::JALR)
261 .addReg(RISCV::X1)
262 .addOperand(CallTargetMCOp)
263 .addImm(0));
264 break;
265 default:
266 llvm_unreachable("Unsupported operand type in statepoint call target");
267 break;
268 }
269 }
270
271 auto &Ctx = OutStreamer.getContext();
272 MCSymbol *MILabel = Ctx.createTempSymbol();
273 OutStreamer.emitLabel(MILabel);
274 SM.recordStatepoint(*MILabel, MI);
275}
276
277bool RISCVAsmPrinter::EmitToStreamer(MCStreamer &S, const MCInst &Inst,
278 const MCSubtargetInfo &SubtargetInfo) {
279 MCInst CInst;
280 bool Res = RISCVRVC::compress(CInst, Inst, SubtargetInfo);
281 if (Res)
282 ++RISCVNumInstrsCompressed;
283 S.emitInstruction(Res ? CInst : Inst, SubtargetInfo);
284 return Res;
285}
286
287// Simple pseudo-instructions have their lowering (with expansion to real
288// instructions) auto-generated.
289#include "RISCVGenMCPseudoLowering.inc"
290
291// Emit a call to a returns_twice function with LPAD.
292// When Zca is enabled, emit .p2align 2 before the call to ensure the
293// following LPAD is 4-byte aligned. For assembly output, wrap with
294// .option push/exact/pop to prevent relaxation. For object output,
295// emit the pseudo directly so MCCodeEmitter handles it without R_RISCV_RELAX.
296void RISCVAsmPrinter::emitLpadAlignedCall(const MachineInstr &MI) {
297 const MCSubtargetInfo &MCSTI = getSubtargetInfo();
298 const bool IsIndirect = MI.getOpcode() == RISCV::PseudoCALLIndirectLpadAlign,
299 HasZca = MCSTI.hasFeature(RISCV::FeatureStdExtZca),
300 HasRelax = MCSTI.hasFeature(RISCV::FeatureRelax);
301
302 if (HasZca)
303 OutStreamer->emitCodeAlignment(Align(4), MCSTI);
304
305 if (OutStreamer->hasRawTextSupport()) {
306 // Assembly path: wrap call with .option push/exact/pop and emit LPAD
307 // separately so the output is human-readable.
308 RISCVTargetStreamer &RTS = getTargetStreamer();
309 if (HasZca && HasRelax) {
312 }
313
314 MCInst CallInst;
315 if (!IsIndirect) {
316 MCOperand MCOp;
317 lowerOperand(MI.getOperand(0), MCOp);
318 CallInst = MCInstBuilder(RISCV::PseudoCALL).addOperand(MCOp);
319 } else {
320 CallInst = MCInstBuilder(RISCV::JALR)
321 .addReg(RISCV::X1)
322 .addReg(MI.getOperand(0).getReg())
323 .addImm(0);
324 }
325
326 if (HasZca && HasRelax) {
327 MCSubtargetInfo NoRelaxSTI(MCSTI);
328 NoRelaxSTI.ToggleFeature(RISCV::FeatureRelax);
329 EmitToStreamer(*OutStreamer, CallInst, NoRelaxSTI);
331 } else {
332 EmitToStreamer(*OutStreamer, CallInst, MCSTI);
333 }
334
335 // LPAD is encoded as AUIPC X0, label.
336 MCInst LpadInst = MCInstBuilder(RISCV::AUIPC)
337 .addReg(RISCV::X0)
338 .addImm(MI.getOperand(1).getImm());
339 EmitToStreamer(*OutStreamer, LpadInst, MCSTI);
340 } else {
341 // Object path: emit PseudoCALL(Indirect)LpadAlign directly.
342 // MCCodeEmitter::expandFunctionCallLpad expands to AUIPC+JALR+LPAD
343 // without emitting R_RISCV_RELAX on the call fixup.
344 MCInst TmpInst;
345 TmpInst.setOpcode(MI.getOpcode());
346 if (!IsIndirect) {
347 MCOperand MCOp;
348 lowerOperand(MI.getOperand(0), MCOp);
349 TmpInst.addOperand(MCOp);
350 } else {
351 TmpInst.addOperand(MCOperand::createReg(MI.getOperand(0).getReg()));
352 }
353 TmpInst.addOperand(MCOperand::createImm(MI.getOperand(1).getImm()));
354 EmitToStreamer(*OutStreamer, TmpInst, MCSTI);
355 }
356}
357
358// If the instruction has a nontemporal MachineMemOperand, emit an NTL hint
359// instruction before it. NTL hints are always safe to emit since they use
360// HINT encodings that are guaranteed not to trap
361// (riscv-non-isa/riscv-elf-psabi-doc#474).
362void RISCVAsmPrinter::emitNTLHint(const MachineInstr *MI) {
363 if (!STI->getInstrInfo()->requiresNTLHint(*MI))
364 return;
365
366 assert(!MI->memoperands_empty());
367
368 MachineMemOperand *MMO = *(MI->memoperands_begin());
369
370 assert(MMO->isNonTemporal());
371
372 unsigned NontemporalMode = 0;
373 if (MMO->getFlags() & MONontemporalBit0)
374 NontemporalMode += 0b1;
375 if (MMO->getFlags() & MONontemporalBit1)
376 NontemporalMode += 0b10;
377
378 MCInst Hint;
379 if (STI->hasStdExtZca())
380 Hint.setOpcode(RISCV::C_ADD);
381 else
382 Hint.setOpcode(RISCV::ADD);
383
384 Hint.addOperand(MCOperand::createReg(RISCV::X0));
385 Hint.addOperand(MCOperand::createReg(RISCV::X0));
386 Hint.addOperand(MCOperand::createReg(RISCV::X2 + NontemporalMode));
387
388 EmitToStreamer(*OutStreamer, Hint);
389}
390
391void RISCVAsmPrinter::emitInstruction(const MachineInstr *MI) {
392 RISCV_MC::verifyInstructionPredicates(MI->getOpcode(), STI->getFeatureBits());
393
394 emitNTLHint(MI);
395
396 // Do any auto-generated pseudo lowerings.
397 if (MCInst OutInst; lowerPseudoInstExpansion(MI, OutInst)) {
398 EmitToStreamer(*OutStreamer, OutInst);
399 return;
400 }
401
402 switch (MI->getOpcode()) {
403 case RISCV::PseudoTAILX7: {
404 // Lower to PseudoTAILReg with X7 as the register operand.
405 MCOperand SymOp;
406 lowerOperand(MI->getOperand(0), SymOp);
407 MCInst TmpInst;
408 TmpInst.setOpcode(RISCV::PseudoTAILReg);
409 TmpInst.addOperand(MCOperand::createReg(RISCV::X7));
410 TmpInst.addOperand(SymOp);
411 EmitToStreamer(*OutStreamer, TmpInst);
412 return;
413 }
414 case RISCV::HWASAN_CHECK_MEMACCESS_SHORTGRANULES:
415 LowerHWASAN_CHECK_MEMACCESS(*MI);
416 return;
417 case RISCV::KCFI_CHECK:
418 LowerKCFI_CHECK(*MI);
419 return;
420 case TargetOpcode::STACKMAP:
421 return LowerSTACKMAP(*OutStreamer, SM, *MI);
422 case TargetOpcode::PATCHPOINT:
423 return LowerPATCHPOINT(*OutStreamer, SM, *MI);
424 case TargetOpcode::STATEPOINT:
425 return LowerSTATEPOINT(*OutStreamer, SM, *MI);
426 case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
427 const Function &F = MI->getParent()->getParent()->getFunction();
428 if (F.hasFnAttribute("patchable-function-entry")) {
429 unsigned Num =
430 F.getFnAttributeAsParsedInteger("patchable-function-entry");
431 emitNops(Num);
432 return;
433 }
434 LowerPATCHABLE_FUNCTION_ENTER(MI);
435 return;
436 }
437 case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
438 LowerPATCHABLE_FUNCTION_EXIT(MI);
439 return;
440 case TargetOpcode::PATCHABLE_TAIL_CALL:
441 LowerPATCHABLE_TAIL_CALL(MI);
442 return;
443 case RISCV::PseudoCALLLpadAlign:
444 case RISCV::PseudoCALLIndirectLpadAlign:
445 emitLpadAlignedCall(*MI);
446 return;
447 }
448
449 MCInst OutInst;
450 lowerToMCInst(MI, OutInst);
451 EmitToStreamer(*OutStreamer, OutInst);
452}
453
454bool RISCVAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
455 const char *ExtraCode, raw_ostream &OS) {
456 // First try the generic code, which knows about modifiers like 'c' and 'n'.
457 if (!AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS))
458 return false;
459
460 const MachineOperand &MO = MI->getOperand(OpNo);
461 if (ExtraCode && ExtraCode[0]) {
462 if (ExtraCode[1] != 0)
463 return true; // Unknown modifier.
464
465 switch (ExtraCode[0]) {
466 default:
467 return true; // Unknown modifier.
468 case 'z': // Print zero register if zero, regular printing otherwise.
469 if (MO.isImm() && MO.getImm() == 0) {
470 OS << RISCVInstPrinter::getRegisterName(CLOpts, RISCV::X0);
471 return false;
472 }
473 break;
474 case 'i': // Literal 'i' if operand is not a register.
475 if (!MO.isReg())
476 OS << 'i';
477 return false;
478 case 'N': { // Print the register encoding as an integer (0-31)
479 if (!MO.isReg())
480 return true;
481
482 const RISCVRegisterInfo *TRI = STI->getRegisterInfo();
483 OS << TRI->getEncodingValue(MO.getReg());
484 return false;
485 }
486 }
487 }
488
489 switch (MO.getType()) {
491 OS << MO.getImm();
492 return false;
494 OS << RISCVInstPrinter::getRegisterName(CLOpts, MO.getReg());
495 return false;
497 PrintSymbolOperand(MO, OS);
498 return false;
500 MCSymbol *Sym = GetBlockAddressSymbol(MO.getBlockAddress());
501 Sym->print(OS, MAI);
502 return false;
503 }
504 default:
505 break;
506 }
507
508 return true;
509}
510
511bool RISCVAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
512 unsigned OpNo,
513 const char *ExtraCode,
514 raw_ostream &OS) {
515 if (ExtraCode)
516 return AsmPrinter::PrintAsmMemoryOperand(MI, OpNo, ExtraCode, OS);
517
518 const MachineOperand &AddrReg = MI->getOperand(OpNo);
519 assert(MI->getNumOperands() > OpNo + 1 && "Expected additional operand");
520 const MachineOperand &Offset = MI->getOperand(OpNo + 1);
521 // All memory operands should have a register and an immediate operand (see
522 // RISCVDAGToDAGISel::SelectInlineAsmMemoryOperand).
523 if (!AddrReg.isReg())
524 return true;
525 if (!Offset.isImm() && !Offset.isGlobal() && !Offset.isBlockAddress() &&
526 !Offset.isMCSymbol())
527 return true;
528
529 MCOperand MCO;
530 if (!lowerOperand(Offset, MCO))
531 return true;
532
533 if (Offset.isImm())
534 OS << MCO.getImm();
535 else if (Offset.isGlobal() || Offset.isBlockAddress() || Offset.isMCSymbol())
536 MAI.printExpr(OS, *MCO.getExpr());
537
538 if (Offset.isMCSymbol())
539 MMI->getContext().registerInlineAsmLabel(Offset.getMCSymbol());
540 if (Offset.isBlockAddress()) {
541 const BlockAddress *BA = Offset.getBlockAddress();
542 MCSymbol *Sym = GetBlockAddressSymbol(BA);
543 MMI->getContext().registerInlineAsmLabel(Sym);
544 }
545
546 OS << "(" << RISCVInstPrinter::getRegisterName(CLOpts, AddrReg.getReg())
547 << ")";
548 return false;
549}
550
551bool RISCVAsmPrinter::emitTargetFeaturePush(const MCSubtargetInfo &STI) {
552 RISCVTargetStreamer &RTS = getTargetStreamer();
553 SmallVector<RISCVOptionArchArg> NeedEmitStdOptionArgs;
554 const MCSubtargetInfo &MCSTI = TM.getMCSubtargetInfo();
555 for (const auto &Feature : MCSTI.getAllProcessorFeatures()) {
556 if (STI.hasFeature(Feature.Value) == MCSTI.hasFeature(Feature.Value))
557 continue;
558
560 continue;
561
562 auto Delta = STI.hasFeature(Feature.Value) ? RISCVOptionArchArgType::Plus
563 : RISCVOptionArchArgType::Minus;
564 StringRef ExtName = Feature.key();
565 ExtName.consume_front("experimental-");
566 NeedEmitStdOptionArgs.emplace_back(Delta, ExtName.str());
567 }
568 if (!NeedEmitStdOptionArgs.empty()) {
570 RTS.emitDirectiveOptionArch(NeedEmitStdOptionArgs);
571 RTS.setArchString(
573 return true;
574 }
575
576 return false;
577}
578
579void RISCVAsmPrinter::emitTargetFeaturePop(const MCSubtargetInfo &STI,
580 bool DidPush) {
581 if (DidPush)
582 getTargetStreamer().emitDirectiveOptionPop();
583}
584
585bool RISCVAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
586 STI = &MF.getSubtarget<RISCVSubtarget>();
587
588 bool EmittedOptionArch = emitTargetFeaturePush(*STI);
589
590 SetupMachineFunction(MF);
591 emitFunctionBody();
592
593 // Emit the XRay table
594 emitXRayTable();
595
596 emitTargetFeaturePop(*STI, EmittedOptionArch);
597 return false;
598}
599
600void RISCVAsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr *MI) {
601 emitSled(MI, SledKind::FUNCTION_ENTER);
602}
603
604void RISCVAsmPrinter::LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr *MI) {
605 emitSled(MI, SledKind::FUNCTION_EXIT);
606}
607
608void RISCVAsmPrinter::LowerPATCHABLE_TAIL_CALL(const MachineInstr *MI) {
609 emitSled(MI, SledKind::TAIL_CALL);
610}
611
612void RISCVAsmPrinter::emitSled(const MachineInstr *MI, SledKind Kind) {
613 // We want to emit the jump instruction and the nops constituting the sled.
614 // The format is as follows:
615 // .Lxray_sled_N
616 // ALIGN
617 // J .tmpN
618 // 21 or 33 C.NOP instructions
619 // .tmpN
620
621 // The following variable holds the count of the number of NOPs to be patched
622 // in for XRay instrumentation during compilation.
623 // Note that RV64 and RV32 each has a sled of 68 and 44 bytes, respectively.
624 // Assuming we're using JAL to jump to .tmpN, then we only need
625 // (68 - 4)/2 = 32 NOPs for RV64 and (44 - 4)/2 = 20 for RV32. However, there
626 // is a chance that we'll use C.JAL instead, so an additional NOP is needed.
627 const uint8_t NoopsInSledCount = STI->is64Bit() ? 33 : 21;
628
629 OutStreamer->emitCodeAlignment(Align(4), *STI);
630 auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
631 OutStreamer->emitLabel(CurSled);
632 auto Target = OutContext.createTempSymbol();
633
634 const MCExpr *TargetExpr = MCSymbolRefExpr::create(Target, OutContext);
635
636 // Emit "J bytes" instruction, which jumps over the nop sled to the actual
637 // start of function.
638 EmitToStreamer(
639 *OutStreamer,
640 MCInstBuilder(RISCV::JAL).addReg(RISCV::X0).addExpr(TargetExpr));
641
642 // Emit NOP instructions
643 for (int8_t I = 0; I < NoopsInSledCount; ++I)
644 EmitToStreamer(*OutStreamer, MCInstBuilder(RISCV::ADDI)
645 .addReg(RISCV::X0)
646 .addReg(RISCV::X0)
647 .addImm(0));
648
649 OutStreamer->emitLabel(Target);
650 recordSled(CurSled, *MI, Kind, 2);
651}
652
653void RISCVAsmPrinter::emitStartOfAsmFile(Module &M) {
654 assert(OutStreamer->getTargetStreamer() &&
655 "target streamer is uninitialized");
656 RISCVTargetStreamer &RTS = getTargetStreamer();
657 StringRef ABIName = M.getTargetABIFromMD();
658 if (!ABIName.empty()) {
660 if (ABI == RISCVABI::ABI::Unknown) {
661 M.getContext().emitError(Twine('\'') + ABIName +
662 "' is not a recognized ABI for this target");
663 } else {
664 RTS.setTargetABI(ABI);
665 }
666 } else if (!RTS.hasTargetABI()) {
667 RTS.setTargetABI(
668 cantFail(RISCVABI::computeTargetABI(TM.getMCSubtargetInfo(), "")));
669 }
670
671 MCSubtargetInfo SubtargetInfo = TM.getMCSubtargetInfo();
672
673 // Use module flag to update feature bits.
674 if (auto *MD = dyn_cast_or_null<MDNode>(M.getModuleFlag("riscv-isa"))) {
675 for (auto &ISA : MD->operands()) {
676 if (auto *ISAString = dyn_cast_or_null<MDString>(ISA)) {
677 auto ParseResult = llvm::RISCVISAInfo::parseArchString(
678 ISAString->getString(), /*EnableExperimentalExtension=*/true,
679 /*ExperimentalExtensionVersionCheck=*/true);
680 if (!errorToBool(ParseResult.takeError())) {
681 auto &ISAInfo = *ParseResult;
682 for (const auto &Feature : SubtargetInfo.getAllProcessorFeatures()) {
683 if (ISAInfo->hasExtension(Feature.key()) &&
684 !SubtargetInfo.hasFeature(Feature.Value))
685 SubtargetInfo.ToggleFeature(Feature.key());
686 }
687 }
688 }
689 }
690
691 RTS.setFlagsFromFeatures(SubtargetInfo);
692 }
693
694 if (M.getTargetTriple().isOSBinFormatELF())
695 RTS.emitTargetAttributes(SubtargetInfo, /*EmitStackAlign=*/true);
696}
697
698void RISCVAsmPrinter::emitEndOfAsmFile(Module &M) {
699 RISCVTargetStreamer &RTS = getTargetStreamer();
700
701 if (M.getTargetTriple().isOSBinFormatELF()) {
703 emitNoteGnuProperty(M);
704 }
705 EmitHwasanMemaccessSymbols(M);
706}
707
708void RISCVAsmPrinter::emitFunctionEntryLabel() {
709 const auto *RMFI = MF->getInfo<RISCVMachineFunctionInfo>();
710 if (RMFI->isVectorCall()) {
711 RISCVTargetStreamer &RTS = getTargetStreamer();
712 RTS.emitDirectiveVariantCC(*CurrentFnSym);
713 }
715}
716
717// Force static initialization.
725
726void RISCVAsmPrinter::LowerHWASAN_CHECK_MEMACCESS(const MachineInstr &MI) {
727 Register Reg = MI.getOperand(0).getReg();
728 uint32_t AccessInfo = MI.getOperand(1).getImm();
729 MCSymbol *&Sym =
730 HwasanMemaccessSymbols[HwasanMemaccessTuple(Reg, AccessInfo)];
731 if (!Sym) {
732 // FIXME: Make this work on non-ELF.
733 if (!TM.getTargetTriple().isOSBinFormatELF())
734 report_fatal_error("llvm.hwasan.check.memaccess only supported on ELF");
735
736 std::string SymName = "__hwasan_check_x" + utostr(Reg - RISCV::X0) + "_" +
737 utostr(AccessInfo) + "_short";
738 Sym = OutContext.getOrCreateSymbol(SymName);
739 }
740 auto Res = MCSymbolRefExpr::create(Sym, OutContext);
741 auto Expr = MCSpecifierExpr::create(Res, RISCV::S_CALL_PLT, OutContext);
742
743 EmitToStreamer(*OutStreamer, MCInstBuilder(RISCV::PseudoCALL).addExpr(Expr));
744}
745
746void RISCVAsmPrinter::LowerKCFI_CHECK(const MachineInstr &MI) {
747 Register AddrReg = MI.getOperand(0).getReg();
748 assert(std::next(MI.getIterator())->isCall() &&
749 "KCFI_CHECK not followed by a call instruction");
750 assert(std::next(MI.getIterator())->getOperand(0).getReg() == AddrReg &&
751 "KCFI_CHECK call target doesn't match call operand");
752
753 // Temporary registers for comparing the hashes. If a register is used
754 // for the call target, or reserved by the user, we can clobber another
755 // temporary register as the check is immediately followed by the
756 // call. The check defaults to X6/X7, but can fall back to X28-X31 if
757 // needed.
758 MCRegister ScratchRegs[] = {RISCV::X6, RISCV::X7};
759 static const MCPhysReg FallbackRegArray[] = {RISCV::X28, RISCV::X29,
760 RISCV::X30, RISCV::X31};
761 ArrayRef<MCPhysReg> FallbackRegs(FallbackRegArray);
762 auto isRegAvailable = [&](MCRegister Reg) {
763 // If cf-protection=branch is enabled, x7 is reserved for the zicfilp
764 // extension and cannot be used as scratch register.
765 if (Reg == RISCV::X7 && MI.getMF()
766 ->getInfo<RISCVMachineFunctionInfo>()
767 ->hasCFProtectionBranch())
768 return false;
769 return AddrReg != Reg && !STI->isRegisterReservedByUser(Reg);
770 };
771 for (auto &Reg : ScratchRegs) {
772 if (isRegAvailable(Reg))
773 continue;
774 const MCPhysReg *It = find_if(FallbackRegs, isRegAvailable);
775 if (It == FallbackRegs.end())
776 report_fatal_error("Unable to find scratch registers for KCFI_CHECK");
777 Reg = *It;
778 // Don't hand out the same fallback register twice.
779 FallbackRegs = FallbackRegs.drop_front(It - FallbackRegs.begin() + 1);
780 }
781
782 if (AddrReg == RISCV::X0) {
783 // Checking X0 makes no sense. Instead of emitting a load, zero
784 // ScratchRegs[0].
785 EmitToStreamer(*OutStreamer, MCInstBuilder(RISCV::ADDI)
786 .addReg(ScratchRegs[0])
787 .addReg(RISCV::X0)
788 .addImm(0));
789 } else {
790 // Adjust the offset for patchable-function-prefix. This assumes that
791 // patchable-function-prefix is the same for all functions.
792 int NopSize = STI->hasStdExtZca() ? 2 : 4;
793 int64_t PrefixNops =
794 MI.getMF()->getFunction().getFnAttributeAsParsedInteger(
795 "patchable-function-prefix");
796
797 // Load the target function type hash.
798 EmitToStreamer(*OutStreamer, MCInstBuilder(RISCV::LW)
799 .addReg(ScratchRegs[0])
800 .addReg(AddrReg)
801 .addImm(-(PrefixNops * NopSize + 4)));
802 }
803
804 // Load the expected 32-bit type hash.
805 const int64_t Type = MI.getOperand(1).getImm();
806 const int64_t Hi20 = ((Type + 0x800) >> 12) & 0xFFFFF;
807 const int64_t Lo12 = SignExtend64<12>(Type);
808 if (Hi20) {
809 EmitToStreamer(
810 *OutStreamer,
811 MCInstBuilder(RISCV::LUI).addReg(ScratchRegs[1]).addImm(Hi20));
812 }
813 if (Lo12 || Hi20 == 0) {
814 EmitToStreamer(*OutStreamer,
815 MCInstBuilder((STI->hasFeature(RISCV::Feature64Bit) && Hi20)
816 ? RISCV::ADDIW
817 : RISCV::ADDI)
818 .addReg(ScratchRegs[1])
819 .addReg(ScratchRegs[1])
820 .addImm(Lo12));
821 }
822
823 // Compare the hashes and trap if there's a mismatch.
824 MCSymbol *Pass = OutContext.createTempSymbol();
825 EmitToStreamer(*OutStreamer,
826 MCInstBuilder(RISCV::BEQ)
827 .addReg(ScratchRegs[0])
828 .addReg(ScratchRegs[1])
829 .addExpr(MCSymbolRefExpr::create(Pass, OutContext)));
830
831 MCSymbol *Trap = OutContext.createTempSymbol();
832 OutStreamer->emitLabel(Trap);
833 EmitToStreamer(*OutStreamer, MCInstBuilder(RISCV::EBREAK));
834 emitKCFITrapEntry(*MI.getMF(), Trap);
835 OutStreamer->emitLabel(Pass);
836}
837
838void RISCVAsmPrinter::EmitHwasanMemaccessSymbols(Module &M) {
839 if (HwasanMemaccessSymbols.empty())
840 return;
841
842 assert(M.getTargetTriple().isOSBinFormatELF());
843 // Use MCSubtargetInfo from TargetMachine. Individual functions may have
844 // attributes that differ from other functions in the module and we have no
845 // way to know which function is correct.
846 const MCSubtargetInfo &MCSTI = TM.getMCSubtargetInfo();
847
848 MCSymbol *HwasanTagMismatchV2Sym =
849 OutContext.getOrCreateSymbol("__hwasan_tag_mismatch_v2");
850 // Annotate symbol as one having incompatible calling convention, so
851 // run-time linkers can instead eagerly bind this function.
852 RISCVTargetStreamer &RTS = getTargetStreamer();
853 RTS.emitDirectiveVariantCC(*HwasanTagMismatchV2Sym);
854
855 const MCSymbolRefExpr *HwasanTagMismatchV2Ref =
856 MCSymbolRefExpr::create(HwasanTagMismatchV2Sym, OutContext);
857 auto Expr = MCSpecifierExpr::create(HwasanTagMismatchV2Ref, RISCV::S_CALL_PLT,
858 OutContext);
859
860 for (auto &P : HwasanMemaccessSymbols) {
861 unsigned Reg = std::get<0>(P.first);
862 uint32_t AccessInfo = std::get<1>(P.first);
863 MCSymbol *Sym = P.second;
864
865 unsigned Size =
866 1 << ((AccessInfo >> HWASanAccessInfo::AccessSizeShift) & 0xf);
867 OutStreamer->switchSection(OutContext.getELFSection(
868 ".text.hot", ELF::SHT_PROGBITS,
870 /*IsComdat=*/true));
871
873 OutStreamer->emitSymbolAttribute(Sym, MCSA_Weak);
874 OutStreamer->emitSymbolAttribute(Sym, MCSA_Hidden);
875 OutStreamer->emitLabel(Sym);
876
877 // Extract shadow offset from ptr
878 EmitToStreamer(
879 *OutStreamer,
880 MCInstBuilder(RISCV::SLLI).addReg(RISCV::X6).addReg(Reg).addImm(8),
881 MCSTI);
882 EmitToStreamer(*OutStreamer,
883 MCInstBuilder(RISCV::SRLI)
884 .addReg(RISCV::X6)
885 .addReg(RISCV::X6)
886 .addImm(12),
887 MCSTI);
888 // load shadow tag in X6, X5 contains shadow base
889 EmitToStreamer(*OutStreamer,
890 MCInstBuilder(RISCV::ADD)
891 .addReg(RISCV::X6)
892 .addReg(RISCV::X5)
893 .addReg(RISCV::X6),
894 MCSTI);
895 EmitToStreamer(
896 *OutStreamer,
897 MCInstBuilder(RISCV::LBU).addReg(RISCV::X6).addReg(RISCV::X6).addImm(0),
898 MCSTI);
899 // Extract tag from pointer and compare it with loaded tag from shadow
900 EmitToStreamer(
901 *OutStreamer,
902 MCInstBuilder(RISCV::SRLI).addReg(RISCV::X7).addReg(Reg).addImm(56),
903 MCSTI);
904 MCSymbol *HandleMismatchOrPartialSym = OutContext.createTempSymbol();
905 // X7 contains tag from the pointer, while X6 contains tag from memory
906 EmitToStreamer(*OutStreamer,
907 MCInstBuilder(RISCV::BNE)
908 .addReg(RISCV::X7)
909 .addReg(RISCV::X6)
911 HandleMismatchOrPartialSym, OutContext)),
912 MCSTI);
913 MCSymbol *ReturnSym = OutContext.createTempSymbol();
914 OutStreamer->emitLabel(ReturnSym);
915 EmitToStreamer(*OutStreamer,
916 MCInstBuilder(RISCV::JALR)
917 .addReg(RISCV::X0)
918 .addReg(RISCV::X1)
919 .addImm(0),
920 MCSTI);
921 OutStreamer->emitLabel(HandleMismatchOrPartialSym);
922
923 EmitToStreamer(*OutStreamer,
924 MCInstBuilder(RISCV::ADDI)
925 .addReg(RISCV::X28)
926 .addReg(RISCV::X0)
927 .addImm(16),
928 MCSTI);
929 MCSymbol *HandleMismatchSym = OutContext.createTempSymbol();
930 EmitToStreamer(
931 *OutStreamer,
932 MCInstBuilder(RISCV::BGEU)
933 .addReg(RISCV::X6)
934 .addReg(RISCV::X28)
935 .addExpr(MCSymbolRefExpr::create(HandleMismatchSym, OutContext)),
936 MCSTI);
937
938 EmitToStreamer(
939 *OutStreamer,
940 MCInstBuilder(RISCV::ANDI).addReg(RISCV::X28).addReg(Reg).addImm(0xF),
941 MCSTI);
942
943 if (Size != 1)
944 EmitToStreamer(*OutStreamer,
945 MCInstBuilder(RISCV::ADDI)
946 .addReg(RISCV::X28)
947 .addReg(RISCV::X28)
948 .addImm(Size - 1),
949 MCSTI);
950 EmitToStreamer(
951 *OutStreamer,
952 MCInstBuilder(RISCV::BGE)
953 .addReg(RISCV::X28)
954 .addReg(RISCV::X6)
955 .addExpr(MCSymbolRefExpr::create(HandleMismatchSym, OutContext)),
956 MCSTI);
957
958 EmitToStreamer(
959 *OutStreamer,
960 MCInstBuilder(RISCV::ORI).addReg(RISCV::X6).addReg(Reg).addImm(0xF),
961 MCSTI);
962 EmitToStreamer(
963 *OutStreamer,
964 MCInstBuilder(RISCV::LBU).addReg(RISCV::X6).addReg(RISCV::X6).addImm(0),
965 MCSTI);
966 EmitToStreamer(*OutStreamer,
967 MCInstBuilder(RISCV::BEQ)
968 .addReg(RISCV::X6)
969 .addReg(RISCV::X7)
970 .addExpr(MCSymbolRefExpr::create(ReturnSym, OutContext)),
971 MCSTI);
972
973 OutStreamer->emitLabel(HandleMismatchSym);
974
975 // | Previous stack frames... |
976 // +=================================+ <-- [SP + 256]
977 // | ... |
978 // | |
979 // | Stack frame space for x12 - x31.|
980 // | |
981 // | ... |
982 // +---------------------------------+ <-- [SP + 96]
983 // | Saved x11(arg1), as |
984 // | __hwasan_check_* clobbers it. |
985 // +---------------------------------+ <-- [SP + 88]
986 // | Saved x10(arg0), as |
987 // | __hwasan_check_* clobbers it. |
988 // +---------------------------------+ <-- [SP + 80]
989 // | |
990 // | Stack frame space for x9. |
991 // +---------------------------------+ <-- [SP + 72]
992 // | |
993 // | Saved x8(fp), as |
994 // | __hwasan_check_* clobbers it. |
995 // +---------------------------------+ <-- [SP + 64]
996 // | ... |
997 // | |
998 // | Stack frame space for x2 - x7. |
999 // | |
1000 // | ... |
1001 // +---------------------------------+ <-- [SP + 16]
1002 // | Return address (x1) for caller |
1003 // | of __hwasan_check_*. |
1004 // +---------------------------------+ <-- [SP + 8]
1005 // | Reserved place for x0, possibly |
1006 // | junk, since we don't save it. |
1007 // +---------------------------------+ <-- [x2 / SP]
1008
1009 // Adjust sp
1010 EmitToStreamer(*OutStreamer,
1011 MCInstBuilder(RISCV::ADDI)
1012 .addReg(RISCV::X2)
1013 .addReg(RISCV::X2)
1014 .addImm(-256),
1015 MCSTI);
1016
1017 // store x10(arg0) by new sp
1018 EmitToStreamer(*OutStreamer,
1019 MCInstBuilder(RISCV::SD)
1020 .addReg(RISCV::X10)
1021 .addReg(RISCV::X2)
1022 .addImm(8 * 10),
1023 MCSTI);
1024 // store x11(arg1) by new sp
1025 EmitToStreamer(*OutStreamer,
1026 MCInstBuilder(RISCV::SD)
1027 .addReg(RISCV::X11)
1028 .addReg(RISCV::X2)
1029 .addImm(8 * 11),
1030 MCSTI);
1031
1032 // store x8(fp) by new sp
1033 EmitToStreamer(
1034 *OutStreamer,
1035 MCInstBuilder(RISCV::SD).addReg(RISCV::X8).addReg(RISCV::X2).addImm(8 *
1036 8),
1037 MCSTI);
1038 // store x1(ra) by new sp
1039 EmitToStreamer(
1040 *OutStreamer,
1041 MCInstBuilder(RISCV::SD).addReg(RISCV::X1).addReg(RISCV::X2).addImm(1 *
1042 8),
1043 MCSTI);
1044 if (Reg != RISCV::X10)
1045 EmitToStreamer(
1046 *OutStreamer,
1047 MCInstBuilder(RISCV::ADDI).addReg(RISCV::X10).addReg(Reg).addImm(0),
1048 MCSTI);
1049 EmitToStreamer(*OutStreamer,
1050 MCInstBuilder(RISCV::ADDI)
1051 .addReg(RISCV::X11)
1052 .addReg(RISCV::X0)
1053 .addImm(AccessInfo & HWASanAccessInfo::RuntimeMask),
1054 MCSTI);
1055
1056 EmitToStreamer(*OutStreamer, MCInstBuilder(RISCV::PseudoCALL).addExpr(Expr),
1057 MCSTI);
1058 }
1059}
1060
1061void RISCVAsmPrinter::emitNoteGnuProperty(const Module &M) {
1062 assert(M.getTargetTriple().isOSBinFormatELF() && "invalid binary format");
1063 uint32_t GnuProps = 0;
1064 if (const Metadata *const Flag = M.getModuleFlag("cf-protection-return");
1065 Flag && !mdconst::extract<ConstantInt>(Flag)->isZero())
1067
1068 if (const Metadata *const Flag = M.getModuleFlag("cf-protection-branch");
1069 Flag && !mdconst::extract<ConstantInt>(Flag)->isZero()) {
1070 using namespace llvm::RISCVISAUtils;
1071 const Metadata *const CFBranchLabelSchemeFlag =
1072 M.getModuleFlag("cf-branch-label-scheme");
1073 assert(CFBranchLabelSchemeFlag &&
1074 "cf-protection=branch should come with cf-branch-label-scheme=... "
1075 "on RISC-V targets");
1076 const StringRef CFBranchLabelScheme =
1077 cast<MDString>(CFBranchLabelSchemeFlag)->getString();
1078 switch (llvm::RISCVCFI::getZicfilpLabelScheme(CFBranchLabelScheme)) {
1080 reportFatalInternalError("invalid RISC-V Zicfilp label scheme");
1083 break;
1085 // TODO: Emit the func-sig bit after the feature is implemented
1086 reportFatalUsageError("the complete func-sig label scheme feature is not "
1087 "implemented yet");
1088 break;
1089 }
1090 }
1091
1092 if (!GnuProps)
1093 return;
1094
1095 auto &RTS = static_cast<RISCVTargetELFStreamer &>(getTargetStreamer());
1096 RTS.emitNoteGnuPropertySection(GnuProps);
1097}
1098
1100 const AsmPrinter &AP) {
1101 MCContext &Ctx = AP.OutContext;
1102 RISCV::Specifier Kind;
1103
1104 switch (MO.getTargetFlags()) {
1105 default:
1106 llvm_unreachable("Unknown target flag on GV operand");
1107 case RISCVII::MO_None:
1108 Kind = RISCV::S_None;
1109 break;
1110 case RISCVII::MO_CALL:
1111 Kind = RISCV::S_CALL_PLT;
1112 break;
1113 case RISCVII::MO_LO:
1114 Kind = RISCV::S_LO;
1115 break;
1116 case RISCVII::MO_HI:
1117 Kind = ELF::R_RISCV_HI20;
1118 break;
1120 Kind = RISCV::S_PCREL_LO;
1121 break;
1123 Kind = RISCV::S_PCREL_HI;
1124 break;
1125 case RISCVII::MO_GOT_HI:
1126 Kind = RISCV::S_GOT_HI;
1127 break;
1129 Kind = RISCV::S_TPREL_LO;
1130 break;
1132 Kind = ELF::R_RISCV_TPREL_HI20;
1133 break;
1135 Kind = ELF::R_RISCV_TPREL_ADD;
1136 break;
1138 Kind = ELF::R_RISCV_TLS_GOT_HI20;
1139 break;
1141 Kind = ELF::R_RISCV_TLS_GD_HI20;
1142 break;
1144 Kind = ELF::R_RISCV_TLSDESC_HI20;
1145 break;
1147 Kind = ELF::R_RISCV_TLSDESC_LOAD_LO12;
1148 break;
1150 Kind = ELF::R_RISCV_TLSDESC_ADD_LO12;
1151 break;
1153 Kind = ELF::R_RISCV_TLSDESC_CALL;
1154 break;
1156 Kind = RISCV::S_QC_ACCESS;
1157 break;
1158 }
1159
1160 const MCExpr *ME = MCSymbolRefExpr::create(Sym, Ctx);
1161
1162 if (!MO.isJTI() && !MO.isMBB() && MO.getOffset())
1164 ME, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
1165
1166 if (Kind != RISCV::S_None)
1167 ME = MCSpecifierExpr::create(ME, Kind, Ctx);
1168 return MCOperand::createExpr(ME);
1169}
1170
1171bool RISCVAsmPrinter::lowerOperand(const MachineOperand &MO,
1172 MCOperand &MCOp) const {
1173 switch (MO.getType()) {
1174 default:
1175 report_fatal_error("lowerOperand: unknown operand type");
1177 // Ignore all implicit register operands.
1178 if (MO.isImplicit())
1179 return false;
1180 MCOp = MCOperand::createReg(MO.getReg());
1181 break;
1183 // Regmasks are like implicit defs.
1184 return false;
1186 MCOp = MCOperand::createImm(MO.getImm());
1187 break;
1189 MCOp = lowerSymbolOperand(MO, MO.getMBB()->getSymbol(), *this);
1190 break;
1192 MCOp = lowerSymbolOperand(MO, getSymbolPreferLocal(*MO.getGlobal()), *this);
1193 break;
1195 MCOp = lowerSymbolOperand(MO, GetBlockAddressSymbol(MO.getBlockAddress()),
1196 *this);
1197 break;
1199 MCOp = lowerSymbolOperand(MO, GetExternalSymbolSymbol(MO.getSymbolName()),
1200 *this);
1201 break;
1203 MCOp = lowerSymbolOperand(MO, GetCPISymbol(MO.getIndex()), *this);
1204 break;
1206 MCOp = lowerSymbolOperand(MO, GetJTISymbol(MO.getIndex()), *this);
1207 break;
1209 MCOp = lowerSymbolOperand(MO, MO.getMCSymbol(), *this);
1210 break;
1211 }
1212 return true;
1213}
1214
1216 MCInst &OutMI,
1217 const RISCVSubtarget *STI) {
1219 RISCVVPseudosTable::getPseudoInfo(MI->getOpcode());
1220 if (!RVV)
1221 return false;
1222
1223 OutMI.setOpcode(RVV->BaseInstr);
1224
1225 const TargetInstrInfo *TII = STI->getInstrInfo();
1226 const TargetRegisterInfo *TRI = STI->getRegisterInfo();
1227 assert(TRI && "TargetRegisterInfo expected");
1228
1229 const MCInstrDesc &MCID = MI->getDesc();
1230 uint64_t TSFlags = MCID.TSFlags;
1231 unsigned NumOps = MI->getNumExplicitOperands();
1232
1233 // Skip policy, SEW, VL, VXRM/FRM operands which are the last operands if
1234 // present.
1235 if (RISCVII::hasVecPolicyOp(TSFlags))
1236 --NumOps;
1237 if (RISCVII::hasSEWOp(TSFlags))
1238 --NumOps;
1239 if (RISCVII::hasVLOp(TSFlags))
1240 --NumOps;
1241 if (RISCVII::hasRoundModeOp(TSFlags))
1242 --NumOps;
1243 if (RISCVII::hasTWidenOp(TSFlags))
1244 --NumOps;
1245 if (RISCVII::hasTMOp(TSFlags))
1246 --NumOps;
1247 if (RISCVII::hasTKOp(TSFlags))
1248 --NumOps;
1249
1250 bool hasVLOutput = RISCVInstrInfo::isFaultOnlyFirstLoad(*MI);
1251 for (unsigned OpNo = 0; OpNo != NumOps; ++OpNo) {
1252 const MachineOperand &MO = MI->getOperand(OpNo);
1253 // Skip vl output. It should be the second output.
1254 if (hasVLOutput && OpNo == 1)
1255 continue;
1256
1257 // Skip passthru op. It should be the first operand after the defs.
1258 if (OpNo == MI->getNumExplicitDefs() && MO.isReg() && MO.isTied()) {
1259 assert(MCID.getOperandConstraint(OpNo, MCOI::TIED_TO) == 0 &&
1260 "Expected tied to first def.");
1261 const MCInstrDesc &OutMCID = TII->get(OutMI.getOpcode());
1262 // Skip if the next operand in OutMI is not supposed to be tied. Unless it
1263 // is a _TIED instruction.
1264 if (OutMCID.getOperandConstraint(OutMI.getNumOperands(), MCOI::TIED_TO) <
1265 0 &&
1266 !RISCVII::isTiedPseudo(TSFlags))
1267 continue;
1268 }
1269
1270 MCOperand MCOp;
1271 switch (MO.getType()) {
1272 default:
1273 llvm_unreachable("Unknown operand type");
1275 Register Reg = MO.getReg();
1276
1277 if (RISCV::VRM2RegClass.contains(Reg) ||
1278 RISCV::VRM4RegClass.contains(Reg) ||
1279 RISCV::VRM8RegClass.contains(Reg)) {
1280 Reg = TRI->getSubReg(Reg, RISCV::sub_vrm1_0);
1281 assert(Reg && "Subregister does not exist");
1282 } else if (RISCV::FPR16RegClass.contains(Reg)) {
1283 Reg =
1284 TRI->getMatchingSuperReg(Reg, RISCV::sub_16, &RISCV::FPR32RegClass);
1285 assert(Reg && "Subregister does not exist");
1286 } else if (RISCV::FPR64RegClass.contains(Reg)) {
1287 Reg = TRI->getSubReg(Reg, RISCV::sub_32);
1288 assert(Reg && "Superregister does not exist");
1289 } else if (RISCV::VRN2M1RegClass.contains(Reg) ||
1290 RISCV::VRN2M2RegClass.contains(Reg) ||
1291 RISCV::VRN2M4RegClass.contains(Reg) ||
1292 RISCV::VRN3M1RegClass.contains(Reg) ||
1293 RISCV::VRN3M2RegClass.contains(Reg) ||
1294 RISCV::VRN4M1RegClass.contains(Reg) ||
1295 RISCV::VRN4M2RegClass.contains(Reg) ||
1296 RISCV::VRN5M1RegClass.contains(Reg) ||
1297 RISCV::VRN6M1RegClass.contains(Reg) ||
1298 RISCV::VRN7M1RegClass.contains(Reg) ||
1299 RISCV::VRN8M1RegClass.contains(Reg)) {
1300 Reg = TRI->getSubReg(Reg, RISCV::sub_vrm1_0);
1301 assert(Reg && "Subregister does not exist");
1302 }
1303
1304 MCOp = MCOperand::createReg(Reg);
1305 break;
1306 }
1308 MCOp = MCOperand::createImm(MO.getImm());
1309 break;
1310 }
1311 OutMI.addOperand(MCOp);
1312 }
1313
1314 // Unmasked pseudo instructions need to append dummy mask operand to
1315 // V instructions. All V instructions are modeled as the masked version.
1316 const MCInstrDesc &OutMCID = TII->get(OutMI.getOpcode());
1317 if (OutMI.getNumOperands() < OutMCID.getNumOperands()) {
1318 assert(OutMCID.operands()[OutMI.getNumOperands()].OperandType ==
1320 "Expected only mask operand to be missing");
1321 OutMI.addOperand(MCOperand::createReg(RISCV::NoRegister));
1322 }
1323
1324 assert(OutMI.getNumOperands() == OutMCID.getNumOperands());
1325 return true;
1326}
1327
1328void RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
1329 if (lowerRISCVVMachineInstrToMCInst(MI, OutMI, STI))
1330 return;
1331
1332 OutMI.setOpcode(MI->getOpcode());
1333
1334 for (const MachineOperand &MO : MI->operands()) {
1335 MCOperand MCOp;
1336 if (lowerOperand(MO, MCOp))
1337 OutMI.addOperand(MCOp);
1338 }
1339}
1340
1341void RISCVAsmPrinter::emitMachineConstantPoolValue(
1342 MachineConstantPoolValue *MCPV) {
1343 auto *RCPV = static_cast<RISCVConstantPoolValue *>(MCPV);
1344 MCSymbol *MCSym;
1345
1346 if (RCPV->isGlobalValue()) {
1347 auto *GV = RCPV->getGlobalValue();
1348 MCSym = getSymbol(GV);
1349 } else {
1350 assert(RCPV->isExtSymbol() && "unrecognized constant pool type");
1351 auto Sym = RCPV->getSymbol();
1352 MCSym = GetExternalSymbolSymbol(Sym);
1353 }
1354
1355 const MCExpr *Expr = MCSymbolRefExpr::create(MCSym, OutContext);
1356 uint64_t Size = getDataLayout().getTypeAllocSize(RCPV->getType());
1357 OutStreamer->emitValue(Expr, Size);
1358}
1359
1360MaybeAlign
1361RISCVAsmPrinter::getRequiredGlobalAlignmentGranule(const GlobalVariable &GV) {
1362 const MCSubtargetInfo &MCSTI = TM.getMCSubtargetInfo();
1363 if (!GV.getValueType()->isSized())
1364 return std::nullopt;
1365
1366 // When the alignment granule is determined by a CHERI requirement,
1367 // don't increase alignment if a custom section has been specified,
1368 // as doing so can break existing code that relies on the lack of
1369 // padding (e.g. linker sets).
1370 if (GV.hasSection())
1371 return std::nullopt;
1372
1373 uint64_t Size = GV.getGlobalSize(getDataLayout());
1374 if (MCSTI.hasFeature(RISCV::FeatureVendorXCheriot))
1375 return CHERIoTCapabilityFormat::getRequiredAlignment(Size);
1376
1377 if (MCSTI.hasFeature(RISCV::FeatureStdExtY)) {
1378 if (MCSTI.hasFeature(RISCV::Feature64Bit))
1380 else
1382 }
1383
1384 return std::nullopt;
1385}
1386
1387char RISCVAsmPrinter::ID = 0;
1388
1389INITIALIZE_PASS(RISCVAsmPrinter, "riscv-asm-printer", "RISC-V Assembly Printer",
1390 false, false)
1391
1394 RISCVAsmPrinter &AsmPrinter = static_cast<RISCVAsmPrinter &>(
1395 MAM.getResult<AsmPrinterAnalysis>(M).getPrinter());
1398 return PreservedAnalyses::all();
1399}
1400
1401PreservedAnalyses
1404 RISCVAsmPrinter &AsmPrinter = static_cast<RISCVAsmPrinter &>(
1406 .getCachedResult<AsmPrinterAnalysis>(*MF.getFunction().getParent())
1407 ->getPrinter());
1410 return PreservedAnalyses::all();
1411}
1412
1415 RISCVAsmPrinter &AsmPrinter = static_cast<RISCVAsmPrinter &>(
1416 MAM.getResult<AsmPrinterAnalysis>(M).getPrinter());
1419 return PreservedAnalyses::all();
1420}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock & MBB
static const Function * getParent(const Value *V)
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
dxil translate DXIL Translate Metadata
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
static LVOptions Options
Definition LVOptions.cpp:25
static MCOperand lowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym, const AsmPrinter &AP)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
print mir2vec MIR2Vec Vocabulary Printer Pass
Definition MIR2Vec.cpp:656
Machine Check Debug Module
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define P(N)
ModuleAnalysisManager MAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, const RISCVSubtarget *STI)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVAsmPrinter()
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:479
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
std::unique_ptr< MCStreamer > && Streamer
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:94
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition AsmPrinter.h:104
bool doFinalization(Module &M) override
Shut down the asmprinter.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition AsmPrinter.h:477
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...
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
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.
bool hasSection() const
Check if this global has a custom object file section.
Type * getValueType() const
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
Definition Globals.cpp:640
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:342
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:84
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
unsigned getNumOperands() const
Definition MCInst.h:212
unsigned getOpcode() const
Definition MCInst.h:202
void addOperand(const MCOperand Op)
Definition MCInst.h:215
void setOpcode(unsigned Op)
Definition MCInst.h:201
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specified operand constraint if it is present.
Instances of this class represent operands of the MCInst class.
Definition MCInst.h:40
static MCOperand createExpr(const MCExpr *Val)
Definition MCInst.h:166
int64_t getImm() const
Definition MCInst.h:84
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:138
static MCOperand createImm(int64_t Val)
Definition MCInst.h:145
const MCExpr * getExpr() const
Definition MCInst.h:118
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:743
Streaming machine code generation interface.
Definition MCStreamer.h:222
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
virtual void emitCodeAlignment(Align Alignment, const MCSubtargetInfo &STI, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
virtual bool hasRawTextSupport() const
Return true if this asm streamer supports emitting unformatted text to the .s file with EmitRawText.
Definition MCStreamer.h:385
MCContext & getContext() const
Definition MCStreamer.h:326
void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
MCTargetStreamer * getTargetStreamer()
Definition MCStreamer.h:336
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
bool hasFeature(unsigned Feature) const
const FeatureBitset & ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
ArrayRef< SubtargetFeatureKV > getAllProcessorFeatures() const
Return processor features.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:213
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition MCSymbol.cpp:60
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
Flags getFlags() const
Return the raw flags of the source value,.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
const BlockAddress * getBlockAddress() const
unsigned getTargetFlags() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
MCSymbol * getMCSymbol() const
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_MCSymbol
MCSymbol reference (for debug/eh info)
@ MO_GlobalAddress
Address of a global value.
@ MO_RegisterMask
Mask of preserved registers.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
int64_t getOffset() const
Return the offset from the symbol in this operand.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
static LLVM_ABI bool isSupportedExtensionFeature(StringRef Ext)
static LLVM_ABI llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseArchString(StringRef Arch, bool EnableExperimentalExtension, bool ExperimentalExtensionVersionCheck=true)
Parse RISC-V ISA info from arch string.
static const char * getRegisterName(const RISCVMCOptions &CLOpts, MCRegister Reg)
bool requiresNTLHint(const MachineInstr &MI) const
Return true if the instruction requires an NTL hint to be emitted.
const RISCVRegisterInfo * getRegisterInfo() const override
const RISCVInstrInfo * getInstrInfo() const override
virtual void setArchString(StringRef Arch)
virtual void emitDirectiveVariantCC(MCSymbol &Symbol)
void emitTargetAttributes(const MCSubtargetInfo &STI, bool EmitStackAlign)
virtual void setFlagsFromFeatures(const MCSubtargetInfo &STI)
void setTargetABI(RISCVABI::ABI ABI)
virtual void emitDirectiveOptionArch(ArrayRef< RISCVOptionArchArg > Args)
Wrapper class representing virtual and physical registers.
Definition Register.h:20
reference emplace_back(ArgTypes &&... Args)
LLVM_ABI void recordStatepoint(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a statepoint instruction.
LLVM_ABI void recordPatchPoint(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a patchpoint instruction.
LLVM_ABI void recordStackMap(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a stackmap instruction.
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition StringRef.h:653
TargetInstrInfo - Interface to description of machine instruction set.
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isSized() const
Return true if it makes sense to take the size of this type.
Definition Type.h:321
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED
Definition ELF.h:1770
@ GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS
Definition ELF.h:1771
@ SHF_ALLOC
Definition ELF.h:1098
@ SHF_GROUP
Definition ELF.h:1120
@ SHF_EXECINSTR
Definition ELF.h:1101
@ SHT_PROGBITS
Definition ELF.h:996
ABI getTargetABI(StringRef ABIName)
Expected< ABI > computeTargetABI(const MCSubtargetInfo &STI, StringRef ABIName)
ZicfilpLabelSchemeKind getZicfilpLabelScheme(const StringRef CFBranchLabelScheme)
llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseFeatureBits(const MCSubtargetInfo &STI)
static bool hasRoundModeOp(uint64_t TSFlags)
static bool hasTWidenOp(uint64_t TSFlags)
static bool isTiedPseudo(uint64_t TSFlags)
static bool hasTKOp(uint64_t TSFlags)
static bool hasVLOp(uint64_t TSFlags)
static bool hasTMOp(uint64_t TSFlags)
static bool hasVecPolicyOp(uint64_t TSFlags)
static bool hasSEWOp(uint64_t TSFlags)
void generateMCInstSeq(int64_t Val, const MCSubtargetInfo &STI, MCRegister DestReg, SmallVectorImpl< MCInst > &Insts)
bool compress(MCInst &OutInst, const MCInst &MI, const MCSubtargetInfo &STI)
uint16_t Specifier
void emitInstruction(MCObjectStreamer &, const MCInst &Inst, const MCSubtargetInfo &STI)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:680
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
Definition Error.h:1129
@ Offset
Definition DWP.cpp:577
static const MachineMemOperand::Flags MONontemporalBit1
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Target & getTheRISCV32Target()
static const MachineMemOperand::Flags MONontemporalBit0
std::string utostr(uint64_t X, bool isNeg=false)
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
Target & getTheRISCV64beTarget()
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
Definition Error.cpp:173
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
LLVM_ABI void setupModuleAsmPrinter(Module &M, ModuleAnalysisManager &MAM, AsmPrinter &AsmPrinter)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
Target & getTheRISCV64Target()
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
LLVM_ABI void setupMachineFunctionAsmPrinter(MachineFunctionAnalysisManager &MFAM, MachineFunction &MF, AsmPrinter &AsmPrinter)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1788
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Definition MathExtras.h:572
@ MCSA_Weak
.weak
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
@ MCSA_Hidden
.hidden (ELF)
Target & getTheRISCV32beTarget()
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
static Align getRequiredAlignment(AddressType Length)
Returns the required alignment for an allocation of size Length.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...