[llvm-commits] CVS: llvm/include/llvm/CodeGen/MachineInstr.h MachineFunction.h MachineBasicBlock.h
Alkis Evlogimenos
alkis at cs.uiuc.edu
Wed Feb 11 20:28:50 PST 2004
Changes in directory llvm/include/llvm/CodeGen:
MachineInstr.h updated: 1.127 -> 1.128
MachineFunction.h updated: 1.31 -> 1.32
MachineBasicBlock.h updated: 1.13 -> 1.14
---
Log message:
Change MachineBasicBlock's vector of MachineInstr pointers into an
ilist of MachineInstr objects. This allows constant time removal and
insertion of MachineInstr instances from anywhere in each
MachineBasicBlock. It also allows for constant time splicing of
MachineInstrs into or out of MachineBasicBlocks.
---
Diffs of the changes: (+36 -19)
Index: llvm/include/llvm/CodeGen/MachineInstr.h
diff -u llvm/include/llvm/CodeGen/MachineInstr.h:1.127 llvm/include/llvm/CodeGen/MachineInstr.h:1.128
--- llvm/include/llvm/CodeGen/MachineInstr.h:1.127 Wed Feb 11 19:34:03 2004
+++ llvm/include/llvm/CodeGen/MachineInstr.h Wed Feb 11 20:27:10 2004
@@ -28,6 +28,8 @@
class TargetMachine;
class GlobalValue;
+template <typename T> class ilist_traits;
+
typedef int MachineOpCode;
//===----------------------------------------------------------------------===//
@@ -353,12 +355,24 @@
unsigned opCodeFlags; // flags modifying instrn behavior
std::vector<MachineOperand> operands; // the operands
unsigned numImplicitRefs; // number of implicit operands
-
+ MachineInstr* prev, *next; // links for our intrusive list
// OperandComplete - Return true if it's illegal to add a new operand
bool OperandsComplete() const;
MachineInstr(const MachineInstr &); // DO NOT IMPLEMENT
void operator=(const MachineInstr&); // DO NOT IMPLEMENT
+
+private:
+ // Intrusive list support
+ //
+ friend class ilist_traits<MachineInstr>;
+ MachineInstr() { /* this is for ilist use only to create the sentinel */ }
+ MachineInstr* getPrev() const { return prev; }
+ MachineInstr* getNext() const { return next; }
+
+ void setPrev(MachineInstr* mi) { prev = mi; }
+ void setNext(MachineInstr* mi) { next = mi; }
+
public:
MachineInstr(int Opcode, unsigned numOperands);
Index: llvm/include/llvm/CodeGen/MachineFunction.h
diff -u llvm/include/llvm/CodeGen/MachineFunction.h:1.31 llvm/include/llvm/CodeGen/MachineFunction.h:1.32
--- llvm/include/llvm/CodeGen/MachineFunction.h:1.31 Sat Dec 20 04:18:58 2003
+++ llvm/include/llvm/CodeGen/MachineFunction.h Wed Feb 11 20:27:10 2004
@@ -20,7 +20,6 @@
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "Support/Annotation.h"
-#include "Support/ilist"
namespace llvm {
Index: llvm/include/llvm/CodeGen/MachineBasicBlock.h
diff -u llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.13 llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.14
--- llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.13 Tue Nov 11 16:41:31 2003
+++ llvm/include/llvm/CodeGen/MachineBasicBlock.h Wed Feb 11 20:27:10 2004
@@ -14,16 +14,17 @@
#ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
#define LLVM_CODEGEN_MACHINEBASICBLOCK_H
-#include <vector>
+#include "llvm/CodeGen/MachineInstr.h"
+#include "Support/ilist"
namespace llvm {
class BasicBlock;
-class MachineInstr;
-template <typename T> struct ilist_traits;
class MachineBasicBlock {
- std::vector<MachineInstr*> Insts;
+public:
+ typedef ilist<MachineInstr> Instructions;
+ Instructions Insts;
MachineBasicBlock *Prev, *Next;
const BasicBlock *BB;
public:
@@ -35,19 +36,27 @@
///
const BasicBlock *getBasicBlock() const { return BB; }
- typedef std::vector<MachineInstr*>::iterator iterator;
- typedef std::vector<MachineInstr*>::const_iterator const_iterator;
+ typedef ilist<MachineInstr>::iterator iterator;
+ typedef ilist<MachineInstr>::const_iterator const_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
unsigned size() const { return Insts.size(); }
bool empty() const { return Insts.empty(); }
- MachineInstr * operator[](unsigned i) const { return Insts[i]; }
- MachineInstr *&operator[](unsigned i) { return Insts[i]; }
+ const MachineInstr& operator[](unsigned i) const {
+ const_iterator it = Insts.begin();
+ std::advance(it, i);
+ return *it;
+ }
+ MachineInstr& operator[](unsigned i) {
+ iterator it = Insts.begin();
+ std::advance(it, i);
+ return *it;
+ }
- MachineInstr *front() const { return Insts.front(); }
- MachineInstr *back() const { return Insts.back(); }
+ MachineInstr& front() { return Insts.front(); }
+ MachineInstr& back() { return Insts.back(); }
iterator begin() { return Insts.begin(); }
const_iterator begin() const { return Insts.begin(); }
@@ -64,16 +73,11 @@
iterator insert(iterator I, MachineInstr *M) { return Insts.insert(I, M); }
// erase - Remove the specified element or range from the instruction list.
- // These functions do not delete any instructions removed.
+ // These functions delete any instructions removed.
//
iterator erase(iterator I) { return Insts.erase(I); }
iterator erase(iterator I, iterator E) { return Insts.erase(I, E); }
-
- MachineInstr *pop_back() {
- MachineInstr *R = back();
- Insts.pop_back();
- return R;
- }
+ MachineInstr* remove(iterator &I) { return Insts.remove(I); }
private: // Methods used to maintain doubly linked list of blocks...
friend class ilist_traits<MachineBasicBlock>;
More information about the llvm-commits
mailing list