- << " in instr: " << *MI);
- for (unsigned ii = 0, ee = MI->getNumOperands(); ii != ee; ++ii) {
- MachineOperand &op = MI->getOperand(ii);
- if (op.isPCRelativeDisp()) {
- // the instruction's branch target is made such that it branches to
- // PC + (branchTarget * 4), so undo that arithmetic here:
- // Location is the target of the branch
- // Ref is the location of the instruction, and hence the PC
- int64_t branchTarget = (Location - (long)Ref) >> 2;
- MI->SetMachineOperandConst(ii, MachineOperand::MO_SignExtendedImmed,
- branchTarget);
- unsigned fixedInstr = PPC32CodeEmitter::getBinaryCodeForInstr(*MI);
- MCE.emitWordAt(fixedInstr, Ref);
- break;
- }
+ << "\n");
+ unsigned Instr = *Ref;
+ intptr_t BranchTargetDisp = (Location - (intptr_t)Ref) >> 2;
+
+ switch (Instr >> 26) {
+ default: assert(0 && "Unknown branch user!");
+ case 18: // This is B or BL
+ *Ref |= (BranchTargetDisp & ((1 << 24)-1)) << 2;
+ break;
+ case 16: // This is BLT,BLE,BEQ,BGE,BGT,BNE, or other bcx instruction
+ *Ref |= (BranchTargetDisp & ((1 << 14)-1)) << 2;
+ break;