From e225e2541b59f77bec8585a58dad848295395f43 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Fri, 11 Mar 2016 17:27:54 +0000 Subject: [PATCH] [IRTranslator] Update getOrCreateVReg API to use references. A value that we want to keep in a virtual register cannot be null. Reflect that in the API. llvm-svn: 263263 --- llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h | 5 +++-- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h index 621321d..443b178 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h @@ -111,8 +111,9 @@ private: // * Clear the different maps. void finalize(); - /// Get the sequence of VRegs for that \p Val. - unsigned getOrCreateVReg(const Value *Val); + /// Get the VReg that represents \p Val. + /// If such VReg does not exist, it is created. + unsigned getOrCreateVReg(const Value &Val); /// Get the MachineBasicBlock that represents \p BB. /// If such basic block does not exist, it is created. diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index adf5133..fb2f559 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -34,16 +34,16 @@ IRTranslator::IRTranslator() : MachineFunctionPass(ID), MRI(nullptr) { initializeIRTranslatorPass(*PassRegistry::getPassRegistry()); } -unsigned IRTranslator::getOrCreateVReg(const Value *Val) { - unsigned &ValReg = ValToVReg[Val]; +unsigned IRTranslator::getOrCreateVReg(const Value &Val) { + unsigned &ValReg = ValToVReg[&Val]; // Check if this is the first time we see Val. if (!ValReg) { // Fill ValRegsSequence with the sequence of registers // we need to concat together to produce the value. - assert(Val->getType()->isSized() && + assert(Val.getType()->isSized() && "Don't know how to create an empty vreg"); - assert(!Val->getType()->isAggregateType() && "Not yet implemented"); - unsigned Size = Val->getType()->getPrimitiveSizeInBits(); + assert(!Val.getType()->isAggregateType() && "Not yet implemented"); + unsigned Size = Val.getType()->getPrimitiveSizeInBits(); unsigned VReg = MRI->createGenericVirtualRegister(Size); ValReg = VReg; assert(!isa(Val) && "Not yet implemented"); @@ -66,9 +66,9 @@ bool IRTranslator::translateADD(const Instruction &Inst) { // Unless the value is a Constant => loadimm cst? // or inline constant each time? // Creation of a virtual register needs to have a size. - unsigned Op0 = getOrCreateVReg(Inst.getOperand(0)); - unsigned Op1 = getOrCreateVReg(Inst.getOperand(1)); - unsigned Res = getOrCreateVReg(&Inst); + unsigned Op0 = getOrCreateVReg(*Inst.getOperand(0)); + unsigned Op1 = getOrCreateVReg(*Inst.getOperand(1)); + unsigned Res = getOrCreateVReg(Inst); MIRBuilder.buildInstr(TargetOpcode::G_ADD, Inst.getType(), Res, Op0, Op1); return true; } @@ -79,7 +79,7 @@ bool IRTranslator::translateReturn(const Instruction &Inst) { // The target may mess up with the insertion point, but // this is not important as a return is the last instruction // of the block anyway. - return CLI->LowerReturn(MIRBuilder, Ret, !Ret ? 0 : getOrCreateVReg(Ret)); + return CLI->LowerReturn(MIRBuilder, Ret, !Ret ? 0 : getOrCreateVReg(*Ret)); } bool IRTranslator::translate(const Instruction &Inst) { @@ -115,7 +115,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &MF) { MIRBuilder.setMBB(MBB); SmallVector VRegArgs; for (const Argument &Arg: F.args()) - VRegArgs.push_back(getOrCreateVReg(&Arg)); + VRegArgs.push_back(getOrCreateVReg(Arg)); bool Succeeded = CLI->LowerFormalArguments(MIRBuilder, F.getArgumentList(), VRegArgs); if (!Succeeded) -- 2.7.4