diff --git a/lib/Target/ARM/ARMExport.cpp b/lib/Target/ARM/ARMExport.cpp index 3409fd5c00d4b8593284b5cb2ddc55875802b0c7..15063d59cecf21a78b002d081a568df13da94453 100644 --- a/lib/Target/ARM/ARMExport.cpp +++ b/lib/Target/ARM/ARMExport.cpp @@ -41,137 +41,137 @@ using namespace llvm; namespace llvm { - class ARMMachineExport : public PMLMachineExport { - - public: - ARMMachineExport(ARMBaseTargetMachine &tm, ModulePass &mp, - PMLInstrInfo *PII) - : PMLMachineExport(tm, mp, PII) {} - - - virtual bool doExportInstruction(const MachineInstr *Ins) { - return Ins->getOpcode() != ARM::PSEUDO_LOOPBOUND - && Ins->getOpcode() != ARM::IMPLICIT_DEF; - } - - virtual void serialize(MachineFunction &MF); - - }; - - - class ARMModuleExportPass : public PMLModuleExportPass { - static char ID; - - public: - ARMModuleExportPass(ARMBaseTargetMachine &tm, StringRef filename, - ArrayRef<std::string> roots, bool SerializeAll) - : PMLModuleExportPass(ID, tm, filename, roots, SerializeAll) - { - setPMLInstrInfo(new PMLInstrInfo()); - } - - virtual const char *getPassName() const { - return "ARM YAML/PML Module Export"; - } - - }; - - char ARMModuleExportPass::ID = 0; - - - /// createARMExportPass - Returns a new ARMExportPass - /// \see ARMExportPass - ModulePass *createARMModuleExportPass(ARMBaseTargetMachine &TM, - std::string& Filename, - std::string& BitcodeFilename, - ArrayRef<std::string> Roots, - bool SerializeAll) - { - ARMModuleExportPass *PEP = - new ARMModuleExportPass(TM, Filename, Roots, SerializeAll); - - // Add our own export passes - PEP->addExporter( new PMLBitcodeExport(TM, *PEP) ); - PEP->addExporter( new PMLRelationGraphExport(TM, *PEP) ); - PEP->addExporter( new ARMMachineExport(TM, *PEP, PEP->getPMLInstrInfo())); - if (! BitcodeFilename.empty()) - PEP->writeBitcode(BitcodeFilename); - return PEP; - } - - void ARMMachineExport::serialize(MachineFunction &MF) - { - yaml::PMLDoc &YDoc = getPMLDoc(); - Function* F = const_cast<Function*>(MF.getFunction()); - MachineLoopInfo &MLI(P.getAnalysis<MachineLoopInfo>(*F)); - - yaml::MachineFunction *PMF = - new yaml::MachineFunction(MF.getFunctionNumber()); - - PMF->MapsTo = yaml::Name(MF.getFunction()->getName()); - PMF->Level = yaml::level_machinecode; - yaml::MachineBlock *B; - - // export argument-register mapping if available - exportArgumentRegisterMapping(PMF, MF); - - for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB) - { - B = PMF->addBlock( - new yaml::MachineBlock(BB->getNumber())); - - for (MachineBasicBlock::const_pred_iterator BBPred = BB->pred_begin(), - E = BB->pred_end(); BBPred != E; ++BBPred) - B->Predecessors.push_back(yaml::Name((*BBPred)->getNumber())); - for (MachineBasicBlock::const_succ_iterator BBSucc = BB->succ_begin(), - E = BB->succ_end(); BBSucc != E; ++BBSucc) - B->Successors.push_back(yaml::Name((*BBSucc)->getNumber())); - - B->MapsTo = yaml::Name(BB->getName()); - - // export loop information - MachineLoop *Loop = MLI.getLoopFor(&(*BB)); - if (Loop && Loop->getHeader() == BB) { - exportLoopInfo(MF, YDoc, Loop); - } - while (Loop) { - B->Loops.push_back(yaml::Name(Loop->getHeader()->getNumber())); - Loop = Loop->getParentLoop(); - } - - unsigned Index = 0; - bool IsBundled = false; - for (MachineBasicBlock::instr_iterator Ins = BB->instr_begin(), - E = BB->instr_end(); Ins != E; ++Ins) - { - // check if this is the first instruction, only set to bundled once we - // exported at least one instruction from the bundle (skipping pseudos) - if (!Ins->isBundledWithPred()) { - IsBundled = false; - } - - // NOTE: I see no reason to increment the index, as platin fails with an - // assertion if the indices are not consecutive. - // TODO FIXME - if (!doExportInstruction(&(*Ins))) - continue; - - yaml::MachineInstruction *I = B->addInstruction( - new yaml::MachineInstruction(Index++)); - exportInstruction(MF, I, &(*Ins), IsBundled); - - DebugLoc dl = Ins->getDebugLoc(); - B->setSrcLocOnce(dl, dl.getScope()); - - IsBundled = true; - } - } - - exportSubfunctions(MF, PMF); - - // TODO: we do not compute a hash yet - PMF->Hash = StringRef("0"); - YDoc.addMachineFunction(PMF); - } + class ARMMachineExport : public PMLMachineExport { + + public: + ARMMachineExport(ARMBaseTargetMachine &tm, ModulePass &mp, + PMLInstrInfo *PII) + : PMLMachineExport(tm, mp, PII) {} + + + virtual bool doExportInstruction(const MachineInstr *Ins) { + return Ins->getOpcode() != ARM::PSEUDO_LOOPBOUND + && Ins->getOpcode() != ARM::IMPLICIT_DEF; + } + + virtual void serialize(MachineFunction &MF); + + }; + + + class ARMModuleExportPass : public PMLModuleExportPass { + static char ID; + + public: + ARMModuleExportPass(ARMBaseTargetMachine &tm, StringRef filename, + ArrayRef<std::string> roots, bool SerializeAll) + : PMLModuleExportPass(ID, tm, filename, roots, SerializeAll) + { + setPMLInstrInfo(new PMLInstrInfo()); + } + + virtual const char *getPassName() const { + return "ARM YAML/PML Module Export"; + } + + }; + + char ARMModuleExportPass::ID = 0; + + + /// createARMExportPass - Returns a new ARMExportPass + /// \see ARMExportPass + ModulePass *createARMModuleExportPass(ARMBaseTargetMachine &TM, + std::string& Filename, + std::string& BitcodeFilename, + ArrayRef<std::string> Roots, + bool SerializeAll) + { + ARMModuleExportPass *PEP = + new ARMModuleExportPass(TM, Filename, Roots, SerializeAll); + + // Add our own export passes + PEP->addExporter( new PMLBitcodeExport(TM, *PEP) ); + PEP->addExporter( new PMLRelationGraphExport(TM, *PEP) ); + PEP->addExporter( new ARMMachineExport(TM, *PEP, PEP->getPMLInstrInfo())); + if (! BitcodeFilename.empty()) + PEP->writeBitcode(BitcodeFilename); + return PEP; + } + + void ARMMachineExport::serialize(MachineFunction &MF) + { + yaml::PMLDoc &YDoc = getPMLDoc(); + Function* F = const_cast<Function*>(MF.getFunction()); + MachineLoopInfo &MLI(P.getAnalysis<MachineLoopInfo>(*F)); + + yaml::MachineFunction *PMF = + new yaml::MachineFunction(MF.getFunctionNumber()); + + PMF->MapsTo = yaml::Name(MF.getFunction()->getName()); + PMF->Level = yaml::level_machinecode; + yaml::MachineBlock *B; + + // export argument-register mapping if available + exportArgumentRegisterMapping(PMF, MF); + + for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB) + { + B = PMF->addBlock( + new yaml::MachineBlock(BB->getNumber())); + + for (MachineBasicBlock::const_pred_iterator BBPred = BB->pred_begin(), + E = BB->pred_end(); BBPred != E; ++BBPred) + B->Predecessors.push_back(yaml::Name((*BBPred)->getNumber())); + for (MachineBasicBlock::const_succ_iterator BBSucc = BB->succ_begin(), + E = BB->succ_end(); BBSucc != E; ++BBSucc) + B->Successors.push_back(yaml::Name((*BBSucc)->getNumber())); + + B->MapsTo = yaml::Name(BB->getName()); + + // export loop information + MachineLoop *Loop = MLI.getLoopFor(&(*BB)); + if (Loop && Loop->getHeader() == BB) { + exportLoopInfo(MF, YDoc, Loop); + } + while (Loop) { + B->Loops.push_back(yaml::Name(Loop->getHeader()->getNumber())); + Loop = Loop->getParentLoop(); + } + + unsigned Index = 0; + bool IsBundled = false; + for (MachineBasicBlock::instr_iterator Ins = BB->instr_begin(), + E = BB->instr_end(); Ins != E; ++Ins) + { + // check if this is the first instruction, only set to bundled once we + // exported at least one instruction from the bundle (skipping pseudos) + if (!Ins->isBundledWithPred()) { + IsBundled = false; + } + + // NOTE: I see no reason to increment the index, as platin fails with an + // assertion if the indices are not consecutive. + // TODO FIXME + if (!doExportInstruction(&(*Ins))) + continue; + + yaml::MachineInstruction *I = B->addInstruction( + new yaml::MachineInstruction(Index++)); + exportInstruction(MF, I, &(*Ins), IsBundled); + + DebugLoc dl = Ins->getDebugLoc(); + B->setSrcLocOnce(dl, dl.getScope()); + + IsBundled = true; + } + } + + exportSubfunctions(MF, PMF); + + // TODO: we do not compute a hash yet + PMF->Hash = StringRef("0"); + YDoc.addMachineFunction(PMF); + } } // end namespace llvm