Skip to content

Commit ed6c6d3

Browse files
committed
comments
1 parent 711f7c5 commit ed6c6d3

File tree

11 files changed

+33
-177
lines changed

11 files changed

+33
-177
lines changed

llvm/include/llvm/IR/MemoryModelRelaxationAnnotations.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#include <set>
2121
#include <string>
22-
#include <tuple>
2322
#include <vector>
2423

2524
namespace llvm {
2625

2726
class MDNode;
2827
class MDTuple;
28+
class Metadata;
2929
class StringRef;
3030
class raw_ostream;
3131
class LLVMContext;
@@ -57,6 +57,9 @@ class MMRAMetadata {
5757
return MMRAMetadata(A).isCompatibleWith(B);
5858
}
5959

60+
/// \returns true if \p MD is a well-formed MMRA tag.
61+
static bool isTagMD(const Metadata *MD);
62+
6063
/// \returns whether this set of tags is compatible with \p Other.
6164
bool isCompatibleWith(const MMRAMetadata &Other) const;
6265

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,12 +796,10 @@ Instruction *llvm::propagateMetadata(Instruction *Inst, ArrayRef<Value *> VL) {
796796
LLVMContext::MD_nontemporal, LLVMContext::MD_invariant_load,
797797
LLVMContext::MD_access_group, LLVMContext::MD_mmra}) {
798798
MDNode *MD = I0->getMetadata(Kind);
799-
if (Kind == LLVMContext::MD_mmra && !MD)
800-
continue;
801-
802799
for (int J = 1, E = VL.size(); MD && J != E; ++J) {
803800
const Instruction *IJ = cast<Instruction>(VL[J]);
804801
MDNode *IMD = IJ->getMetadata(Kind);
802+
805803
switch (Kind) {
806804
case LLVMContext::MD_mmra: {
807805
auto Tags = MMRAMetadata(dyn_cast_or_null<MDTuple>(MD));

llvm/lib/IR/MemoryModelRelaxationAnnotations.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ MMRAMetadata::MMRAMetadata(MDNode *MD) {
3434
// CTor can use the tryParse & just fatal on err.
3535

3636
MDTuple *Tuple = dyn_cast<MDTuple>(MD);
37-
if (!Tuple)
38-
report_fatal_error("MMRAs should always be MDTuples!");
37+
assert(Tuple && "Invalid MMRA structure");
3938

4039
const auto HandleTagMD = [this](MDNode *TagMD) {
4140
addTag(cast<MDString>(TagMD->getOperand(0))->getString(),
@@ -49,18 +48,20 @@ MMRAMetadata::MMRAMetadata(MDNode *MD) {
4948

5049
for (const MDOperand &Op : Tuple->operands()) {
5150
MDNode *MDOp = cast<MDNode>(Op.get());
52-
if (!isTagMD(MDOp)) {
53-
errs() << "MD Node:\n";
54-
MD->print(errs());
55-
errs() << "Operand:\n";
56-
Op->print(errs());
57-
report_fatal_error("Invalid MMRA Metadata Structure!");
58-
}
59-
51+
assert(isTagMD(MDOp));
6052
HandleTagMD(MDOp);
6153
}
6254
}
6355

56+
bool MMRAMetadata::isTagMD(const Metadata *MD) {
57+
if (auto *Tuple = dyn_cast<MDTuple>(MD)) {
58+
return Tuple->getNumOperands() == 2 &&
59+
isa<MDString>(Tuple->getOperand(0)) &&
60+
isa<MDString>(Tuple->getOperand(1));
61+
}
62+
return false;
63+
}
64+
6465
bool MMRAMetadata::isCompatibleWith(const MMRAMetadata &Other) const {
6566
// Two sets of tags are compatible iff, for every unique tag prefix P
6667
// present in at least one set:

llvm/lib/IR/Verifier.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4829,14 +4829,18 @@ void Verifier::visitMMRAMetadata(Instruction &I, MDNode *MD) {
48294829
isa<MDString>(Tuple->getOperand(1));
48304830
};
48314831

4832-
// Simple MMRA metadata like !{!"foo", "!bar"} -> ok.
4833-
if (IsLeaf(MD))
4832+
// MMRA Metadata should either be a tag, e.g. !{!"foo", !"bar"}, or a
4833+
// list of tags such as !2 in the following example:
4834+
// !0 = !{!"a", !"b"}
4835+
// !1 = !{!"c", !"d"}
4836+
// !2 = !{!0, !1}
4837+
if (MMRAMetadata::isTagMD(MD))
48344838
return;
48354839

48364840
Check(isa<MDTuple>(MD), "!mmra expected to be a metadata tuple", I, MD);
48374841
for (const MDOperand &MDOp : MD->operands())
4838-
Check(IsLeaf(MDOp), "!mmra metadata tuple operand is not an MMRA tag", I,
4839-
MDOp.get());
4842+
Check(MMRAMetadata::isTagMD(MDOp.get()),
4843+
"!mmra metadata tuple operand is not an MMRA tag", I, MDOp.get());
48404844
}
48414845

48424846
void Verifier::visitCallStackMetadata(MDNode *MD) {

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "llvm/IR/DebugInfoMetadata.h"
2121
#include "llvm/IR/IntrinsicInst.h"
2222
#include "llvm/IR/LLVMContext.h"
23-
#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
2423
#include "llvm/IR/PatternMatch.h"
2524
#include "llvm/Transforms/InstCombine/InstCombiner.h"
2625
#include "llvm/Transforms/Utils/Local.h"
@@ -1522,8 +1521,7 @@ bool InstCombinerImpl::mergeStoreIntoSuccessor(StoreInst &SI) {
15221521
auto *SIVTy = SI.getValueOperand()->getType();
15231522
auto *OSVTy = OtherStore->getValueOperand()->getType();
15241523
return CastInst::isBitOrNoopPointerCastable(OSVTy, SIVTy, DL) &&
1525-
SI.hasSameSpecialState(OtherStore) &&
1526-
MMRAMetadata(SI) == MMRAMetadata(*OtherStore);
1524+
SI.hasSameSpecialState(OtherStore);
15271525
};
15281526

15291527
// If the other block ends in an unconditional branch, check for the 'if then

llvm/lib/Transforms/Scalar/EarlyCSE.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "llvm/IR/Instructions.h"
3737
#include "llvm/IR/IntrinsicInst.h"
3838
#include "llvm/IR/LLVMContext.h"
39-
#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
4039
#include "llvm/IR/PassManager.h"
4140
#include "llvm/IR/PatternMatch.h"
4241
#include "llvm/IR/Type.h"
@@ -363,11 +362,6 @@ static bool isEqualImpl(SimpleValue LHS, SimpleValue RHS) {
363362

364363
if (LHSI->getOpcode() != RHSI->getOpcode())
365364
return false;
366-
367-
// Avoid aggressively combining MMRAs.
368-
if (MMRAMetadata(*LHSI) != MMRAMetadata(*RHSI))
369-
return false;
370-
371365
if (LHSI->isIdenticalToWhenDefined(RHSI)) {
372366
// Convergent calls implicitly depend on the set of threads that is
373367
// currently executing, so conservatively return false if they are in
@@ -1591,10 +1585,6 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
15911585
LLVM_DEBUG(dbgs() << "Skipping due to debug counter\n");
15921586
continue;
15931587
}
1594-
if (MMRAMetadata(Inst) != MMRAMetadata(*InVal.DefInst)) {
1595-
LLVM_DEBUG(dbgs() << "Skipping due to MMRAs being different\n");
1596-
continue;
1597-
}
15981588
if (InVal.IsLoad)
15991589
if (auto *I = dyn_cast<Instruction>(Op))
16001590
combineMetadataForCSE(I, &Inst, false);
@@ -1642,10 +1632,6 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
16421632
LLVM_DEBUG(dbgs() << "Skipping due to debug counter\n");
16431633
continue;
16441634
}
1645-
if (MMRAMetadata(Inst) != MMRAMetadata(*InVal.first)) {
1646-
LLVM_DEBUG(dbgs() << "Skipping due to MMRAs being different\n");
1647-
continue;
1648-
}
16491635
if (!Inst.use_empty())
16501636
Inst.replaceAllUsesWith(InVal.first);
16511637
salvageKnowledge(&Inst, &AC);

llvm/lib/Transforms/Scalar/GVNHoist.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ static void combineKnownMetadata(Instruction *ReplInst, Instruction *I) {
246246
LLVMContext::MD_fpmath,
247247
LLVMContext::MD_invariant_load,
248248
LLVMContext::MD_invariant_group,
249-
LLVMContext::MD_access_group,
250-
LLVMContext::MD_mmra};
249+
LLVMContext::MD_access_group};
251250
combineMetadata(ReplInst, I, KnownIDs, true);
252251
}
253252

llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
#include "llvm/Analysis/GlobalsModRef.h"
8181
#include "llvm/IR/IRBuilder.h"
8282
#include "llvm/IR/Instructions.h"
83-
#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
8483
#include "llvm/Support/Debug.h"
8584
#include "llvm/Support/raw_ostream.h"
8685
#include "llvm/Transforms/Scalar.h"
@@ -197,11 +196,10 @@ StoreInst *MergedLoadStoreMotion::canSinkFromBlock(BasicBlock *BB1,
197196
!isStoreSinkBarrierInRange(*Store1->getNextNode(), BB1->back(), Loc1) &&
198197
!isStoreSinkBarrierInRange(*Store0->getNextNode(), BB0->back(), Loc0) &&
199198
Store0->hasSameSpecialState(Store1) &&
200-
MMRAMetadata(*Store0) == MMRAMetadata(*Store1) &
201-
CastInst::isBitOrNoopPointerCastable(
202-
Store0->getValueOperand()->getType(),
203-
Store1->getValueOperand()->getType(),
204-
Store0->getModule()->getDataLayout()))
199+
CastInst::isBitOrNoopPointerCastable(
200+
Store0->getValueOperand()->getType(),
201+
Store1->getValueOperand()->getType(),
202+
Store0->getModule()->getDataLayout()))
205203
return Store1;
206204
}
207205
return nullptr;

llvm/test/Transforms/EarlyCSE/mmra.ll

Lines changed: 0 additions & 56 deletions
This file was deleted.

llvm/test/Transforms/GVNHoist/hoist-md.ll

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -157,35 +157,6 @@ return: ; preds = %if.end, %if.then
157157
ret ptr %retval.0
158158
}
159159

160-
; TODO: We might want to disable GVN if MMRAs differ.
161-
define void @test6(i1 %b, ptr %x) {
162-
; CHECK-LABEL: define void @test6
163-
; CHECK-SAME: (i1 [[B:%.*]], ptr [[X:%.*]]) {
164-
; CHECK-NEXT: entry:
165-
; CHECK-NEXT: store i32 2, ptr [[X]], align 4, !mmra [[META4:![0-9]+]]
166-
; CHECK-NEXT: br i1 [[B]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
167-
; CHECK: if.then:
168-
; CHECK-NEXT: br label [[IF_END:%.*]]
169-
; CHECK: if.else:
170-
; CHECK-NEXT: br label [[IF_END]]
171-
; CHECK: if.end:
172-
; CHECK-NEXT: ret void
173-
;
174-
entry:
175-
br i1 %b, label %if.then, label %if.else
176-
177-
if.then: ; preds = %entry
178-
store i32 2, ptr %x, align 4, !mmra !13
179-
br label %if.end
180-
181-
if.else: ; preds = %entry
182-
store i32 2, ptr %x, align 4, !mmra !14
183-
br label %if.end
184-
185-
if.end: ; preds = %if.else, %if.then
186-
ret void
187-
}
188-
189160
!1 = !{!2, !2, i64 0}
190161
!2 = !{!"int", !3, i64 0}
191162
!3 = !{!"omnipotent char", !4, i64 0}
@@ -195,19 +166,9 @@ if.end: ; preds = %if.else, %if.then
195166
!7 = !{i32 0, i32 2}
196167
!8 = !{i32 3, i32 4}
197168
!9 = !{}
198-
199-
!10 = !{!"foo", !"bar"}
200-
!11 = !{!"foo", !"bux"}
201-
!12 = !{!"bar", !"baz"}
202-
!13 = !{!10, !11}
203-
!14 = !{!11, !12}
204-
205169
;.
206-
; CHECK: [[TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0}
207-
; CHECK: [[META1]] = !{!"omnipotent char", [[META2:![0-9]+]], i64 0}
208-
; CHECK: [[META2]] = !{!"Simple C++ TBAA"}
170+
; CHECK: [[TBAA0]] = !{!1, !1, i64 0}
171+
; CHECK: [[META1:![0-9]+]] = !{!"omnipotent char", !2, i64 0}
172+
; CHECK: [[META2:![0-9]+]] = !{!"Simple C++ TBAA"}
209173
; CHECK: [[RNG3]] = !{i32 0, i32 2, i32 3, i32 4}
210-
; CHECK: [[META4]] = !{[[META5:![0-9]+]], [[META6:![0-9]+]]}
211-
; CHECK: [[META5]] = !{!"foo", !"bar"}
212-
; CHECK: [[META6]] = !{!"foo", !"bux"}
213174
;.

llvm/test/Transforms/MergedLoadStoreMotion/st_sink_mmras.ll

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)