Skip to content

Commit 7202186

Browse files
author
git apple-llvm automerger
committed
Merge commit '0557af29dc3e' from apple/stable/20200714 into swift/release/5.4
2 parents 0a21abc + 0557af2 commit 7202186

File tree

9 files changed

+402
-88
lines changed

9 files changed

+402
-88
lines changed

clang/test/CodeGenCXX/auto-var-init.cpp

Lines changed: 33 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,7 @@ TEST_UNINIT(empty, empty);
597597
// PATTERN-O1: store i8 [[I8]], {{.*}} align 1, !annotation [[AUTO_INIT]]
598598
// ZERO-LABEL: @test_empty_uninit()
599599
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
600-
// ZERO-O1: store i8 0, {{.*}} align 1
601-
// FIXME: !annotation dropped by optimizations
602-
// ZERO-O1-NOT: !annotation
600+
// ZERO-O1: store i8 0, {{.*}} align 1, !annotation [[AUTO_INIT]]
603601

604602
TEST_BRACES(empty, empty);
605603
// CHECK-LABEL: @test_empty_braces()
@@ -618,9 +616,7 @@ TEST_UNINIT(small, small);
618616
// PATTERN-O1: store i8 [[I8]], {{.*}} align 1, !annotation [[AUTO_INIT]]
619617
// ZERO-LABEL: @test_small_uninit()
620618
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
621-
// ZERO-O1: store i8 0, {{.*}} align 1
622-
// FIXME: !annotation dropped by optimizations
623-
// ZERO-O1-NOT: !annotation
619+
// ZERO-O1: store i8 0, {{.*}} align 1, !annotation [[AUTO_INIT]]
624620

625621
TEST_BRACES(small, small);
626622
// CHECK-LABEL: @test_small_braces()
@@ -671,10 +667,8 @@ TEST_UNINIT(smallpartinit, smallpartinit);
671667
// PATTERN-O1: store i8 42, {{.*}} align 1
672668
// ZERO-LABEL: @test_smallpartinit_uninit()
673669
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
674-
// ZERO-O1-LEGACY: store i16 0, i16* %uninit, align 2
675-
// ZERO-O1-NEWPM: store i16 0, i16* %uninit, align 2
676-
// FIXME: !annotation dropped by optimizations
677-
// ZERO-O1-NOT: !annotation
670+
// ZERO-O1-LEGACY: store i16 0, i16* %uninit, align 2, !annotation [[AUTO_INIT]]
671+
// ZERO-O1-NEWPM: store i16 0, i16* %uninit, align 2, !annotation [[AUTO_INIT]]
678672

679673
TEST_BRACES(smallpartinit, smallpartinit);
680674
// CHECK-LABEL: @test_smallpartinit_braces()
@@ -726,14 +720,10 @@ TEST_UNINIT(padded, padded);
726720
// CHECK-NEXT: call void @{{.*}}used{{.*}}%uninit)
727721
// PATTERN-LABEL: @test_padded_uninit()
728722
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_padded_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
729-
// PATTERN-O1: store i64 [[I64]], i64* %uninit, align 8
730-
// FIXME: !annotation dropped by optimizations
731-
// PATTERN-O1-NOT: !annotation
723+
// PATTERN-O1: store i64 [[I64]], i64* %uninit, align 8, !annotation [[AUTO_INIT]]
732724
// ZERO-LABEL: @test_padded_uninit()
733-
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}})
734-
// ZERO-O1: store i64 0, i64* %uninit, align 8
735-
// FIXME: !annotation dropped by optimizations
736-
// ZERO-O1-NOT: !annotation
725+
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
726+
// ZERO-O1: store i64 0, i64* %uninit, align 8, !annotation [[AUTO_INIT]]
737727

738728
TEST_BRACES(padded, padded);
739729
// CHECK-LABEL: @test_padded_braces()
@@ -758,15 +748,16 @@ TEST_UNINIT(paddednullinit, paddednullinit);
758748
// CHECK-NEXT: call void @{{.*}}used{{.*}}%uninit)
759749
// PATTERN-LABEL: @test_paddednullinit_uninit()
760750
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_paddednullinit_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
761-
// PATTERN-O1-LEGACY: store i64 [[I64]], i64* %uninit, align 8
762-
// PATTERN-O1-NEWPM: store i64 [[I64]], i64* %uninit, align 8
763-
// FIXME: !annotation dropped by optimizations
764-
// PATTERN-O1-NOT: !annotation
751+
// PATTERN-O1-LEGACY: store i64 [[I64]], i64* %uninit, align 8, !annotation [[AUTO_INIT]]
752+
// PATTERN-O1-NEWPM: store i64 [[I64]], i64* %uninit, align 8, !annotation [[AUTO_INIT]]
765753
// ZERO-LABEL: @test_paddednullinit_uninit()
766-
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,
767-
// ZERO-O1: store i64 0, i64* %uninit, align 8
754+
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0, {{.*}}, !annotation [[AUTO_INIT]]
755+
// ZERO-O1-LEGACY: store i64 0, i64* %uninit, align 8, !annotation [[AUTO_INIT]]
756+
// ZERO-O1-NEWPM: store i64 0, i64* %uninit, align 8
768757
// FIXME: !annotation dropped by optimizations
769-
// ZERO-O1-NOT: !annotation
758+
// ZERO-O1-NEWPM-NOT: !annotation
759+
// ZERO: ret
760+
770761

771762
TEST_BRACES(paddednullinit, paddednullinit);
772763
// CHECK-LABEL: @test_paddednullinit_braces()
@@ -922,9 +913,7 @@ TEST_UNINIT(bitfield, bitfield);
922913
// PATTERN-O1-NOT: !annotation
923914
// ZERO-LABEL: @test_bitfield_uninit()
924915
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0{{.+}}), !annotation [[AUTO_INIT]]
925-
// ZERO-O1: store i32 0, i32* %uninit, align 4
926-
// FIXME: !annotation dropped by optimizations
927-
// ZERO-O1-NOT: !annotation
916+
// ZERO-O1: store i32 0, i32* %uninit, align 4, !annotation [[AUTO_INIT]]
928917

929918
TEST_BRACES(bitfield, bitfield);
930919
// CHECK-LABEL: @test_bitfield_braces()
@@ -953,9 +942,7 @@ TEST_UNINIT(bitfieldaligned, bitfieldaligned);
953942
// PATTERN-O1-NOT: !annotation
954943
// ZERO-LABEL: @test_bitfieldaligned_uninit()
955944
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
956-
// ZERO-O1: store i64 0, i64* %uninit, align 8
957-
// FIXME: !annotation dropped by optimizations
958-
// ZERO-O1-NOT: !annotation
945+
// ZERO-O1: store i64 0, i64* %uninit, align 8, !annotation [[AUTO_INIT]]
959946

960947
TEST_BRACES(bitfieldaligned, bitfieldaligned);
961948
// CHECK-LABEL: @test_bitfieldaligned_braces()
@@ -1007,9 +994,7 @@ TEST_UNINIT(arraytail, arraytail);
1007994
// PATTERN-O1: store i32 [[I32]], {{.*}} align 4, !annotation [[AUTO_INIT]]
1008995
// ZERO-LABEL: @test_arraytail_uninit()
1009996
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
1010-
// ZERO-O1: store i32 0, {{.*}} align 4
1011-
// FIXME: !annotation dropped by optimizations
1012-
// ZERO-O1-NOT: !annotation
997+
// ZERO-O1: store i32 0, {{.*}} align 4, !annotation [[AUTO_INIT]]
1013998

1014999
TEST_BRACES(arraytail, arraytail);
10151000
// CHECK-LABEL: @test_arraytail_braces()
@@ -1053,9 +1038,7 @@ TEST_UNINIT(int1, int[1]);
10531038
// PATTERN-O1: store i32 [[I32]], {{.*}} align 4, !annotation [[AUTO_INIT]]
10541039
// ZERO-LABEL: @test_int1_uninit()
10551040
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
1056-
// ZERO-O1: store i32 0, {{.*}} align 4
1057-
// FIXME: !annotation dropped by optimizations
1058-
// ZERO-O1-NOT: !annotation
1041+
// ZERO-O1: store i32 0, {{.*}} align 4, !annotation [[AUTO_INIT]]
10591042

10601043
TEST_BRACES(int1, int[1]);
10611044
// CHECK-LABEL: @test_int1_braces()
@@ -1109,9 +1092,7 @@ TEST_UNINIT(bool4, bool[4]);
11091092
// PATTERN-O1-NOT: !annotation
11101093
// ZERO-LABEL: @test_bool4_uninit()
11111094
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
1112-
// ZERO-O1: store i32 0, i32* %uninit, align 4
1113-
// FIXME: !annotation dropped by optimizations
1114-
// ZERO-O1-NOT: !annotation
1095+
// ZERO-O1: store i32 0, i32* %uninit, align 4, !annotation [[AUTO_INIT]]
11151096

11161097
TEST_BRACES(bool4, bool[4]);
11171098
// CHECK-LABEL: @test_bool4_braces()
@@ -1244,7 +1225,7 @@ TEST_UNINIT(atomicnotlockfree, _Atomic(notlockfree));
12441225
// PATTERN-LABEL: @test_atomicnotlockfree_uninit()
12451226
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_atomicnotlockfree_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
12461227
// PATTERN-O1: bitcast
1247-
// PATTERN-O1: call void @llvm.memset{{.*}}({{.*}}, i8 [[I8]], i64 32
1228+
// PATTERN-O1: call void @llvm.memset{{.*}}({{.*}}, i8 [[I8]], i64 32{{.*}}
12481229
// FIXME: !annotation dropped by optimizations
12491230
// PATTERN-O1-NOT: !annotation
12501231
// ZERO-LABEL: @test_atomicnotlockfree_uninit()
@@ -1256,14 +1237,10 @@ TEST_UNINIT(atomicpadded, _Atomic(padded));
12561237
// CHECK-NEXT: call void @{{.*}}used{{.*}}%uninit)
12571238
// PATTERN-LABEL: @test_atomicpadded_uninit()
12581239
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_atomicpadded_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
1259-
// PATTERN-O1: store i64 [[IPTR]], i64* %uninit, align 8
1260-
// FIXME: !annotation dropped by optimizations
1261-
// PATTERN-O1-NOT: !annotation
1240+
// PATTERN-O1: store i64 [[IPTR]], i64* %uninit, align 8, !annotation [[AUTO_INIT]]
12621241
// ZERO-LABEL: @test_atomicpadded_uninit()
12631242
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0, {{.+}}), !annotation [[AUTO_INIT]]
1264-
// ZERO-O1: store i64 0, i64* %uninit, align 8
1265-
// FIXME: !annotation dropped by optimizations
1266-
// ZERO-O1-NOT: !annotation
1243+
// ZERO-O1: store i64 0, i64* %uninit, align 8, !annotation [[AUTO_INIT]]
12671244

12681245
TEST_UNINIT(atomictailpad, _Atomic(tailpad));
12691246
// CHECK-LABEL: @test_atomictailpad_uninit()
@@ -1273,9 +1250,7 @@ TEST_UNINIT(atomictailpad, _Atomic(tailpad));
12731250
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_atomictailpad_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
12741251
// ZERO-LABEL: @test_atomictailpad_uninit()
12751252
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
1276-
// ZERO-O1: store i32 0, i32* %uninit, align 4
1277-
// FIXME: !annotation dropped by optimizations
1278-
// ZERO-O1-NOT: !annotation
1253+
// ZERO-O1: store i32 0, i32* %uninit, align 4, !annotation [[AUTO_INIT]]
12791254

12801255
TEST_UNINIT(complexfloat, _Complex float);
12811256
// CHECK-LABEL: @test_complexfloat_uninit()
@@ -1291,9 +1266,7 @@ TEST_UNINIT(complexfloat, _Complex float);
12911266

12921267
// ZERO-LABEL: @test_complexfloat_uninit()
12931268
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0, {{.+}}), !annotation [[AUTO_INIT]]
1294-
// ZERO-O1: store i64 0, i64* %uninit, align 8
1295-
// FIXME: !annotation dropped by optimizations
1296-
// ZERO-O1-NOT: !annotation
1269+
// ZERO-O1: store i64 0, i64* %uninit, align 8, !annotation [[AUTO_INIT]]
12971270

12981271
TEST_BRACES(complexfloat, _Complex float);
12991272
// CHECK-LABEL: @test_complexfloat_braces()
@@ -1372,9 +1345,7 @@ TEST_UNINIT(semivolatile, semivolatile);
13721345
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_semivolatile_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
13731346
// ZERO-LABEL: @test_semivolatile_uninit()
13741347
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0, {{.+}}), !annotation [[AUTO_INIT]]
1375-
// ZERO-O1: store i64 0, i64* %uninit, align 8
1376-
// FIXME: !annotation dropped by optimizations
1377-
// ZERO-O1-NOT: !annotation
1348+
// ZERO-O1: store i64 0, i64* %uninit, align 8, !annotation [[AUTO_INIT]]
13781349

13791350
TEST_BRACES(semivolatile, semivolatile);
13801351
// CHECK-LABEL: @test_semivolatile_braces()
@@ -1433,8 +1404,7 @@ TEST_UNINIT(base, base);
14331404
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
14341405
// ZERO-O1-LEGACY: store i64 0, {{.*}} align 8
14351406
// ZERO-O1-NEWPM: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTV4base, i64 0, inrange i32 0, i64 2) to i32 (...)**), {{.*}}, align 8
1436-
// FIXME: !annotation dropped by optimizations
1437-
// ZERO-O1-NOT: !annotation
1407+
// ZERO-O1-NOT-NEWPM: !annotation
14381408

14391409
TEST_BRACES(base, base);
14401410
// CHECK-LABEL: @test_base_braces()
@@ -1454,10 +1424,8 @@ TEST_UNINIT(derived, derived);
14541424
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_derived_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
14551425
// ZERO-LABEL: @test_derived_uninit()
14561426
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0, {{.+}}), !annotation [[AUTO_INIT]]
1457-
// ZERO-O1-LEGACY: store i64 0, {{.*}} align 8
1427+
// ZERO-O1: store i64 0, {{.*}} align 8, !annotation [[AUTO_INIT]]
14581428
// ZERO-O1-NEWPM: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTV7derived, i64 0, inrange i32 0, i64 2) to i32 (...)**), {{.*}} align 8
1459-
// FIXME: !annotation dropped by optimizations
1460-
// ZERO-O1-NOT: !annotation
14611429

14621430
TEST_BRACES(derived, derived);
14631431
// CHECK-LABEL: @test_derived_braces()
@@ -1497,9 +1465,7 @@ TEST_UNINIT(matching, matching);
14971465
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_matching_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
14981466
// ZERO-LABEL: @test_matching_uninit()
14991467
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0, {{.+}}), !annotation [[AUTO_INIT]]
1500-
// ZERO-O1: store i32 0, {{.*}} align 4
1501-
// FIXME: !annotation dropped by optimizations
1502-
// ZERO-O1-NOT: !annotation
1468+
// ZERO-O1: store i32 0, {{.*}} align 4, !annotation [[AUTO_INIT]]
15031469

15041470
TEST_BRACES(matching, matching);
15051471
// CHECK-LABEL: @test_matching_braces()
@@ -1529,9 +1495,7 @@ TEST_UNINIT(matchingreverse, matchingreverse);
15291495
// PATTERN-O1: store float 0xFFFFFFFFE0000000, {{.+}}, !annotation [[AUTO_INIT]]
15301496
// ZERO-LABEL: @test_matchingreverse_uninit()
15311497
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0,{{.+}}), !annotation [[AUTO_INIT]]
1532-
// ZERO-O1: store i32 0, {{.*}} align 4
1533-
// FIXME: !annotation dropped by optimizations
1534-
// ZERO-O1-NOT: !annotation
1498+
// ZERO-O1: store i32 0, {{.*}} align 4, !annotation [[AUTO_INIT]]
15351499

15361500
TEST_BRACES(matchingreverse, matchingreverse);
15371501
// CHECK-LABEL: @test_matchingreverse_braces()
@@ -1559,9 +1523,7 @@ TEST_UNINIT(unmatched, unmatched);
15591523
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_unmatched_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
15601524
// ZERO-LABEL: @test_unmatched_uninit()
15611525
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0, {{.+}}), !annotation [[AUTO_INIT]]
1562-
// ZERO-O1: store i32 0, {{.*}} align 4
1563-
// FIXME: !annotation dropped by optimizations
1564-
// ZERO-O1-NOT: !annotation
1526+
// ZERO-O1: store i32 0, {{.*}} align 4, !annotation [[AUTO_INIT]]
15651527

15661528
TEST_BRACES(unmatched, unmatched);
15671529
// CHECK-LABEL: @test_unmatched_braces()
@@ -1589,9 +1551,7 @@ TEST_UNINIT(unmatchedreverse, unmatchedreverse);
15891551
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_unmatchedreverse_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
15901552
// ZERO-LABEL: @test_unmatchedreverse_uninit()
15911553
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0, {{.+}}), !annotation [[AUTO_INIT]]
1592-
// ZERO-O1: store i32 0, {{.*}} align 4
1593-
// FIXME: !annotation dropped by optimizations
1594-
// ZERO-O1-NOT: !annotation
1554+
// ZERO-O1: store i32 0, {{.*}} align 4, !annotation [[AUTO_INIT]]
15951555

15961556
TEST_BRACES(unmatchedreverse, unmatchedreverse);
15971557
// CHECK-LABEL: @test_unmatchedreverse_braces()
@@ -1619,9 +1579,7 @@ TEST_UNINIT(unmatchedfp, unmatchedfp);
16191579
// PATTERN-O0: call void @llvm.memcpy{{.*}} @__const.test_unmatchedfp_uninit.uninit{{.+}}), !annotation [[AUTO_INIT]]
16201580
// ZERO-LABEL: @test_unmatchedfp_uninit()
16211581
// ZERO-O0: call void @llvm.memset{{.*}}, i8 0, {{.+}}), !annotation [[AUTO_INIT]]
1622-
// ZERO-O1: store i64 0, {{.*}} align 8
1623-
// FIXME: !annotation dropped by optimizations
1624-
// ZERO-O1-NOT: !annotation
1582+
// ZERO-O1: store i64 0, {{.*}} align 8, !annotation [[AUTO_INIT]]
16251583

16261584
TEST_BRACES(unmatchedfp, unmatchedfp);
16271585
// CHECK-LABEL: @test_unmatchedfp_braces()

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
#include "llvm-c/Types.h"
1818
#include "llvm/ADT/ArrayRef.h"
1919
#include "llvm/ADT/None.h"
20+
#include "llvm/ADT/STLExtras.h"
2021
#include "llvm/ADT/StringRef.h"
2122
#include "llvm/ADT/Twine.h"
2223
#include "llvm/IR/BasicBlock.h"
2324
#include "llvm/IR/Constant.h"
2425
#include "llvm/IR/ConstantFolder.h"
2526
#include "llvm/IR/Constants.h"
2627
#include "llvm/IR/DataLayout.h"
28+
#include "llvm/IR/DebugInfoMetadata.h"
2729
#include "llvm/IR/DebugLoc.h"
2830
#include "llvm/IR/DerivedTypes.h"
2931
#include "llvm/IR/Function.h"
@@ -91,7 +93,28 @@ class IRBuilderCallbackInserter : public IRBuilderDefaultInserter {
9193

9294
/// Common base class shared among various IRBuilders.
9395
class IRBuilderBase {
94-
DebugLoc CurDbgLocation;
96+
/// Pairs of (metadata kind, MDNode *) that should be added to all newly
97+
/// created instructions, like !dbg metadata.
98+
SmallVector<std::pair<unsigned, MDNode *>, 2> MetadataToCopy;
99+
100+
/// Add or update the an entry (Kind, MD) to MetadataToCopy, if \p MD is not
101+
/// null. If \p MD is null, remove the entry with \p Kind.
102+
void AddOrRemoveMetadataToCopy(unsigned Kind, MDNode *MD) {
103+
if (!MD) {
104+
erase_if(MetadataToCopy, [Kind](const std::pair<unsigned, MDNode *> &KV) {
105+
return KV.first == Kind;
106+
});
107+
return;
108+
}
109+
110+
for (auto &KV : MetadataToCopy)
111+
if (KV.first == Kind) {
112+
KV.second = MD;
113+
return;
114+
}
115+
116+
MetadataToCopy.emplace_back(Kind, MD);
117+
}
95118

96119
protected:
97120
BasicBlock *BB;
@@ -125,7 +148,7 @@ class IRBuilderBase {
125148
template<typename InstTy>
126149
InstTy *Insert(InstTy *I, const Twine &Name = "") const {
127150
Inserter.InsertHelper(I, Name, BB, InsertPt);
128-
SetInstDebugLocation(I);
151+
AddMetadataToInst(I);
129152
return I;
130153
}
131154

@@ -182,16 +205,42 @@ class IRBuilderBase {
182205
}
183206

184207
/// Set location information used by debugging information.
185-
void SetCurrentDebugLocation(DebugLoc L) { CurDbgLocation = std::move(L); }
208+
void SetCurrentDebugLocation(DebugLoc L) {
209+
AddOrRemoveMetadataToCopy(LLVMContext::MD_dbg, L.getAsMDNode());
210+
}
211+
212+
/// Collect metadata with IDs \p MetadataKinds from \p Src which should be
213+
/// added to all created instructions. Entries present in MedataDataToCopy but
214+
/// not on \p Src will be dropped from MetadataToCopy.
215+
void CollectMetadataToCopy(Instruction *Src,
216+
ArrayRef<unsigned> MetadataKinds) {
217+
for (unsigned K : MetadataKinds)
218+
AddOrRemoveMetadataToCopy(K, Src->getMetadata(K));
219+
}
186220

187221
/// Get location information used by debugging information.
188-
const DebugLoc &getCurrentDebugLocation() const { return CurDbgLocation; }
222+
DebugLoc getCurrentDebugLocation() const {
223+
for (auto &KV : MetadataToCopy)
224+
if (KV.first == LLVMContext::MD_dbg)
225+
return {cast<DILocation>(KV.second)};
226+
227+
return {};
228+
}
189229

190230
/// If this builder has a current debug location, set it on the
191231
/// specified instruction.
192232
void SetInstDebugLocation(Instruction *I) const {
193-
if (CurDbgLocation)
194-
I->setDebugLoc(CurDbgLocation);
233+
for (const auto &KV : MetadataToCopy)
234+
if (KV.first == LLVMContext::MD_dbg) {
235+
I->setDebugLoc(DebugLoc(KV.second));
236+
return;
237+
}
238+
}
239+
240+
/// Add all entries in MetadataToCopy to \p I.
241+
void AddMetadataToInst(Instruction *I) const {
242+
for (auto &KV : MetadataToCopy)
243+
I->setMetadata(KV.first, KV.second);
195244
}
196245

197246
/// Get the return type of the current function that we're emitting

llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ namespace llvm {
305305
}
306306

307307
/// Get location information used by debugging information.
308-
const DebugLoc &getCurrentDebugLocation() const {
308+
DebugLoc getCurrentDebugLocation() const {
309309
return Builder.getCurrentDebugLocation();
310310
}
311311

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ void PassManagerBuilder::populateModulePassManager(
547547
// new unnamed globals.
548548
MPM.add(createNameAnonGlobalPass());
549549
}
550+
551+
MPM.add(createAnnotationRemarksLegacyPass());
550552
return;
551553
}
552554

0 commit comments

Comments
 (0)