aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/CodeGen
diff options
context:
space:
mode:
authorAlkis Evlogimenos <alkis@evlogimenos.com>2004-02-12 02:27:10 +0000
committerAlkis Evlogimenos <alkis@evlogimenos.com>2004-02-12 02:27:10 +0000
commitc0b9dc5be79f009d260edb5cd5e1d8346587aaa2 (patch)
treef68d35cea961a4c0fdb0c5bd9f943e77c5f34161 /include/llvm/CodeGen
parent918cdd420b52a4745ce7d4495759c87fd1b32fd5 (diff)
downloadexternal_llvm-c0b9dc5be79f009d260edb5cd5e1d8346587aaa2.zip
external_llvm-c0b9dc5be79f009d260edb5cd5e1d8346587aaa2.tar.gz
external_llvm-c0b9dc5be79f009d260edb5cd5e1d8346587aaa2.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11340 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/CodeGen')
-rw-r--r--include/llvm/CodeGen/MachineBasicBlock.h38
-rw-r--r--include/llvm/CodeGen/MachineFunction.h1
-rw-r--r--include/llvm/CodeGen/MachineInstr.h16
3 files changed, 36 insertions, 19 deletions
diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h
index b8a0361..7285057 100644
--- a/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/include/llvm/CodeGen/MachineBasicBlock.h
@@ -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 @@ public:
///
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 @@ public:
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>;
diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h
index 4f25559..2c44396 100644
--- a/include/llvm/CodeGen/MachineFunction.h
+++ b/include/llvm/CodeGen/MachineFunction.h
@@ -20,7 +20,6 @@
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "Support/Annotation.h"
-#include "Support/ilist"
namespace llvm {
diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h
index ff05631..0cc46b0 100644
--- a/include/llvm/CodeGen/MachineInstr.h
+++ b/include/llvm/CodeGen/MachineInstr.h
@@ -28,6 +28,8 @@ class MachineBasicBlock;
class TargetMachine;
class GlobalValue;
+template <typename T> class ilist_traits;
+
typedef int MachineOpCode;
//===----------------------------------------------------------------------===//
@@ -353,12 +355,24 @@ class MachineInstr {
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);