[llvm] r263263 - [IRTranslator] Update getOrCreateVReg API to use references.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 11 09:27:55 PST 2016


Author: qcolombet
Date: Fri Mar 11 11:27:54 2016
New Revision: 263263

URL: http://llvm.org/viewvc/llvm-project?rev=263263&view=rev
Log:
[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.

Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
    llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h?rev=263263&r1=263262&r2=263263&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h Fri Mar 11 11:27:54 2016
@@ -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.

Modified: llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp?rev=263263&r1=263262&r2=263263&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/IRTranslator.cpp Fri Mar 11 11:27:54 2016
@@ -34,16 +34,16 @@ IRTranslator::IRTranslator() : MachineFu
   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<Constant>(Val) && "Not yet implemented");
@@ -66,9 +66,9 @@ bool IRTranslator::translateADD(const In
   // 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
   // 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(
   MIRBuilder.setMBB(MBB);
   SmallVector<unsigned, 8> 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)




More information about the llvm-commits mailing list