Commit 58b0a3b4 authored by Pawel Wodnicki's avatar Pawel Wodnicki
Browse files

Merging r168354: into 3.2 release branch

Make the AttrListPtr object a part of the LLVMContext.

When code deletes the context, the AttributeImpls that the AttrListPtr points to
are now invalid. Therefore, instead of keeping a separate managed static for the
AttrListPtrs that's reference counted, move it into the LLVMContext and delete
it when deleting the AttributeImpls.

llvm-svn: 168486
parent 64b1fc8f
Loading
Loading
Loading
Loading
+10 −12
Original line number Diff line number Diff line
@@ -318,21 +318,26 @@ public:
    FunctionIndex = ~0U
  };
private:
  /// AttrList - The attributes that we are managing.  This can be null to
  /// represent the empty attributes list.
  /// @brief The attributes that we are managing.  This can be null to represent
  /// the empty attributes list.
  AttributeListImpl *AttrList;

  /// @brief The attributes for the specified index are returned.  Attributes
  /// for the result are denoted with Idx = 0.
  Attributes getAttributes(unsigned Idx) const;

  explicit AttrListPtr(AttributeListImpl *LI) : AttrList(LI) {}
public:
  AttrListPtr() : AttrList(0) {}
  AttrListPtr(const AttrListPtr &P);
  AttrListPtr(const AttrListPtr &P) : AttrList(P.AttrList) {}
  const AttrListPtr &operator=(const AttrListPtr &RHS);
  ~AttrListPtr();

  //===--------------------------------------------------------------------===//
  // Attribute List Construction and Mutation
  //===--------------------------------------------------------------------===//

  /// get - Return a Attributes list with the specified parameters in it.
  static AttrListPtr get(ArrayRef<AttributeWithIndex> Attrs);
  static AttrListPtr get(LLVMContext &C, ArrayRef<AttributeWithIndex> Attrs);

  /// addAttr - Add the specified attribute at the specified index to this
  /// attribute list.  Since attribute lists are immutable, this
@@ -419,13 +424,6 @@ public:
  const AttributeWithIndex &getSlot(unsigned Slot) const;

  void dump() const;

private:
  explicit AttrListPtr(AttributeListImpl *L);

  /// getAttributes - The attributes for the specified index are
  /// returned.  Attributes for the result are denoted with Idx = 0.
  Attributes getAttributes(unsigned Idx) const;
};

} // End llvm namespace
+3 −3
Original line number Diff line number Diff line
@@ -2794,7 +2794,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
                              Attributes::get(RetType->getContext(),
                                              FuncAttrs)));

  AttrListPtr PAL = AttrListPtr::get(Attrs);
  AttrListPtr PAL = AttrListPtr::get(Context, Attrs);

  if (PAL.getParamAttributes(1).hasAttribute(Attributes::StructRet) &&
      !RetType->isVoidTy())
@@ -3351,7 +3351,7 @@ bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
                                              FnAttrs)));

  // Finish off the Attributes and check them
  AttrListPtr PAL = AttrListPtr::get(Attrs);
  AttrListPtr PAL = AttrListPtr::get(Context, Attrs);

  InvokeInst *II = InvokeInst::Create(Callee, NormalBB, UnwindBB, Args);
  II->setCallingConv(CC);
@@ -3753,7 +3753,7 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
                                              FnAttrs)));

  // Finish off the Attributes and check them
  AttrListPtr PAL = AttrListPtr::get(Attrs);
  AttrListPtr PAL = AttrListPtr::get(Context, Attrs);

  CallInst *CI = CallInst::Create(Callee, Args);
  CI->setTailCall(isTail);
+1 −1
Original line number Diff line number Diff line
@@ -487,7 +487,7 @@ bool BitcodeReader::ParseAttributeBlock() {
                                                  Attributes::get(Context, B)));
      }

      MAttributes.push_back(AttrListPtr::get(Attrs));
      MAttributes.push_back(AttrListPtr::get(Context, Attrs));
      Attrs.clear();
      break;
    }
+5 −3
Original line number Diff line number Diff line
@@ -611,7 +611,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
  
  // Recompute the parameter attributes list based on the new arguments for
  // the function.
  NF->setAttributes(AttrListPtr::get(AttributesVec));
  NF->setAttributes(AttrListPtr::get(F->getContext(), AttributesVec));
  AttributesVec.clear();

  F->getParent()->getFunctionList().insert(F, NF);
@@ -731,11 +731,13 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
      New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
                               Args, "", Call);
      cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
      cast<InvokeInst>(New)->setAttributes(AttrListPtr::get(AttributesVec));
      cast<InvokeInst>(New)->setAttributes(AttrListPtr::get(II->getContext(),
                                                            AttributesVec));
    } else {
      New = CallInst::Create(NF, Args, "", Call);
      cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
      cast<CallInst>(New)->setAttributes(AttrListPtr::get(AttributesVec));
      cast<CallInst>(New)->setAttributes(AttrListPtr::get(New->getContext(),
                                                          AttributesVec));
      if (cast<CallInst>(Call)->isTailCall())
        cast<CallInst>(New)->setTailCall();
    }
+3 −3
Original line number Diff line number Diff line
@@ -280,7 +280,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
      if (FnAttrs.hasAttributes())
        AttributesVec.push_back(AttributeWithIndex::get(AttrListPtr::FunctionIndex,
                                                        FnAttrs));
      PAL = AttrListPtr::get(AttributesVec);
      PAL = AttrListPtr::get(Fn.getContext(), AttributesVec);
    }

    Instruction *New;
@@ -806,7 +806,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
                                                    FnAttrs));

  // Reconstruct the AttributesList based on the vector we constructed.
  AttrListPtr NewPAL = AttrListPtr::get(AttributesVec);
  AttrListPtr NewPAL = AttrListPtr::get(F->getContext(), AttributesVec);

  // Create the new function type based on the recomputed parameters.
  FunctionType *NFTy = FunctionType::get(NRetTy, Params, FTy->isVarArg());
@@ -874,7 +874,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
                                                      FnAttrs));

    // Reconstruct the AttributesList based on the vector we constructed.
    AttrListPtr NewCallPAL = AttrListPtr::get(AttributesVec);
    AttrListPtr NewCallPAL = AttrListPtr::get(F->getContext(), AttributesVec);

    Instruction *New;
    if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
Loading