From 466b534a570f574ed485d875bbca8454f68dcb52 Mon Sep 17 00:00:00 2001 From: Tanya Lattner Date: Sun, 23 May 2004 19:35:12 +0000 Subject: [PATCH] Adding support to clone MachineInstr git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13661 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineInstr.h | 14 +++++++++++++- lib/CodeGen/MachineInstr.cpp | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index dac1c47c961..b6c18610ad3 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -172,6 +172,7 @@ public: contents.SymbolName = new std::string(M.getSymbolName()); } + ~MachineOperand() { if (isExternalSymbol()) delete contents.SymbolName; @@ -367,7 +368,9 @@ class MachineInstr { // OperandComplete - Return true if it's illegal to add a new operand bool OperandsComplete() const; - MachineInstr(const MachineInstr &); // DO NOT IMPLEMENT + //Constructor used by clone() method + MachineInstr(const MachineInstr&); + void operator=(const MachineInstr&); // DO NOT IMPLEMENT // Intrusive list support @@ -395,6 +398,9 @@ public: const MachineBasicBlock* getParent() const { return parent; } MachineBasicBlock* getParent() { return parent; } + //void setParent(const MachineBasicBlock *MBB) { parent = MBB; } + void setParent(MachineBasicBlock *MBB) { parent = MBB; } + /// getOpcode - Returns the opcode of this MachineInstr. /// const int getOpcode() const { return Opcode; } @@ -455,6 +461,12 @@ public: MachineOperand::MO_VirtualRegister, V); } + //Clone Instruction + //Create a copy of 'this' instruction that is + //identical in all ways except the following: The instruction has no + //parent The instruction has no name + MachineInstr* clone(); + // // Debugging support // diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 38cd62e83f5..e1e44fd47e0 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -69,11 +69,29 @@ MachineInstr::MachineInstr(MachineBasicBlock *MBB, short opcode, MBB->push_back(this); // Add instruction to end of basic block! } +///MachineInstr ctor - Copies MachineInstr arg exactly +MachineInstr::MachineInstr(const MachineInstr &MI) { + Opcode = MI.getOpcode(); + numImplicitRefs = MI.getNumImplicitRefs(); + + //Add operands + for(unsigned i=0; i < MI.getNumOperands(); ++i) + operands.push_back(MachineOperand(MI.getOperand(i))); +} + + MachineInstr::~MachineInstr() { LeakDetector::removeGarbageObject(this); } +///clone - Create a copy of 'this' instruction that is identical in +///all ways except the following: The instruction has no parent The +///instruction has no name +MachineInstr* MachineInstr::clone() { + MachineInstr* newInst = new MachineInstr(*this); +} + /// OperandComplete - Return true if it's illegal to add a new operand /// bool MachineInstr::OperandsComplete() const { @@ -93,6 +111,7 @@ void MachineInstr::replace(short opcode, unsigned numOperands) { Opcode = opcode; operands.clear(); operands.resize(numOperands, MachineOperand()); + } void MachineInstr::SetMachineOperandVal(unsigned i,