llvm.org GIT mirror llvm / 7d2093c
Merging MIPS JIT/MCJIT changeset into 3.2 release branch. Merging r169183: RuntimeDyld: Fix up r169178. MSVC doesn't like "or". Merging r169178: Runtime dynamic linker for MCJIT should support MIPS BigEndian architecture. This small change adds support for that. It will make all MCJIT tests pass in make-check on BigEndian platforms. Patch by Petar Jovanovic. Merging r169177: Classic JIT is still being supported by MIPS, along with MCJIT. This change adds endian-awareness to MipsJITInfo and emitWordLE in MipsCodeEmitter has become emitWord now to support both endianness. Patch by Petar Jovanovic. Merging r169174: Functions in MipsCodeEmitter.cpp that expand unaligned loads/stores are dead code. Removing it. Patch by Petar Jovanovic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@169296 91177308-0d34-0410-b5e6-96231b3b80d8 Pawel Wodnicki 6 years ago
6 changed file(s) with 28 addition(s) and 117 deletion(s). Raw diff Collapse all Expand all
345345 uint32_t *StubAddr = (uint32_t*)Addr;
346346 *StubAddr = 0xe51ff004; // ldr pc,
347347 return (uint8_t*)++StubAddr;
348 } else if (Arch == Triple::mipsel) {
348 } else if (Arch == Triple::mipsel || Arch == Triple::mips) {
349349 uint32_t *StubAddr = (uint32_t*)Addr;
350350 // 0: 3c190000 lui t9,%hi(addr).
351351 // 4: 27390000 addiu t9,t9,%lo(addr).
675675 RelType, 0);
676676 Section.StubOffset += getMaxStubSize();
677677 }
678 } else if (Arch == Triple::mipsel && RelType == ELF::R_MIPS_26) {
678 } else if ((Arch == Triple::mipsel || Arch == Triple::mips) &&
679 RelType == ELF::R_MIPS_26) {
679680 // This is an Mips branch relocation, need to use a stub function.
680681 DEBUG(dbgs() << "\t\tThis is a Mips branch relocation.");
681682 SectionEntry &Section = Sections[Rel.SectionID];
167167 inline unsigned getMaxStubSize() {
168168 if (Arch == Triple::arm || Arch == Triple::thumb)
169169 return 8; // 32-bit instruction and 32-bit address
170 else if (Arch == Triple::mipsel)
170 else if (Arch == Triple::mipsel || Arch == Triple::mips)
171171 return 16;
172172 else if (Arch == Triple::ppc64)
173173 return 44;
8484
8585 private:
8686
87 void emitWordLE(unsigned Word);
87 void emitWord(unsigned Word);
8888
8989 /// Routines that handle operands which add machine relocations which are
9090 /// fixed up by the relocation stage.
111111 unsigned getSizeExtEncoding(const MachineInstr &MI, unsigned OpNo) const;
112112 unsigned getSizeInsEncoding(const MachineInstr &MI, unsigned OpNo) const;
113113
114 int emitULW(const MachineInstr &MI);
115 int emitUSW(const MachineInstr &MI);
116 int emitULH(const MachineInstr &MI);
117 int emitULHu(const MachineInstr &MI);
118 int emitUSH(const MachineInstr &MI);
119
120114 void emitGlobalAddressUnaligned(const GlobalValue *GV, unsigned Reloc,
121115 int Offset) const;
122116 };
132126 MCPEs = &MF.getConstantPool()->getConstants();
133127 MJTEs = 0;
134128 if (MF.getJumpTableInfo()) MJTEs = &MF.getJumpTableInfo()->getJumpTables();
135 JTI->Initialize(MF, IsPIC);
129 JTI->Initialize(MF, IsPIC, Subtarget->isLittle());
136130 MCE.setModuleInfo(&getAnalysis ());
137131
138132 do {
270264 Reloc, BB));
271265 }
272266
273 int MipsCodeEmitter::emitUSW(const MachineInstr &MI) {
274 unsigned src = getMachineOpValue(MI, MI.getOperand(0));
275 unsigned base = getMachineOpValue(MI, MI.getOperand(1));
276 unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
277 // swr src, offset(base)
278 // swl src, offset+3(base)
279 MCE.emitWordLE(
280 (0x2e << 26) | (base << 21) | (src << 16) | (offset & 0xffff));
281 MCE.emitWordLE(
282 (0x2a << 26) | (base << 21) | (src << 16) | ((offset+3) & 0xffff));
283 return 2;
284 }
285
286 int MipsCodeEmitter::emitULW(const MachineInstr &MI) {
287 unsigned dst = getMachineOpValue(MI, MI.getOperand(0));
288 unsigned base = getMachineOpValue(MI, MI.getOperand(1));
289 unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
290 unsigned at = 1;
291 if (dst != base) {
292 // lwr dst, offset(base)
293 // lwl dst, offset+3(base)
294 MCE.emitWordLE(
295 (0x26 << 26) | (base << 21) | (dst << 16) | (offset & 0xffff));
296 MCE.emitWordLE(
297 (0x22 << 26) | (base << 21) | (dst << 16) | ((offset+3) & 0xffff));
298 return 2;
299 } else {
300 // lwr at, offset(base)
301 // lwl at, offset+3(base)
302 // addu dst, at, $zero
303 MCE.emitWordLE(
304 (0x26 << 26) | (base << 21) | (at << 16) | (offset & 0xffff));
305 MCE.emitWordLE(
306 (0x22 << 26) | (base << 21) | (at << 16) | ((offset+3) & 0xffff));
307 MCE.emitWordLE(
308 (0x0 << 26) | (at << 21) | (0x0 << 16) | (dst << 11) | (0x0 << 6) | 0x21);
309 return 3;
310 }
311 }
312
313 int MipsCodeEmitter::emitUSH(const MachineInstr &MI) {
314 unsigned src = getMachineOpValue(MI, MI.getOperand(0));
315 unsigned base = getMachineOpValue(MI, MI.getOperand(1));
316 unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
317 unsigned at = 1;
318 // sb src, offset(base)
319 // srl at,src,8
320 // sb at, offset+1(base)
321 MCE.emitWordLE(
322 (0x28 << 26) | (base << 21) | (src << 16) | (offset & 0xffff));
323 MCE.emitWordLE(
324 (0x0 << 26) | (0x0 << 21) | (src << 16) | (at << 11) | (0x8 << 6) | 0x2);
325 MCE.emitWordLE(
326 (0x28 << 26) | (base << 21) | (at << 16) | ((offset+1) & 0xffff));
327 return 3;
328 }
329
330 int MipsCodeEmitter::emitULH(const MachineInstr &MI) {
331 unsigned dst = getMachineOpValue(MI, MI.getOperand(0));
332 unsigned base = getMachineOpValue(MI, MI.getOperand(1));
333 unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
334 unsigned at = 1;
335 // lbu at, offset(base)
336 // lb dst, offset+1(base)
337 // sll dst,dst,8
338 // or dst,dst,at
339 MCE.emitWordLE(
340 (0x24 << 26) | (base << 21) | (at << 16) | (offset & 0xffff));
341 MCE.emitWordLE(
342 (0x20 << 26) | (base << 21) | (dst << 16) | ((offset+1) & 0xffff));
343 MCE.emitWordLE(
344 (0x0 << 26) | (0x0 << 21) | (dst << 16) | (dst << 11) | (0x8 << 6) | 0x0);
345 MCE.emitWordLE(
346 (0x0 << 26) | (dst << 21) | (at << 16) | (dst << 11) | (0x0 << 6) | 0x25);
347 return 4;
348 }
349
350 int MipsCodeEmitter::emitULHu(const MachineInstr &MI) {
351 unsigned dst = getMachineOpValue(MI, MI.getOperand(0));
352 unsigned base = getMachineOpValue(MI, MI.getOperand(1));
353 unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
354 unsigned at = 1;
355 // lbu at, offset(base)
356 // lbu dst, offset+1(base)
357 // sll dst,dst,8
358 // or dst,dst,at
359 MCE.emitWordLE(
360 (0x24 << 26) | (base << 21) | (at << 16) | (offset & 0xffff));
361 MCE.emitWordLE(
362 (0x24 << 26) | (base << 21) | (dst << 16) | ((offset+1) & 0xffff));
363 MCE.emitWordLE(
364 (0x0 << 26) | (0x0 << 21) | (dst << 16) | (dst << 11) | (0x8 << 6) | 0x0);
365 MCE.emitWordLE(
366 (0x0 << 26) | (dst << 21) | (at << 16) | (dst << 11) | (0x0 << 6) | 0x25);
367 return 4;
368 }
369
370267 void MipsCodeEmitter::emitInstruction(const MachineInstr &MI) {
371268 DEBUG(errs() << "JIT: " << (void*)MCE.getCurrentPCValue() << ":\t" << MI);
372269
376273 if ((MI.getDesc().TSFlags & MipsII::FormMask) == MipsII::Pseudo)
377274 return;
378275
379 emitWordLE(getBinaryCodeForInstr(MI));
276 emitWord(getBinaryCodeForInstr(MI));
380277 ++NumEmitted; // Keep track of the # of mi's emitted
381278
382279 MCE.processDebugLoc(MI.getDebugLoc(), false);
383280 }
384281
385 void MipsCodeEmitter::emitWordLE(unsigned Word) {
282 void MipsCodeEmitter::emitWord(unsigned Word) {
386283 DEBUG(errs() << " 0x";
387284 errs().write_hex(Word) << "\n");
388 MCE.emitWordLE(Word);
285 if (Subtarget->isLittle())
286 MCE.emitWordLE(Word);
287 else
288 MCE.emitWordBE(Word);
389289 }
390290
391291 /// createMipsJITCodeEmitterPass - Return a pass that emits the collected Mips
221221 // addiu t9, t9, %lo(EmittedAddr)
222222 // jalr t8, t9
223223 // nop
224 JCE.emitWordLE(0xf << 26 | 25 << 16 | Hi);
225 JCE.emitWordLE(9 << 26 | 25 << 21 | 25 << 16 | Lo);
226 JCE.emitWordLE(25 << 21 | 24 << 11 | 9);
227 JCE.emitWordLE(0);
224 if (IsLittleEndian) {
225 JCE.emitWordLE(0xf << 26 | 25 << 16 | Hi);
226 JCE.emitWordLE(9 << 26 | 25 << 21 | 25 << 16 | Lo);
227 JCE.emitWordLE(25 << 21 | 24 << 11 | 9);
228 JCE.emitWordLE(0);
229 } else {
230 JCE.emitWordBE(0xf << 26 | 25 << 16 | Hi);
231 JCE.emitWordBE(9 << 26 | 25 << 21 | 25 << 16 | Lo);
232 JCE.emitWordBE(25 << 21 | 24 << 11 | 9);
233 JCE.emitWordBE(0);
234 }
228235
229236 sys::Memory::InvalidateInstructionCache(Addr, 16);
230237 if (!sys::Memory::setRangeExecutable(Addr, 16))
2525 class MipsJITInfo : public TargetJITInfo {
2626
2727 bool IsPIC;
28 bool IsLittleEndian;
2829
2930 public:
3031 explicit MipsJITInfo() :
31 IsPIC(false) {}
32 IsPIC(false), IsLittleEndian(true) {}
3233
3334 /// replaceMachineCodeForFunction - Make it so that calling the function
3435 /// whose machine code is at OLD turns into a call to NEW, perhaps by
5758 unsigned NumRelocs, unsigned char *GOTBase);
5859
5960 /// Initialize - Initialize internal stage for the function being JITted.
60 void Initialize(const MachineFunction &MF, bool isPIC) {
61 void Initialize(const MachineFunction &MF, bool isPIC,
62 bool isLittleEndian) {
6163 IsPIC = isPIC;
64 IsLittleEndian = isLittleEndian;
6265 }
6366
6467 };