@@ -5737,90 +5737,6 @@ void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
5737
5737
Var->addDebugInfo (GVE);
5738
5738
}
5739
5739
5740
- void CGDebugInfo::EmitPseudoVariable (CGBuilderTy &Builder,
5741
- llvm::Instruction *Value, QualType Ty) {
5742
- // Only when -g2 or above is specified, debug info for variables will be
5743
- // generated.
5744
- if (CGM.getCodeGenOpts ().getDebugInfo () <=
5745
- llvm::codegenoptions::DebugLineTablesOnly)
5746
- return ;
5747
-
5748
- llvm::DebugLoc SaveDebugLoc = Builder.getCurrentDebugLocation ();
5749
- if (!SaveDebugLoc.get ())
5750
- return ;
5751
-
5752
- llvm::DIFile *Unit = SaveDebugLoc->getFile ();
5753
- llvm::DIType *Type = getOrCreateType (Ty, Unit);
5754
-
5755
- // Check if Value is already a declared variable and has debug info, in this
5756
- // case we have nothing to do. Clang emits declared variable as alloca, and
5757
- // it is loaded upon use, so we identify such pattern here.
5758
- if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(Value)) {
5759
- llvm::Value *Var = Load->getPointerOperand ();
5760
- if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists (Var)) {
5761
- if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists (
5762
- CGM.getLLVMContext (), MDValue)) {
5763
- for (llvm::User *U : DbgValue->users ()) {
5764
- if (llvm::CallInst *DbgDeclare = dyn_cast<llvm::CallInst>(U)) {
5765
- if (DbgDeclare->getCalledFunction ()->getIntrinsicID () ==
5766
- llvm::Intrinsic::dbg_declare &&
5767
- DbgDeclare->getArgOperand (0 ) == DbgValue) {
5768
- // There can be implicit type cast applied on a variable if it is
5769
- // an opaque ptr, in this case its debug info may not match the
5770
- // actual type of object being used as in the next instruction, so
5771
- // we will need to emit a pseudo variable for type-casted value.
5772
- llvm::DILocalVariable *MDNode = cast<llvm::DILocalVariable>(
5773
- cast<llvm::MetadataAsValue>(DbgDeclare->getOperand (1 ))
5774
- ->getMetadata ());
5775
- if (MDNode->getType () == Type)
5776
- return ;
5777
- }
5778
- }
5779
- }
5780
- }
5781
- }
5782
- }
5783
-
5784
- // Find the correct location to insert a sequence of instructions to
5785
- // materialize Value on the stack.
5786
- auto SaveInsertionPoint = Builder.saveIP ();
5787
- if (llvm::InvokeInst *Invoke = dyn_cast<llvm::InvokeInst>(Value))
5788
- Builder.SetInsertPoint (Invoke->getNormalDest ()->begin ());
5789
- else if (llvm::Instruction *Next = Value->getIterator ()->getNextNode ())
5790
- Builder.SetInsertPoint (Next);
5791
- else
5792
- Builder.SetInsertPoint (Value->getParent ());
5793
- llvm::DebugLoc DL = Value->getDebugLoc ();
5794
- if (DL.get ())
5795
- Builder.SetCurrentDebugLocation (DL);
5796
- else if (!Builder.getCurrentDebugLocation ().get ())
5797
- Builder.SetCurrentDebugLocation (SaveDebugLoc);
5798
-
5799
- llvm::AllocaInst *PseudoVar = Builder.CreateAlloca (Value->getType ());
5800
- Address PseudoVarAddr (PseudoVar, Value->getType (),
5801
- CharUnits::fromQuantity (PseudoVar->getAlign ()));
5802
- llvm::LoadInst *Load = Builder.CreateLoad (PseudoVarAddr);
5803
- Value->replaceAllUsesWith (Load);
5804
- Builder.SetInsertPoint (Load);
5805
- Builder.CreateStore (Value, PseudoVarAddr);
5806
-
5807
- // Emit debug info for materialized Value.
5808
- unsigned Line = Builder.getCurrentDebugLocation ().getLine ();
5809
- unsigned Column = Builder.getCurrentDebugLocation ().getCol ();
5810
- llvm::DILocalVariable *D = DBuilder.createAutoVariable (
5811
- LexicalBlockStack.back (), " " , nullptr , 0 , Type, false ,
5812
- llvm::DINode::FlagArtificial);
5813
- llvm::DILocation *DIL =
5814
- llvm::DILocation::get (CGM.getLLVMContext (), Line, Column,
5815
- LexicalBlockStack.back (), CurInlinedAt);
5816
- SmallVector<uint64_t > Expr;
5817
- DBuilder.insertDeclare (PseudoVar, D, DBuilder.createExpression (Expr), DIL,
5818
- Load);
5819
-
5820
- Builder.restoreIP (SaveInsertionPoint);
5821
- Builder.SetCurrentDebugLocation (SaveDebugLoc);
5822
- }
5823
-
5824
5740
void CGDebugInfo::EmitGlobalAlias (const llvm::GlobalValue *GV,
5825
5741
const GlobalDecl GD) {
5826
5742
0 commit comments