From ee571f2b410f13b46f000010fd1592c6e7f52a48 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 26 Jul 2018 00:27:47 +0000 Subject: [PATCH] CodeGen: Cleanup regmask construction; NFC - Avoid duplication of regmask size calculation. - Simplify allocateRegisterMask() call. - Rename allocateRegisterMask() to allocateRegMask() to be consistent with naming in MachineOperand. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337986 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineFunction.h | 8 +------- include/llvm/CodeGen/MachineOperand.h | 5 +++++ lib/CodeGen/MIRParser/MIParser.cpp | 8 ++------ lib/CodeGen/MachineFunction.cpp | 8 ++++++++ lib/CodeGen/RegUsageInfoCollector.cpp | 2 +- lib/CodeGen/StackMapLivenessAnalysis.cpp | 2 +- lib/Target/X86/X86ISelLowering.cpp | 6 +++--- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h index d2a2691f70f..e8a4d529faa 100644 --- a/include/llvm/CodeGen/MachineFunction.h +++ b/include/llvm/CodeGen/MachineFunction.h @@ -709,13 +709,7 @@ public: } /// Allocate and initialize a register mask with @p NumRegister bits. - uint32_t *allocateRegisterMask(unsigned NumRegister) { - unsigned Size = (NumRegister + 31) / 32; - uint32_t *Mask = Allocator.Allocate(Size); - for (unsigned i = 0; i != Size; ++i) - Mask[i] = 0; - return Mask; - } + uint32_t *allocateRegMask(); /// allocateMemRefsArray - Allocate an array to hold MachineMemOperand /// pointers. This array is owned by the MachineFunction. diff --git a/include/llvm/CodeGen/MachineOperand.h b/include/llvm/CodeGen/MachineOperand.h index dc210e0f45e..53e8889d118 100644 --- a/include/llvm/CodeGen/MachineOperand.h +++ b/include/llvm/CodeGen/MachineOperand.h @@ -616,6 +616,11 @@ public: return Contents.RegMask; } + /// Returns number of elements needed for a regmask array. + static unsigned getRegMaskSize(unsigned NumRegs) { + return (NumRegs + 31) / 32; + } + /// getRegLiveOut - Returns a bit mask of live-out registers. const uint32_t *getRegLiveOut() const { assert(isRegLiveOut() && "Wrong MachineOperand accessor"); diff --git a/lib/CodeGen/MIRParser/MIParser.cpp b/lib/CodeGen/MIRParser/MIParser.cpp index 09ff77b1af9..a61e7872f1a 100644 --- a/lib/CodeGen/MIRParser/MIParser.cpp +++ b/lib/CodeGen/MIRParser/MIParser.cpp @@ -1958,13 +1958,11 @@ bool MIParser::parseTargetIndexOperand(MachineOperand &Dest) { bool MIParser::parseCustomRegisterMaskOperand(MachineOperand &Dest) { assert(Token.stringValue() == "CustomRegMask" && "Expected a custom RegMask"); - const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); - assert(TRI && "Expected target register info"); lex(); if (expectAndConsume(MIToken::lparen)) return true; - uint32_t *Mask = MF.allocateRegisterMask(TRI->getNumRegs()); + uint32_t *Mask = MF.allocateRegMask(); while (true) { if (Token.isNot(MIToken::NamedRegister)) return error("expected a named register"); @@ -1987,9 +1985,7 @@ bool MIParser::parseCustomRegisterMaskOperand(MachineOperand &Dest) { bool MIParser::parseLiveoutRegisterMaskOperand(MachineOperand &Dest) { assert(Token.is(MIToken::kw_liveout)); - const auto *TRI = MF.getSubtarget().getRegisterInfo(); - assert(TRI && "Expected target register info"); - uint32_t *Mask = MF.allocateRegisterMask(TRI->getNumRegs()); + uint32_t *Mask = MF.allocateRegMask(); lex(); if (expectAndConsume(MIToken::lparen)) return true; diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index a376614ade9..dd668bcf619 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -486,6 +486,14 @@ const char *MachineFunction::createExternalSymbolName(StringRef Name) { return Dest; } +uint32_t *MachineFunction::allocateRegMask() { + unsigned NumRegs = getSubtarget().getRegisterInfo()->getNumRegs(); + unsigned Size = MachineOperand::getRegMaskSize(NumRegs); + uint32_t *Mask = Allocator.Allocate(Size); + memset(Mask, 0, Size * sizeof(Mask[0])); + return Mask; +} + #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void MachineFunction::dump() const { print(dbgs()); diff --git a/lib/CodeGen/RegUsageInfoCollector.cpp b/lib/CodeGen/RegUsageInfoCollector.cpp index 1bf205d5e60..6a976285ecc 100644 --- a/lib/CodeGen/RegUsageInfoCollector.cpp +++ b/lib/CodeGen/RegUsageInfoCollector.cpp @@ -96,7 +96,7 @@ bool RegUsageInfoCollector::runOnMachineFunction(MachineFunction &MF) { // Compute the size of the bit vector to represent all the registers. // The bit vector is broken into 32-bit chunks, thus takes the ceil of // the number of registers divided by 32 for the size. - unsigned RegMaskSize = (TRI->getNumRegs() + 31) / 32; + unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs()); RegMask.resize(RegMaskSize, 0xFFFFFFFF); const Function &F = MF.getFunction(); diff --git a/lib/CodeGen/StackMapLivenessAnalysis.cpp b/lib/CodeGen/StackMapLivenessAnalysis.cpp index fc2895a03f6..00cf8070be5 100644 --- a/lib/CodeGen/StackMapLivenessAnalysis.cpp +++ b/lib/CodeGen/StackMapLivenessAnalysis.cpp @@ -160,7 +160,7 @@ void StackMapLiveness::addLiveOutSetToMI(MachineFunction &MF, /// register live set. uint32_t *StackMapLiveness::createRegisterMask(MachineFunction &MF) const { // The mask is owned and cleaned up by the Machine Function. - uint32_t *Mask = MF.allocateRegisterMask(TRI->getNumRegs()); + uint32_t *Mask = MF.allocateRegMask(); for (auto Reg : LiveRegs) Mask[Reg / 32] |= 1U << (Reg % 32); diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index e019fbdfa1a..ce1e1a578ba 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -3909,9 +3909,9 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo(); // Allocate a new Reg Mask and copy Mask. - RegMask = MF.allocateRegisterMask(TRI->getNumRegs()); - unsigned RegMaskSize = (TRI->getNumRegs() + 31) / 32; - memcpy(RegMask, Mask, sizeof(uint32_t) * RegMaskSize); + RegMask = MF.allocateRegMask(); + unsigned RegMaskSize = MachineOperand::getRegMaskSize(TRI->getNumRegs()); + memcpy(RegMask, Mask, sizeof(RegMask[0]) * RegMaskSize); // Make sure all sub registers of the argument registers are reset // in the RegMask. -- 2.11.0