- // Special encoding for MTCRF and MFOCRF, which uses a bit mask for the
- // register, not the register number directly.
- if ((MI.getOpcode() == PPC::MTCRF || MI.getOpcode() == PPC::MFOCRF) &&
- (MO.getReg() >= PPC::CR0 && MO.getReg() <= PPC::CR7)) {
- rv = 0x80 >> rv;
- }
- } else if (MO.isImmediate()) {
- rv = MO.getImmedValue();
- } else if (MO.isGlobalAddress() || MO.isExternalSymbol()) {
- bool isExternal = MO.isExternalSymbol() ||
- MO.getGlobal()->hasWeakLinkage() ||
- MO.getGlobal()->isExternal();
- unsigned Reloc = 0;
- if (MI.getOpcode() == PPC::CALLpcrel)
- Reloc = PPC::reloc_pcrel_bx;
- else {
- switch (MI.getOpcode()) {
- default: MI.dump(); assert(0 && "Unknown instruction for relocation!");
- case PPC::LIS:
- if (isExternal)
- Reloc = PPC::reloc_absolute_ptr_high; // Pointer to stub
- else
- Reloc = PPC::reloc_absolute_high; // Pointer to symbol
- break;
- case PPC::LA:
- assert(!isExternal && "Something in the ISEL changed\n");
- Reloc = PPC::reloc_absolute_low;
- break;
- case PPC::LBZ:
- case PPC::LHA:
- case PPC::LHZ:
- case PPC::LWZ:
- case PPC::LFS:
- case PPC::LFD:
- case PPC::STB:
- case PPC::STH:
- case PPC::STW:
- case PPC::STFS:
- case PPC::STFD:
- if (isExternal)
- Reloc = PPC::reloc_absolute_ptr_low;
- else
- Reloc = PPC::reloc_absolute_low;
- break;
- }
- }
- if (MO.isGlobalAddress())
- MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
- Reloc, MO.getGlobal(), 0));
- else
- MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
- Reloc, MO.getSymbolName(), 0));
- } else if (MO.isMachineBasicBlock()) {
- unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue();
- BBRefs.push_back(std::make_pair(MO.getMachineBasicBlock(), CurrPC));
- } else if (MO.isConstantPoolIndex()) {
- unsigned index = MO.getConstantPoolIndex();
- unsigned Opcode = MI.getOpcode();
- rv = MCE.getConstantPoolEntryAddress(index);
- if (Opcode == PPC::LIS) {
- // lis wants hi16(addr)
- if ((short)rv < 0) rv += 1 << 16;
- rv >>= 16;
- } else if (Opcode == PPC::LWZ || Opcode == PPC::LA ||
- Opcode == PPC::LFS || Opcode == PPC::LFD) {
- // These load opcodes want lo16(addr)
- rv &= 0xffff;
- } else {
- assert(0 && "Unknown constant pool using instruction!");
- }
- } else {
- std::cerr << "ERROR: Unknown type of MachineOperand: " << MO << "\n";
- abort();
+unsigned PPCCodeEmitter::getAbsDirectBrEncoding(const MachineInstr &MI,
+ unsigned OpNo) const {
+ const MachineOperand &MO = MI.getOperand(OpNo);
+ if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO);
+
+ llvm_unreachable("Absolute branch relocations unsupported on the old JIT.");
+}
+
+unsigned PPCCodeEmitter::getAbsCondBrEncoding(const MachineInstr &MI,
+ unsigned OpNo) const {
+ llvm_unreachable("Absolute branch relocations unsupported on the old JIT.");
+}
+
+unsigned PPCCodeEmitter::getImm16Encoding(const MachineInstr &MI,
+ unsigned OpNo) const {
+ const MachineOperand &MO = MI.getOperand(OpNo);
+ if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO);
+
+ unsigned RelocID;
+ switch (MO.getTargetFlags() & PPCII::MO_ACCESS_MASK) {
+ default: llvm_unreachable("Unsupported target operand flags!");
+ case PPCII::MO_LO: RelocID = PPC::reloc_absolute_low; break;
+ case PPCII::MO_HA: RelocID = PPC::reloc_absolute_high; break;