From c01ff9c1f945e1c3e40890e31f75a5d380a96fe9 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 28 Oct 2002 21:43:57 +0000 Subject: [PATCH] Use BuildMI instead of explicit code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4362 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../SparcV9/SparcV9PrologEpilogInserter.cpp | 49 ++++++------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp b/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp index 220953b9b53..da6c9ca5803 100644 --- a/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp +++ b/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp @@ -13,7 +13,7 @@ #include "SparcRegClassInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineCodeForInstruction.h" -#include "llvm/CodeGen/MachineInstr.h" +#include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/InstrSelectionSupport.h" #include "llvm/Pass.h" #include "llvm/Function.h" @@ -60,7 +60,7 @@ void InsertPrologEpilogCode::InsertPrologCode(Function &F) // See the comments below for the choice of this register. // MachineFunction& mcInfo = MachineFunction::get(&F); - unsigned int staticStackSize = mcInfo.getStaticStackSize(); + unsigned staticStackSize = mcInfo.getStaticStackSize(); if (staticStackSize < (unsigned) frameInfo.getMinStackFrameSize()) staticStackSize = (unsigned) frameInfo.getMinStackFrameSize(); @@ -69,51 +69,34 @@ void InsertPrologEpilogCode::InsertPrologCode(Function &F) (unsigned) frameInfo.getStackFrameSizeAlignment())) staticStackSize += frameInfo.getStackFrameSizeAlignment() - padsz; - if (Target.getInstrInfo().constantFitsInImmedField(SAVE, staticStackSize)) - { - M = new MachineInstr(SAVE); - M->SetMachineOperandReg(0, Target.getRegInfo().getStackPointer()); - M->SetMachineOperandConst(1, MachineOperand::MO_SignExtendedImmed, - - (int) staticStackSize); - M->SetMachineOperandReg(2, Target.getRegInfo().getStackPointer()); - mvec.push_back(M); - } - else - { + int32_t C = - (int) staticStackSize; + int SP = Target.getRegInfo().getStackPointer(); + if (Target.getInstrInfo().constantFitsInImmedField(SAVE, staticStackSize)) { + M = BuildMI(SAVE, 3).addMReg(SP).addSImm(C).addMReg(SP); + mvec.push_back(M); + } else { // We have to put the stack size value into a register before SAVE. // Use register %g1 since it is volatile across calls. Note that the // local (%l) and in (%i) registers cannot be used before the SAVE! // Do this by creating a code sequence equivalent to: // SETSW -(stackSize), %g1 - int32_t C = - (int) staticStackSize; int uregNum = Target.getRegInfo().getUnifiedRegNum( Target.getRegInfo().getRegClassIDOfType(Type::IntTy), SparcIntRegClass::g1); - M = new MachineInstr(SETHI); - M->SetMachineOperandConst(0, MachineOperand::MO_SignExtendedImmed, C); - M->SetMachineOperandReg(1, uregNum); + M = BuildMI(SETHI, 2).addSImm(C).addMReg(uregNum); M->setOperandHi32(0); mvec.push_back(M); - M = new MachineInstr(OR); - M->SetMachineOperandReg(0, uregNum); - M->SetMachineOperandConst(1, MachineOperand::MO_SignExtendedImmed, C); - M->SetMachineOperandReg(2, uregNum); + M = BuildMI(OR, 3).addMReg(uregNum).addSImm(C).addMReg(uregNum); M->setOperandLo32(1); mvec.push_back(M); - M = new MachineInstr(SRA); - M->SetMachineOperandReg(0, uregNum); - M->SetMachineOperandConst(1, MachineOperand::MO_UnextendedImmed, 0); - M->SetMachineOperandReg(2, uregNum); + M = BuildMI(SRA, 3).addMReg(uregNum).addZImm(0).addMReg(uregNum); mvec.push_back(M); // Now generate the SAVE using the value in register %g1 - M = new MachineInstr(SAVE); - M->SetMachineOperandReg(0, Target.getRegInfo().getStackPointer()); - M->SetMachineOperandReg(1, uregNum); - M->SetMachineOperandReg(2, Target.getRegInfo().getStackPointer()); + M = BuildMI(SAVE, 3).addMReg(SP).addMReg(uregNum).addMReg(SP); mvec.push_back(M); } @@ -130,11 +113,9 @@ void InsertPrologEpilogCode::InsertEpilogCode(Function &F) Instruction *TermInst = (Instruction*)BB.getTerminator(); if (TermInst->getOpcode() == Instruction::Ret) { - MachineInstr *Restore = new MachineInstr(RESTORE); - Restore->SetMachineOperandReg(0, Target.getRegInfo().getZeroRegNum()); - Restore->SetMachineOperandConst(1, MachineOperand::MO_SignExtendedImmed, - (int64_t)0); - Restore->SetMachineOperandReg(2, Target.getRegInfo().getZeroRegNum()); + int ZR = Target.getRegInfo().getZeroRegNum(); + MachineInstr *Restore = + BuildMI(RESTORE, 3).addMReg(ZR).addSImm(0).addMReg(ZR); MachineCodeForInstruction &termMvec = MachineCodeForInstruction::get(TermInst);