[llvm-branch-commits] [llvm-branch] r135984 - in /llvm/branches/exception-handling-rewrite: include/llvm/Instruction.def include/llvm/Instructions.h include/llvm/Support/InstVisitor.h lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h lib/VMCore/Instructions.cpp

Bill Wendling isanbard at gmail.com
Mon Jul 25 15:03:09 PDT 2011


Author: void
Date: Mon Jul 25 17:03:09 2011
New Revision: 135984

URL: http://llvm.org/viewvc/llvm-project?rev=135984&view=rev
Log:
Initial rough-in for the LandingPadInstr.

The OperandList is a list of the Values it can catch. There is a private vector
that has an enum that's used to decrypt the Value. It's a bit inelegant, but was
done this way so that the clauses could "interleave." E.g., you could have a
catch-filter-catch sequence.

It doesn't have any functionality just yet.

Modified:
    llvm/branches/exception-handling-rewrite/include/llvm/Instruction.def
    llvm/branches/exception-handling-rewrite/include/llvm/Instructions.h
    llvm/branches/exception-handling-rewrite/include/llvm/Support/InstVisitor.h
    llvm/branches/exception-handling-rewrite/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    llvm/branches/exception-handling-rewrite/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
    llvm/branches/exception-handling-rewrite/lib/VMCore/Instructions.cpp

Modified: llvm/branches/exception-handling-rewrite/include/llvm/Instruction.def
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/include/llvm/Instruction.def?rev=135984&r1=135983&r2=135984&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/include/llvm/Instruction.def (original)
+++ llvm/branches/exception-handling-rewrite/include/llvm/Instruction.def Mon Jul 25 17:03:09 2011
@@ -168,8 +168,9 @@
 HANDLE_OTHER_INST(52, ShuffleVector, ShuffleVectorInst)  // shuffle two vectors.
 HANDLE_OTHER_INST(53, ExtractValue, ExtractValueInst)// extract from aggregate
 HANDLE_OTHER_INST(54, InsertValue, InsertValueInst)  // insert into aggregate
+HANDLE_OTHER_INST(55, LandingPad, LandingPadInst)  // Landing pad instruction.
 
-  LAST_OTHER_INST(54)
+  LAST_OTHER_INST(55)
 
 #undef  FIRST_TERM_INST
 #undef HANDLE_TERM_INST

Modified: llvm/branches/exception-handling-rewrite/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/include/llvm/Instructions.h?rev=135984&r1=135983&r2=135984&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/include/llvm/Instructions.h (original)
+++ llvm/branches/exception-handling-rewrite/include/llvm/Instructions.h Mon Jul 25 17:03:09 2011
@@ -1804,6 +1804,98 @@
 
 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
 
+//===----------------------------------------------------------------------===//
+//                           LandingPadInst Class
+//===----------------------------------------------------------------------===//
+
+class LandingPadInst : public Instruction {
+  /// ReservedSpace - The number of operands actually allocated.  NumOperands is
+  /// the number actually in use.
+  unsigned ReservedSpace;
+  LandingPadInst(const LandingPadInst &LP);
+public:
+  enum ClauseType { Catch, Filter };
+private:
+  /// ClauseIdxs - This indexes into the OperandList, indicating what the
+  /// values are at a given index.
+  SmallVector<ClauseType, 8> ClauseIdxs;
+
+  void *operator new(size_t, unsigned);  // DO NOT IMPLEMENT
+  // Allocate space for exactly zero operands.
+  void *operator new(size_t s) {
+    return User::operator new(s, 0);
+  }
+  void growOperands(unsigned Size);
+
+  explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
+                          const Twine &NameStr, Instruction *InsertBefore)
+    : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertBefore),
+      ReservedSpace(NumReservedValues) {
+    setName(NameStr);
+    OperandList = allocHungoffUses(ReservedSpace);
+  }
+  explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
+                          const Twine &NameStr, BasicBlock *InsertAtEnd)
+    : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertAtEnd),
+      ReservedSpace(NumReservedValues) {
+    setName(NameStr);
+    OperandList = allocHungoffUses(ReservedSpace);
+  }
+protected:
+  virtual LandingPadInst *clone_impl() const;
+public:
+  static LandingPadInst *Create(Type *RetTy, unsigned NumReservedValues,
+                                const Twine &NameStr = "",
+                                Instruction *InsertBefore = 0) {
+    return new LandingPadInst(RetTy, NumReservedValues, NameStr, InsertBefore);
+  }
+  static LandingPadInst *Create(Type *RetTy, unsigned NumReservedValues,
+                                const Twine &NameStr = "",
+                                BasicBlock *InsertAtEnd = 0) {
+    return new LandingPadInst(RetTy, NumReservedValues, NameStr, InsertAtEnd);
+  }
+  ~LandingPadInst();
+
+  /// Provide fast operand accessors
+  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
+  /// addCatchTypes - Add catch types to the landing pad.
+  void addCatchClauses(ArrayRef<Value*> Catches);
+
+  /// addCatchTypes - Add filter types to the landing pad.
+  void addFilterClauses(ArrayRef<Value*> Filters);
+
+  /// getClauseType - Return the type of the clause at this index. The two
+  /// supported clauses are Catch and Filter.
+  ClauseType getClauseType(unsigned I) const {
+    assert(I < ClauseIdxs.size() && "Index too large!");
+    return ClauseIdxs[I];
+  }
+
+  /// getClauseValue - Return the value of the clause at this index.
+  const Value *getClauseValue(unsigned I) const {
+    assert(I < getNumOperands() && "Index too large!");
+    return OperandList[I];
+  }
+
+  /// getNumClauses - Get the number of clauses for this landing pad.
+  unsigned getNumClauses() const { return getNumOperands(); }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const LandingPadInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return I->getOpcode() == Instruction::LandingPad;
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
+};
+
+template <>
+struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
 
 //===----------------------------------------------------------------------===//
 //                               ReturnInst Class

Modified: llvm/branches/exception-handling-rewrite/include/llvm/Support/InstVisitor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/include/llvm/Support/InstVisitor.h?rev=135984&r1=135983&r2=135984&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/include/llvm/Support/InstVisitor.h (original)
+++ llvm/branches/exception-handling-rewrite/include/llvm/Support/InstVisitor.h Mon Jul 25 17:03:09 2011
@@ -191,6 +191,7 @@
   RetTy visitShuffleVectorInst(ShuffleVectorInst &I) { DELEGATE(Instruction); }
   RetTy visitExtractValueInst(ExtractValueInst &I)  { DELEGATE(Instruction);}
   RetTy visitInsertValueInst(InsertValueInst &I)    { DELEGATE(Instruction); }
+  RetTy visitLandingPadInst(LandingPadInst &I)      { DELEGATE(Instruction); }
 
   // Next level propagators: If the user does not overload a specific
   // instruction type, they can overload one of these to get the whole class

Modified: llvm/branches/exception-handling-rewrite/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=135984&r1=135983&r2=135984&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Mon Jul 25 17:03:09 2011
@@ -914,6 +914,11 @@
   llvm_unreachable("SelectionDAGBuilder shouldn't visit PHI nodes!");
 }
 
+void SelectionDAGBuilder::visitLandingPad(const LandingPadInst &) {
+  // FIXME:
+  llvm_unreachable("SelectionDAGBuilder shouldn't visit LandingPad instrs!");
+}
+
 void SelectionDAGBuilder::visit(unsigned Opcode, const User &I) {
   // Note: this doesn't use InstVisitor, because it has to work with
   // ConstantExpr's in addition to instructions.

Modified: llvm/branches/exception-handling-rewrite/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h?rev=135984&r1=135983&r2=135984&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h (original)
+++ llvm/branches/exception-handling-rewrite/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h Mon Jul 25 17:03:09 2011
@@ -497,6 +497,7 @@
 
   void visitExtractValue(const ExtractValueInst &I);
   void visitInsertValue(const InsertValueInst &I);
+  void visitLandingPad(const LandingPadInst &I);
 
   void visitGetElementPtr(const User &I);
   void visitSelect(const User &I);

Modified: llvm/branches/exception-handling-rewrite/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/VMCore/Instructions.cpp?rev=135984&r1=135983&r2=135984&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/VMCore/Instructions.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/VMCore/Instructions.cpp Mon Jul 25 17:03:09 2011
@@ -166,6 +166,69 @@
   return ConstantValue;
 }
 
+//===----------------------------------------------------------------------===//
+//                       LandingPadInst Implementation
+//===----------------------------------------------------------------------===//
+
+LandingPadInst::LandingPadInst(const LandingPadInst &LP)
+  : Instruction(LP.getType(), Instruction::LandingPad,
+                allocHungoffUses(LP.getNumOperands()), LP.getNumOperands()),
+    ReservedSpace(LP.getNumOperands()) {
+  Use *OL = OperandList, *InOL = LP.OperandList;
+  for (unsigned I = 0, E = ReservedSpace; I != E; ++I)
+    OL[I] = InOL[I];
+
+  SubclassOptionalData = LP.SubclassOptionalData;
+}
+
+LandingPadInst::~LandingPadInst() {
+  dropHungoffUses();
+}
+
+/// growOperands - grow operands - This grows the operand list in response to a
+/// push_back style of operation. This grows the number of ops by 2 times.
+void LandingPadInst::growOperands(unsigned Size) {
+  unsigned e = getNumOperands();
+  ReservedSpace = (e + Size) * 2;
+
+  Use *NewOps = allocHungoffUses(ReservedSpace);
+  Use *OldOps = OperandList;
+  for (unsigned i = 0; i != e; ++i)
+      NewOps[i] = OldOps[i];
+
+  OperandList = NewOps;
+  Use::zap(OldOps, OldOps + e, true);
+}
+
+void LandingPadInst::addCatchClauses(ArrayRef<Value*> Catches) {
+  unsigned Size = Catches.size();
+  unsigned OpNo = getNumOperands();
+  if (OpNo + Size > ReservedSpace)
+    growOperands(Size);
+
+  assert(OpNo + Size - 1 < ReservedSpace && "Growing didn't work!");
+
+  unsigned Idx = OpNo;
+  for (unsigned I = 0; I < Size; ++I) {
+    ClauseIdxs.push_back(Catch);
+    OperandList[Idx++] = Catches[I];
+  }
+}
+
+void LandingPadInst::addFilterClauses(ArrayRef<Value*> Filters) {
+  unsigned Size = Filters.size();
+  unsigned OpNo = getNumOperands();
+  if (OpNo + Size > ReservedSpace)
+    growOperands(Size);
+
+  assert(OpNo + Size - 1 < ReservedSpace && "Growing didn't work!");
+
+  unsigned Idx = OpNo;
+  for (unsigned I = 0; I < Size; ++I) {
+    ClauseIdxs.push_back(Filter);
+    OperandList[Idx++] = Filters[I];
+  }
+}
 
 //===----------------------------------------------------------------------===//
 //                        CallInst Implementation
@@ -3155,6 +3218,10 @@
   return new PHINode(*this);
 }
 
+LandingPadInst *LandingPadInst::clone_impl() const {
+  return new LandingPadInst(*this);
+}
+
 ReturnInst *ReturnInst::clone_impl() const {
   return new(getNumOperands()) ReturnInst(*this);
 }





More information about the llvm-branch-commits mailing list