[llvm-commits] [hlvm] r38359 - in /hlvm/trunk: hlvm/AST/AST.cpp hlvm/AST/AST.h hlvm/AST/Bundle.cpp hlvm/AST/MemoryOps.h hlvm/Pass/Validate.cpp hlvm/Reader/XMLReader.cpp tools/hlvm-gentestcase/Generate.cpp

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


Author: reid
Date: Sat Jul  7 19:02:38 2007
New Revision: 38359

URL: http://llvm.org/viewvc/llvm-project?rev=38359&view=rev
Log:
Do not alter ReferenceOp type to be pointer type. The need to do this is purely
a code generation detail and not something expressible in the HLVM tree. When a
value is referenced with the ReferenceOp, the type is the same as the type of
the referent, not a pointer to the referent.

Modified:
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/Bundle.cpp
    hlvm/trunk/hlvm/AST/MemoryOps.h
    hlvm/trunk/hlvm/Pass/Validate.cpp
    hlvm/trunk/hlvm/Reader/XMLReader.cpp
    hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 19:02:38 2007
@@ -631,6 +631,7 @@
 ConstantPointer* 
 AST::new_ConstantPointer(
   const std::string& name,
+  const Type* Ty,
   Constant* referent,
   const Locator* loc
 )
@@ -638,7 +639,7 @@
   ConstantPointer* result = new ConstantPointer(referent);
   result->setLocator(loc);
   result->setName(name);
-  result->setType( getPointerTo(referent->getType()) );
+  result->setType(Ty);
   return result;
 }
 
@@ -822,11 +823,9 @@
   hlvmAssert(V != 0 && "ReferenceOp must have a Value to reference");
   ReferenceOp* result = new ReferenceOp();
   const Type* refType = V->getType();
-  if (llvm::isa<ConstantValue>(V) || llvm::isa<Argument>(V)) {
+  if (llvm::isa<Constant>(V) || llvm::isa<Argument>(V) ||
+      llvm::isa<AutoVarOp>(V)) {
     result->setType(refType);
-  } else if (llvm::isa<AutoVarOp>(V) || llvm::isa<Constant>(V)) {
-    PointerType* PT = getPointerTo(refType);
-    result->setType(PT);
   } else {
     hlvmAssert(!"Invalid referent type");
   }
@@ -1242,22 +1241,13 @@
 // Memory Operators
 template StoreOp*  
 AST::new_BinaryOp<StoreOp>(const Type*, Operator*op1,Operator*op2,const Locator*loc);
-template<> StoreOp*  
-AST::new_BinaryOp<StoreOp>(Operator*op1,Operator*op2,const Locator*loc)
-{
-  return new_BinaryOp<StoreOp>(0,op1,op2,loc);
-}
+template StoreOp*  
+AST::new_BinaryOp<StoreOp>(Operator*op1,Operator*op2,const Locator*loc);
 
 template LoadOp*   
 AST::new_UnaryOp<LoadOp>(const Type* Ty, Operator*op1,const Locator*loc);
-template<> LoadOp*   
-AST::new_UnaryOp<LoadOp>(Operator*op1,const Locator*loc)
-{
-  hlvmAssert(llvm::isa<PointerType>(op1->getType()) && 
-      "LoadOp Requires PointerType operand");
-  const Type* Ty = llvm::cast<PointerType>(op1->getType())->getElementType();
-  return new_UnaryOp<LoadOp>(Ty, op1, loc);
-}
+template LoadOp*   
+AST::new_UnaryOp<LoadOp>(Operator*op1,const Locator*loc);
 
 // Input/Output Operators
 template OpenOp* 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 19:02:38 2007
@@ -483,6 +483,7 @@
     /// Create a new ConstantPointer node.
     ConstantPointer* new_ConstantPointer(
       const std::string& name,  ///< The name of the constant
+      const Type* type,         ///< The type of the constant pointer
       Constant* referent,       ///< The value pointed to
       const Locator* loc = 0    ///< The source locator
     );

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.cpp (original)
+++ hlvm/trunk/hlvm/AST/Bundle.cpp Sat Jul  7 19:02:38 2007
@@ -43,14 +43,14 @@
 Bundle::insertChild(Node* kid)
 {
   hlvmAssert(kid && "Null child!");
-  if (isa<Type>(kid))
-    types.insert(cast<Type>(kid)->getName(), cast<Type>(kid));
+  if (const Type* Ty = dyn_cast<Type>(kid))
+    types.insert(Ty->getName(), Ty);
   else if (Constant* C = dyn_cast<Constant>(kid)) {
     const std::string& name = C->getName();
     values.push_back(C);
-    if (isa<ConstantValue>(kid)) {
+    if (isa<ConstantValue>(C)) {
       cvals.insert(name, cast<ConstantValue>(kid));
-    } else if (isa<Linkable>(kid)) {
+    } else if (isa<Linkable>(C)) {
       linkables.insert(name, cast<Linkable>(kid));
     }
   } else
@@ -61,16 +61,16 @@
 Bundle::removeChild(Node* kid)
 {
   hlvmAssert(kid && "Null child!");
-  if (isa<Type>(kid))
-    types.erase(cast<Type>(kid)->getName());
-  else if (isa<Value>(kid)) {
+  if (const Type* Ty = dyn_cast<Type>(kid))
+    types.erase(Ty->getName());
+  else if (Constant* C = dyn_cast<Constant>(kid)) {
     // This is sucky slow, but we probably won't be removing nodes that much.
     for (value_iterator I = value_begin(), E = value_end(); I != E; ++I )
-      if (*I == kid) { values.erase(I); break; }
-    if (isa<ConstantValue>(kid))
-      cvals.erase(cast<ConstantValue>(kid)->getName());
-    else if (isa<Linkable>(kid))
-      linkables.erase(cast<Linkable>(kid)->getName());
+      if (*I == C) { values.erase(I); break; }
+    if (isa<ConstantValue>(C))
+      cvals.erase(cast<ConstantValue>(C)->getName());
+    else if (isa<Linkable>(C))
+      linkables.erase(cast<Linkable>(C)->getName());
   } else 
     hlvmAssert(!"That node isn't my child");
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/MemoryOps.h (original)
+++ hlvm/trunk/hlvm/AST/MemoryOps.h Sat Jul  7 19:02:38 2007
@@ -94,6 +94,7 @@
   /// @}
   friend class AST;
 };
+
 /// This class provides an Abstract Syntax Tree node that represents an operator
 /// for loading a value from a memory location. This operator takes a single
 /// operand which must resolve to the address of a memory location, either 
@@ -129,10 +130,10 @@
 };
 
 /// This class provides an Abstract Syntax Tree node that represents an operator
-/// for storing a a value into a memory location. The first operand 
+/// for storing a value into a memory location. The first operand 
 /// resolves to the storage location into which the value is stored. The second
-/// operand provides the value to store. The operator returns a void value.
-/// @brief AST Memory Store Operator
+/// operand provides the value to store. The operator returns the value stored.
+/// @brief AST Memory Set Operator
 class StoreOp : public BinaryOperator
 {
   /// @name Constructors

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

==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul  7 19:02:38 2007
@@ -425,25 +425,37 @@
 template<> inline void
 ValidateImpl::validate(ArrayType* n)
 {
-  checkUniformContainer(n, ArrayTypeID);
+  if (checkUniformContainer(n, ArrayTypeID)) {
+    if (n->getMaxSize() == 0)
+      error(n,"Array of 0 elements not permited");
+  }
 }
 
 template<> inline void
 ValidateImpl::validate(VectorType* n)
 {
-  checkUniformContainer(n, VectorTypeID);
+  if (checkUniformContainer(n, VectorTypeID)) {
+    if (n->getSize() == 0)
+      error(n,"Vector of 0 elements not permited");
+  }
 }
 
 template<> inline void
 ValidateImpl::validate(StructureType* n)
 {
-  checkDisparateContainer(n, StructureTypeID);
+  if (checkDisparateContainer(n, StructureTypeID)) {
+    if (n->size() == 0)
+      error(n,"Structure of 0 fields not permited");
+  }
 }
 
 template<> inline void
 ValidateImpl::validate(ContinuationType* n)
 {
-  checkDisparateContainer(n, ContinuationTypeID);
+  if (checkDisparateContainer(n, ContinuationTypeID)) {
+    if (n->size() == 0)
+      error(n,"Continuation of 0 fields not permited");
+  }
 }
 
 template<> inline void
@@ -577,36 +589,101 @@
 template<> inline void
 ValidateImpl::validate(ConstantPointer* n)
 {
-  checkConstant(n,ConstantPointerID);
-  // FIXME: validate fields vs. type
+  if (checkConstant(n,ConstantPointerID)) {
+    if (const PointerType* PT = dyn_cast<PointerType>(n->getType()))
+      if (PT->getElementType() != n->getValue()->getType())
+        error(n,"ConstantPointer referent does not match pointer type");
+    else 
+      error(n,"ConstantPointer must have pointer type");
+  }
 }
 
 template<> inline void
 ValidateImpl::validate(ConstantArray* n)
 {
-  checkConstant(n,ConstantArrayID);
-  // FIXME: validate fields vs. type
+  if (checkConstant(n,ConstantArrayID)) {
+    if (const ArrayType* AT = dyn_cast<ArrayType>(n->getType())) {
+      if (n->size() > AT->getMaxSize())
+        error(n,"Too many elements (" + utostr(n->size()) + ") for array "
+                "of size " + utostr(AT->getMaxSize()));
+      else if (n->size() == 0)
+        error(n,"Zero sized ConstantArray is not permited");
+      for (ConstantArray::iterator I = n->begin(), E = n->end(); I != E; ++I)
+        if ((*I)->getType() != AT->getElementType())
+          error(n,"Element #" + utostr(I-n->begin()) + "of type '" + 
+                   (*I)->getType()->getName() + "' does not conform to array "+
+                   "element type (" + AT->getElementType()->getName() + ")");
+    } else
+      error(n,"ConstantArray must have array type");
+  }
 }
 
 template<> inline void
 ValidateImpl::validate(ConstantVector* n)
 {
-  checkConstant(n,ConstantVectorID);
-  // FIXME: validate fields vs. type
+  if (checkConstant(n,ConstantVectorID)) {
+    if (const VectorType* VT = dyn_cast<VectorType>(n->getType())) {
+      if (n->size() != VT->getSize())
+        error(n,"Too " + 
+          (n->size() < VT->getSize() ? std::string("few") :
+           std::string("many")) + " elements (" + utostr(n->size()) + 
+            ") for array of size " + utostr(VT->getSize()));
+      for (ConstantArray::iterator I = n->begin(), E = n->end(); I != E; ++I)
+        if ((*I)->getType() != VT->getElementType())
+          error(n,"Element #" + utostr(I-n->begin()) + "of type '" + 
+                   (*I)->getType()->getName() + "' does not conform to vector "+
+                   "element type (" + VT->getElementType()->getName() + ")");
+    } else
+      error(n,"ConstantVector must have vector type");
+  }
 }
 
 template<> inline void
 ValidateImpl::validate(ConstantStructure* n)
 {
-  checkConstant(n,ConstantStructureID);
-  // FIXME: validate fields vs. type
+  if (checkConstant(n,ConstantStructureID)) {
+    if (const StructureType* ST = dyn_cast<StructureType>(n->getType())) {
+      if (n->size() != ST->size())
+        error(n,"Too " + 
+          (n->size() < ST->size() ? std::string("few") :
+          std::string("many")) + " elements (" + utostr(n->size()) + 
+          ") for structure with " + utostr(ST->size()) + " fields");
+      StructureType::const_iterator STI = ST->begin();
+      for (ConstantStructure::iterator I = n->begin(), E = n->end(); 
+           I != E; ++I) {
+        if ((*I)->getType() != (*STI)->getType())
+          error(n,"Field #" + utostr(I-n->begin()) + " of type '" 
+              + (*I)->getType()->getName() + 
+              "' does not conform to type of structure field (" + 
+              (*STI)->getName() + ") of type '" + (*STI)->getType()->getName());
+      }
+    } else
+      error(n,"ConstantStructure must have structure type");
+  }
 }
 
 template<> inline void
 ValidateImpl::validate(ConstantContinuation* n)
 {
-  checkConstant(n,ConstantContinuationID);
-  // FIXME: validate fields vs. type
+  if (checkConstant(n,ConstantContinuationID)) {
+    if (const ContinuationType* CT = dyn_cast<ContinuationType>(n->getType())) {
+      if (n->size() != CT->size())
+        error(n,"Too " + 
+          (n->size() < CT->size() ? std::string("few") :
+          std::string("many")) + " elements (" + utostr(n->size()) + 
+          ") for continuation with " + utostr(CT->size()) + " fields");
+      ContinuationType::const_iterator CTI = CT->begin();
+      for (ConstantContinuation::iterator I = n->begin(), E = n->end(); 
+           I != E; ++I) {
+        if ((*I)->getType() != (*CTI)->getType())
+          error(n,"Field #" + utostr(I-n->begin()) + "of type '" 
+              + (*I)->getType()->getName() + 
+              "' does not conform to type of continuation field (" + 
+              (*CTI)->getName() + ") of type '" + (*CTI)->getType()->getName());
+      }
+    } else
+      error(n,"ConstantContinuation must have continuation type");
+  }
 }
 
 template<> inline void
@@ -876,10 +953,9 @@
 ValidateImpl::validate(LoadOp* n)
 {
   if (checkOperator(n,LoadOpID,1)) {
-    const Type* Ty = n->getOperand(0)->getType();
-    if (!isa<PointerType>(Ty))
-      error(n,"LoadOp expects a pointer type operand");
-    else if (n->getType() != cast<PointerType>(Ty)->getElementType())
+    const Type* Ty1 = n->getOperand(0)->getType();
+    const Type* Ty2 = n->getType();
+    if (Ty1 != Ty2)
       error(n,"LoadOp type and operand type do not agree");
   }
 }
@@ -890,9 +966,7 @@
   if (checkOperator(n,StoreOpID,2)) {
     const Type* Ty1 = n->getOperand(0)->getType();
     const Type* Ty2 = n->getOperand(1)->getType();
-    if (!isa<PointerType>(Ty1))
-      error(n,"StoreOp expects first operand to be pointer type");
-    else if (cast<PointerType>(Ty1)->getElementType() != Ty2) {
+    if (Ty1 != Ty2) {
       error(n,"StoreOp operands do not agree in type");
     } else if (const ReferenceOp* ref = 
                dyn_cast<ReferenceOp>(n->getOperand(0))) {

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

==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul  7 19:02:38 2007
@@ -378,7 +378,7 @@
   isError = true;
 }
 
-Type* 
+Type*
 XMLReaderImpl::getType(const std::string& name )
 {
   Type* Ty = recognize_builtin_type(ast,name);
@@ -493,7 +493,8 @@
       // Didn't find a constant? Try a linkable
       if (!referent)
         referent = bundle->find_linkable(id);
-      C = ast->new_ConstantPointer(name,referent,loc);
+      C = ast->new_ConstantPointer(
+        name,ast->getPointerTo(referent->getType()),referent,loc);
       break;
     }
     case TKN_arr:

Modified: hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp?rev=38359&r1=38358&r2=38359&view=diff

==============================================================================
--- hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp (original)
+++ hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp Sat Jul  7 19:02:38 2007
@@ -427,7 +427,7 @@
       const PointerType* PT = llvm::cast<PointerType>(Ty);
       const Type* referent = PT->getElementType();
       C = ast->new_ConstantPointer(
-          std::string("cptr_") + utostr(line),
+          std::string("cptr_") + utostr(line), referent,
           cast<ConstantValue>(genValue(referent,true)),loc);
       break;
     }





More information about the llvm-commits mailing list