From: Matthias Braun Date: Thu, 26 Jul 2018 00:27:47 +0000 (+0000) Subject: CodeGen: Cleanup regmask construction; NFC X-Git-Tag: llvmorg-7.0.0-rc1~562 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=57dd5b3dead6338d3a0647c835deebf6dbd86910;p=platform%2Fupstream%2Fllvm.git 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. llvm-svn: 337986 --- diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index d2a2691..e8a4d52 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/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/llvm/include/llvm/CodeGen/MachineOperand.h b/llvm/include/llvm/CodeGen/MachineOperand.h index dc210e0..53e8889 100644 --- a/llvm/include/llvm/CodeGen/MachineOperand.h +++ b/llvm/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/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 09ff77b..a61e787 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/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/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index a376614..dd668bc 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/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/llvm/lib/CodeGen/RegUsageInfoCollector.cpp b/llvm/lib/CodeGen/RegUsageInfoCollector.cpp index 1bf205d..6a97628 100644 --- a/llvm/lib/CodeGen/RegUsageInfoCollector.cpp +++ b/llvm/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/llvm/lib/CodeGen/StackMapLivenessAnalysis.cpp b/llvm/lib/CodeGen/StackMapLivenessAnalysis.cpp index fc2895a..00cf807 100644 --- a/llvm/lib/CodeGen/StackMapLivenessAnalysis.cpp +++ b/llvm/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/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index e019fbd..ce1e1a5 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/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.