LLVM: lib/Target/LoongArch/LoongArchAsmPrinter.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

29

30using namespace llvm;

31

32#define DEBUG_TYPE "loongarch-asm-printer"

33

35 "loongarch-annotate-tablejump", cl::Hidden,

37 "Annotate table jump instruction to correlate it with the jump table."),

39

40

41

42#include "LoongArchGenMCPseudoLowering.inc"

43

45 LoongArch_MC::verifyInstructionPredicates(

47

48

51 return;

52 }

53

54 switch (MI->getOpcode()) {

55 case TargetOpcode::STATEPOINT:

57 return;

58 case TargetOpcode::PATCHABLE_FUNCTION_ENTER:

60 return;

61 case TargetOpcode::PATCHABLE_FUNCTION_EXIT:

63 return;

64 case TargetOpcode::PATCHABLE_TAIL_CALL:

66 return;

67 }

68

72}

73

75 const char *ExtraCode,

77

79 return false;

80

82 if (ExtraCode && ExtraCode[0]) {

83 if (ExtraCode[1] != 0)

84 return true;

85

86 switch (ExtraCode[0]) {

87 default:

88 return true;

89 case 'z':

92 return false;

93 }

94 break;

95 case 'u':

96 case 'w':

97 {

98

99

100

101 unsigned RegID = MO.getReg().id(), FirstReg;

102 if (RegID >= LoongArch::XR0 && RegID <= LoongArch::XR31)

103 FirstReg = LoongArch::XR0;

104 else if (RegID >= LoongArch::VR0 && RegID <= LoongArch::VR31)

105 FirstReg = LoongArch::VR0;

106 else if (RegID >= LoongArch::F0_64 && RegID <= LoongArch::F31_64)

107 FirstReg = LoongArch::F0_64;

108 else if (RegID >= LoongArch::F0 && RegID <= LoongArch::F31)

109 FirstReg = LoongArch::F0;

110 else

111 return true;

112 OS << '$'

114 RegID - FirstReg +

115 (ExtraCode[0] == 'u' ? LoongArch::XR0 : LoongArch::VR0));

116 return false;

117 }

118

119 }

120 }

121

125 return false;

128 return false;

131 return false;

132 default:

134 }

135

136 return true;

137}

138

140 unsigned OpNo,

141 const char *ExtraCode,

143

144 if (ExtraCode)

145 return true;

146

147

148

150

151 if (!BaseMO.isReg())

152 return true;

153

155

159 return true;

160 if (OffsetMO.isReg())

162 else if (OffsetMO.isImm())

163 OS << ", " << OffsetMO.getImm();

166 OS << ", ";

168 } else

169 return true;

170

171 return false;

172}

173

177 assert(PatchBytes % 4 == 0 && "Invalid number of NOP bytes requested!");

179 } else {

180

183 switch (CallTarget.getType()) {

189 break;

194 break;

198 .addReg(LoongArch::R1)

200 .addImm(0));

201 break;

202 default:

203 llvm_unreachable("Unsupported operand type in statepoint call target");

204 break;

205 }

206 }

207

209 MCSymbol *MILabel = Ctx.createTempSymbol();

211 SM.recordStatepoint(*MILabel, MI);

212}

213

217 if (F.hasFnAttribute("patchable-function-entry")) {

218 unsigned Num;

219 if (F.getFnAttribute("patchable-function-entry")

220 .getValueAsString()

221 .getAsInteger(10, Num))

222 return;

224 return;

225 }

226

228}

229

233

237

239

240

241

242

243

244

245

246

247

248

249

250 const int8_t NoopsInSledCount = 11;

252 MCSymbol *BeginOfSled = OutContext.createTempSymbol("xray_sled_begin");

261}

262

265

267 return;

268

269 assert(TM.getTargetTriple().isOSBinFormatELF());

270

273 auto JTI = MF->getJumpTableInfo();

274

275 if (!JTI || 0 == EntrySize)

276 return;

277

279 auto JT = JTI->getJumpTables();

280

281

282

283

284 OutStreamer->switchSection(MMI->getContext().getELFSection(

286

287 for (unsigned Idx = 0; Idx < EntrySize; ++Idx) {

288 int JTIIdx = LAFI->getJumpInfoJTIIndex(Idx);

289 if (JT[JTIIdx].MBBs.empty())

290 continue;

297 }

298}

299

302

304 return true;

305}

306

308

310 "LoongArch Assembly Printer", false, false)

311

312

314LLVMInitializeLoongArchAsmPrinter() {

317}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)

#define LLVM_EXTERNAL_VISIBILITY

cl::opt< bool > LArchAnnotateTableJump("loongarch-annotate-tablejump", cl::Hidden, cl::desc("Annotate table jump instruction to correlate it with the jump table."), cl::init(false))

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")

static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")

void emitNops(unsigned N)

Emit N NOP instructions.

void EmitToStreamer(MCStreamer &S, const MCInst &Inst)

TargetMachine & TM

Target machine description.

void emitXRayTable()

Emit a table with all XRay instrumentation points.

virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)

Print the MachineOperand as a symbol.

const MCAsmInfo * MAI

Target Asm Printer information.

MachineFunction * MF

The current machine function.

virtual void emitJumpTableInfo()

Print assembly representations of the jump tables used by the current function to the current output ...

MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const

Return the symbol for the specified jump table entry.

void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)

MachineModuleInfo * MMI

This is a pointer to the current MachineModuleInfo.

MCContext & OutContext

This is the context for the output file that we are streaming.

bool runOnMachineFunction(MachineFunction &MF) override

Emit the specified function out to the OutStreamer.

std::unique_ptr< MCStreamer > OutStreamer

This is the MCStreamer object for the file we are generating.

const DataLayout & getDataLayout() const

Return information about data layout.

const MCSubtargetInfo & getSubtargetInfo() const

Return information about subtarget.

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.

LLVM_ABI unsigned getPointerSize(unsigned AS=0) const

The pointer representation size in bytes, rounded up to a whole number of bytes.

void emitSled(const MachineInstr &MI, SledKind Kind)

Definition LoongArchAsmPrinter.cpp:238

void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI)

Definition LoongArchAsmPrinter.cpp:230

bool runOnMachineFunction(MachineFunction &MF) override

Emit the specified function out to the OutStreamer.

Definition LoongArchAsmPrinter.cpp:300

void LowerSTATEPOINT(const MachineInstr &MI)

Definition LoongArchAsmPrinter.cpp:174

void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI)

Definition LoongArchAsmPrinter.cpp:214

void emitInstruction(const MachineInstr *MI) override

Targets should implement this to emit instructions.

Definition LoongArchAsmPrinter.cpp:44

bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override

Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...

Definition LoongArchAsmPrinter.cpp:139

bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const

bool lowerPseudoInstExpansion(const MachineInstr *MI, MCInst &Inst)

void emitJumpTableInfo() override

Print assembly representations of the jump tables used by the current function to the current output ...

Definition LoongArchAsmPrinter.cpp:263

bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override

Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.

Definition LoongArchAsmPrinter.cpp:74

void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI)

Definition LoongArchAsmPrinter.cpp:234

static const char * getRegisterName(MCRegister Reg)

LoongArchMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private Lo...

unsigned getJumpInfoSize()

Instances of this class represent a single low-level machine instruction.

Instances of this class represent operands of the MCInst class.

static MCOperand createReg(MCRegister Reg)

static MCOperand createImm(int64_t Val)

const MCExpr * getExpr() const

static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...

Representation of each machine instruction.

MachineOperand class - Representation of each machine instruction operand.

bool isReg() const

isReg - Tests if this is a MO_Register operand.

bool isCPI() const

isCPI - Tests if this is a MO_ConstantPoolIndex operand.

bool isImm() const

isImm - Tests if this is a MO_Immediate operand.

bool isGlobal() const

isGlobal - Tests if this is a MO_GlobalAddress operand.

MachineOperandType getType() const

getType - Returns the MachineOperandType for this operand.

bool isBlockAddress() const

isBlockAddress - Tests if this is a MO_BlockAddress operand.

Register getReg() const

getReg - Returns the register number.

@ MO_Immediate

Immediate operand.

@ MO_GlobalAddress

Address of a global value.

@ MO_Register

Register operand.

@ MO_ExternalSymbol

Name of external global symbol.

constexpr unsigned id() const

MI-level Statepoint operands.

uint32_t getNumPatchBytes() const

Return the number of patchable bytes the given statepoint should emit.

const MachineOperand & getCallTarget() const

Return the target of the underlying call.

This class implements an extremely fast bulk output stream that can only output to a stream.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

initializer< Ty > init(const Ty &Val)

This is an optimization pass for GlobalISel generic memory operations.

Target & getTheLoongArch64Target()

bool lowerLoongArchMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, AsmPrinter &AP)

Target & getTheLoongArch32Target()

This struct is a compact representation of a valid (non-zero power of two) alignment.

RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...