diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/StackColoring.cpp | 16 | ||||
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 64 |
2 files changed, 16 insertions, 64 deletions
diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp index 505d6fd8896..3541b33a844 100644 --- a/llvm/lib/CodeGen/StackColoring.cpp +++ b/llvm/lib/CodeGen/StackColoring.cpp @@ -21,6 +21,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/CodeGen/Passes.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/PostOrderIterator.h" @@ -39,7 +40,6 @@ #include "llvm/CodeGen/MachineMemOperand.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h" -#include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/PseudoSourceValue.h" #include "llvm/CodeGen/SlotIndexes.h" #include "llvm/CodeGen/StackProtector.h" @@ -47,7 +47,6 @@ #include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" -#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" @@ -495,21 +494,10 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) { // upcoming replacement. SP->adjustForColoring(From, To); - // The new alloca might not be valid in a llvm.dbg.declare for this - // variable, so undef out the use to make the verifier happy. - AllocaInst *FromAI = const_cast<AllocaInst *>(From); - if (FromAI->isUsedByMetadata()) - ValueAsMetadata::handleRAUW(FromAI, UndefValue::get(FromAI->getType())); - for (auto &Use : FromAI->uses()) { - if (BitCastInst *BCI = dyn_cast<BitCastInst>(Use.get())) - if (BCI->isUsedByMetadata()) - ValueAsMetadata::handleRAUW(BCI, UndefValue::get(BCI->getType())); - } - // Note that this will not replace uses in MMOs (which we'll update below), // or anywhere else (which is why we won't delete the original // instruction). - FromAI->replaceAllUsesWith(Inst); + const_cast<AllocaInst *>(From)->replaceAllUsesWith(Inst); } // Remap all instructions to the new stack slots. diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 165f745b506..64d7575b8a1 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -432,7 +432,8 @@ private: // Module-level debug info verification... void verifyTypeRefs(); template <class MapTy> - void verifyDIExpression(const DbgInfoIntrinsic &I, const MapTy &TypeRefs); + void verifyBitPieceExpression(const DbgInfoIntrinsic &I, + const MapTy &TypeRefs); void visitUnresolvedTypeRef(const MDString *S, const MDNode *N); }; } // End anonymous namespace @@ -3853,34 +3854,15 @@ static uint64_t getVariableSize(const DILocalVariable &V, const MapTy &Map) { } template <class MapTy> -void Verifier::verifyDIExpression(const DbgInfoIntrinsic &I, - const MapTy &TypeRefs) { +void Verifier::verifyBitPieceExpression(const DbgInfoIntrinsic &I, + const MapTy &TypeRefs) { DILocalVariable *V; DIExpression *E; - const Value *Arg; - uint64_t ArgumentTypeSizeInBits = 0; if (auto *DVI = dyn_cast<DbgValueInst>(&I)) { - Arg = DVI->getValue(); - if (Arg) - ArgumentTypeSizeInBits = - M->getDataLayout().getTypeAllocSizeInBits(Arg->getType()); V = dyn_cast_or_null<DILocalVariable>(DVI->getRawVariable()); E = dyn_cast_or_null<DIExpression>(DVI->getRawExpression()); } else { auto *DDI = cast<DbgDeclareInst>(&I); - // For declare intrinsics, get the total size of the alloca, to allow - // case where the variable may span more than one element. - Arg = DDI->getAddress(); - if (Arg) - Arg = Arg->stripPointerCasts(); - const AllocaInst *AI = dyn_cast_or_null<AllocaInst>(Arg); - if (AI) { - // We can only say something about constant size allocations - if (const ConstantInt *CI = dyn_cast<ConstantInt>(AI->getArraySize())) - ArgumentTypeSizeInBits = - CI->getLimitedValue() * - M->getDataLayout().getTypeAllocSizeInBits(AI->getAllocatedType()); - } V = dyn_cast_or_null<DILocalVariable>(DDI->getRawVariable()); E = dyn_cast_or_null<DIExpression>(DDI->getRawExpression()); } @@ -3889,6 +3871,10 @@ void Verifier::verifyDIExpression(const DbgInfoIntrinsic &I, if (!V || !E || !E->isValid()) return; + // Nothing to do if this isn't a bit piece expression. + if (!E->isBitPiece()) + return; + // The frontend helps out GDB by emitting the members of local anonymous // unions as artificial local variables with shared storage. When SROA splits // the storage for artificial local variables that are smaller than the entire @@ -3904,33 +3890,11 @@ void Verifier::verifyDIExpression(const DbgInfoIntrinsic &I, if (!VarSize) return; - if (E->isBitPiece()) { - unsigned PieceSize = E->getBitPieceSize(); - unsigned PieceOffset = E->getBitPieceOffset(); - Assert(PieceSize + PieceOffset <= VarSize, - "piece is larger than or outside of variable", &I, V, E); - Assert(PieceSize != VarSize, "piece covers entire variable", &I, V, E); - return; - } - - if (!ArgumentTypeSizeInBits) - return; // We were unable to determine the size of the argument - - if (E->getNumElements() == 0) { - // In the case where the expression is empty, verify the size of the - // argument. Doing this in the general case would require looking through - // any dereferences that may be in the expression. - Assert(ArgumentTypeSizeInBits == VarSize, - "size of passed value (" + std::to_string(ArgumentTypeSizeInBits) + - ") does not match size of declared variable (" + - std::to_string(VarSize) + ")", - &I, Arg, V, V->getType(), E); - } else if (E->getElement(0) == dwarf::DW_OP_deref) { - Assert(ArgumentTypeSizeInBits == M->getDataLayout().getPointerSizeInBits(), - "the operation of the expression is a deref, but the passed value " - "is not pointer sized", - &I, Arg, V, V->getType(), E); - } + unsigned PieceSize = E->getBitPieceSize(); + unsigned PieceOffset = E->getBitPieceOffset(); + Assert(PieceSize + PieceOffset <= VarSize, + "piece is larger than or outside of variable", &I, V, E); + Assert(PieceSize != VarSize, "piece covers entire variable", &I, V, E); } void Verifier::visitUnresolvedTypeRef(const MDString *S, const MDNode *N) { @@ -3963,7 +3927,7 @@ void Verifier::verifyTypeRefs() { for (const BasicBlock &BB : F) for (const Instruction &I : BB) if (auto *DII = dyn_cast<DbgInfoIntrinsic>(&I)) - verifyDIExpression(*DII, TypeRefs); + verifyBitPieceExpression(*DII, TypeRefs); // Return early if all typerefs were resolved. if (UnresolvedTypeRefs.empty()) |