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)

41 : AsmPrinter(TM, std::move(Streamer)), MCInstLowering(OutContext, *this) {}

42

46

47

48

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

117 else

119 return;

120}

121

123

124

125 if (!InConstantPool)

126 return;

127 InConstantPool = false;

128}

129

132 emitAttributes();

133}

134

138

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

173 switch (Modifier) {

190 }

192}

193

199

202 cast(CCPV)->getBlockAddress();

205 const GlobalValue *GV = cast(CCPV)->getGV();

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

211 signed JTI = cast(CCPV)->getJTI();

214 const Constant *C = cast(CCPV)->getConstantPool();

216 } else {

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

218 StringRef Sym = cast(CCPV)->getSymbol();

220 }

221

224

226

230

233

234

239 }

241 }

242

243

246

248}

249

250void CSKYAsmPrinter::emitAttributes() {

253

258

259

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

261

263}

264

267

269 return false;

270

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

273 if (ExtraCode[1] != 0)

274 return true;

275

276 switch (ExtraCode[0]) {

277 default:

278 return true;

279 case 'R':

282 return false;

283 }

284 }

285 }

286

290 return false;

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

293 return false;

295 return false;

298 return false;

302 return false;

303 }

304 default:

305 break;

306 }

307

308 return true;

309}

310

312 unsigned OpNo, const char *ExtraCode,

314 if (!ExtraCode) {

316

317

319 return true;

320

322 return false;

323 }

324

326}

327

330}

static MCSymbolRefExpr::VariantKind getModifierVariantKind(ARMCP::ARMCPModifier Modifier)

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYAsmPrinter()

#define LLVM_EXTERNAL_VISIBILITY

static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")

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

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

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

#define STATISTIC(VARNAME, DESC)

This class is intended to be used as a driving class for all asm writers.

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.

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.

MCSymbol * GetExternalSymbolSymbol(Twine Sym) const

Return the MCSymbol for the specified ExternalSymbol.

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.

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.

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

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

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.

void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override

bool runOnMachineFunction(MachineFunction &MF) override

Emit the specified function out to the OutStreamer.

void emitEndOfAsmFile(Module &M) override

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

void emitInstruction(const MachineInstr *MI) override

Targets should implement this to emit instructions.

void emitStartOfAsmFile(Module &M) override

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

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

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)

static const CSKYMCExpr * create(const MCExpr *Expr, VariantKind Kind, MCContext &Ctx)

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.

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)

MCSymbol * createTempSymbol()

Create a temporary symbol with a unique name.

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.

const MCInstrDesc & get(unsigned Opcode) const

Return the machine instruction descriptor that corresponds to the specified instruction opcode.

Streaming machine code generation interface.

Generic base class for all target subtargets.

void setFeatureBits(const FeatureBitset &FeatureBits_)

const FeatureBitset & getFeatureBits() const

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

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

MCSymbol * getSymbol() const

Return the MCSymbol for this basic block.

This class is a data container for one entry in a MachineConstantPool.

bool isMachineConstantPoolEntry() const

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

union llvm::MachineConstantPoolEntry::@204 Val

The constant itself.

MachineConstantPoolValue * MachineCPVal

const Constant * ConstVal

Abstract base class for all machine specific constantpool value subclasses.

const std::vector< MachineConstantPoolEntry > & getConstants() const

unsigned getConstantPoolIndex(const Constant *C, Align Alignment)

getConstantPoolIndex - Create a new entry in the constant pool or return an existing one.

const TargetSubtargetInfo & getSubtarget() const

getSubtarget - Return the subtarget for which this machine code is being compiled.

const DataLayout & getDataLayout() const

Return the DataLayout attached to the Module associated to this MF.

MachineConstantPool * getConstantPool()

getConstantPool - Return the constant pool object for the current function.

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

const MCSubtargetInfo * getMCSubtargetInfo() const

StringRef getTargetFeatureString() const

StringRef getTargetCPU() const

virtual const TargetInstrInfo * getInstrInfo() const

Triple - Helper class for working with autoconf configuration names.

bool isOSBinFormatELF() const

Tests whether the OS uses the ELF binary format.

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.

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