Skip to content

Commit 54f80f0

Browse files
Address review comments
1 parent b470dfd commit 54f80f0

File tree

7 files changed

+33
-31
lines changed

7 files changed

+33
-31
lines changed

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def IntrInaccessibleMemOnly : IntrinsicProperty;
5252

5353

5454
class IntrinsicMemoryLocation;
55-
// This should be added in the Target, but once in IntrinsicsAArch64.td
55+
// These are used to represent Generic Memory Location.
5656
def TargetMem0 : IntrinsicMemoryLocation;
5757
def TargetMem1 : IntrinsicMemoryLocation;
5858
// IntrInaccessible{Read|Write}MemOnly needs to set Location

llvm/include/llvm/Support/ModRef.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ enum class IRMemLocation {
7373

7474
/// Helpers to iterate all locations in the MemoryEffectsBase class.
7575
First = ArgMem,
76-
Last = TargetMem1,
7776
FirstTarget = TargetMem0,
77+
// TargetMem IDs must be at the end of the list.
78+
Last = TargetMem1,
7879
};
7980

8081
template <typename LocationEnum> class MemoryEffectsBase {

llvm/lib/IR/AsmWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5012,7 +5012,7 @@ void AssemblyWriter::writeAllAttributeGroups() {
50125012

50135013
for (const auto &I : asVec)
50145014
Out << "attributes #" << I.second << " = { "
5015-
<< I.first.getAsString(true) << " }\n";
5015+
<< I.first.getAsString(true) << " }\n";
50165016
}
50175017

50185018
void AssemblyWriter::printUseListOrder(const Value *V,

llvm/lib/IR/Attributes.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,10 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
640640
if (MR == OtherMR)
641641
continue;
642642

643-
// Dont want to print Target Location if NoModRef
643+
// Dont Print Target Location if MR and target_mems ModRefInfo
644+
// are NoModRef.
645+
// Printing Inacessiblemem: none implies that target_mems are also
646+
// not affected.
644647
if (ME.isTargetMemLoc(Loc) && (MR == ModRefInfo::NoModRef))
645648
continue;
646649

@@ -660,15 +663,13 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
660663
break;
661664
case IRMemLocation::Other:
662665
llvm_unreachable("This is represented as the default access kind");
663-
break;
664666
case IRMemLocation::TargetMem0:
665667
OS << "target_mem0: ";
666668
break;
667669
case IRMemLocation::TargetMem1:
668670
OS << "target_mem1: ";
669671
break;
670672
}
671-
672673
OS << getModRefStr(MR);
673674
}
674675
OS << ")";

llvm/test/TableGen/intrinsic-attrs-fp8.td renamed to llvm/test/TableGen/target-mem-intrinsic-attrs.td

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

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

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

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

9-
def int_aarch64_get_fpmr_set_za : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrInaccessibleReadMemOnly<TargetMem0>, IntrInaccessibleWriteMemOnly<TargetMem1>]>;
9+
def int_aarch64_get_target_mem0_set_target_mem1 : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [IntrInaccessibleReadMemOnly<TargetMem0>, IntrInaccessibleWriteMemOnly<TargetMem1>]>;
1010

1111
// CHECK: static constexpr unsigned IntrinsicNameOffsetTable[] = {
1212
// CHECK-NEXT: 1, // not_intrinsic
13-
// CHECK-NEXT: 15, // llvm.aarch64.get.fpmr.set.za
14-
// CHECK-NEXT: 44, // llvm.aarch64.get.za.2
15-
// CHECK-NEXT: 66, // llvm.aarch64.set.fpmr.2
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
1616

1717
// CHECK: static AttributeSet getIntrinsicFnAttributeSet(LLVMContext &C, unsigned ID) {
1818
// CHECK-NEXT: switch (ID) {
@@ -46,8 +46,3 @@ def int_aarch64_get_fpmr_set_za : DefaultAttrsIntrinsic<[], [llvm_i64_ty], [In
4646
// CHECK-NEXT: Attribute::get(C, Attribute::WillReturn),
4747
// CHECK-NEXT: // ArgMem: NoModRef, InaccessibleMem: NoModRef, ErrnoMem: NoModRef, Other: NoModRef, TargetMem0: Mod, TargetMem1: NoModRef
4848
// CHECK-NEXT: Attribute::getWithMemoryEffects(C, MemoryEffects::createFromIntValue(512)),
49-
50-
// CHECK: 0 << 1 | 0, // llvm.aarch64.get.fpmr.set.za
51-
// CHECK-NEXT: 1 << 1 | 0, // llvm.aarch64.get.za.2
52-
// CHECK-NEXT: 2 << 1 | 0, // llvm.aarch64.set.fpmr.2
53-
// CHECK-NEXT:};

llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "CodeGenIntrinsics.h"
1414
#include "llvm/ADT/ArrayRef.h"
1515
#include "llvm/ADT/STLExtras.h"
16+
#include "llvm/ADT/StringSwitch.h"
1617
#include "llvm/ADT/Twine.h"
1718
#include "llvm/Support/ErrorHandling.h"
1819
#include "llvm/TableGen/Error.h"
@@ -375,13 +376,13 @@ void CodeGenIntrinsic::setProperty(const Record *R) {
375376
else if (R->getName() == "IntrInaccessibleMemOnly")
376377
ME &= MemoryEffects::inaccessibleMemOnly();
377378
else if (R->isSubClassOf("IntrInaccessibleReadMemOnly")) {
378-
llvm::IRMemLocation Loc = getLocationTypeAsInt(R, "Loc");
379+
llvm::IRMemLocation Loc = getValueAsIRMemLocation(R, "Loc");
379380
if (ME.onlyAccessTargetMemoryLocation())
380381
ME = ME.getWithModRef(Loc, ModRefInfo::Ref);
381382
else
382383
ME &= MemoryEffects::inaccessibleReadMemOnly(Loc);
383384
} else if (R->isSubClassOf("IntrInaccessibleWriteMemOnly")) {
384-
llvm::IRMemLocation Loc = getLocationTypeAsInt(R, "Loc");
385+
llvm::IRMemLocation Loc = getValueAsIRMemLocation(R, "Loc");
385386
if (ME.onlyAccessTargetMemoryLocation())
386387
ME = ME.getWithModRef(Loc, ModRefInfo::Mod);
387388
else
@@ -462,18 +463,22 @@ void CodeGenIntrinsic::setProperty(const Record *R) {
462463
}
463464

464465
llvm::IRMemLocation
465-
CodeGenIntrinsic::getLocationTypeAsInt(const Record *R,
466-
StringRef FieldName) const {
466+
CodeGenIntrinsic::getValueAsIRMemLocation(const Record *R,
467+
StringRef FieldName) const {
467468
const Record *LocRec = R->getValueAsDef(FieldName);
468469
StringRef Name = LocRec->getName();
469-
if (Name == "TargetMem0")
470-
return IRMemLocation::TargetMem0;
471-
else if (Name == "TargetMem1")
472-
return IRMemLocation::TargetMem1;
473-
else if (Name == "InaccessibleMem")
474-
return llvm::IRMemLocation::InaccessibleMem;
475-
else
476-
PrintFatalError(R->getLoc(), "unknown IRMemLocation: " + Name);
470+
471+
IRMemLocation Loc =
472+
StringSwitch<IRMemLocation>(Name)
473+
.Case("TargetMem0", IRMemLocation::TargetMem0)
474+
.Case("TargetMem1", IRMemLocation::TargetMem1)
475+
.Case("InaccessibleMem", IRMemLocation::InaccessibleMem)
476+
.Default(IRMemLocation::Other); // fallback enum
477+
478+
if (Loc == IRMemLocation::Other)
479+
PrintFatalError(R->getLoc(), "unknown Target IRMemLocation: " + Name);
480+
481+
return Loc;
477482
}
478483

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

llvm/utils/TableGen/Basic/CodeGenIntrinsics.h

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

171171
bool isParamImmArg(unsigned ParamIdx) const;
172172

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

176176
CodeGenIntrinsic(const Record *R, const CodeGenIntrinsicContext &Ctx);
177177
};

0 commit comments

Comments
 (0)