Merge the contents from exception-handling-rewrite to the mainline.

This adds the new instructions 'landingpad' and 'resume'.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136253 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 76771c2..547abfe 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -2885,6 +2885,7 @@
   case lltok::kw_switch:      return ParseSwitch(Inst, PFS);
   case lltok::kw_indirectbr:  return ParseIndirectBr(Inst, PFS);
   case lltok::kw_invoke:      return ParseInvoke(Inst, PFS);
+  case lltok::kw_resume:      return ParseResume(Inst, PFS);
   // Binary Operators.
   case lltok::kw_add:
   case lltok::kw_sub:
@@ -2944,6 +2945,7 @@
   case lltok::kw_insertelement:  return ParseInsertElement(Inst, PFS);
   case lltok::kw_shufflevector:  return ParseShuffleVector(Inst, PFS);
   case lltok::kw_phi:            return ParsePHI(Inst, PFS);
+  case lltok::kw_landingpad:     return ParseLandingPad(Inst, PFS);
   case lltok::kw_call:           return ParseCall(Inst, PFS, false);
   case lltok::kw_tail:           return ParseCall(Inst, PFS, true);
   // Memory.
@@ -3247,7 +3249,18 @@
   return false;
 }
 
+/// ParseResume
+///   ::= 'resume' TypeAndValue
+bool LLParser::ParseResume(Instruction *&Inst, PerFunctionState &PFS) {
+  Value *Exn; LocTy ExnLoc;
+  LocTy Loc = Lex.getLoc();
+  if (ParseTypeAndValue(Exn, ExnLoc, PFS))
+    return true;
 
+  ResumeInst *RI = ResumeInst::Create(Context, Exn);
+  Inst = RI;
+  return false;
+}
 
 //===----------------------------------------------------------------------===//
 // Binary Operators.
@@ -3495,6 +3508,56 @@
   return AteExtraComma ? InstExtraComma : InstNormal;
 }
 
+/// ParseLandingPad
+///   ::= 'landingpad' Type 'personality' TypeAndValue 'cleanup'?
+///       (ClauseID ClauseList)+
+/// ClauseID
+///   ::= 'catch'
+///   ::= 'filter'
+/// ClauseList
+///   ::= TypeAndValue (',' TypeAndValue)*
+bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {
+  Type *Ty = 0; LocTy TyLoc;
+  Value *PersFn; LocTy PersFnLoc;
+  LocTy LPLoc = Lex.getLoc();
+
+  if (ParseType(Ty, TyLoc) ||
+      ParseToken(lltok::kw_personality, "expected 'personality'") ||
+      ParseTypeAndValue(PersFn, PersFnLoc, PFS))
+    return true;
+
+  bool IsCleanup = EatIfPresent(lltok::kw_cleanup);
+
+  SmallVector<std::pair<LandingPadInst::ClauseType, Value*>, 16> Clauses;
+  while (Lex.getKind() == lltok::kw_catch || Lex.getKind() == lltok::kw_filter){
+    LandingPadInst::ClauseType CT;
+    if (Lex.getKind() == lltok::kw_catch) {
+      CT = LandingPadInst::Catch;
+      ParseToken(lltok::kw_catch, "expected 'catch'");
+    } else {
+      CT = LandingPadInst::Filter;
+      ParseToken(lltok::kw_filter, "expected 'filter'");
+    }
+
+    do {
+      Value *V; LocTy VLoc;
+      if (ParseTypeAndValue(V, VLoc, PFS))
+        return true;
+      Clauses.push_back(std::make_pair(CT, V));
+    } while (EatIfPresent(lltok::comma));
+  }
+
+  LandingPadInst *LP = LandingPadInst::Create(Ty, PersFn, Clauses.size());
+  LP->setCleanup(IsCleanup);
+
+  for (SmallVectorImpl<std::pair<LandingPadInst::ClauseType, Value*> >::iterator
+         I = Clauses.begin(), E = Clauses.end(); I != E; ++I)
+    LP->addClause(I->first, I->second);
+
+  Inst = LP;
+  return false;
+}
+
 /// ParseCall
 ///   ::= 'tail'? 'call' OptionalCallingConv OptionalAttrs Type Value
 ///       ParameterList OptionalAttrs