diff options
Diffstat (limited to 'llvm/lib/CodeGen/MIRPrinter.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MIRPrinter.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index f14ce574a08..0a95a0ced0f 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -129,6 +129,9 @@ public: const MachineJumpTableInfo &JTI); void convertStackObjects(yaml::MachineFunction &YMF, const MachineFunction &MF, ModuleSlotTracker &MST); + void convertCallSiteObjects(yaml::MachineFunction &YMF, + const MachineFunction &MF, + ModuleSlotTracker &MST); private: void initRegisterMaskIds(const MachineFunction &MF); @@ -212,6 +215,7 @@ void MIRPrinter::print(const MachineFunction &MF) { MST.incorporateFunction(MF.getFunction()); convert(MST, YamlMF.FrameInfo, MF.getFrameInfo()); convertStackObjects(YamlMF, MF, MST); + convertCallSiteObjects(YamlMF, MF, MST); if (const auto *ConstantPool = MF.getConstantPool()) convert(YamlMF, *ConstantPool); if (const auto *JumpTableInfo = MF.getJumpTableInfo()) @@ -460,6 +464,39 @@ void MIRPrinter::convertStackObjects(yaml::MachineFunction &YMF, } } +void MIRPrinter::convertCallSiteObjects(yaml::MachineFunction &YMF, + const MachineFunction &MF, + ModuleSlotTracker &MST) { + const auto *TRI = MF.getSubtarget().getRegisterInfo(); + for (auto CSInfo : MF.getCallSitesInfo()) { + yaml::CallSiteInfo YmlCS; + yaml::CallSiteInfo::MachineInstrLoc CallLocation; + + // Prepare instruction position. + MachineBasicBlock::const_iterator CallI = CSInfo.first->getIterator(); + CallLocation.BlockNum = CallI->getParent()->getNumber(); + // Get call instruction offset from the beginning of block. + CallLocation.Offset = std::distance(CallI->getParent()->begin(), CallI); + YmlCS.CallLocation = CallLocation; + // Construct call arguments and theirs forwarding register info. + for (auto ArgReg : CSInfo.second) { + yaml::CallSiteInfo::ArgRegPair YmlArgReg; + YmlArgReg.ArgNo = ArgReg.ArgNo; + printRegMIR(ArgReg.Reg, YmlArgReg.Reg, TRI); + YmlCS.ArgForwardingRegs.emplace_back(YmlArgReg); + } + YMF.CallSitesInfo.push_back(YmlCS); + } + + // Sort call info by position of call instructions. + llvm::sort(YMF.CallSitesInfo.begin(), YMF.CallSitesInfo.end(), + [](yaml::CallSiteInfo A, yaml::CallSiteInfo B) { + if (A.CallLocation.BlockNum == B.CallLocation.BlockNum) + return A.CallLocation.Offset < B.CallLocation.Offset; + return A.CallLocation.BlockNum < B.CallLocation.BlockNum; + }); +} + void MIRPrinter::convert(yaml::MachineFunction &MF, const MachineConstantPool &ConstantPool) { unsigned ID = 0; |