Added MachineCodeForInstruction object as an argument to
authorVikram S. Adve <vadve@cs.uiuc.edu>
Sat, 31 May 2003 07:41:24 +0000 (07:41 +0000)
committerVikram S. Adve <vadve@cs.uiuc.edu>
Sat, 31 May 2003 07:41:24 +0000 (07:41 +0000)
TmpInstruction constructors because every TmpInstruction object has
to be registered with a MachineCodeForInstruction to prevent leaks.
This simplifies the user's code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6469 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/InstrSelection.h
lib/CodeGen/InstrSelection/InstrSelection.cpp
lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp
lib/Target/SparcV9/InstrSelection/InstrSelection.cpp
lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp

index 256a1807f788ae4a59b0cdb272e5ee003d8b5fa7..c1ed86ed4363dce9283e7af96761bef04832d6e4 100644 (file)
@@ -13,6 +13,7 @@ class InstrForest;
 class MachineInstr;
 class InstructionNode;
 class TargetMachine;
+class MachineCodeForInstruction;
 class Pass;
 
 //===--------------------- Required Functions ---------------------------------
@@ -68,14 +69,19 @@ class TmpInstruction : public Instruction {
 public:
   // Constructor that uses the type of S1 as the type of the temporary.
   // s1 must be a valid value.  s2 may be NULL.
-  TmpInstruction(Value *s1, Value *s2 = 0, const std::string &name = "");
+  TmpInstruction(MachineCodeForInstruction& mcfi,
+                 Value *s1, Value *s2 = 0, const std::string &name = "");
   
   // Constructor that requires the type of the temporary to be specified.
   // Both S1 and S2 may be NULL.
-  TmpInstruction(const Type *Ty, Value *s1 = 0, Value* s2 = 0,
+  TmpInstruction(MachineCodeForInstruction& mcfi,
+                 const Type *Ty, Value *s1 = 0, Value* s2 = 0,
                  const std::string &name = "");
   
-  virtual Instruction *clone() const { return new TmpInstruction(*this); }
+  virtual Instruction *clone() const {
+    assert(0 && "Cannot clone TmpInstructions!");
+    return 0;
+  }
   virtual const char *getOpcodeName() const {
     return "TempValueForMachineInstr";
   }
index 5e0fb8ec7259d238ff5d64432e9f267ac79d3c3b..e4dd2e9dace1722adaf6e506156068fc53a6875c 100644 (file)
@@ -78,8 +78,12 @@ namespace {
 static RegisterLLC<InstructionSelection>
 X("instselect", "Instruction Selection", createInstructionSelectionPass);
 
-TmpInstruction::TmpInstruction(Value *s1, Value *s2, const std::string &name)
-  : Instruction(s1->getType(), Instruction::UserOp1, name) {
+TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
+                               Value *s1, Value *s2, const std::string &name)
+  : Instruction(s1->getType(), Instruction::UserOp1, name)
+{
+  mcfi.addTemp(this);
+
   Operands.push_back(Use(s1, this));  // s1 must be nonnull
   if (s2) {
     Operands.push_back(Use(s2, this));
@@ -91,9 +95,13 @@ TmpInstruction::TmpInstruction(Value *s1, Value *s2, const std::string &name)
   
 // Constructor that requires the type of the temporary to be specified.
 // Both S1 and S2 may be NULL.(
-TmpInstruction::TmpInstruction(const Type *Ty, Value *s1, Value* s2,
+TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
+                               const Type *Ty, Value *s1, Value* s2,
                                const std::string &name)
-  : Instruction(Ty, Instruction::UserOp1, name) {
+  : Instruction(Ty, Instruction::UserOp1, name)
+{
+  mcfi.addTemp(this);
+
   if (s1) { Operands.push_back(Use(s1, this)); }
   if (s2) { Operands.push_back(Use(s2, this)); }
 
index a5a3662e937c062dcb7896b169be1012d4c2984f..268fb3d877c432197826876241772aea5efc2302 100644 (file)
@@ -33,9 +33,8 @@ InsertCodeToLoadConstant(Function *F,
                          TargetMachine& target)
 {
   // Create a tmp virtual register to hold the constant.
-  TmpInstruction* tmpReg = new TmpInstruction(opValue);
   MachineCodeForInstruction &mcfi = MachineCodeForInstruction::get(vmInstr);
-  mcfi.addTemp(tmpReg);
+  TmpInstruction* tmpReg = new TmpInstruction(mcfi, opValue);
   
   target.getInstrInfo().CreateCodeToLoadConst(target, F, opValue, tmpReg,
                                               loadConstVec, mcfi);
index 5e0fb8ec7259d238ff5d64432e9f267ac79d3c3b..e4dd2e9dace1722adaf6e506156068fc53a6875c 100644 (file)
@@ -78,8 +78,12 @@ namespace {
 static RegisterLLC<InstructionSelection>
 X("instselect", "Instruction Selection", createInstructionSelectionPass);
 
-TmpInstruction::TmpInstruction(Value *s1, Value *s2, const std::string &name)
-  : Instruction(s1->getType(), Instruction::UserOp1, name) {
+TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
+                               Value *s1, Value *s2, const std::string &name)
+  : Instruction(s1->getType(), Instruction::UserOp1, name)
+{
+  mcfi.addTemp(this);
+
   Operands.push_back(Use(s1, this));  // s1 must be nonnull
   if (s2) {
     Operands.push_back(Use(s2, this));
@@ -91,9 +95,13 @@ TmpInstruction::TmpInstruction(Value *s1, Value *s2, const std::string &name)
   
 // Constructor that requires the type of the temporary to be specified.
 // Both S1 and S2 may be NULL.(
-TmpInstruction::TmpInstruction(const Type *Ty, Value *s1, Value* s2,
+TmpInstruction::TmpInstruction(MachineCodeForInstruction& mcfi,
+                               const Type *Ty, Value *s1, Value* s2,
                                const std::string &name)
-  : Instruction(Ty, Instruction::UserOp1, name) {
+  : Instruction(Ty, Instruction::UserOp1, name)
+{
+  mcfi.addTemp(this);
+
   if (s1) { Operands.push_back(Use(s1, this)); }
   if (s2) { Operands.push_back(Use(s2, this)); }
 
index a5a3662e937c062dcb7896b169be1012d4c2984f..268fb3d877c432197826876241772aea5efc2302 100644 (file)
@@ -33,9 +33,8 @@ InsertCodeToLoadConstant(Function *F,
                          TargetMachine& target)
 {
   // Create a tmp virtual register to hold the constant.
-  TmpInstruction* tmpReg = new TmpInstruction(opValue);
   MachineCodeForInstruction &mcfi = MachineCodeForInstruction::get(vmInstr);
-  mcfi.addTemp(tmpReg);
+  TmpInstruction* tmpReg = new TmpInstruction(mcfi, opValue);
   
   target.getInstrInfo().CreateCodeToLoadConst(target, F, opValue, tmpReg,
                                               loadConstVec, mcfi);