[PATCH] D21395: Fix for Bug 28144
Vivek Pandya via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 15 12:15:17 PDT 2016
vivekvpandya created this revision.
vivekvpandya added reviewers: mehdi_amini, qcolombet, hfinkel, MatzeB.
vivekvpandya added subscribers: llvm-commits, mcrosier, karthikthecool.
This patch contains fix for the bug https://llvm.org/bugs/show_bug.cgi?id=28144 related to register usage calculation, previously it was not considering callee RegMasks at callsites in the Machinefunction thus generating wrong register usage information.
This patch also makes AsmPrinter print call preserved registers as comment at call sites in generated assembly.
http://reviews.llvm.org/D21395
Files:
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/RegUsageInfoCollector.cpp
Index: lib/CodeGen/RegUsageInfoCollector.cpp
===================================================================
--- lib/CodeGen/RegUsageInfoCollector.cpp
+++ lib/CodeGen/RegUsageInfoCollector.cpp
@@ -86,8 +86,7 @@
bool RegUsageInfoCollector::runOnMachineFunction(MachineFunction &MF) {
MachineRegisterInfo *MRI = &MF.getRegInfo();
- TargetRegisterInfo *TRI =
- (TargetRegisterInfo *)MF.getSubtarget().getRegisterInfo();
+ const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
const TargetMachine &TM = MF.getTarget();
DEBUG(dbgs() << " -------------------- " << getPassName()
@@ -107,17 +106,31 @@
PRUI->setTargetMachine(&TM);
DEBUG(dbgs() << "Clobbered Registers: ");
- for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg) {
+ for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg)
if (!MRI->reg_nodbg_empty(PReg) && MRI->isPhysRegUsed(PReg))
markRegClobbered(TRI, &RegMask[0], PReg);
- }
const uint32_t *CallPreservedMask =
TRI->getCallPreservedMask(MF, MF.getFunction()->getCallingConv());
// Set callee saved register as preserved.
- for (unsigned index = 0; index < regMaskSize; index++) {
+ for (unsigned index = 0; index < regMaskSize; index++)
RegMask[index] = RegMask[index] | CallPreservedMask[index];
+
+ for (MachineBasicBlock &MBB : MF) {
+ for (MachineInstr &MI : MBB) {
+ if (!MI.isCall())
+ continue;
+ for (MachineOperand &MO : MI.operands()) {
+ if (MO.isRegMask()) {
+ const uint32_t *CalleeRegMask = MO.getRegMask();
+ for (unsigned index = 0; index < regMaskSize; index++)
+ RegMask[index] = RegMask[index] & CalleeRegMask[index];
+ break;
+ }
+ }
+ }
}
+
for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg) {
if (MachineOperand::clobbersPhysReg(&(RegMask[0]), PReg))
DEBUG(dbgs() << TRI->getName(PReg) << " ");
Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -27,6 +27,7 @@
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
+#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/Mangler.h"
@@ -625,6 +626,7 @@
static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS) {
const MachineFunction *MF = MI.getParent()->getParent();
const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
+ const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
// Check for spills and reloads
int FI;
@@ -655,6 +657,23 @@
// Check for spill-induced copies
if (MI.getAsmPrinterFlag(MachineInstr::ReloadReuse))
CommentOS << " Reload Reuse\n";
+
+ if (MI.isCall()) {
+ const uint32_t *CalleeRegMask;
+ CommentOS << "Call Preserved Registers: ";
+
+ for (const MachineOperand &MO : MI.operands())
+ if (MO.isRegMask()) {
+ CalleeRegMask = MO.getRegMask();
+ break;
+ }
+
+ for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg) {
+ if (!MachineOperand::clobbersPhysReg(CalleeRegMask, PReg))
+ CommentOS << TRI->getName(PReg) << " ";
+ }
+ CommentOS << "\n";
+ }
}
/// emitImplicitDef - This method emits the specified machine instruction
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21395.60874.patch
Type: text/x-patch
Size: 3532 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160615/d83392d0/attachment.bin>
More information about the llvm-commits
mailing list