Skip to content

Commit dbc1676

Browse files
Set target_mem when they are not set with inaccessiblemem
1 parent 3de8c96 commit dbc1676

File tree

18 files changed

+96
-87
lines changed

18 files changed

+96
-87
lines changed

clang/test/CodeGen/sanitize-metadata-nosanitize.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// CHECK: @llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered2.module_ctor, ptr @__sanitizer_metadata_covered2.module_ctor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics2.module_ctor, ptr @__sanitizer_metadata_atomics2.module_ctor }]
1111
// CHECK: @llvm.global_dtors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered2.module_dtor, ptr @__sanitizer_metadata_covered2.module_dtor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics2.module_dtor, ptr @__sanitizer_metadata_atomics2.module_dtor }]
1212
//.
13-
// CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none)
13+
// CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, target_mem0: none, target_mem1: none)
1414
// CHECK-LABEL: define dso_local void @escape(
1515
// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !pcsections [[META6:![0-9]+]] {
1616
// CHECK-NEXT: [[ENTRY:.*:]]
@@ -21,7 +21,7 @@ __attribute__((noinline, not_tail_called)) void escape(const volatile void *p) {
2121
sink = p;
2222
}
2323

24-
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
24+
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem0: none, target_mem1: none)
2525
// CHECK-LABEL: define dso_local i32 @normal_function(
2626
// CHECK-SAME: ptr noundef [[X:%.*]], ptr noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] !pcsections [[META8:![0-9]+]] {
2727
// CHECK-NEXT: [[ENTRY:.*:]]
@@ -38,7 +38,7 @@ int normal_function(int *x, int *y) {
3838
return *y;
3939
}
4040

41-
// CHECK: Function Attrs: disable_sanitizer_instrumentation mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
41+
// CHECK: Function Attrs: disable_sanitizer_instrumentation mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem0: none, target_mem1: none)
4242
// CHECK-LABEL: define dso_local i32 @test_disable_sanitize_instrumentation(
4343
// CHECK-SAME: ptr noundef [[X:%.*]], ptr noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] {
4444
// CHECK-NEXT: [[ENTRY:.*:]]
@@ -55,7 +55,7 @@ __attribute__((disable_sanitizer_instrumentation)) int test_disable_sanitize_ins
5555
return *y;
5656
}
5757

58-
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
58+
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem0: none, target_mem1: none)
5959
// CHECK-LABEL: define dso_local i32 @test_no_sanitize_thread(
6060
// CHECK-SAME: ptr noundef [[X:%.*]], ptr noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] !pcsections [[META14:![0-9]+]] {
6161
// CHECK-NEXT: [[ENTRY:.*:]]
@@ -72,7 +72,7 @@ __attribute__((no_sanitize("thread"))) int test_no_sanitize_thread(int *x, int *
7272
return *y;
7373
}
7474

75-
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none)
75+
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem0: none, target_mem1: none)
7676
// CHECK-LABEL: define dso_local i32 @test_no_sanitize_all(
7777
// CHECK-SAME: ptr noundef [[X:%.*]], ptr noundef readonly captures(none) [[Y:%.*]]) local_unnamed_addr #[[ATTR3]] !pcsections [[META14]] {
7878
// CHECK-NEXT: [[ENTRY:.*:]]
@@ -89,10 +89,10 @@ __attribute__((no_sanitize("all"))) int test_no_sanitize_all(int *x, int *y) {
8989
return *y;
9090
}
9191
//.
92-
// CHECK: attributes #[[ATTR0]] = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
93-
// CHECK: attributes #[[ATTR1]] = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
94-
// CHECK: attributes #[[ATTR2]] = { disable_sanitizer_instrumentation mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
95-
// CHECK: attributes #[[ATTR3]] = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "no_sanitize_thread" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
92+
// CHECK: attributes #[[ATTR0]] = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none, target_mem0: none, target_mem1: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
93+
// CHECK: attributes #[[ATTR1]] = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem0: none, target_mem1: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
94+
// CHECK: attributes #[[ATTR2]] = { disable_sanitizer_instrumentation mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem0: none, target_mem1: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
95+
// CHECK: attributes #[[ATTR3]] = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none, target_mem0: none, target_mem1: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "no_sanitize_thread" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
9696
// CHECK: attributes #[[ATTR4:[0-9]+]] = { nounwind "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
9797
//.
9898
// CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}

llvm/docs/LangRef.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,8 @@ For example:
21782178
This attribute specifies the possible memory effects of the call-site or
21792179
function. It allows specifying the possible access kinds (``none``,
21802180
``read``, ``write``, or ``readwrite``) for the possible memory location
2181-
kinds (``argmem``, ``inaccessiblemem``, ``errnomem``, as well as a default).
2181+
kinds (``argmem``, ``inaccessiblemem``, ``errnomem``, ``target_mem0``,
2182+
``target_mem1``, as well as a default).
21822183
It is best understood by example:
21832184

21842185
- ``memory(none)``: Does not access any memory.
@@ -2220,6 +2221,10 @@ For example:
22202221
accessing inaccessible memory itself). Inaccessible memory is often used
22212222
to model control dependencies of intrinsics.
22222223
- ``errnomem``: This refers to accesses to the ``errno`` variable.
2224+
- ``target_mem#`` : These refer to target specific state that cannot be
2225+
accessed by any other means. # is a number between 0 and 1 inclusive.
2226+
2227+
22232228
- The default access kind (specified without a location prefix) applies to
22242229
all locations that haven't been specified explicitly, including those that
22252230
don't currently have a dedicated location kind (e.g. accesses to globals

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,30 @@ def IntrArgMemOnly : IntrinsicProperty;
4949
// accessible by the module being compiled. This is a weaker form of IntrNoMem.
5050
def IntrInaccessibleMemOnly : IntrinsicProperty;
5151

52+
// IntrInaccessibleMemOrArgMemOnly -- This intrinsic only accesses memory that
53+
// its pointer-typed arguments point to or memory that is not accessible
54+
// by the module being compiled. This is a weaker form of IntrArgMemOnly.
55+
def IntrInaccessibleMemOrArgMemOnly : IntrinsicProperty;
5256

53-
54-
class IntrinsicMemoryLocation;
5557
// Tablegen representation of IRMemLocation.
58+
class IntrinsicMemoryLocation;
59+
5660
// TODO: Populate with all IRMemLocation enum values and update
5761
// getValueAsIRMemLocation accordingly.
5862
def InaccessibleMem : IntrinsicMemoryLocation;
5963
def TargetMem0 : IntrinsicMemoryLocation;
6064
def TargetMem1 : IntrinsicMemoryLocation;
65+
6166
// The list of IRMemoryLocations that are read from.
6267
class IntrRead<list<IntrinsicMemoryLocation> idx> : IntrinsicProperty {
6368
list<IntrinsicMemoryLocation> MemLoc=idx;
6469
}
65-
// The list of IRMemoryLocations that are write from.
70+
71+
// The list of IRMemoryLocations that are write to.
6672
class IntrWrite<list<IntrinsicMemoryLocation> idx> : IntrinsicProperty {
6773
list<IntrinsicMemoryLocation> MemLoc=idx;
6874
}
6975

70-
71-
// IntrInaccessibleMemOrArgMemOnly -- This intrinsic only accesses memory that
72-
// its pointer-typed arguments point to or memory that is not accessible
73-
// by the module being compiled. This is a weaker form of IntrArgMemOnly.
74-
def IntrInaccessibleMemOrArgMemOnly : IntrinsicProperty;
75-
7676
// Commutative - This intrinsic is commutative: X op Y == Y op X.
7777
def Commutative : IntrinsicProperty;
7878

llvm/include/llvm/Support/ModRef.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ enum class IRMemLocation {
6666
ErrnoMem = 2,
6767
/// Any other memory.
6868
Other = 3,
69-
/// Target Memory Location
70-
/// Used by a target to represent target specif memory regions
69+
/// Represents target specific state.
7170
TargetMem0 = 4,
7271
TargetMem1 = 5,
7372

@@ -184,11 +183,6 @@ template <typename LocationEnum> class MemoryEffectsBase {
184183
return MemoryEffectsBase(Data);
185184
}
186185

187-
bool isTargetMemLoc(IRMemLocation Loc) {
188-
return static_cast<unsigned>(Loc) >=
189-
static_cast<unsigned>(Location::FirstTarget);
190-
}
191-
192186
/// Convert MemoryEffectsBase into an encoded integer value (used by memory
193187
/// attribute).
194188
uint32_t toIntValue() const {
@@ -243,9 +237,9 @@ template <typename LocationEnum> class MemoryEffectsBase {
243237

244238
/// Whether this function only (at most) accesses inaccessible memory.
245239
bool onlyAccessesInaccessibleMem() const {
246-
return getWithoutLoc(IRMemLocation::TargetMem0)
240+
return getWithoutLoc(Location::InaccessibleMem)
241+
.getWithoutLoc(IRMemLocation::TargetMem0)
247242
.getWithoutLoc(IRMemLocation::TargetMem1)
248-
.getWithoutLoc(Location::InaccessibleMem)
249243
.doesNotAccessMemory();
250244
}
251245

@@ -259,6 +253,8 @@ template <typename LocationEnum> class MemoryEffectsBase {
259253
bool onlyAccessesInaccessibleOrArgMem() const {
260254
return getWithoutLoc(Location::InaccessibleMem)
261255
.getWithoutLoc(Location::ArgMem)
256+
.getWithoutLoc(Location::TargetMem0)
257+
.getWithoutLoc(Location::TargetMem1)
262258
.doesNotAccessMemory();
263259
}
264260

llvm/lib/IR/Attributes.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
630630
// Print access kind for "other" as the default access kind. This way it
631631
// will apply to any new location kinds that get split out of "other".
632632
ModRefInfo OtherMR = ME.getModRef(IRMemLocation::Other);
633-
ModRefInfo InaccessibleMemMR = ME.getModRef(IRMemLocation::InaccessibleMem);
634633
if (OtherMR != ModRefInfo::NoModRef || ME.getModRef() == OtherMR) {
635634
First = false;
636635
OS << getModRefStr(OtherMR);
@@ -641,11 +640,6 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
641640
if (MR == OtherMR)
642641
continue;
643642

644-
// Only prints Target Location if InaccessibleMem and Target_MemX
645-
// ModRefInfo is different. Otherwise skpit Target_Mem print
646-
if (ME.isTargetMemLoc(Loc) && MR == InaccessibleMemMR)
647-
continue;
648-
649643
if (!First)
650644
OS << ", ";
651645
First = false;

llvm/test/Assembler/memory-attribute.ll

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,27 @@ declare void @fn_read_target_mem0_write_mem_target1()
109109
declare void @fn_inaccessiblemem_write_new()
110110
memory(inaccessiblemem: write)
111111

112-
; CHECK: Function Attrs: memory(inaccessiblemem: read)
112+
; CHECK: Function Attrs: memory(inaccessiblemem: read, target_mem0: read, target_mem1: read)
113113
; CHECK: @fn_inaccessiblemem_target_mem0_1read()
114114
declare void @fn_inaccessiblemem_target_mem0_1read()
115-
memory(inaccessiblemem: read, target_mem0: read, target_mem0: read)
115+
memory(inaccessiblemem: read, target_mem0: read, target_mem1: read)
116116

117117
; CHECK: Function Attrs: memory(target_mem0: read)
118118
; CHECK: @fn_inaccessiblemem_none_target_mem0_read()
119119
declare void @fn_inaccessiblemem_none_target_mem0_read()
120120
memory(inaccessiblemem: none, target_mem0: read)
121+
122+
; CHECK: Function Attrs: memory(write, inaccessiblemem: read)
123+
; CHECK: @fn_write_inaccessiblemem_read_target_mem0_write
124+
declare void @fn_write_inaccessiblemem_read_target_mem0_write()
125+
memory(write, inaccessiblemem: read, target_mem0: write)
126+
127+
; CHECK: Function Attrs: memory(write, target_mem0: read)
128+
; CHECK: @fn_write_inaccessiblemem_write_target_mem0_read()
129+
declare void @fn_write_inaccessiblemem_write_target_mem0_read()
130+
memory(write, inaccessiblemem: write, target_mem0: read)
131+
132+
; CHECK: Function Attrs: memory(write, target_mem0: read)
133+
; CHECK: @fn_write_target_mem0_readwrite()
134+
declare void @fn_write_target_mem0_readwrite()
135+
memory(write, target_mem0: read)

llvm/test/Bitcode/memory-attribute-upgrade.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
; CHECK: ; Function Attrs: memory(write, argmem: read, target_mem0: none, target_mem1: none)
44
; CHECK-NEXT: define void @test_any_write_argmem_read(ptr %p)
55

6-
; CHECK: ; Function Attrs: memory(read, argmem: readwrite, inaccessiblemem: none)
6+
; CHECK: ; Function Attrs: memory(read, argmem: readwrite, inaccessiblemem: none, target_mem0: none, target_mem1: none)
77
; CHECK-NEXT: define void @test_any_read_argmem_readwrite(ptr %p)

llvm/test/TableGen/target-mem-intrinsic-attrs.td

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
include "llvm/IR/Intrinsics.td"
44

5-
def int_aarch64_set_inaccessible_mem : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrWriteMem, IntrWrite<[InaccessibleMem]>]>;
5+
def int_aarch64_get_target_mem0_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrReadMem, IntrRead<[TargetMem0, TargetMem1]>]>;
66

7-
def int_aarch64_set_target_mem0 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrWriteMem, IntrWrite<[TargetMem0]>]>;
7+
def int_aarch64_get_target_mem0_set_target_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrRead<[TargetMem0]>, IntrWrite<[TargetMem1]>]>;
88

99
def int_aarch64_get_target_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrReadMem, IntrRead<[TargetMem1]>]>;
1010

11-
def int_aarch64_get_target_mem0_set_target_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrRead<[TargetMem0]>, IntrWrite<[TargetMem1]>]>;
12-
1311
def int_aarch64_get_target_mem1_set_target_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrRead<[TargetMem1]>, IntrWrite<[TargetMem1]>]>;
1412

15-
def int_aarch64_get_target_mem0_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrReadMem, IntrRead<[TargetMem0, TargetMem1]>]>;
13+
def int_aarch64_set_inaccessible_mem : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrWriteMem, IntrWrite<[InaccessibleMem]>]>;
1614

15+
def int_aarch64_set_target_mem0 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrWriteMem, IntrWrite<[TargetMem0]>]>;
1716

1817
// CHECK: static AttributeSet getIntrinsicFnAttributeSet(LLVMContext &C, unsigned ID) {
1918
// CHECK-NEXT: switch (ID) {

0 commit comments

Comments
 (0)