[PATCH] D22153: MSP430: Avoid implicit iterator conversions, NFC
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 8 13:32:12 PDT 2016
This is obvious goodness. LGTM.
"Duncan P. N. Exon Smith via llvm-commits" <llvm-commits at lists.llvm.org>
writes:
> dexonsmith created this revision.
> dexonsmith added a subscriber: llvm-commits.
>
> Avoid implicit conversions from MachineInstrBundleInstr to MachineInstr*
> in the MSP430 backend by preferring MachineInstr& over MachineInstr*
> when a pointer isn't nullable.
>
>
> http://reviews.llvm.org/D22153
>
> Files:
> lib/Target/MSP430/MSP430BranchSelector.cpp
> lib/Target/MSP430/MSP430FrameLowering.cpp
> lib/Target/MSP430/MSP430InstrInfo.cpp
> lib/Target/MSP430/MSP430InstrInfo.h
>
> Index: lib/Target/MSP430/MSP430InstrInfo.h
> ===================================================================
> --- lib/Target/MSP430/MSP430InstrInfo.h
> +++ lib/Target/MSP430/MSP430InstrInfo.h
> @@ -68,7 +68,7 @@
> const TargetRegisterClass *RC,
> const TargetRegisterInfo *TRI) const override;
>
> - unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
> + unsigned GetInstSizeInBytes(const MachineInstr &MI) const;
>
> // Branch folding goodness
> bool
> Index: lib/Target/MSP430/MSP430InstrInfo.cpp
> ===================================================================
> --- lib/Target/MSP430/MSP430InstrInfo.cpp
> +++ lib/Target/MSP430/MSP430InstrInfo.cpp
> @@ -293,8 +293,8 @@
> /// GetInstSize - Return the number of bytes of code the specified
> /// instruction may be. This returns the maximum number of bytes.
> ///
> -unsigned MSP430InstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const {
> - const MCInstrDesc &Desc = MI->getDesc();
> +unsigned MSP430InstrInfo::GetInstSizeInBytes(const MachineInstr &MI) const {
> + const MCInstrDesc &Desc = MI.getDesc();
>
> switch (Desc.TSFlags & MSP430II::SizeMask) {
> default:
> @@ -307,14 +307,14 @@
> case TargetOpcode::DBG_VALUE:
> return 0;
> case TargetOpcode::INLINEASM: {
> - const MachineFunction *MF = MI->getParent()->getParent();
> + const MachineFunction *MF = MI.getParent()->getParent();
> const TargetInstrInfo &TII = *MF->getSubtarget().getInstrInfo();
> - return TII.getInlineAsmLength(MI->getOperand(0).getSymbolName(),
> + return TII.getInlineAsmLength(MI.getOperand(0).getSymbolName(),
> *MF->getTarget().getMCAsmInfo());
> }
> }
> case MSP430II::SizeSpecial:
> - switch (MI->getOpcode()) {
> + switch (MI.getOpcode()) {
> default: llvm_unreachable("Unknown instruction size!");
> case MSP430::SAR8r1c:
> case MSP430::SAR16r1c:
> Index: lib/Target/MSP430/MSP430FrameLowering.cpp
> ===================================================================
> --- lib/Target/MSP430/MSP430FrameLowering.cpp
> +++ lib/Target/MSP430/MSP430FrameLowering.cpp
> @@ -235,8 +235,8 @@
> // adjcallstackup instruction into a 'sub SP, <amt>' and the
> // adjcallstackdown instruction into 'add SP, <amt>'
> // TODO: consider using push / pop instead of sub + store / add
> - MachineInstr *Old = I;
> - uint64_t Amount = Old->getOperand(0).getImm();
> + MachineInstr &Old = *I;
> + uint64_t Amount = Old.getOperand(0).getImm();
> if (Amount != 0) {
> // We need to keep the stack aligned properly. To do this, we round the
> // amount of space needed for the outgoing arguments up to the next
> @@ -244,19 +244,21 @@
> Amount = (Amount+StackAlign-1)/StackAlign*StackAlign;
>
> MachineInstr *New = nullptr;
> - if (Old->getOpcode() == TII.getCallFrameSetupOpcode()) {
> - New = BuildMI(MF, Old->getDebugLoc(),
> - TII.get(MSP430::SUB16ri), MSP430::SP)
> - .addReg(MSP430::SP).addImm(Amount);
> + if (Old.getOpcode() == TII.getCallFrameSetupOpcode()) {
> + New =
> + BuildMI(MF, Old.getDebugLoc(), TII.get(MSP430::SUB16ri), MSP430::SP)
> + .addReg(MSP430::SP)
> + .addImm(Amount);
> } else {
> - assert(Old->getOpcode() == TII.getCallFrameDestroyOpcode());
> + assert(Old.getOpcode() == TII.getCallFrameDestroyOpcode());
> // factor out the amount the callee already popped.
> - uint64_t CalleeAmt = Old->getOperand(1).getImm();
> + uint64_t CalleeAmt = Old.getOperand(1).getImm();
> Amount -= CalleeAmt;
> if (Amount)
> - New = BuildMI(MF, Old->getDebugLoc(),
> - TII.get(MSP430::ADD16ri), MSP430::SP)
> - .addReg(MSP430::SP).addImm(Amount);
> + New = BuildMI(MF, Old.getDebugLoc(), TII.get(MSP430::ADD16ri),
> + MSP430::SP)
> + .addReg(MSP430::SP)
> + .addImm(Amount);
> }
>
> if (New) {
> @@ -271,10 +273,11 @@
> // If we are performing frame pointer elimination and if the callee pops
> // something off the stack pointer, add it back.
> if (uint64_t CalleeAmt = I->getOperand(1).getImm()) {
> - MachineInstr *Old = I;
> + MachineInstr &Old = *I;
> MachineInstr *New =
> - BuildMI(MF, Old->getDebugLoc(), TII.get(MSP430::SUB16ri),
> - MSP430::SP).addReg(MSP430::SP).addImm(CalleeAmt);
> + BuildMI(MF, Old.getDebugLoc(), TII.get(MSP430::SUB16ri), MSP430::SP)
> + .addReg(MSP430::SP)
> + .addImm(CalleeAmt);
> // The SRW implicit def is dead.
> New->getOperand(3).setIsDead();
>
> Index: lib/Target/MSP430/MSP430BranchSelector.cpp
> ===================================================================
> --- lib/Target/MSP430/MSP430BranchSelector.cpp
> +++ lib/Target/MSP430/MSP430BranchSelector.cpp
> @@ -67,16 +67,12 @@
>
> // Measure each MBB and compute a size for the entire function.
> unsigned FuncSize = 0;
> - for (MachineFunction::iterator MFI = Fn.begin(), E = Fn.end(); MFI != E;
> - ++MFI) {
> - MachineBasicBlock *MBB = &*MFI;
> -
> + for (MachineBasicBlock &MBB : Fn) {
> unsigned BlockSize = 0;
> - for (MachineBasicBlock::iterator MBBI = MBB->begin(), EE = MBB->end();
> - MBBI != EE; ++MBBI)
> - BlockSize += TII->GetInstSizeInBytes(MBBI);
> + for (MachineInstr &MI : MBB)
> + BlockSize += TII->GetInstSizeInBytes(MI);
>
> - BlockSizes[MBB->getNumber()] = BlockSize;
> + BlockSizes[MBB.getNumber()] = BlockSize;
> FuncSize += BlockSize;
> }
>
> @@ -111,7 +107,7 @@
> I != E; ++I) {
> if ((I->getOpcode() != MSP430::JCC || I->getOperand(0).isImm()) &&
> I->getOpcode() != MSP430::JMP) {
> - MBBStartOffset += TII->GetInstSizeInBytes(I);
> + MBBStartOffset += TII->GetInstSizeInBytes(*I);
> continue;
> }
>
> @@ -145,8 +141,8 @@
>
> // Otherwise, we have to expand it to a long branch.
> unsigned NewSize;
> - MachineInstr *OldBranch = I;
> - DebugLoc dl = OldBranch->getDebugLoc();
> + MachineInstr &OldBranch = *I;
> + DebugLoc dl = OldBranch.getDebugLoc();
>
> if (I->getOpcode() == MSP430::JMP) {
> NewSize = 4;
> @@ -168,7 +164,7 @@
> I = BuildMI(MBB, I, dl, TII->get(MSP430::Bi)).addMBB(Dest);
>
> // Remove the old branch from the function.
> - OldBranch->eraseFromParent();
> + OldBranch.eraseFromParent();
>
> // Remember that this instruction is NewSize bytes, increase the size of the
> // block by NewSize-2, remember to iterate.
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list