Skip to content

Commit 7d2093c

Browse files
committed
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
1 parent bdcb222 commit 7d2093c

File tree

6 files changed

+28
-117
lines changed

6 files changed

+28
-117
lines changed

lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ uint8_t *RuntimeDyldImpl::createStubFunction(uint8_t *Addr) {
346346
uint32_t *StubAddr = (uint32_t*)Addr;
347347
*StubAddr = 0xe51ff004; // ldr pc,<label>
348348
return (uint8_t*)++StubAddr;
349-
} else if (Arch == Triple::mipsel) {
349+
} else if (Arch == Triple::mipsel || Arch == Triple::mips) {
350350
uint32_t *StubAddr = (uint32_t*)Addr;
351351
// 0: 3c190000 lui t9,%hi(addr).
352352
// 4: 27390000 addiu t9,t9,%lo(addr).

lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,8 @@ void RuntimeDyldELF::processRelocationRef(const ObjRelocationInfo &Rel,
676676
RelType, 0);
677677
Section.StubOffset += getMaxStubSize();
678678
}
679-
} else if (Arch == Triple::mipsel && RelType == ELF::R_MIPS_26) {
679+
} else if ((Arch == Triple::mipsel || Arch == Triple::mips) &&
680+
RelType == ELF::R_MIPS_26) {
680681
// This is an Mips branch relocation, need to use a stub function.
681682
DEBUG(dbgs() << "\t\tThis is a Mips branch relocation.");
682683
SectionEntry &Section = Sections[Rel.SectionID];

lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class RuntimeDyldImpl {
168168
inline unsigned getMaxStubSize() {
169169
if (Arch == Triple::arm || Arch == Triple::thumb)
170170
return 8; // 32-bit instruction and 32-bit address
171-
else if (Arch == Triple::mipsel)
171+
else if (Arch == Triple::mipsel || Arch == Triple::mips)
172172
return 16;
173173
else if (Arch == Triple::ppc64)
174174
return 44;

lib/Target/Mips/MipsCodeEmitter.cpp

Lines changed: 8 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class MipsCodeEmitter : public MachineFunctionPass {
8585

8686
private:
8787

88-
void emitWordLE(unsigned Word);
88+
void emitWord(unsigned Word);
8989

9090
/// Routines that handle operands which add machine relocations which are
9191
/// fixed up by the relocation stage.
@@ -112,12 +112,6 @@ class MipsCodeEmitter : public MachineFunctionPass {
112112
unsigned getSizeExtEncoding(const MachineInstr &MI, unsigned OpNo) const;
113113
unsigned getSizeInsEncoding(const MachineInstr &MI, unsigned OpNo) const;
114114

115-
int emitULW(const MachineInstr &MI);
116-
int emitUSW(const MachineInstr &MI);
117-
int emitULH(const MachineInstr &MI);
118-
int emitULHu(const MachineInstr &MI);
119-
int emitUSH(const MachineInstr &MI);
120-
121115
void emitGlobalAddressUnaligned(const GlobalValue *GV, unsigned Reloc,
122116
int Offset) const;
123117
};
@@ -133,7 +127,7 @@ bool MipsCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
133127
MCPEs = &MF.getConstantPool()->getConstants();
134128
MJTEs = 0;
135129
if (MF.getJumpTableInfo()) MJTEs = &MF.getJumpTableInfo()->getJumpTables();
136-
JTI->Initialize(MF, IsPIC);
130+
JTI->Initialize(MF, IsPIC, Subtarget->isLittle());
137131
MCE.setModuleInfo(&getAnalysis<MachineModuleInfo> ());
138132

139133
do {
@@ -271,103 +265,6 @@ void MipsCodeEmitter::emitMachineBasicBlock(MachineBasicBlock *BB,
271265
Reloc, BB));
272266
}
273267

274-
int MipsCodeEmitter::emitUSW(const MachineInstr &MI) {
275-
unsigned src = getMachineOpValue(MI, MI.getOperand(0));
276-
unsigned base = getMachineOpValue(MI, MI.getOperand(1));
277-
unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
278-
// swr src, offset(base)
279-
// swl src, offset+3(base)
280-
MCE.emitWordLE(
281-
(0x2e << 26) | (base << 21) | (src << 16) | (offset & 0xffff));
282-
MCE.emitWordLE(
283-
(0x2a << 26) | (base << 21) | (src << 16) | ((offset+3) & 0xffff));
284-
return 2;
285-
}
286-
287-
int MipsCodeEmitter::emitULW(const MachineInstr &MI) {
288-
unsigned dst = getMachineOpValue(MI, MI.getOperand(0));
289-
unsigned base = getMachineOpValue(MI, MI.getOperand(1));
290-
unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
291-
unsigned at = 1;
292-
if (dst != base) {
293-
// lwr dst, offset(base)
294-
// lwl dst, offset+3(base)
295-
MCE.emitWordLE(
296-
(0x26 << 26) | (base << 21) | (dst << 16) | (offset & 0xffff));
297-
MCE.emitWordLE(
298-
(0x22 << 26) | (base << 21) | (dst << 16) | ((offset+3) & 0xffff));
299-
return 2;
300-
} else {
301-
// lwr at, offset(base)
302-
// lwl at, offset+3(base)
303-
// addu dst, at, $zero
304-
MCE.emitWordLE(
305-
(0x26 << 26) | (base << 21) | (at << 16) | (offset & 0xffff));
306-
MCE.emitWordLE(
307-
(0x22 << 26) | (base << 21) | (at << 16) | ((offset+3) & 0xffff));
308-
MCE.emitWordLE(
309-
(0x0 << 26) | (at << 21) | (0x0 << 16) | (dst << 11) | (0x0 << 6) | 0x21);
310-
return 3;
311-
}
312-
}
313-
314-
int MipsCodeEmitter::emitUSH(const MachineInstr &MI) {
315-
unsigned src = getMachineOpValue(MI, MI.getOperand(0));
316-
unsigned base = getMachineOpValue(MI, MI.getOperand(1));
317-
unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
318-
unsigned at = 1;
319-
// sb src, offset(base)
320-
// srl at,src,8
321-
// sb at, offset+1(base)
322-
MCE.emitWordLE(
323-
(0x28 << 26) | (base << 21) | (src << 16) | (offset & 0xffff));
324-
MCE.emitWordLE(
325-
(0x0 << 26) | (0x0 << 21) | (src << 16) | (at << 11) | (0x8 << 6) | 0x2);
326-
MCE.emitWordLE(
327-
(0x28 << 26) | (base << 21) | (at << 16) | ((offset+1) & 0xffff));
328-
return 3;
329-
}
330-
331-
int MipsCodeEmitter::emitULH(const MachineInstr &MI) {
332-
unsigned dst = getMachineOpValue(MI, MI.getOperand(0));
333-
unsigned base = getMachineOpValue(MI, MI.getOperand(1));
334-
unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
335-
unsigned at = 1;
336-
// lbu at, offset(base)
337-
// lb dst, offset+1(base)
338-
// sll dst,dst,8
339-
// or dst,dst,at
340-
MCE.emitWordLE(
341-
(0x24 << 26) | (base << 21) | (at << 16) | (offset & 0xffff));
342-
MCE.emitWordLE(
343-
(0x20 << 26) | (base << 21) | (dst << 16) | ((offset+1) & 0xffff));
344-
MCE.emitWordLE(
345-
(0x0 << 26) | (0x0 << 21) | (dst << 16) | (dst << 11) | (0x8 << 6) | 0x0);
346-
MCE.emitWordLE(
347-
(0x0 << 26) | (dst << 21) | (at << 16) | (dst << 11) | (0x0 << 6) | 0x25);
348-
return 4;
349-
}
350-
351-
int MipsCodeEmitter::emitULHu(const MachineInstr &MI) {
352-
unsigned dst = getMachineOpValue(MI, MI.getOperand(0));
353-
unsigned base = getMachineOpValue(MI, MI.getOperand(1));
354-
unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
355-
unsigned at = 1;
356-
// lbu at, offset(base)
357-
// lbu dst, offset+1(base)
358-
// sll dst,dst,8
359-
// or dst,dst,at
360-
MCE.emitWordLE(
361-
(0x24 << 26) | (base << 21) | (at << 16) | (offset & 0xffff));
362-
MCE.emitWordLE(
363-
(0x24 << 26) | (base << 21) | (dst << 16) | ((offset+1) & 0xffff));
364-
MCE.emitWordLE(
365-
(0x0 << 26) | (0x0 << 21) | (dst << 16) | (dst << 11) | (0x8 << 6) | 0x0);
366-
MCE.emitWordLE(
367-
(0x0 << 26) | (dst << 21) | (at << 16) | (dst << 11) | (0x0 << 6) | 0x25);
368-
return 4;
369-
}
370-
371268
void MipsCodeEmitter::emitInstruction(const MachineInstr &MI) {
372269
DEBUG(errs() << "JIT: " << (void*)MCE.getCurrentPCValue() << ":\t" << MI);
373270

@@ -377,16 +274,19 @@ void MipsCodeEmitter::emitInstruction(const MachineInstr &MI) {
377274
if ((MI.getDesc().TSFlags & MipsII::FormMask) == MipsII::Pseudo)
378275
return;
379276

380-
emitWordLE(getBinaryCodeForInstr(MI));
277+
emitWord(getBinaryCodeForInstr(MI));
381278
++NumEmitted; // Keep track of the # of mi's emitted
382279

383280
MCE.processDebugLoc(MI.getDebugLoc(), false);
384281
}
385282

386-
void MipsCodeEmitter::emitWordLE(unsigned Word) {
283+
void MipsCodeEmitter::emitWord(unsigned Word) {
387284
DEBUG(errs() << " 0x";
388285
errs().write_hex(Word) << "\n");
389-
MCE.emitWordLE(Word);
286+
if (Subtarget->isLittle())
287+
MCE.emitWordLE(Word);
288+
else
289+
MCE.emitWordBE(Word);
390290
}
391291

392292
/// createMipsJITCodeEmitterPass - Return a pass that emits the collected Mips

lib/Target/Mips/MipsJITInfo.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,17 @@ void *MipsJITInfo::emitFunctionStub(const Function *F, void *Fn,
222222
// addiu t9, t9, %lo(EmittedAddr)
223223
// jalr t8, t9
224224
// nop
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);
225+
if (IsLittleEndian) {
226+
JCE.emitWordLE(0xf << 26 | 25 << 16 | Hi);
227+
JCE.emitWordLE(9 << 26 | 25 << 21 | 25 << 16 | Lo);
228+
JCE.emitWordLE(25 << 21 | 24 << 11 | 9);
229+
JCE.emitWordLE(0);
230+
} else {
231+
JCE.emitWordBE(0xf << 26 | 25 << 16 | Hi);
232+
JCE.emitWordBE(9 << 26 | 25 << 21 | 25 << 16 | Lo);
233+
JCE.emitWordBE(25 << 21 | 24 << 11 | 9);
234+
JCE.emitWordBE(0);
235+
}
229236

230237
sys::Memory::InvalidateInstructionCache(Addr, 16);
231238
if (!sys::Memory::setRangeExecutable(Addr, 16))

lib/Target/Mips/MipsJITInfo.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ class MipsTargetMachine;
2626
class MipsJITInfo : public TargetJITInfo {
2727

2828
bool IsPIC;
29+
bool IsLittleEndian;
2930

3031
public:
3132
explicit MipsJITInfo() :
32-
IsPIC(false) {}
33+
IsPIC(false), IsLittleEndian(true) {}
3334

3435
/// replaceMachineCodeForFunction - Make it so that calling the function
3536
/// whose machine code is at OLD turns into a call to NEW, perhaps by
@@ -58,8 +59,10 @@ class MipsJITInfo : public TargetJITInfo {
5859
unsigned NumRelocs, unsigned char *GOTBase);
5960

6061
/// Initialize - Initialize internal stage for the function being JITted.
61-
void Initialize(const MachineFunction &MF, bool isPIC) {
62+
void Initialize(const MachineFunction &MF, bool isPIC,
63+
bool isLittleEndian) {
6264
IsPIC = isPIC;
65+
IsLittleEndian = isLittleEndian;
6366
}
6467

6568
};

0 commit comments

Comments
 (0)