Skip to content

Commit 2f79e06

Browse files
arichardsonresistor
authored andcommitted
[InstSimplify] Simplify getoffset/getaddr folding. NFC
Now that we depend on C++14, we can use switches in constexpr functions and no longer need to pass two template parameters.
1 parent 96f3f03 commit 2f79e06

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

llvm/include/llvm/IR/CheriIntrinsics.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
namespace llvm {
2222
namespace cheri {
2323

24-
inline Intrinsic::ID correspondingSetIntrinsic(Intrinsic::ID GetIntrin) {
24+
inline constexpr Intrinsic::ID
25+
correspondingSetIntrinsic(Intrinsic::ID GetIntrin) {
2526
switch (GetIntrin) {
2627
case Intrinsic::cheri_cap_offset_get:
2728
return Intrinsic::cheri_cap_offset_set;
@@ -33,7 +34,8 @@ inline Intrinsic::ID correspondingSetIntrinsic(Intrinsic::ID GetIntrin) {
3334
llvm_unreachable("No matching set intrinsic");
3435
}
3536
}
36-
inline Intrinsic::ID correspondingGetIntrinsic(Intrinsic::ID SetIntrin) {
37+
inline constexpr Intrinsic::ID
38+
correspondingGetIntrinsic(Intrinsic::ID SetIntrin) {
3739
switch (SetIntrin) {
3840
case Intrinsic::cheri_cap_offset_set:
3941
return Intrinsic::cheri_cap_offset_get;

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6366,9 +6366,10 @@ stripAndAccumulateGEPsAndPointerCastsSameRepr(Value *V, const DataLayout &DL,
63666366
return Result;
63676367
}
63686368

6369-
template <Intrinsic::ID Intrin, Intrinsic::ID SetIntrin>
6369+
template <Intrinsic::ID Intrin>
63706370
static Value *inferCapabilityOffsetOrAddr(Value *V, Type *ResultTy,
63716371
const DataLayout &DL) {
6372+
constexpr Intrinsic::ID SetIntrin = cheri::correspondingSetIntrinsic(Intrin);
63726373
// Try to infer the offset/address from a prior setoffset/setaddr value
63736374
Value *IntrinArg = nullptr;
63746375
// getaddr(setaddr(A, B)) -> B and getoffset(setoffset(A, B)) -> B
@@ -6427,20 +6428,6 @@ static Value *inferCapabilityOffsetOrAddr(Value *V, Type *ResultTy,
64276428
return nullptr;
64286429
}
64296430

6430-
Value *simplifyCapabilityGetOffset(Value *V, Type *ResultTy,
6431-
const DataLayout &DL) {
6432-
return inferCapabilityOffsetOrAddr<Intrinsic::cheri_cap_offset_get,
6433-
Intrinsic::cheri_cap_offset_set>(
6434-
V, ResultTy, DL);
6435-
}
6436-
6437-
Value *simplifyCapabilityGetAddress(Value *V, Type *ResultTy,
6438-
const DataLayout &DL) {
6439-
return inferCapabilityOffsetOrAddr<Intrinsic::cheri_cap_address_get,
6440-
Intrinsic::cheri_cap_address_set>(
6441-
V, ResultTy, DL);
6442-
}
6443-
64446431
static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
64456432
const SimplifyQuery &Q,
64466433
const CallBase *Call) {
@@ -6519,11 +6506,13 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
65196506
case Intrinsic::cheri_cap_length_get:
65206507
break;
65216508
case Intrinsic::cheri_cap_address_get:
6522-
if (Value *V = simplifyCapabilityGetAddress(Op0, F->getReturnType(), Q.DL))
6509+
if (auto *V = inferCapabilityOffsetOrAddr<Intrinsic::cheri_cap_address_get>(
6510+
Op0, F->getReturnType(), Q.DL))
65236511
return V;
65246512
break;
65256513
case Intrinsic::cheri_cap_offset_get:
6526-
if (Value *V = simplifyCapabilityGetOffset(Op0, F->getReturnType(), Q.DL))
6514+
if (auto *V = inferCapabilityOffsetOrAddr<Intrinsic::cheri_cap_offset_get>(
6515+
Op0, F->getReturnType(), Q.DL))
65276516
return V;
65286517
break;
65296518

0 commit comments

Comments
 (0)