LLVM: lib/Target/M68k/MCTargetDesc/M68kAsmBackend.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

16

38

39using namespace llvm;

40

41#define DEBUG_TYPE "M68k-asm-backend"

42

43namespace {

44

46 bool Allows32BitBranch;

47

48public:

52 .CasesLower({"m68020", "m68030", "m68040"}, true)

54

57

60

61 bool fixupNeedsRelaxation(const MCFixup &Fixup,

63

64 void relaxInstruction(MCInst &Inst,

66

67

68

69

70 unsigned getMinimumNopSize() const override { return 2; }

71

72

73

76};

77}

78

82 if (!IsResolved)

83 Asm->getWriter().recordRelocation(F, Fixup, Target, Value);

84

86 assert(Fixup.getOffset() + Size <= F.getSize() && "Invalid fixup offset!");

87

88

89

90

92 "Value does not fit in the Fixup field");

93

94

95 for (unsigned i = 0; i != Size; ++i)

96 Data[i] = uint8_t(static_cast<int64_t>(Value) >> ((Size - i - 1) * 8));

97}

98

99

100

101

102

103

104

105

106

108 switch (Op) {

109 default:

110 return Op;

111

112

113 case M68k::BRA8:

114 return M68k::BRA16;

115 case M68k::Bcc8:

116 return M68k::Bcc16;

117 case M68k::Bls8:

118 return M68k::Bls16;

119 case M68k::Blt8:

120 return M68k::Blt16;

121 case M68k::Beq8:

122 return M68k::Beq16;

123 case M68k::Bmi8:

124 return M68k::Bmi16;

125 case M68k::Bne8:

126 return M68k::Bne16;

127 case M68k::Bge8:

128 return M68k::Bge16;

129 case M68k::Bcs8:

130 return M68k::Bcs16;

131 case M68k::Bpl8:

132 return M68k::Bpl16;

133 case M68k::Bgt8:

134 return M68k::Bgt16;

135 case M68k::Bhi8:

136 return M68k::Bhi16;

137 case M68k::Bvc8:

138 return M68k::Bvc16;

139 case M68k::Ble8:

140 return M68k::Ble16;

141 case M68k::Bvs8:

142 return M68k::Bvs16;

143

144

145 case M68k::BRA16:

146 return M68k::BRA32;

147 case M68k::Bcc16:

148 return M68k::Bcc32;

149 case M68k::Bls16:

150 return M68k::Bls32;

151 case M68k::Blt16:

152 return M68k::Blt32;

153 case M68k::Beq16:

154 return M68k::Beq32;

155 case M68k::Bmi16:

156 return M68k::Bmi32;

157 case M68k::Bne16:

158 return M68k::Bne32;

159 case M68k::Bge16:

160 return M68k::Bge32;

161 case M68k::Bcs16:

162 return M68k::Bcs32;

163 case M68k::Bpl16:

164 return M68k::Bpl32;

165 case M68k::Bgt16:

166 return M68k::Bgt32;

167 case M68k::Bhi16:

168 return M68k::Bhi32;

169 case M68k::Bvc16:

170 return M68k::Bvc32;

171 case M68k::Ble16:

172 return M68k::Ble32;

173 case M68k::Bvs16:

174 return M68k::Bvs32;

175 }

176}

177

182

183bool M68kAsmBackend::mayNeedRelaxation(unsigned Opcode, ArrayRef,

184 const MCSubtargetInfo &STI) const {

185

187

188

189}

190

191bool M68kAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,

192 uint64_t UnsignedValue) const {

193 int64_t Value = static_cast<int64_t>(UnsignedValue);

194

196 llvm_unreachable("Cannot relax the instruction, value does not fit");

197

198

199

200

202 bool FixupFieldTooSmall = false;

204 FixupFieldTooSmall = true;

206 FixupFieldTooSmall = true;

207

208

209

210

211

212 bool ZeroDisplacementNeedsFixup = Value == 0 && KindLog2Size == 0;

213

214 return ZeroDisplacementNeedsFixup || FixupFieldTooSmall;

215}

216

217

218

219void M68kAsmBackend::relaxInstruction(MCInst &Inst,

220 const MCSubtargetInfo &STI) const {

224}

225

226bool M68kAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,

227 const MCSubtargetInfo *STI) const {

228

229 if (Count % 2 != 0)

230 return false;

231

232 uint64_t NumNops = Count / 2;

233 for (uint64_t i = 0; i != NumNops; ++i) {

234 OS << "\x4E\x71";

235 }

236

237 return true;

238}

239

240namespace {

241

242class M68kELFAsmBackend : public M68kAsmBackend {

243public:

244 uint8_t OSABI;

245 M68kELFAsmBackend(const Target &T, const MCSubtargetInfo &STI, uint8_t OSABI)

246 : M68kAsmBackend(T, STI), OSABI(OSABI) {}

247

248 std::unique_ptr

249 createObjectTargetWriter() const override {

251 }

252};

253

254}

255

262 return new M68kELFAsmBackend(T, STI, OSABI);

263}

unsigned const MachineRegisterInfo * MRI

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

static unsigned getRelaxedOpcodeBranch(unsigned Op)

cc—Carry clear GE—Greater than or equal LS—Lower or same PL—Plus CS—Carry set GT—Greater than LT—Less...

Definition M68kAsmBackend.cpp:107

static unsigned getRelaxedOpcode(unsigned Opcode)

Definition M68kAsmBackend.cpp:178

This file contains small standalone helper functions and enum definitions for the M68k target useful ...

This file contains M68k specific fixup entries.

PowerPC TLS Dynamic Call Fixup

This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

Generic interface to target specific assembler backends.

Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...

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

unsigned getOpcode() const

void setOpcode(unsigned Op)

MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...

Generic base class for all target subtargets.

const Triple & getTargetTriple() const

A switch()-like statement whose cases are string literals.

StringSwitch & CasesLower(std::initializer_list< StringLiteral > CaseStrings, T Value)

Target - Wrapper for Target specific information.

Triple - Helper class for working with autoconf configuration names.

OSType getOS() const

Get the parsed operating system type of this triple.

LLVM Value Representation.

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.

This is an optimization pass for GlobalISel generic memory operations.

FunctionAddr VTableAddr Value

static unsigned getFixupKindLog2Size(unsigned Kind)

constexpr bool isInt(int64_t x)

Checks if an integer fits into the given bit width.

std::unique_ptr< MCObjectTargetWriter > createM68kELFObjectWriter(uint8_t OSABI)

Construct an M68k ELF object writer.

MCAsmBackend * createM68kAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)

Definition M68kAsmBackend.cpp:256

FunctionAddr VTableAddr Count

FunctionAddr VTableAddr uintptr_t uintptr_t Data

DWARFExpression::Operation Op

ArrayRef(const T &OneElt) -> ArrayRef< T >

constexpr bool isIntN(unsigned N, int64_t x)

Checks if an signed integer fits into the given (dynamic) bit width.