mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-28 17:46:04 +00:00
[OpaquePtr] Make atomicrmw work with opaque pointers
FullTy is only necessary when we need to figure out what type an instruction works with given a pointer's pointee type. However, we just end up using the value operand's type, so FullTy isn't necessary. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D102788
This commit is contained in:
parent
1b25fce404
commit
0bebda17be
@ -7668,7 +7668,8 @@ int LLParser::parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS) {
|
|||||||
return tokError("atomicrmw cannot be unordered");
|
return tokError("atomicrmw cannot be unordered");
|
||||||
if (!Ptr->getType()->isPointerTy())
|
if (!Ptr->getType()->isPointerTy())
|
||||||
return error(PtrLoc, "atomicrmw operand must be a pointer");
|
return error(PtrLoc, "atomicrmw operand must be a pointer");
|
||||||
if (cast<PointerType>(Ptr->getType())->getElementType() != Val->getType())
|
if (!cast<PointerType>(Ptr->getType())
|
||||||
|
->isOpaqueOrPointeeTypeMatches(Val->getType()))
|
||||||
return error(ValLoc, "atomicrmw value and pointer type do not match");
|
return error(ValLoc, "atomicrmw value and pointer type do not match");
|
||||||
|
|
||||||
if (Operation == AtomicRMWInst::Xchg) {
|
if (Operation == AtomicRMWInst::Xchg) {
|
||||||
|
@ -5231,15 +5231,18 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
|
|||||||
unsigned OpNum = 0;
|
unsigned OpNum = 0;
|
||||||
|
|
||||||
Value *Ptr = nullptr;
|
Value *Ptr = nullptr;
|
||||||
if (getValueTypePair(Record, OpNum, NextValueNo, Ptr, &FullTy))
|
if (getValueTypePair(Record, OpNum, NextValueNo, Ptr))
|
||||||
return error("Invalid record");
|
return error("Invalid record");
|
||||||
|
|
||||||
if (!isa<PointerType>(Ptr->getType()))
|
if (!isa<PointerType>(Ptr->getType()))
|
||||||
return error("Invalid record");
|
return error("Invalid record");
|
||||||
|
|
||||||
Value *Val = nullptr;
|
Value *Val = nullptr;
|
||||||
if (popValue(Record, OpNum, NextValueNo,
|
if (popValue(Record, OpNum, NextValueNo, nullptr, Val))
|
||||||
getPointerElementFlatType(FullTy), Val))
|
return error("Invalid record");
|
||||||
|
|
||||||
|
if (!cast<PointerType>(Ptr->getType())
|
||||||
|
->isOpaqueOrPointeeTypeMatches(Val->getType()))
|
||||||
return error("Invalid record");
|
return error("Invalid record");
|
||||||
|
|
||||||
if (!(NumRecords == (OpNum + 4) || NumRecords == (OpNum + 5)))
|
if (!(NumRecords == (OpNum + 4) || NumRecords == (OpNum + 5)))
|
||||||
@ -5272,7 +5275,6 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
|
|||||||
Align(TheModule->getDataLayout().getTypeStoreSize(Val->getType()));
|
Align(TheModule->getDataLayout().getTypeStoreSize(Val->getType()));
|
||||||
|
|
||||||
I = new AtomicRMWInst(Operation, Ptr, Val, *Alignment, Ordering, SSID);
|
I = new AtomicRMWInst(Operation, Ptr, Val, *Alignment, Ordering, SSID);
|
||||||
FullTy = getPointerElementFlatType(FullTy);
|
|
||||||
cast<AtomicRMWInst>(I)->setVolatile(IsVol);
|
cast<AtomicRMWInst>(I)->setVolatile(IsVol);
|
||||||
|
|
||||||
InstructionList.push_back(I);
|
InstructionList.push_back(I);
|
||||||
|
@ -1609,9 +1609,9 @@ void AtomicRMWInst::Init(BinOp Operation, Value *Ptr, Value *Val,
|
|||||||
"All operands must be non-null!");
|
"All operands must be non-null!");
|
||||||
assert(getOperand(0)->getType()->isPointerTy() &&
|
assert(getOperand(0)->getType()->isPointerTy() &&
|
||||||
"Ptr must have pointer type!");
|
"Ptr must have pointer type!");
|
||||||
assert(getOperand(1)->getType() ==
|
assert(cast<PointerType>(getOperand(0)->getType())
|
||||||
cast<PointerType>(getOperand(0)->getType())->getElementType()
|
->isOpaqueOrPointeeTypeMatches(getOperand(1)->getType()) &&
|
||||||
&& "Ptr must be a pointer to Val type!");
|
"Ptr must be a pointer to Val type!");
|
||||||
assert(Ordering != AtomicOrdering::NotAtomic &&
|
assert(Ordering != AtomicOrdering::NotAtomic &&
|
||||||
"AtomicRMW instructions must be atomic!");
|
"AtomicRMW instructions must be atomic!");
|
||||||
}
|
}
|
||||||
|
@ -3868,7 +3868,7 @@ void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
|
|||||||
auto Op = RMWI.getOperation();
|
auto Op = RMWI.getOperation();
|
||||||
PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType());
|
PointerType *PTy = dyn_cast<PointerType>(RMWI.getOperand(0)->getType());
|
||||||
Assert(PTy, "First atomicrmw operand must be a pointer.", &RMWI);
|
Assert(PTy, "First atomicrmw operand must be a pointer.", &RMWI);
|
||||||
Type *ElTy = PTy->getElementType();
|
Type *ElTy = RMWI.getOperand(1)->getType();
|
||||||
if (Op == AtomicRMWInst::Xchg) {
|
if (Op == AtomicRMWInst::Xchg) {
|
||||||
Assert(ElTy->isIntegerTy() || ElTy->isFloatingPointTy(), "atomicrmw " +
|
Assert(ElTy->isIntegerTy() || ElTy->isFloatingPointTy(), "atomicrmw " +
|
||||||
AtomicRMWInst::getOperationName(Op) +
|
AtomicRMWInst::getOperationName(Op) +
|
||||||
@ -3886,7 +3886,7 @@ void Verifier::visitAtomicRMWInst(AtomicRMWInst &RMWI) {
|
|||||||
&RMWI, ElTy);
|
&RMWI, ElTy);
|
||||||
}
|
}
|
||||||
checkAtomicMemAccessSize(ElTy, &RMWI);
|
checkAtomicMemAccessSize(ElTy, &RMWI);
|
||||||
Assert(ElTy == RMWI.getOperand(1)->getType(),
|
Assert(PTy->isOpaqueOrPointeeTypeMatches(ElTy),
|
||||||
"Argument value type does not match pointer operand type!", &RMWI,
|
"Argument value type does not match pointer operand type!", &RMWI,
|
||||||
ElTy);
|
ElTy);
|
||||||
Assert(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP,
|
Assert(AtomicRMWInst::FIRST_BINOP <= Op && Op <= AtomicRMWInst::LAST_BINOP,
|
||||||
|
@ -56,3 +56,11 @@ define void @cmpxchg(ptr %p, i32 %a, i32 %b) {
|
|||||||
%val_success = cmpxchg ptr %p, i32 %a, i32 %b acq_rel monotonic
|
%val_success = cmpxchg ptr %p, i32 %a, i32 %b acq_rel monotonic
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; CHECK: define void @atomicrmw(ptr %a, i32 %i)
|
||||||
|
; CHECK: %b = atomicrmw add ptr %a, i32 %i acquire
|
||||||
|
; CHECK: ret void
|
||||||
|
define void @atomicrmw(ptr %a, i32 %i) {
|
||||||
|
%b = atomicrmw add ptr %a, i32 %i acquire
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
@ -17,3 +17,9 @@ define void @cmpxchg(ptr %p, i32 %a, i32 %b) {
|
|||||||
%val_success = cmpxchg ptr %p, i32 %a, i32 %b acq_rel monotonic
|
%val_success = cmpxchg ptr %p, i32 %a, i32 %b acq_rel monotonic
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; CHECK: @atomicrmw
|
||||||
|
define void @atomicrmw(ptr %a, i32 %i) {
|
||||||
|
%b = atomicrmw add ptr %a, i32 %i acquire
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user