From 5e1ac45b93b06df8caff98d6671742a939b73a49 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 2 Feb 2012 23:52:57 +0000 Subject: [PATCH] Require non-NULL register masks. It doesn't seem worthwhile to give meaning to a NULL register mask pointer. It complicates all the code using register mask operands. llvm-svn: 149646 --- llvm/include/llvm/CodeGen/MachineOperand.h | 6 +++--- llvm/include/llvm/Target/TargetRegisterInfo.h | 5 ++++- llvm/lib/CodeGen/DeadMachineInstructionElim.cpp | 5 +---- llvm/lib/CodeGen/MachineInstr.cpp | 2 +- llvm/lib/CodeGen/MachineLICM.cpp | 5 +---- llvm/lib/Target/X86/X86ISelLowering.cpp | 4 ++-- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineOperand.h b/llvm/include/llvm/CodeGen/MachineOperand.h index 6a2e38dd84ee..59da26c71cc8 100644 --- a/llvm/include/llvm/CodeGen/MachineOperand.h +++ b/llvm/include/llvm/CodeGen/MachineOperand.h @@ -446,12 +446,11 @@ public: assert(isRegMask() && "Wrong MachineOperand accessor"); // See TargetRegisterInfo.h. assert(PhysReg < (1u << 30) && "Not a physical register"); - return !Contents.RegMask || - !(Contents.RegMask[PhysReg / 32] & (1u << PhysReg % 32)); + return !(Contents.RegMask[PhysReg / 32] & (1u << PhysReg % 32)); } /// getRegMask - Returns a bit mask of registers preserved by this RegMask - /// operand. A NULL pointer means that all registers are clobbered. + /// operand. const uint32_t *getRegMask() const { assert(isRegMask() && "Wrong MachineOperand accessor"); return Contents.RegMask; @@ -616,6 +615,7 @@ public: /// Any physreg with a 0 bit in the mask is clobbered by the instruction. /// static MachineOperand CreateRegMask(const uint32_t *Mask) { + assert(Mask && "Missing register mask"); MachineOperand Op(MachineOperand::MO_RegisterMask); Op.Contents.RegMask = Mask; return Op; diff --git a/llvm/include/llvm/Target/TargetRegisterInfo.h b/llvm/include/llvm/Target/TargetRegisterInfo.h index 36ac5df12019..711129f833ed 100644 --- a/llvm/include/llvm/Target/TargetRegisterInfo.h +++ b/llvm/include/llvm/Target/TargetRegisterInfo.h @@ -376,7 +376,10 @@ public: /// /// Bits are numbered from the LSB, so the bit for physical register Reg can /// be found as (Mask[Reg / 32] >> Reg % 32) & 1. - /// NULL pointer is equivalent to an all-zero mask. + /// + /// A NULL pointer means that no register mask will be used, and call + /// instructions should use implicit-def operands to indicate call clobbered + /// registers. /// virtual const uint32_t *getCallPreservedMask(CallingConv::ID) const { // The default mask clobbers everything. All targets should override. diff --git a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp index aeb0b3ed0222..020b64d883cb 100644 --- a/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp +++ b/llvm/lib/CodeGen/DeadMachineInstructionElim.cpp @@ -175,10 +175,7 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) { } } else if (MO.isRegMask()) { // Register mask of preserved registers. All clobbers are dead. - if (const uint32_t *Mask = MO.getRegMask()) - LivePhysRegs.clearBitsNotInMask(Mask); - else - LivePhysRegs.reset(); + LivePhysRegs.clearBitsNotInMask(MO.getRegMask()); LivePhysRegs |= ReservedRegs; } } diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index c281cd1149bb..7cf282c25c28 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -327,7 +327,7 @@ void MachineOperand::print(raw_ostream &OS, const TargetMachine *TM) const { OS << '>'; break; case MachineOperand::MO_RegisterMask: - OS << (getRegMask() ? "" : ""); + OS << ""; break; case MachineOperand::MO_Metadata: OS << '<'; diff --git a/llvm/lib/CodeGen/MachineLICM.cpp b/llvm/lib/CodeGen/MachineLICM.cpp index 49a109e252c3..9b058c341628 100644 --- a/llvm/lib/CodeGen/MachineLICM.cpp +++ b/llvm/lib/CodeGen/MachineLICM.cpp @@ -417,10 +417,7 @@ void MachineLICM::ProcessMI(MachineInstr *MI, // We can't hoist an instruction defining a physreg that is clobbered in // the loop. if (MO.isRegMask()) { - if (const uint32_t *Mask = MO.getRegMask()) - PhysRegClobbers.setBitsNotInMask(Mask); - else - PhysRegClobbers.set(); + PhysRegClobbers.setBitsNotInMask(MO.getRegMask()); continue; } diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 5d99a1c7d8ba..05c0ebd5ca1a 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -2515,8 +2515,8 @@ X86TargetLowering::LowerCall(SDValue Chain, SDValue Callee, // registers. if (UseRegMask) { const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo(); - const uint32_t *Mask = TRI->getCallPreservedMask(CallConv); - Ops.push_back(DAG.getRegisterMask(Mask)); + if (const uint32_t *Mask = TRI->getCallPreservedMask(CallConv)) + Ops.push_back(DAG.getRegisterMask(Mask)); } if (InFlag.getNode())