[llvm] r329753 - [Verifier] Refactor duplicate code for atomic mem intrinsic verification (NFC)
Daniel Neilson via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 10 13:23:50 PDT 2018
Author: dneilson
Date: Tue Apr 10 13:23:50 2018
New Revision: 329753
URL: http://llvm.org/viewvc/llvm-project?rev=329753&view=rev
Log:
[Verifier] Refactor duplicate code for atomic mem intrinsic verification (NFC)
Summary:
The verification rules for the intrinsics for atomic memcpy, atomic memmove,
and atomic memset are basically code clones. This change merges their verification
rules into a single block to remove duplication.
Modified:
llvm/trunk/lib/IR/Verifier.cpp
Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=329753&r1=329752&r2=329753&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Tue Apr 10 13:23:50 2018
@@ -4085,81 +4085,13 @@ void Verifier::visitIntrinsicCallSite(In
CS);
break;
}
- case Intrinsic::memcpy_element_unordered_atomic: {
- const AtomicMemCpyInst *MI = cast<AtomicMemCpyInst>(CS.getInstruction());
-
- ConstantInt *ElementSizeCI =
- dyn_cast<ConstantInt>(MI->getRawElementSizeInBytes());
- Assert(ElementSizeCI,
- "element size of the element-wise unordered atomic memory "
- "intrinsic must be a constant int",
- CS);
- const APInt &ElementSizeVal = ElementSizeCI->getValue();
- Assert(ElementSizeVal.isPowerOf2(),
- "element size of the element-wise atomic memory intrinsic "
- "must be a power of 2",
- CS);
-
- if (auto *LengthCI = dyn_cast<ConstantInt>(MI->getLength())) {
- uint64_t Length = LengthCI->getZExtValue();
- uint64_t ElementSize = MI->getElementSizeInBytes();
- Assert((Length % ElementSize) == 0,
- "constant length must be a multiple of the element size in the "
- "element-wise atomic memory intrinsic",
- CS);
- }
-
- auto IsValidAlignment = [&](uint64_t Alignment) {
- return isPowerOf2_64(Alignment) && ElementSizeVal.ule(Alignment);
- };
- uint64_t DstAlignment = CS.getParamAlignment(0),
- SrcAlignment = CS.getParamAlignment(1);
- Assert(IsValidAlignment(DstAlignment),
- "incorrect alignment of the destination argument", CS);
- Assert(IsValidAlignment(SrcAlignment),
- "incorrect alignment of the source argument", CS);
- break;
- }
- case Intrinsic::memmove_element_unordered_atomic: {
- auto *MI = cast<AtomicMemMoveInst>(CS.getInstruction());
-
- ConstantInt *ElementSizeCI =
- dyn_cast<ConstantInt>(MI->getRawElementSizeInBytes());
- Assert(ElementSizeCI,
- "element size of the element-wise unordered atomic memory "
- "intrinsic must be a constant int",
- CS);
- const APInt &ElementSizeVal = ElementSizeCI->getValue();
- Assert(ElementSizeVal.isPowerOf2(),
- "element size of the element-wise atomic memory intrinsic "
- "must be a power of 2",
- CS);
-
- if (auto *LengthCI = dyn_cast<ConstantInt>(MI->getLength())) {
- uint64_t Length = LengthCI->getZExtValue();
- uint64_t ElementSize = MI->getElementSizeInBytes();
- Assert((Length % ElementSize) == 0,
- "constant length must be a multiple of the element size in the "
- "element-wise atomic memory intrinsic",
- CS);
- }
-
- auto IsValidAlignment = [&](uint64_t Alignment) {
- return isPowerOf2_64(Alignment) && ElementSizeVal.ule(Alignment);
- };
- uint64_t DstAlignment = CS.getParamAlignment(0),
- SrcAlignment = CS.getParamAlignment(1);
- Assert(IsValidAlignment(DstAlignment),
- "incorrect alignment of the destination argument", CS);
- Assert(IsValidAlignment(SrcAlignment),
- "incorrect alignment of the source argument", CS);
- break;
- }
+ case Intrinsic::memcpy_element_unordered_atomic:
+ case Intrinsic::memmove_element_unordered_atomic:
case Intrinsic::memset_element_unordered_atomic: {
- auto *MI = cast<AtomicMemSetInst>(CS.getInstruction());
+ const auto *AMI = cast<AtomicMemIntrinsic>(CS.getInstruction());
ConstantInt *ElementSizeCI =
- dyn_cast<ConstantInt>(MI->getRawElementSizeInBytes());
+ dyn_cast<ConstantInt>(AMI->getRawElementSizeInBytes());
Assert(ElementSizeCI,
"element size of the element-wise unordered atomic memory "
"intrinsic must be a constant int",
@@ -4170,9 +4102,9 @@ void Verifier::visitIntrinsicCallSite(In
"must be a power of 2",
CS);
- if (auto *LengthCI = dyn_cast<ConstantInt>(MI->getLength())) {
+ if (auto *LengthCI = dyn_cast<ConstantInt>(AMI->getLength())) {
uint64_t Length = LengthCI->getZExtValue();
- uint64_t ElementSize = MI->getElementSizeInBytes();
+ uint64_t ElementSize = AMI->getElementSizeInBytes();
Assert((Length % ElementSize) == 0,
"constant length must be a multiple of the element size in the "
"element-wise atomic memory intrinsic",
@@ -4182,9 +4114,14 @@ void Verifier::visitIntrinsicCallSite(In
auto IsValidAlignment = [&](uint64_t Alignment) {
return isPowerOf2_64(Alignment) && ElementSizeVal.ule(Alignment);
};
- uint64_t DstAlignment = CS.getParamAlignment(0);
+ uint64_t DstAlignment = AMI->getDestAlignment();
Assert(IsValidAlignment(DstAlignment),
"incorrect alignment of the destination argument", CS);
+ if (const auto *AMT = dyn_cast<AtomicMemTransferInst>(AMI)) {
+ uint64_t SrcAlignment = AMT->getSourceAlignment();
+ Assert(IsValidAlignment(SrcAlignment),
+ "incorrect alignment of the source argument", CS);
+ }
break;
}
case Intrinsic::gcroot:
More information about the llvm-commits
mailing list