// Create an MCInst from a MachineInstr void llvm::HexagonLowerToMC(const MachineInstr* MI, HexagonMCInst& MCI, HexagonAsmPrinter& AP) { MCI.setOpcode(MI->getOpcode()); MCI.setDesc(MI->getDesc()); for (unsigned i = 0, e = MI->getNumOperands(); i < e; i++) { const MachineOperand &MO = MI->getOperand(i); MCOperand MCO; switch (MO.getType()) { default: MI->dump(); llvm_unreachable("unknown operand type"); case MachineOperand::MO_Register: // Ignore all implicit register operands. if (MO.isImplicit()) continue; MCO = MCOperand::CreateReg(MO.getReg()); break; case MachineOperand::MO_FPImmediate: { APFloat Val = MO.getFPImm()->getValueAPF(); // FP immediates are used only when setting GPRs, so they may be dealt // with like regular immediates from this point on. MCO = MCOperand::CreateImm(*Val.bitcastToAPInt().getRawData()); break; } case MachineOperand::MO_Immediate: MCO = MCOperand::CreateImm(MO.getImm()); break; case MachineOperand::MO_MachineBasicBlock: MCO = MCOperand::CreateExpr (MCSymbolRefExpr::Create(MO.getMBB()->getSymbol(), AP.OutContext)); break; case MachineOperand::MO_GlobalAddress: MCO = GetSymbolRef(MO, AP.Mang->getSymbol(MO.getGlobal()), AP); break; case MachineOperand::MO_ExternalSymbol: MCO = GetSymbolRef(MO, AP.GetExternalSymbolSymbol(MO.getSymbolName()), AP); break; case MachineOperand::MO_JumpTableIndex: MCO = GetSymbolRef(MO, AP.GetJTISymbol(MO.getIndex()), AP); break; case MachineOperand::MO_ConstantPoolIndex: MCO = GetSymbolRef(MO, AP.GetCPISymbol(MO.getIndex()), AP); break; case MachineOperand::MO_BlockAddress: MCO = GetSymbolRef(MO, AP.GetBlockAddressSymbol(MO.getBlockAddress()),AP); break; } MCI.addOperand(MCO); } }
/// printMachineInstruction -- Print out a single Hexagon MI in Darwin syntax to /// the current output stream. /// void HexagonAsmPrinter::EmitInstruction(const MachineInstr *MI) { if (MI->isBundle()) { std::vector<const MachineInstr*> BundleMIs; const MachineBasicBlock *MBB = MI->getParent(); MachineBasicBlock::const_instr_iterator MII = MI; ++MII; unsigned int IgnoreCount = 0; while (MII != MBB->end() && MII->isInsideBundle()) { const MachineInstr *MInst = MII; if (MInst->getOpcode() == TargetOpcode::DBG_VALUE || MInst->getOpcode() == TargetOpcode::IMPLICIT_DEF) { IgnoreCount++; ++MII; continue; } //BundleMIs.push_back(&*MII); BundleMIs.push_back(MInst); ++MII; } unsigned Size = BundleMIs.size(); assert((Size+IgnoreCount) == MI->getBundleSize() && "Corrupt Bundle!"); for (unsigned Index = 0; Index < Size; Index++) { HexagonMCInst MCI (BundleMIs[Index]->getOpcode()); MCI.setPacketBegin(Index == 0); MCI.setPacketEnd(Index == (Size-1)); HexagonLowerToMC(BundleMIs[Index], MCI, *this); EmitToStreamer(OutStreamer, MCI); } } else { HexagonMCInst MCI(MI->getOpcode()); if (MI->getOpcode() == Hexagon::ENDLOOP0) { MCI.setPacketBegin(true); MCI.setPacketEnd(true); } HexagonLowerToMC(MI, MCI, *this); EmitToStreamer(OutStreamer, MCI); } return; }
void HexagonInstPrinter::printInst(const HexagonMCInst *MI, raw_ostream &O, StringRef Annot) { const char packetPadding[] = " "; const char startPacket = '{', endPacket = '}'; // TODO: add outer HW loop when it's supported too. if (MI->getOpcode() == Hexagon::ENDLOOP0) { // Ending a harware loop is different from ending an regular packet. assert(MI->isEndPacket() && "Loop end must also end the packet"); if (MI->isStartPacket()) { // There must be a packet to end a loop. // FIXME: when shuffling is always run, this shouldn't be needed. HexagonMCInst Nop; StringRef NoAnnot; Nop.setOpcode (Hexagon::NOP); Nop.setStartPacket (MI->isStartPacket()); printInst (&Nop, O, NoAnnot); } // Close the packet. if (MI->isEndPacket()) O << packetPadding << endPacket; printInstruction(MI, O); } else { // Prefix the insn opening the packet. if (MI->isStartPacket()) O << packetPadding << startPacket << '\n'; printInstruction(MI, O); // Suffix the insn closing the packet. if (MI->isEndPacket()) // Suffix the packet in a new line always, since the GNU assembler has // issues with a closing brace on the same line as CONST{32,64}. O << '\n' << packetPadding << endPacket; } printAnnotation(O, Annot); }