diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 | 
| commit | eb11fae6d08f479c0799db45860a98af528fa6e7 (patch) | |
| tree | 44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /lib/IR/Value.cpp | |
| parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) | |
Notes
Diffstat (limited to 'lib/IR/Value.cpp')
| -rw-r--r-- | lib/IR/Value.cpp | 61 | 
1 files changed, 23 insertions, 38 deletions
diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp index 163c785f5d762..295d6ecf0db03 100644 --- a/lib/IR/Value.cpp +++ b/lib/IR/Value.cpp @@ -39,6 +39,10 @@  using namespace llvm; +static cl::opt<unsigned> NonGlobalValueMaxNameSize( +    "non-global-value-max-name-size", cl::Hidden, cl::init(1024), +    cl::desc("Maximum size for the name of non-global values.")); +  //===----------------------------------------------------------------------===//  //                                Value Class  //===----------------------------------------------------------------------===// @@ -244,6 +248,11 @@ void Value::setNameImpl(const Twine &NewName) {    if (getName() == NameRef)      return; +  // Cap the size of non-GlobalValue names. +  if (NameRef.size() > NonGlobalValueMaxNameSize && !isa<GlobalValue>(this)) +    NameRef = +        NameRef.substr(0, std::max(1u, (unsigned)NonGlobalValueMaxNameSize)); +    assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");    // Get the symbol table to update for this object. @@ -456,41 +465,12 @@ void Value::replaceUsesOutsideBlock(Value *New, BasicBlock *BB) {    }  } -void Value::replaceUsesExceptBlockAddr(Value *New) { -  SmallSetVector<Constant *, 4> Constants; -  use_iterator UI = use_begin(), E = use_end(); -  for (; UI != E;) { -    Use &U = *UI; -    ++UI; - -    if (isa<BlockAddress>(U.getUser())) -      continue; - -    // Must handle Constants specially, we cannot call replaceUsesOfWith on a -    // constant because they are uniqued. -    if (auto *C = dyn_cast<Constant>(U.getUser())) { -      if (!isa<GlobalValue>(C)) { -        // Save unique users to avoid processing operand replacement -        // more than once. -        Constants.insert(C); -        continue; -      } -    } - -    U.set(New); -  } - -  // Process operand replacement of saved constants. -  for (auto *C : Constants) -    C->handleOperandChange(this, New); -} -  namespace {  // Various metrics for how much to strip off of pointers.  enum PointerStripKind {    PSK_ZeroIndices,    PSK_ZeroIndicesAndAliases, -  PSK_ZeroIndicesAndAliasesAndBarriers, +  PSK_ZeroIndicesAndAliasesAndInvariantGroups,    PSK_InBoundsConstantIndices,    PSK_InBounds  }; @@ -509,7 +489,7 @@ static const Value *stripPointerCastsAndOffsets(const Value *V) {      if (auto *GEP = dyn_cast<GEPOperator>(V)) {        switch (StripKind) {        case PSK_ZeroIndicesAndAliases: -      case PSK_ZeroIndicesAndAliasesAndBarriers: +      case PSK_ZeroIndicesAndAliasesAndInvariantGroups:        case PSK_ZeroIndices:          if (!GEP->hasAllZeroIndices())            return V; @@ -537,11 +517,12 @@ static const Value *stripPointerCastsAndOffsets(const Value *V) {            V = RV;            continue;          } -        // The result of invariant.group.barrier must alias it's argument, +        // The result of launder.invariant.group must alias it's argument,          // but it can't be marked with returned attribute, that's why it needs          // special case. -        if (StripKind == PSK_ZeroIndicesAndAliasesAndBarriers && -            CS.getIntrinsicID() == Intrinsic::invariant_group_barrier) { +        if (StripKind == PSK_ZeroIndicesAndAliasesAndInvariantGroups && +            (CS.getIntrinsicID() == Intrinsic::launder_invariant_group || +             CS.getIntrinsicID() == Intrinsic::strip_invariant_group)) {            V = CS.getArgOperand(0);            continue;          } @@ -567,8 +548,8 @@ const Value *Value::stripInBoundsConstantOffsets() const {    return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(this);  } -const Value *Value::stripPointerCastsAndBarriers() const { -  return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliasesAndBarriers>( +const Value *Value::stripPointerCastsAndInvariantGroups() const { +  return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliasesAndInvariantGroups>(        this);  } @@ -578,9 +559,9 @@ Value::stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,    if (!getType()->isPointerTy())      return this; -  assert(Offset.getBitWidth() == DL.getPointerSizeInBits(cast<PointerType>( +  assert(Offset.getBitWidth() == DL.getIndexSizeInBits(cast<PointerType>(                                       getType())->getAddressSpace()) && -         "The offset must have exactly as many bits as our pointer."); +         "The offset bit width does not match the DL specification.");    // Even though we don't look through PHI nodes, we could be called on an    // instruction in an unreachable block, which may be on a cycle. @@ -676,6 +657,10 @@ unsigned Value::getPointerAlignment(const DataLayout &DL) const {    unsigned Align = 0;    if (auto *GO = dyn_cast<GlobalObject>(this)) { +    // Don't make any assumptions about function pointer alignment. Some +    // targets use the LSBs to store additional information. +    if (isa<Function>(GO)) +      return 0;      Align = GO->getAlignment();      if (Align == 0) {        if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {  | 
