Commit 9282c9fd authored by Duncan P. N. Exon Smith's avatar Duncan P. N. Exon Smith
Browse files

Merging r226048:

------------------------------------------------------------------------
r226048 | dexonsmith | 2015-01-14 14:27:36 -0800 (Wed, 14 Jan 2015) | 17 lines

IR: Move MDLocation into place

This commit moves `MDLocation`, finishing off PR21433.  There's an
accompanying clang commit for frontend testcases.  I'll attach the
testcase upgrade script I used to PR21433 to help out-of-tree
frontends/backends.

This changes the schema for `DebugLoc` and `DILocation` from:

    !{i32 3, i32 7, !7, !8}

to:

    !MDLocation(line: 3, column: 7, scope: !7, inlinedAt: !8)

Note that empty fields (line/column: 0 and inlinedAt: null) don't get
printed by the assembly writer.
------------------------------------------------------------------------

llvm-svn: 226094
parent aa9a09be
Loading
Loading
Loading
Loading
+23 −5
Original line number Diff line number Diff line
@@ -877,10 +877,26 @@ class DILocation : public DIDescriptor {
public:
  explicit DILocation(const MDNode *N) : DIDescriptor(N) {}

  unsigned getLineNumber() const { return getUnsignedField(0); }
  unsigned getColumnNumber() const { return getUnsignedField(1); }
  DIScope getScope() const { return getFieldAs<DIScope>(2); }
  DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
  unsigned getLineNumber() const {
    if (auto *L = dyn_cast_or_null<MDLocation>(DbgNode))
      return L->getLine();
    return 0;
  }
  unsigned getColumnNumber() const {
    if (auto *L = dyn_cast_or_null<MDLocation>(DbgNode))
      return L->getColumn();
    return 0;
  }
  DIScope getScope() const {
    if (auto *L = dyn_cast_or_null<MDLocation>(DbgNode))
      return DIScope(dyn_cast_or_null<MDNode>(L->getScope()));
    return DIScope(nullptr);
  }
  DILocation getOrigLocation() const {
    if (auto *L = dyn_cast_or_null<MDLocation>(DbgNode))
      return DILocation(dyn_cast_or_null<MDNode>(L->getInlinedAt()));
    return DILocation(nullptr);
  }
  StringRef getFilename() const { return getScope().getFilename(); }
  StringRef getDirectory() const { return getScope().getDirectory(); }
  bool Verify() const;
@@ -901,7 +917,9 @@ public:
    // sure this location is a lexical block before retrieving its
    // value.
    return getScope().isLexicalBlockFile()
               ? getFieldAs<DILexicalBlockFile>(2).getDiscriminator()
               ? DILexicalBlockFile(
                     cast<MDNode>(cast<MDLocation>(DbgNode)->getScope()))
                     .getDiscriminator()
               : 0;
  }

+6 −13
Original line number Diff line number Diff line
@@ -592,10 +592,7 @@ bool DIExpression::Verify() const {
}

bool DILocation::Verify() const {
  if (!DbgNode)
    return false;

  return DbgNode->getNumOperands() == 4;
  return DbgNode && isa<MDLocation>(DbgNode);
}

bool DINameSpace::Verify() const {
@@ -830,16 +827,12 @@ void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) {

DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
                                        DILexicalBlockFile NewScope) {
  SmallVector<Metadata *, 10> Elts;
  assert(Verify());
  for (unsigned I = 0; I < DbgNode->getNumOperands(); ++I) {
    if (I != 2)
      Elts.push_back(DbgNode->getOperand(I));
    else
      Elts.push_back(NewScope);
  }
  MDNode *NewDIL = MDNode::get(Ctx, Elts);
  return DILocation(NewDIL);
  assert(NewScope && "Expected valid scope");

  const auto *Old = cast<MDLocation>(DbgNode);
  return DILocation(MDLocation::get(Ctx, Old->getLine(), Old->getColumn(),
                                    NewScope, Old->getInlinedAt()));
}

unsigned DILocation::computeNewDiscriminator(LLVMContext &Ctx) {
+2 −6
Original line number Diff line number Diff line
@@ -58,12 +58,8 @@ DebugLoc DebugLoc::get(unsigned Line, unsigned Col,
  if (Col > 255) Col = 0;
  if (Line >= (1 << 24)) Line = 0;

  LLVMContext &Context = Scope->getContext();
  Type *Int32 = Type::getInt32Ty(Context);
  Metadata *Elts[] = {ConstantAsMetadata::get(ConstantInt::get(Int32, Line)),
                      ConstantAsMetadata::get(ConstantInt::get(Int32, Col)),
                      Scope, InlinedAt};
  return getFromDILocation(MDNode::get(Context, Elts));
  return getFromDILocation(
      MDLocation::get(Scope->getContext(), Line, Col, Scope, InlinedAt));
}

/// getAsMDNode - This method converts the compressed DebugLoc node into a
+2 −2
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ entry:

!llvm.module.flags = !{!4}

!0 = !{i32 662302, i32 26, !1, null}
!0 = !MDLocation(line: 662302, column: 26, scope: !1)
!1 = !{i32 4, !"foo"}
!2 = !{!"bar"}
!3 = !{!"foo"}
@@ -49,7 +49,7 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata) nounwind readnon

; CHECK: !foo = !{![[FOO]]}
; CHECK: !bar = !{![[BAR]]}
; CHECK: ![[ID0]] = !{i32 662302, i32 26, ![[ID1]], null}
; CHECK: ![[ID0]] = !MDLocation(line: 662302, column: 26, scope: ![[ID1]])
; CHECK: ![[ID1]] = !{i32 4, !"foo"}
; CHECK: ![[ID2]] = !{!"bar"}
; CHECK: ![[ID3]] = !{!"foo"}
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ define void @test() {
  ret void, !foo !0, !bar !1
}

!0 = !{i32 662302, i32 26, !1, null}
!0 = !MDLocation(line: 662302, column: 26, scope: !1)
!1 = !{i32 4, !"foo"}

declare void @llvm.dbg.func.start(metadata) nounwind readnone
Loading