[llvm-commits] [hlvm] r38394 - in /hlvm/trunk/hlvm: AST/AST.cpp AST/ContainerType.h AST/MemoryOps.cpp AST/MemoryOps.h AST/Node.h CodeGen/LLVMGenerator.cpp Pass/Validate.cpp Reader/HLVM.rng Reader/XMLReader.cpp Writer/XMLWriter.cpp

Reid Spencer reid at x10sys.com
Sat Jul 7 17:02:57 PDT 2007


Author: reid
Date: Sat Jul  7 19:02:57 2007
New Revision: 38394

URL: http://llvm.org/viewvc/llvm-project?rev=38394&view=rev
Log:
Differentiate the index operator into getfield and getindex, the former for
structures and the latter for arrays and vectors. Also make this a binary 
operator instead of a multi-operator. These changes remove complexity from the
index operator and make the operations more atomic.

Modified:
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/ContainerType.h
    hlvm/trunk/hlvm/AST/MemoryOps.cpp
    hlvm/trunk/hlvm/AST/MemoryOps.h
    hlvm/trunk/hlvm/AST/Node.h
    hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
    hlvm/trunk/hlvm/Pass/Validate.cpp
    hlvm/trunk/hlvm/Reader/HLVM.rng
    hlvm/trunk/hlvm/Reader/XMLReader.cpp
    hlvm/trunk/hlvm/Writer/XMLWriter.cpp

Modified: hlvm/trunk/hlvm/AST/AST.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.cpp?rev=38394&r1=38393&r2=38394&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 19:02:57 2007
@@ -1205,6 +1205,16 @@
 template LoadOp*   
 AST::new_UnaryOp<LoadOp>(Operator*op1,Bundle* B, const Locator*loc);
 
+template GetFieldOp*  
+AST::new_BinaryOp<GetFieldOp>(const Type*, Operator*op1,Operator*op2,const Locator*loc);
+template GetFieldOp*  
+AST::new_BinaryOp<GetFieldOp>(Operator*op1,Operator*op2,Bundle* B, const Locator*loc);
+
+template GetIndexOp*  
+AST::new_BinaryOp<GetIndexOp>(const Type*, Operator*op1,Operator*op2,const Locator*loc);
+template GetIndexOp*  
+AST::new_BinaryOp<GetIndexOp>(Operator*op1,Operator*op2,Bundle* B, const Locator*loc);
+
 // Input/Output Operators
 template OpenOp* 
 AST::new_UnaryOp<OpenOp>(const Type* Ty, Operator*op1,const Locator*loc);

Modified: hlvm/trunk/hlvm/AST/ContainerType.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.h?rev=38394&r1=38393&r2=38394&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul  7 19:02:57 2007
@@ -267,6 +267,7 @@
   /// @{
   public:
     virtual const char* getPrimitiveName() const;
+    const NamedType* getField(unsigned index) const { return contents[index]; }
     /// Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const DisparateContainerType*) { return true; }
     static inline bool classof(const Node* N) { 

Modified: hlvm/trunk/hlvm/AST/MemoryOps.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/MemoryOps.cpp?rev=38394&r1=38393&r2=38394&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/MemoryOps.cpp (original)
+++ hlvm/trunk/hlvm/AST/MemoryOps.cpp Sat Jul  7 19:02:57 2007
@@ -35,6 +35,7 @@
 StoreOp::~StoreOp() {}
 AutoVarOp::~AutoVarOp() {}
 ReferenceOp::~ReferenceOp() {}
-IndexOp::~IndexOp() {}
+GetIndexOp::~GetIndexOp() {}
+GetFieldOp::~GetFieldOp() {}
 
 }

Modified: hlvm/trunk/hlvm/AST/MemoryOps.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/MemoryOps.h?rev=38394&r1=38393&r2=38394&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/MemoryOps.h (original)
+++ hlvm/trunk/hlvm/AST/MemoryOps.h Sat Jul  7 19:02:57 2007
@@ -253,32 +253,64 @@
 };
 
 /// This class provides an Abstract Syntax Tree node that represents an operator
-/// for indexing into a ContainerType.  The Index operator can have many
-/// operands but in all cases requires at least two.  The first operand must
-/// resolve to the address of a memory location, such as returned by the
-/// ReferenceOp. The second and subsequent operands must all be of integer type.
-/// They specify which elements of the memory object should be indexed. This
-/// operator is the means by which the elements of memory objects of type 
-/// PointerType, ArrayType, VectorType, StructureType, and ContinuationType can
-/// be accessed. The resulting value of the operator is the address of the
-/// corresponding memory location. In the case of StructureType and 
-/// ContinuationType elements, the corresponding index indicates the field, in
-/// declaration order, that is accessed. Field numbering begins at zero.
-/// @brief AST Index Operator
-class IndexOp : public MultiOperator
+/// for getting the address of a field of a StructureType value. The GetFieldOp
+/// takes two operands, a pointer to a memory location that must be of
+/// StructureType type and a string that names the field of the structure. The
+/// second operand does not have to be a constant value, but if it is not, a 
+/// performance penalty is incurred to look up the field.  The GetFieldOp can
+/// be used against a value of any StructureType subclass.  The resulting value
+/// of the operator is the address of the memory location corresponding to the
+/// named field of the structure value.
+/// @brief AST GetFieldOp Operator
+class GetFieldOp : public MultiOperator
 {
   /// @name Constructors
   /// @{
   protected:
-    IndexOp() : MultiOperator(IndexOpID) {}
-    virtual ~IndexOp();
+    GetFieldOp() : MultiOperator(GetFieldOpID) {}
+    virtual ~GetFieldOp();
 
   /// @}
   /// @name Accessors
   /// @{
   public:
-    static inline bool classof(const IndexOp*) { return true; }
-    static inline bool classof(const Node* N) { return N->is(IndexOpID); }
+    static inline bool classof(const GetFieldOp*) { return true; }
+    static inline bool classof(const Node* N) { return N->is(GetFieldOpID); }
+
+  /// @}
+  /// @name Mutators
+  /// @{
+  public:
+
+  /// @}
+  /// @name Data
+  /// @{
+  protected:
+  /// @}
+  friend class AST;
+};
+
+/// This class provides an Abstract Syntax Tree node that represents an operator
+/// for getting the address of a field of an ArrayType or VectorType value. 
+/// The GetIndexOp takes two operands, a pointer to a memory location that 
+/// must be of ArrayType or VectorType and an integer value that indexes into 
+/// the array or vector.  The resulting value of the operator is the address of
+/// the indexed memory location. 
+/// @brief AST GetIndexOp Operator
+class GetIndexOp : public BinaryOperator
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    GetIndexOp() : BinaryOperator(GetIndexOpID) {}
+    virtual ~GetIndexOp();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    static inline bool classof(const GetIndexOp*) { return true; }
+    static inline bool classof(const Node* N) { return N->is(GetIndexOpID); }
 
   /// @}
   /// @name Mutators

Modified: hlvm/trunk/hlvm/AST/Node.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.h?rev=38394&r1=38393&r2=38394&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul  7 19:02:57 2007
@@ -229,6 +229,8 @@
   // Memory Binary Operators
   ReallocateOpID,          ///< The Reallocate Memory Operator 
   StoreOpID,               ///< The Store Operator (store a value to a location)
+  GetIndexOpID,            ///< The GetIndex Operator for indexing an array
+  GetFieldOpID,            ///< The GetField Operator for indexing an structure
 
   // Binary Control Flow Operators
   WhileOpID,               ///< While expression is true loop
@@ -258,7 +260,6 @@
   InvokeOpID,              ///< The Invoke Operator (n operands)
   DispatchOpID,            ///< The Object Method Dispatch Operator (n operands)
   CallWithContOpID,        ///< The Call with Continuation Operator (n operands)
-  IndexOpID,               ///< The Index Operator for indexing an array
   SwitchOpID,              ///< The Switch Operator (n operands)
 LastMultiOperatorID = SwitchOpID,
 LastOperatorID = SwitchOpID,
@@ -534,6 +535,8 @@
   public:
     // Get the type of the value
     virtual const Type* getType() const { return type; }
+    template<class C>
+    bool typeis() const { return llvm::isa<C>(type); }
     const Type* getConcreteType() const;
 
     static inline bool classof(const Value*) { return true; }

Modified: hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp?rev=38394&r1=38393&r2=38394&view=diff

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul  7 19:02:57 2007
@@ -1421,8 +1421,17 @@
 }
 
 template<> void
-LLVMGeneratorPass::gen(IndexOp* r)
+LLVMGeneratorPass::gen(GetFieldOp* i)
 {
+  llvm::Value* location = popOperand(i->getOperand(0));
+  llvm::Value* fld = popOperand(i->getOperand(1));
+}
+
+template<> void
+LLVMGeneratorPass::gen(GetIndexOp* i)
+{
+  llvm::Value* location = popOperand(i->getOperand(0));
+  llvm::Value* index = popOperand(i->getOperand(1));
 }
 
 template<> void
@@ -1723,6 +1732,8 @@
       case CloseOpID:               gen(llvm::cast<CloseOp>(n)); break;
       case WriteOpID:               gen(llvm::cast<WriteOp>(n)); break;
       case ReadOpID:                gen(llvm::cast<ReadOp>(n)); break;
+      case GetIndexOpID:            gen(llvm::cast<GetIndexOp>(n)); break;
+      case GetFieldOpID:            gen(llvm::cast<GetFieldOp>(n)); break;
 
       case BundleID:
         genProgramLinkage();

Modified: hlvm/trunk/hlvm/Pass/Validate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Validate.cpp?rev=38394&r1=38393&r2=38394&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul  7 19:02:57 2007
@@ -296,7 +296,7 @@
 ValidateImpl::checkBooleanExpression(const Operator* op)
 {
   if (checkExpression(op))
-    if (!isa<BooleanType>(op->getType())) {
+    if (!op->typeis<BooleanType>()) {
       error(op,std::string("Expecting boolean expression but type '") +
         op->getType()->getName() + "' was found");
       return false;
@@ -963,7 +963,7 @@
         error(n,"AllocateOp's pointer type has no element type!");
     } else
       error(n,"AllocateOp's type must be a pointer type");
-    if (!llvm::isa<IntegerType>(n->getType())) 
+    if (!n->typeis<IntegerType>()) 
       error(n,"AllocateOp's operand must be of integer type");
   }
 }
@@ -1006,13 +1006,32 @@
         error(n,"Can't store to constant variable");
       else if (isa<AutoVarOp>(R) && cast<AutoVarOp>(R)->isConstant())
         error(n,"Can't store to constant automatic variable");
-    } else if (const IndexOp* ref = dyn_cast<IndexOp>(n)) {
+    } else if (const GetIndexOp* ref = dyn_cast<GetIndexOp>(n)) {
+      /// FIXME: Implement this
+    } else if (const GetFieldOp* ref = dyn_cast<GetFieldOp>(n)) {
       /// FIXME: Implement this
     }
   }
 }
 
 template<> inline void
+ValidateImpl::validate(GetIndexOp* n)
+{
+  if (checkOperator(n,GetIndexOpID,2)) {
+    // FIXME: Implement check for reference on first operand
+    // FIXME: Implement check for integer type on second operand
+  }
+}
+template<> inline void
+ValidateImpl::validate(GetFieldOp* n)
+{
+  if (checkOperator(n,GetFieldOpID,2)) {
+    // FIXME: Implement check for reference on first operand
+    // FIXME: Implement check for string type on second operand
+  }
+}
+
+template<> inline void
 ValidateImpl::validate(AutoVarOp* n)
 {
   if (checkOperator(n,AutoVarOpID,0,false)) {
@@ -1632,6 +1651,8 @@
     case SwitchOpID:             validate(cast<SwitchOp>(n)); break;
     case LoadOpID:               validate(cast<LoadOp>(n)); break;
     case StoreOpID:              validate(cast<StoreOp>(n)); break;
+    case GetIndexOpID:           validate(cast<GetIndexOp>(n)); break;
+    case GetFieldOpID:           validate(cast<GetFieldOp>(n)); break;
     case AllocateOpID:           validate(cast<AllocateOp>(n)); break;
     case DeallocateOpID:         validate(cast<DeallocateOp>(n)); break;
     case ReallocateOpID:         /*validate(cast<ReallocateOp>(n));*/ break;

Modified: hlvm/trunk/hlvm/Reader/HLVM.rng
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/HLVM.rng?rev=38394&r1=38393&r2=38394&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/HLVM.rng Sat Jul  7 19:02:57 2007
@@ -711,7 +711,8 @@
 
   <define name="ConstantExpression.pat">
     <choice>
-      <ref name="index.elem"/>
+      <ref name="getfld.elem"/>
+      <ref name="getidx.elem"/>
       <ref name="cast.elem"/>
       <ref name="select.elem"/>
       <ref name="sizeof.elem"/>
@@ -760,7 +761,8 @@
   <define name="Location.pat">
     <choice>
       <ref name="ref.elem"/>
-      <ref name="index.elem"/>
+      <ref name="getfld.elem"/>
+      <ref name="getidx.elem"/>
     </choice>
   </define>
 
@@ -816,7 +818,8 @@
     <choice>
       <ref name="load.elem"/>
       <ref name="store.elem"/>
-      <ref name="index.elem"/>
+      <ref name="getfld.elem"/>
+      <ref name="getidx.elem"/>
       <ref name="length.elem"/>
       <ref name="autovar.elem"/>
       <ref name="ref.elem"/>
@@ -845,13 +848,19 @@
     </element>
   </define>
 
-  <define name="index.elem">
-    <element name="index">
+  <define name="getfld.elem">
+    <element name="getfld">
       <ref name="Documentation.pat"/>
+      <ref name="Location.pat"/>
+      <ref name="Operators.pat"/>
+    </element>
+  </define>
+
+  <define name="getidx.elem">
+    <element name="getidx">
+      <ref name="Documentation.pat"/>
+      <ref name="Location.pat"/>
       <ref name="Operators.pat"/>
-      <oneOrMore>
-        <ref name="Operators.pat"/>
-      </oneOrMore>
     </element>
   </define>
 

Modified: hlvm/trunk/hlvm/Reader/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XMLReader.cpp?rev=38394&r1=38393&r2=38394&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul  7 19:02:57 2007
@@ -1294,6 +1294,8 @@
       case TKN_call:         op = parseMultiOp<CallOp>(cur); break;
       case TKN_store:        op = parseBinaryOp<StoreOp>(cur); break;
       case TKN_load:         op = parseUnaryOp<LoadOp>(cur); break;
+      case TKN_getidx:       op = parseBinaryOp<GetIndexOp>(cur); break;
+      case TKN_getfld:       op = parseBinaryOp<GetFieldOp>(cur); break;
       case TKN_open:         op = parseUnaryOp<OpenOp>(cur); break;
       case TKN_write:        op = parseBinaryOp<WriteOp>(cur); break;
       case TKN_close:        op = parseUnaryOp<CloseOp>(cur); break;

Modified: hlvm/trunk/hlvm/Writer/XMLWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Writer/XMLWriter.cpp?rev=38394&r1=38393&r2=38394&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Writer/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XMLWriter.cpp Sat Jul  7 19:02:57 2007
@@ -979,6 +979,20 @@
 }
 
 template<> void 
+XMLWriterImpl::WriterPass::put(const GetFieldOp* r)
+{
+  startElement("getfld");
+  putDoc(r);
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put(const GetIndexOp* r)
+{
+  startElement("getidx");
+  putDoc(r);
+}
+
+template<> void 
 XMLWriterImpl::WriterPass::put(const LoadOp* r)
 {
   startElement("load");
@@ -1118,6 +1132,8 @@
       case ResultOpID:             put(cast<ResultOp>(n)); break;
       case CallOpID:               put(cast<CallOp>(n)); break;
       case StoreOpID:              put(cast<StoreOp>(n)); break;
+      case GetFieldOpID:           put(cast<GetFieldOp>(n)); break;
+      case GetIndexOpID:           put(cast<GetIndexOp>(n)); break;
       case LoadOpID:               put(cast<LoadOp>(n)); break;
       case ReferenceOpID:          put(cast<ReferenceOp>(n)); break;
       case OpenOpID:               put(cast<OpenOp>(n)); break;





More information about the llvm-commits mailing list