LLVM: lib/Target/XCore/XCoreAsmPrinter.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

40#include

41#include

42using namespace llvm;

43

44#define DEBUG_TYPE "asm-printer"

45

46namespace {

47 class XCoreAsmPrinter : public AsmPrinter {

50

51 public:

52 static char ID;

53

55 std::unique_ptr Streamer)

56 : AsmPrinter(TM, std::move(Streamer), ID), MCInstLowering(*this) {}

57

58 StringRef getPassName() const override { return "XCore Assembly Printer"; }

59

61 const std::string &directive = ".jmptable");

63 printInlineJT(MI, opNum, O, ".jmptable32");

64 }

66 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,

67 const char *ExtraCode, raw_ostream &O) override;

68 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,

69 const char *ExtraCode, raw_ostream &O) override;

70

72 void emitGlobalVariable(const GlobalVariable *GV) override;

73

74 void emitFunctionEntryLabel() override;

75 void emitInstruction(const MachineInstr *MI) override;

76 void emitFunctionBodyStart() override;

77 void emitFunctionBodyEnd() override;

78 };

79}

80

82 return static_cast<XCoreTargetStreamer&>(*OutStreamer->getTargetStreamer());

83}

84

85void XCoreAsmPrinter::emitArrayBound(MCSymbol *Sym, const GlobalVariable *GV) {

88 "Unexpected linkage");

90

91 MCSymbol *SymGlob = OutContext.getOrCreateSymbol(

92 Twine(Sym->getName() + StringRef(".globound")));

93 OutStreamer->emitSymbolAttribute(SymGlob, MCSA_Global);

94 OutStreamer->emitAssignment(SymGlob,

96 OutContext));

99 OutStreamer->emitSymbolAttribute(SymGlob, MCSA_Weak);

100 }

101 }

102}

103

104void XCoreAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {

105

106 if (!GV->hasInitializer() || emitSpecialLLVMGlobal(GV))

107 return;

108

109 const DataLayout &DL = getDataLayout();

110 OutStreamer->switchSection(getObjFileLowering().SectionForGlobal(GV, TM));

111

112 MCSymbol *GVSym = getSymbol(GV);

114 const Align Alignment = DL.getPrefTypeAlign(C->getType());

115

116

117 getTargetStreamer().emitCCTopData(GVSym->getName());

118

121 report_fatal_error("AppendingLinkage is not supported by this target!");

128 emitArrayBound(GVSym, GV);

129 OutStreamer->emitSymbolAttribute(GVSym, MCSA_Global);

130

133 OutStreamer->emitSymbolAttribute(GVSym, MCSA_Weak);

134 [[fallthrough]];

137 break;

138 default:

140 }

141

142 emitAlignment(std::max(Alignment, Align(4)), GV);

143

146 }

147 unsigned Size = DL.getTypeAllocSize(C->getType());

148 if (MAI->hasDotTypeDotSizeDirective()) {

151 }

152 OutStreamer->emitLabel(GVSym);

153

154 emitGlobalConstant(DL, C);

155

156

157 if (Size < 4)

158 OutStreamer->emitZeros(4 - Size);

159

160

161 getTargetStreamer().emitCCBottomData(GVSym->getName());

162}

163

164void XCoreAsmPrinter::emitFunctionBodyStart() {

165 MCInstLowering.Initialize(&MF->getContext());

166}

167

168

169

170void XCoreAsmPrinter::emitFunctionBodyEnd() {

171

172 getTargetStreamer().emitCCBottomFunction(CurrentFnSym->getName());

173}

174

175void XCoreAsmPrinter::emitFunctionEntryLabel() {

176

177 getTargetStreamer().emitCCTopFunction(CurrentFnSym->getName());

178 OutStreamer->emitLabel(CurrentFnSym);

179}

180

181void XCoreAsmPrinter::

182printInlineJT(const MachineInstr *MI, int opNum, raw_ostream &O,

183 const std::string &directive) {

184 unsigned JTI = MI->getOperand(opNum).getIndex();

185 const MachineFunction *MF = MI->getParent()->getParent();

187 const std::vector &JT = MJTI->getJumpTables();

188 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;

189 O << "\t" << directive << " ";

190 for (unsigned i = 0, e = JTBBs.size(); i != e; ++i) {

191 MachineBasicBlock *MBB = JTBBs[i];

192 if (i > 0)

193 O << ",";

195 }

196}

197

198void XCoreAsmPrinter::printOperand(const MachineInstr *MI, int opNum,

199 raw_ostream &O) {

200 const DataLayout &DL = getDataLayout();

201 const MachineOperand &MO = MI->getOperand(opNum);

205 break;

208 break;

211 break;

213 PrintSymbolOperand(MO, O);

214 break;

216 O << DL.getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'

218 break;

220 GetBlockAddressSymbol(MO.getBlockAddress())->print(O, MAI);

221 break;

222 default:

224 }

225}

226

227

228

229bool XCoreAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,

230 const char *ExtraCode, raw_ostream &O) {

231

232 if (!ExtraCode || !ExtraCode[0]) {

234 return false;

235 }

236

237

239}

240

241bool XCoreAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,

242 unsigned OpNum,

243 const char *ExtraCode,

244 raw_ostream &O) {

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

246 return true;

247 }

249 O << '[';

251 O << ']';

252 return false;

253}

254

255void XCoreAsmPrinter::emitInstruction(const MachineInstr *MI) {

256 XCore_MC::verifyInstructionPredicates(MI->getOpcode(),

257 getSubtargetInfo().getFeatureBits());

258

259 SmallString<128> Str;

260 raw_svector_ostream O(Str);

261

262 switch (MI->getOpcode()) {

263 case XCore::DBG_VALUE:

265 case XCore::ADD_2rus:

266 if (MI->getOperand(2).getImm() == 0) {

267 O << "\tmov "

270 OutStreamer->emitRawText(O.str());

271 return;

272 }

273 break;

274 case XCore::BR_JT:

275 case XCore::BR_JT32:

276 O << "\tbru "

278 if (MI->getOpcode() == XCore::BR_JT)

279 printInlineJT(MI, 0, O);

280 else

281 printInlineJT32(MI, 0, O);

282 O << '\n';

283 OutStreamer->emitRawText(O.str());

284 return;

285 }

286

287 MCInst TmpInst;

288 MCInstLowering.Lower(MI, TmpInst);

289

290 EmitToStreamer(*OutStreamer, TmpInst);

291}

292

293char XCoreAsmPrinter::ID = 0;

294

295INITIALIZE_PASS(XCoreAsmPrinter, "xcore-asm-printer", "XCore Assembly Printer",

296 false, false)

297

298

300LLVMInitializeXCoreAsmPrinter() {

302}

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

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

#define LLVM_EXTERNAL_VISIBILITY

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

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

static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)

This file defines the SmallString class.

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

This file contains the declaration of the XCoreInstPrinter class, which is used to print XCore MCInst...

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

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 hasLinkOnceLinkage() const

bool hasExternalLinkage() const

bool isThreadLocal() const

If the value is "Thread Local", its value isn't shared by the threads.

LinkageTypes getLinkage() const

bool hasWeakLinkage() const

bool hasCommonLinkage() const

@ PrivateLinkage

Like Internal, but omit from symbol table.

@ CommonLinkage

Tentative definitions.

@ InternalLinkage

Rename collisions when linking (static functions).

@ LinkOnceAnyLinkage

Keep one copy of function when linking (inline)

@ WeakODRLinkage

Same, but only replaced by something equivalent.

@ ExternalLinkage

Externally visible function.

@ WeakAnyLinkage

Keep one copy of named function when linking (weak)

@ AppendingLinkage

Special purpose, only applies to global arrays.

@ LinkOnceODRLinkage

Same, but only replaced by something equivalent.

Type * getValueType() const

const Constant * getInitializer() const

getInitializer - Return the initializer for this global variable.

bool hasInitializer() const

Definitions have initializers, declarations don't.

static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)

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.

StringRef getName() const

getName - Get the symbol name.

LLVM_ABI MCSymbol * getSymbol() const

Return the MCSymbol for this basic block.

const MachineJumpTableInfo * getJumpTableInfo() const

getJumpTableInfo - Return the jump table info object for the current function.

Representation of each machine instruction.

const std::vector< MachineJumpTableEntry > & getJumpTables() const

MachineBasicBlock * getMBB() const

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_ConstantPoolIndex

Address of indexed Constant in Constant Pool.

@ MO_GlobalAddress

Address of a global value.

@ MO_BlockAddress

Address of a basic block.

@ MO_MachineBasicBlock

MachineBasicBlock reference.

@ MO_Register

Register operand.

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

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

static const char * getRegisterName(MCRegister Reg)

This class is used to lower an MachineInstr into an MCInst.

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

void Initialize(MCContext *C)

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.

constexpr char Align[]

Key for Kernel::Arg::Metadata::mAlign.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

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

Target & getTheXCoreTarget()

LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)

@ MCSA_Global

.type _foo, @gnu_unique_object

@ MCSA_ELF_TypeObject

.type _foo, STT_OBJECT # aka @object

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