Skip to content

Commit 1bfa52d

Browse files
Address comments about tablegen
1 parent 54f80f0 commit 1bfa52d

File tree

5 files changed

+67
-32
lines changed

5 files changed

+67
-32
lines changed

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ class IntrinsicMemoryLocation;
5656
def TargetMem0 : IntrinsicMemoryLocation;
5757
def TargetMem1 : IntrinsicMemoryLocation;
5858
// IntrInaccessible{Read|Write}MemOnly needs to set Location
59-
class IntrInaccessibleReadMemOnly<IntrinsicMemoryLocation idx> : IntrinsicProperty{IntrinsicMemoryLocation Loc=idx;}
60-
class IntrInaccessibleWriteMemOnly<IntrinsicMemoryLocation idx> : IntrinsicProperty{IntrinsicMemoryLocation Loc=idx;}
59+
class IntrRead<list<IntrinsicMemoryLocation> idx> : IntrinsicProperty {
60+
list<IntrinsicMemoryLocation> Loc=idx;
61+
}
62+
63+
class IntrWrite<list<IntrinsicMemoryLocation> idx> : IntrinsicProperty {
64+
list<IntrinsicMemoryLocation> Loc=idx;
65+
}
66+
6167

6268
// IntrInaccessibleMemOrArgMemOnly -- This intrinsic only accesses memory that
6369
// its pointer-typed arguments point to or memory that is not accessible

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

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,49 @@
22

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

5-
def int_aarch64_set_target_mem0 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrInaccessibleWriteMemOnly<TargetMem0>]>;
5+
def int_aarch64_set_target_mem0 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrWriteMem, IntrWrite<[TargetMem0]>]>;
66

7-
def int_aarch64_get_target_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrInaccessibleReadMemOnly<TargetMem1>]>;
7+
def int_aarch64_get_target_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrReadMem, IntrRead<[TargetMem1]>]>;
88

9-
def int_aarch64_get_target_mem0_set_target_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrInaccessibleReadMemOnly<TargetMem0>, IntrInaccessibleWriteMemOnly<TargetMem1>]>;
9+
def int_aarch64_get_target_mem0_set_target_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrRead<[TargetMem0]>, IntrWrite<[TargetMem1]>]>;
10+
11+
def int_aarch64_get_target_mem1_set_target_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrRead<[TargetMem1]>, IntrWrite<[TargetMem1]>]>;
12+
13+
def int_aarch64_get_target_mem0_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrReadMem, IntrRead<[TargetMem0, TargetMem1]>]>;
1014

1115
// CHECK: static constexpr unsigned IntrinsicNameOffsetTable[] = {
1216
// CHECK-NEXT: 1, // not_intrinsic
13-
// CHECK-NEXT: 15, // llvm.aarch64.get.target.mem0.set.target.mem1
14-
// CHECK-NEXT: 60, // llvm.aarch64.get.target.mem1
15-
// CHECK-NEXT: 89, // llvm.aarch64.set.target.mem0
17+
// CHECK-NEXT: 15, // llvm.aarch64.get.target.mem0.mem1
18+
// CHECK-NEXT: 49, // llvm.aarch64.get.target.mem0.set.target.mem1
19+
// CHECK-NEXT: 94, // llvm.aarch64.get.target.mem1
20+
// CHECK-NEXT: 123, // llvm.aarch64.get.target.mem1.set.target.mem1
21+
// CHECK-NEXT: 168, // llvm.aarch64.set.target.mem0
22+
1623

1724
// CHECK: static AttributeSet getIntrinsicFnAttributeSet(LLVMContext &C, unsigned ID) {
1825
// CHECK-NEXT: switch (ID) {
1926
// CHECK-NEXT: default: llvm_unreachable("Invalid attribute set number");
20-
// CHECK-NEXT: case 0:
27+
// CHECK-NEXT: case 0: // llvm.aarch64.get.target.mem0.mem1
2128
// CHECK-NEXT: return AttributeSet::get(C, {
2229
// CHECK-NEXT: Attribute::get(C, Attribute::NoUnwind),
2330
// CHECK-NEXT: Attribute::get(C, Attribute::NoCallback),
2431
// CHECK-NEXT: Attribute::get(C, Attribute::NoSync),
2532
// CHECK-NEXT: Attribute::get(C, Attribute::NoFree),
2633
// CHECK-NEXT: Attribute::get(C, Attribute::WillReturn),
34+
// CHECK-NEXT: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: Ref, TargetMem1: Ref
35+
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(1280)),
36+
// CHECK-NEXT: });
37+
// CHECK-NEXT: case 1: // llvm.aarch64.get.target.mem0.set.target.mem1
38+
// CHECK-NEXT: return AttributeSet::get(C, {
39+
// CHECK-NEXT: Attribute::get(C, Attribute::NoUnwind),
40+
// CHECK-NEXT: Attribute::get(C, Attribute::NoCallback),
41+
// CHECK-NEXT: Attribute::get(C, Attribute::NoSync),
42+
// CHECK-NEXT: Attribute::get(C, Attribute::NoFree),
43+
// CHECK-NEXT: Attribute::get(C, Attribute::WillReturn),
2744
// CHECK-NEXT: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: Ref, TargetMem1: Mod
2845
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(2304)),
2946
// CHECK-NEXT: });
30-
// CHECK-NEXT: case 1:
47+
// CHECK-NEXT: case 2: // llvm.aarch64.get.target.mem1
3148
// CHECK-NEXT: return AttributeSet::get(C, {
3249
// CHECK-NEXT: Attribute::get(C, Attribute::NoUnwind),
3350
// CHECK-NEXT: Attribute::get(C, Attribute::NoCallback),
@@ -37,7 +54,17 @@ def int_aarch64_get_target_mem0_set_target_mem1 : DefaultAttrsIntrinsic<[], [l
3754
// CHECK-NEXT: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: NoModRef, TargetMem1: Ref
3855
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(1024)),
3956
// CHECK-NEXT: });
40-
// CHECK-NEXT: case 2:
57+
// CHECK-NEXT: case 3: // llvm.aarch64.get.target.mem1.set.target.mem1
58+
// CHECK-NEXT: return AttributeSet::get(C, {
59+
// CHECK-NEXT: Attribute::get(C, Attribute::NoUnwind),
60+
// CHECK-NEXT: Attribute::get(C, Attribute::NoCallback),
61+
// CHECK-NEXT: Attribute::get(C, Attribute::NoSync),
62+
// CHECK-NEXT: Attribute::get(C, Attribute::NoFree),
63+
// CHECK-NEXT: Attribute::get(C, Attribute::WillReturn),
64+
// CHECK-NEXT: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: NoModRef, TargetMem1: ModRef
65+
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(3072)),
66+
// CHECK-NEXT: });
67+
// CHECK-NEXT: case 4: // llvm.aarch64.set.target.mem0
4168
// CHECK-NEXT: return AttributeSet::get(C, {
4269
// CHECK-NEXT: Attribute::get(C, Attribute::NoUnwind),
4370
// CHECK-NEXT: Attribute::get(C, Attribute::NoCallback),

llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,20 @@ void CodeGenIntrinsic::setProperty(const Record *R) {
375375
ME &= MemoryEffects::argMemOnly();
376376
else if (R->getName() == "IntrInaccessibleMemOnly")
377377
ME &= MemoryEffects::inaccessibleMemOnly();
378-
else if (R->isSubClassOf("IntrInaccessibleReadMemOnly")) {
379-
llvm::IRMemLocation Loc = getValueAsIRMemLocation(R, "Loc");
380-
if (ME.onlyAccessTargetMemoryLocation())
381-
ME = ME.getWithModRef(Loc, ModRefInfo::Ref);
382-
else
383-
ME &= MemoryEffects::inaccessibleReadMemOnly(Loc);
384-
} else if (R->isSubClassOf("IntrInaccessibleWriteMemOnly")) {
385-
llvm::IRMemLocation Loc = getValueAsIRMemLocation(R, "Loc");
386-
if (ME.onlyAccessTargetMemoryLocation())
387-
ME = ME.getWithModRef(Loc, ModRefInfo::Mod);
388-
else
389-
ME &= MemoryEffects::inaccessibleWriteMemOnly(Loc);
378+
else if (R->isSubClassOf("IntrRead")) {
379+
MemoryEffects ReadMask = MemoryEffects::writeOnly();
380+
for (const Record *RLoc : R->getValueAsListOfDefs("Loc"))
381+
ReadMask = ReadMask.getWithModRef(getValueAsIRMemLocation(RLoc),
382+
ModRefInfo::ModRef);
383+
ME &= ReadMask;
384+
385+
} else if (R->isSubClassOf("IntrWrite")) {
386+
MemoryEffects WriteMask = MemoryEffects::readOnly();
387+
for (const Record *RLoc : R->getValueAsListOfDefs("Loc"))
388+
WriteMask = WriteMask.getWithModRef(getValueAsIRMemLocation(RLoc),
389+
ModRefInfo::ModRef);
390+
ME &= WriteMask;
391+
390392
} else if (R->getName() == "IntrInaccessibleMemOrArgMemOnly")
391393
ME &= MemoryEffects::inaccessibleOrArgMemOnly();
392394
else if (R->getName() == "Commutative")
@@ -463,11 +465,8 @@ void CodeGenIntrinsic::setProperty(const Record *R) {
463465
}
464466

465467
llvm::IRMemLocation
466-
CodeGenIntrinsic::getValueAsIRMemLocation(const Record *R,
467-
StringRef FieldName) const {
468-
const Record *LocRec = R->getValueAsDef(FieldName);
469-
StringRef Name = LocRec->getName();
470-
468+
CodeGenIntrinsic::getValueAsIRMemLocation(const Record *R) const {
469+
StringRef Name = R->getName();
471470
IRMemLocation Loc =
472471
StringSwitch<IRMemLocation>(Name)
473472
.Case("TargetMem0", IRMemLocation::TargetMem0)
@@ -479,6 +478,10 @@ CodeGenIntrinsic::getValueAsIRMemLocation(const Record *R,
479478
PrintFatalError(R->getLoc(), "unknown Target IRMemLocation: " + Name);
480479

481480
return Loc;
481+
if (Loc == IRMemLocation::Other)
482+
PrintFatalError(R->getLoc(), "unknown Target IRMemLocation: " + Name);
483+
484+
return Loc;
482485
}
483486

484487
bool CodeGenIntrinsic::isParamAPointer(unsigned ParamIdx) const {

llvm/utils/TableGen/Basic/CodeGenIntrinsics.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ struct CodeGenIntrinsic {
170170

171171
bool isParamImmArg(unsigned ParamIdx) const;
172172

173-
llvm::IRMemLocation getValueAsIRMemLocation(const Record *R,
174-
StringRef FieldName) const;
173+
llvm::IRMemLocation getValueAsIRMemLocation(const Record *R) const;
175174

176175
CodeGenIntrinsic(const Record *R, const CodeGenIntrinsicContext &Ctx);
177176
};

llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,10 @@ static AttributeSet getIntrinsicFnAttributeSet(LLVMContext &C, unsigned ID) {
574574
if (!UniqFnAttributes.try_emplace(&Int, ID).second)
575575
continue;
576576
OS << formatv(R"(
577-
case {}:
577+
case {}: // {}
578578
return AttributeSet::get(C, {{
579579
)",
580-
ID);
580+
ID, Int.Name);
581581
auto addAttribute = [&OS](StringRef Attr) {
582582
OS << formatv(" Attribute::get(C, Attribute::{}),\n", Attr);
583583
};

0 commit comments

Comments
 (0)