Don't barf on empty basic blocks. Do not rely on assert
[oota-llvm.git] / lib / VMCore / Function.cpp
index c10f8d75bd4730817836a1492d919e8fd406f4a3..3582b321504f1e19ef94639817116d3195d6c5b7 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/ParameterAttributes.h"
 #include "llvm/IntrinsicInst.h"
+#include "llvm/CodeGen/ValueTypes.h"
 #include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "SymbolTableListTraitsImpl.h"
@@ -90,9 +91,9 @@ std::string
 ParamAttrsList::getParamAttrsText(uint16_t Attrs) {
   std::string Result;
   if (Attrs & ParamAttr::ZExt)
-    Result += "zext ";
+    Result += "zeroext ";
   if (Attrs & ParamAttr::SExt)
-    Result += "sext ";
+    Result += "signext ";
   if (Attrs & ParamAttr::NoReturn)
     Result += "noreturn ";
   if (Attrs & ParamAttr::NoUnwind)
@@ -103,6 +104,10 @@ ParamAttrsList::getParamAttrsText(uint16_t Attrs) {
     Result += "noalias ";
   if (Attrs & ParamAttr::StructRet)
     Result += "sret ";  
+  if (Attrs & ParamAttr::ByVal)
+    Result += "byval ";
+  if (Attrs & ParamAttr::Nest)
+    Result += "nest ";
   return Result;
 }
 
@@ -119,6 +124,10 @@ static ManagedStatic<FoldingSet<ParamAttrsList> > ParamAttrsLists;
 ParamAttrsList *
 ParamAttrsList::get(const ParamAttrsVector &attrVec) {
   assert(!attrVec.empty() && "Illegal to create empty ParamAttrsList");
+#ifndef NDEBUG
+  for (unsigned i = 1, e = attrVec.size(); i < e; ++i)
+    assert(attrVec[i-1].index < attrVec[i].index && "Misordered ParamAttrsList!");
+#endif
   ParamAttrsList key(attrVec);
   FoldingSetNodeID ID;
   key.Profile(ID);
@@ -148,13 +157,10 @@ Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
   assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy)
          && "LLVM functions cannot return aggregate values!");
 
-  // Create the arguments vector, all arguments start out unnamed.
-  for (unsigned i = 0, e = Ty->getNumParams(); i != e; ++i) {
-    assert(Ty->getParamType(i) != Type::VoidTy &&
-           "Cannot have void typed arguments!");
-    ArgumentList.push_back(new Argument(Ty->getParamType(i)));
-  }
-
+  // If the function has arguments, mark them as lazily built.
+  if (Ty->getNumParams())
+    SubclassData = 1;   // Set the "has lazy arguments" bit.
+  
   // Make sure that we get added to a function
   LeakDetector::addGarbageObject(this);
 
@@ -174,6 +180,26 @@ Function::~Function() {
     ParamAttrs->dropRef();
 }
 
+void Function::BuildLazyArguments() const {
+  // Create the arguments vector, all arguments start out unnamed.
+  const FunctionType *FT = getFunctionType();
+  for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
+    assert(FT->getParamType(i) != Type::VoidTy &&
+           "Cannot have void typed arguments!");
+    ArgumentList.push_back(new Argument(FT->getParamType(i)));
+  }
+  
+  // Clear the lazy arguments bit.
+  const_cast<Function*>(this)->SubclassData &= ~1;
+}
+
+size_t Function::arg_size() const {
+  return getFunctionType()->getNumParams();
+}
+bool Function::arg_empty() const {
+  return getFunctionType()->getNumParams() == 0;
+}
+
 void Function::setParent(Module *parent) {
   if (getParent())
     LeakDetector::addGarbageObject(this);
@@ -266,7 +292,7 @@ std::string Intrinsic::getName(ID id, const Type **Tys, unsigned numTys) {
   std::string Result(Table[id]);
   for (unsigned i = 0; i < numTys; ++i) 
     if (Tys[i])
-      Result += "." + Tys[i]->getDescription();
+      Result += "." + MVT::getValueTypeString(MVT::getValueType(Tys[i]));
   return Result;
 }