LLVM: lib/Target/CSKY/CSKYAsmPrinter.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

31

32using namespace llvm;

33

34#define DEBUG_TYPE "csky-asm-printer"

35

37 "Number of C-SKY Compressed instructions emitted");

38

40 std::unique_ptrllvm::MCStreamer Streamer)

42

44 MCP = MF.getConstantPool();

45 TII = MF.getSubtarget().getInstrInfo();

46

47

48

50 OutStreamer->getContext().getSubtargetCopy(*TM.getMCSubtargetInfo());

52 Subtarget = &NewSTI;

53

55}

56

57#define GEN_COMPRESS_INSTR

58#include "CSKYGenCompressInstEmitter.inc"

61 bool Res = compressInst(CInst, Inst, *Subtarget);

62 if (Res)

63 ++CSKYNumInstrsCompressed;

65}

66

67

68

69#include "CSKYGenMCPseudoLowering.inc"

70

71void CSKYAsmPrinter::expandTLSLA(const MachineInstr *MI) {

73

76 "_" + Twine(MI->getOperand(3).getImm()));

77

79

81 .add(MI->getOperand(0))

82 .add(MI->getOperand(2));

84 MCInstLowering.Lower(Instr, LRWInst);

86

88 .add(MI->getOperand(1))

91 MCInstLowering.Lower(Instr, GRSInst);

93 return;

94}

95

96void CSKYAsmPrinter::emitCustomConstantPool(const MachineInstr *MI) {

97

98

99

100

101

102

103 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();

104 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();

105

106

107 if (!InConstantPool) {

109 InConstantPool = true;

110 }

111

113

114 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];

117 else

119 return;

120}

121

123

124

125 if (!InConstantPool)

126 return;

127 InConstantPool = false;

128}

129

131 if (TM.getTargetTriple().isOSBinFormatELF())

132 emitAttributes();

133}

134

138

139 if (TM.getTargetTriple().isOSBinFormatELF())

141}

142

144 CSKY_MC::verifyInstructionPredicates(MI->getOpcode(),

146

147

150 return;

151 }

152

153

154 if (InConstantPool && MI->getOpcode() != CSKY::CONSTPOOL_ENTRY) {

155 InConstantPool = false;

156 }

157

158 if (MI->getOpcode() == CSKY::PseudoTLSLA32)

159 return expandTLSLA(MI);

160

161 if (MI->getOpcode() == CSKY::CONSTPOOL_ENTRY)

162 return emitCustomConstantPool(MI);

163

165 MCInstLowering.Lower(MI, TmpInst);

167}

168

169

170

172 switch (Modifier) {

189 }

191}

192

198

208 MCSym = MBB->getSymbol();

209 } else if (CCPV->isJT()) {

215 } else {

216 assert(CCPV->isExtSymbol() && "unrecognized constant pool value");

219 }

220

222

224

226 Twine(MAI->getPrivateGlobalPrefix()) + "PC" +

228

231

232

237 }

239 }

240

241

244

246}

247

248void CSKYAsmPrinter::emitAttributes() {

251

256

257

258 const CSKYSubtarget STI(TT, CPU, CPU, FS, CTM);

259

261}

262

264 const char *ExtraCode, raw_ostream &OS) {

265

267 return false;

268

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

271 if (ExtraCode[1] != 0)

272 return true;

273

274 switch (ExtraCode[0]) {

275 default:

276 return true;

277 case 'R':

280 return false;

281 }

282 }

283 }

284

288 return false;

290 if (MO.getReg() == CSKY::C)

291 return false;

293 return false;

296 return false;

300 return false;

301 }

302 default:

303 break;

304 }

305

306 return true;

307}

308

310 unsigned OpNo, const char *ExtraCode,

312 if (!ExtraCode) {

314

315

317 return true;

318

320 return false;

321 }

322

324}

325

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

const TargetInstrInfo & TII

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYAsmPrinter()

Definition CSKYAsmPrinter.cpp:326

static CSKY::Specifier getModifierVariantKind(CSKYCP::CSKYCPModifier Modifier)

Definition CSKYAsmPrinter.cpp:171

#define LLVM_EXTERNAL_VISIBILITY

This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

#define STATISTIC(VARNAME, DESC)

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

MCSymbol * getSymbol(const GlobalValue *GV) const

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

TargetMachine & TM

Target machine description.

virtual MCSymbol * GetCPISymbol(unsigned CPID) const

Return the symbol for the specified constant pool entry.

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.

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

Return the symbol for the specified jump table entry.

unsigned getFunctionNumber() const

Return a unique ID for the current function.

AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer, char &ID=AsmPrinter::ID)

void emitGlobalConstant(const DataLayout &DL, const Constant *CV, AliasMapTy *AliasList=nullptr)

EmitGlobalConstant - Print a general LLVM constant to the .s file.

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.

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...

MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const

Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.

const DataLayout & getDataLayout() const

Return information about data layout.

MCSymbol * GetExternalSymbolSymbol(const Twine &Sym) const

Return the MCSymbol for the specified ExternalSymbol.

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.

The address of a basic block.

void emitFunctionBodyEnd() override

Targets can override this to emit stuff after the last basic block in the function.

Definition CSKYAsmPrinter.cpp:122

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

Definition CSKYAsmPrinter.cpp:59

CSKYAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)

Definition CSKYAsmPrinter.cpp:39

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

tblgen'erated driver function for lowering simple MI->MC pseudo instructions.

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 CSKYAsmPrinter.cpp:263

void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override

Definition CSKYAsmPrinter.cpp:193

bool runOnMachineFunction(MachineFunction &MF) override

Emit the specified function out to the OutStreamer.

Definition CSKYAsmPrinter.cpp:43

void emitEndOfAsmFile(Module &M) override

This virtual method can be overridden by targets that want to emit something at the end of their file...

Definition CSKYAsmPrinter.cpp:135

void emitInstruction(const MachineInstr *MI) override

Targets should implement this to emit instructions.

Definition CSKYAsmPrinter.cpp:143

void emitStartOfAsmFile(Module &M) override

This virtual method can be overridden by targets that want to emit something at the start of their fi...

Definition CSKYAsmPrinter.cpp:130

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 CSKYAsmPrinter.cpp:309

CSKYConstantPoolValue - CSKY specific constantpool value.

bool isMachineBasicBlock() const

bool isGlobalValue() const

unsigned getLabelID() const

unsigned getPCAdjustment() const

bool mustAddCurrentAddress() const

bool isBlockAddress() const

CSKYCP::CSKYCPModifier getModifier() const

static const char * getRegisterName(MCRegister Reg)

void Lower(const MachineInstr *MI, MCInst &OutMI) const

virtual void emitTargetAttributes(const MCSubtargetInfo &STI)

virtual void finishAttributeSection()

This is an important base class in LLVM.

LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const

Returns the offset in bytes between successive objects of the specified type, including alignment pad...

StringRef getPrivateGlobalPrefix() const

static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)

LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)

Lookup the symbol inside with the specified Name.

Base class for the full range of assembler expressions which are needed for parsing.

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

static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())

Streaming machine code generation interface.

Generic base class for all target subtargets.

void setFeatureBits(const FeatureBitset &FeatureBits_)

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 ...

LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const

print - Print the value to the stream OS.

union llvm::MachineConstantPoolEntry::@004270020304201266316354007027341142157160323045 Val

The constant itself.

bool isMachineConstantPoolEntry() const

isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...

MachineConstantPoolValue * MachineCPVal

const Constant * ConstVal

Abstract base class for all machine specific constantpool value subclasses.

const MachineInstrBuilder & add(const MachineOperand &MO) const

const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const

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.

const BlockAddress * getBlockAddress() const

MachineOperandType getType() const

getType - Returns the MachineOperandType for this operand.

Register getReg() const

getReg - Returns the register number.

@ MO_Immediate

Immediate operand.

@ MO_GlobalAddress

Address of a global value.

@ MO_BlockAddress

Address of a basic block.

@ MO_Register

Register operand.

A Module instance is used to store all the information related to an LLVM module.

StringRef - Represent a constant reference to a string, i.e.

Primary interface to the complete machine description for the target machine.

const Triple & getTargetTriple() const

StringRef getTargetFeatureString() const

StringRef getTargetCPU() const

Triple - Helper class for working with autoconf configuration names.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

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.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)

Builder interface. Specify how to create the initial instruction itself.

Target & getTheCSKYTarget()

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

Implement std::hash so that hash_code can be used in STL containers.

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,...