diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2014-11-24 09:08:18 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2014-11-24 09:08:18 +0000 | 
| commit | 5ca98fd98791947eba83a1ed3f2c8191ef7afa6c (patch) | |
| tree | f5944309621cee4fe0976be6f9ac619b7ebfc4c2 /lib/Bitcode/Writer/ValueEnumerator.cpp | |
| parent | 68bcb7db193e4bc81430063148253d30a791023e (diff) | |
Notes
Diffstat (limited to 'lib/Bitcode/Writer/ValueEnumerator.cpp')
| -rw-r--r-- | lib/Bitcode/Writer/ValueEnumerator.cpp | 80 | 
1 files changed, 38 insertions, 42 deletions
diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index a1641043b22aa..15f8034a36911 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -73,37 +73,34 @@ ValueEnumerator::ValueEnumerator(const Module *M) {    SmallVector<std::pair<unsigned, MDNode*>, 8> MDs;    // Enumerate types used by function bodies and argument lists. -  for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { - -    for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); -         I != E; ++I) -      EnumerateType(I->getType()); - -    for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB) -      for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){ -        for (User::const_op_iterator OI = I->op_begin(), E = I->op_end(); -             OI != E; ++OI) { -          if (MDNode *MD = dyn_cast<MDNode>(*OI)) +  for (const Function &F : *M) { +    for (const Argument &A : F.args()) +      EnumerateType(A.getType()); + +    for (const BasicBlock &BB : F) +      for (const Instruction &I : BB) { +        for (const Use &Op : I.operands()) { +          if (MDNode *MD = dyn_cast<MDNode>(&Op))              if (MD->isFunctionLocal() && MD->getFunction())                // These will get enumerated during function-incorporation.                continue; -          EnumerateOperandType(*OI); +          EnumerateOperandType(Op);          } -        EnumerateType(I->getType()); -        if (const CallInst *CI = dyn_cast<CallInst>(I)) +        EnumerateType(I.getType()); +        if (const CallInst *CI = dyn_cast<CallInst>(&I))            EnumerateAttributes(CI->getAttributes()); -        else if (const InvokeInst *II = dyn_cast<InvokeInst>(I)) +        else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I))            EnumerateAttributes(II->getAttributes());          // Enumerate metadata attached with this instruction.          MDs.clear(); -        I->getAllMetadataOtherThanDebugLoc(MDs); +        I.getAllMetadataOtherThanDebugLoc(MDs);          for (unsigned i = 0, e = MDs.size(); i != e; ++i)            EnumerateMetadata(MDs[i].second); -        if (!I->getDebugLoc().isUnknown()) { +        if (!I.getDebugLoc().isUnknown()) {            MDNode *Scope, *IA; -          I->getDebugLoc().getScopeAndInlinedAt(Scope, IA, I->getContext()); +          I.getDebugLoc().getScopeAndInlinedAt(Scope, IA, I.getContext());            if (Scope) EnumerateMetadata(Scope);            if (IA) EnumerateMetadata(IA);          } @@ -120,6 +117,12 @@ unsigned ValueEnumerator::getInstructionID(const Instruction *Inst) const {    return I->second;  } +unsigned ValueEnumerator::getComdatID(const Comdat *C) const { +  unsigned ComdatID = Comdats.idFor(C); +  assert(ComdatID && "Comdat not found!"); +  return ComdatID; +} +  void ValueEnumerator::setInstructionID(const Instruction *I) {    InstructionMap[I] = InstructionCount++;  } @@ -159,12 +162,11 @@ void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,      V->dump();      OS << " Uses(" << std::distance(V->use_begin(),V->use_end()) << "):"; -    for (Value::const_use_iterator UI = V->use_begin(), UE = V->use_end(); -         UI != UE; ++UI) { -      if (UI != V->use_begin()) +    for (const Use &U : V->uses()) { +      if (&U != &*V->use_begin())          OS << ","; -      if((*UI)->hasName()) -        OS << " " << (*UI)->getName(); +      if(U->hasName()) +        OS << " " << U->getName();        else          OS << " [null]"; @@ -173,29 +175,19 @@ void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,    }  } -// Optimize constant ordering. -namespace { -  struct CstSortPredicate { -    ValueEnumerator &VE; -    explicit CstSortPredicate(ValueEnumerator &ve) : VE(ve) {} -    bool operator()(const std::pair<const Value*, unsigned> &LHS, -                    const std::pair<const Value*, unsigned> &RHS) { -      // Sort by plane. -      if (LHS.first->getType() != RHS.first->getType()) -        return VE.getTypeID(LHS.first->getType()) < -               VE.getTypeID(RHS.first->getType()); -      // Then by frequency. -      return LHS.second > RHS.second; -    } -  }; -} -  /// OptimizeConstants - Reorder constant pool for denser encoding.  void ValueEnumerator::OptimizeConstants(unsigned CstStart, unsigned CstEnd) {    if (CstStart == CstEnd || CstStart+1 == CstEnd) return; -  CstSortPredicate P(*this); -  std::stable_sort(Values.begin()+CstStart, Values.begin()+CstEnd, P); +  std::stable_sort(Values.begin() + CstStart, Values.begin() + CstEnd, +                   [this](const std::pair<const Value *, unsigned> &LHS, +                          const std::pair<const Value *, unsigned> &RHS) { +    // Sort by plane. +    if (LHS.first->getType() != RHS.first->getType()) +      return getTypeID(LHS.first->getType()) < getTypeID(RHS.first->getType()); +    // Then by frequency. +    return LHS.second > RHS.second; +  });    // Ensure that integer and vector of integer constants are at the start of the    // constant pool.  This is important so that GEP structure indices come before @@ -321,6 +313,10 @@ void ValueEnumerator::EnumerateValue(const Value *V) {      return;    } +  if (auto *GO = dyn_cast<GlobalObject>(V)) +    if (const Comdat *C = GO->getComdat()) +      Comdats.insert(C); +    // Enumerate the type of this value.    EnumerateType(V->getType());  | 
