[llvm-commits] CVS: llvm/include/llvm/Instruction.h Value.h

Chris Lattner lattner at cs.uiuc.edu
Sun Jun 27 13:39:01 PDT 2004


Changes in directory llvm/include/llvm:

Instruction.h updated: 1.58 -> 1.59
Value.h updated: 1.52 -> 1.53

---
Log message:

Eliminate the Instruction::iType field, folding it into the Value::VTy field.
This reduces the size of the instruction class by 4 bytes, and means that 
isa<CallInst>(V) (for example) only needs to do one load from memory instead
of two.


---
Diffs of the changes:  (+15 -6)

Index: llvm/include/llvm/Instruction.h
diff -u llvm/include/llvm/Instruction.h:1.58 llvm/include/llvm/Instruction.h:1.59
--- llvm/include/llvm/Instruction.h:1.58	Sat Jun 26 15:51:50 2004
+++ llvm/include/llvm/Instruction.h	Sun Jun 27 13:38:24 2004
@@ -21,6 +21,7 @@
 namespace llvm {
 
 struct AssemblyAnnotationWriter;
+class BinaryOperator;
 
 template<typename SC> struct ilist_traits;
 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
@@ -38,9 +39,12 @@
   void setParent(BasicBlock *P);
   void init();
 
+private:
+  // FIXME: This is a dirty hack.  Setcc instructions shouldn't encode the CC
+  // into the opcode field.  When they don't, this will be unneeded.
+  void setOpcode(unsigned NewOpcode);
+  friend class BinaryOperator;
 protected:
-  unsigned iType;      // InstructionType: The opcode of the instruction
-
   Instruction(const Type *Ty, unsigned iType, const std::string &Name = "",
               Instruction *InsertBefore = 0);
   Instruction(const Type *Ty, unsigned iType, const std::string &Name,
@@ -81,7 +85,7 @@
   /// Subclass classification... getOpcode() returns a member of 
   /// one of the enums that is coming soon (down below)...
   ///
-  unsigned getOpcode() const { return iType; }
+  unsigned getOpcode() const { return getValueType() - InstructionVal; }
   virtual const char *getOpcodeName() const {
     return getOpcodeName(getOpcode());
   }
@@ -92,11 +96,11 @@
   }
 
   inline bool isTerminator() const {   // Instance of TerminatorInst?
-    return isTerminator(iType);
+    return isTerminator(getOpcode());
   }
 
   inline bool isBinaryOp() const {
-    return iType >= BinaryOpsBegin && iType < BinaryOpsEnd;
+    return getOpcode() >= BinaryOpsBegin && getOpcode() < BinaryOpsEnd;
   }
 
   /// isAssociative - Return true if the instruction is associative:


Index: llvm/include/llvm/Value.h
diff -u llvm/include/llvm/Value.h:1.52 llvm/include/llvm/Value.h:1.53
--- llvm/include/llvm/Value.h:1.52	Sat Jun 26 15:33:27 2004
+++ llvm/include/llvm/Value.h	Sun Jun 27 13:38:24 2004
@@ -133,6 +133,11 @@
   unsigned getValueType() const {
     return SubclassID;
   }
+
+private:
+  /// FIXME: this is a gross hack, needed by another gross hack.  Eliminate!
+  void setValueType(unsigned VT) { SubclassID = VT; }
+  friend class Instruction;
 };
 
 inline std::ostream &operator<<(std::ostream &OS, const Value *V) {
@@ -190,7 +195,7 @@
   return Val.getValueType() == Value::ArgumentVal;
 }
 template <> inline bool isa_impl<Instruction, Value>(const Value &Val) { 
-  return Val.getValueType() == Value::InstructionVal;
+  return Val.getValueType() >= Value::InstructionVal;
 }
 template <> inline bool isa_impl<BasicBlock, Value>(const Value &Val) { 
   return Val.getValueType() == Value::BasicBlockVal;





More information about the llvm-commits mailing list