[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
564eb20e0d
commit
1202f559bd
@ -7671,7 +7671,8 @@ int LLParser::parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS) {
|
||||
return tokError("atomicrmw cannot be unordered");
|
||||
if (!Ptr->getType()->isPointerTy())
|
||||
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");
|
||||
|
||||
if (Operation == AtomicRMWInst::Xchg) {
|
||||
|
||||
@ -5251,9 +5251,11 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
|
||||
if (popValue(Record, OpNum, NextValueNo,
|
||||
getPointerElementFlatType(FullTy), Val))
|
||||
return error("Invalid record");
|
||||
FullTy = getPointerElementFlatType(FullTy);
|
||||
} else {
|
||||
if (getValueTypePair(Record, OpNum, NextValueNo, Val))
|
||||
return error("Invalid record");
|
||||
FullTy = Val->getType();
|
||||
}
|
||||
|
||||
if (!(NumRecords == (OpNum + 4) || NumRecords == (OpNum + 5)))
|
||||
@ -5286,7 +5288,6 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
|
||||
Align(TheModule->getDataLayout().getTypeStoreSize(Val->getType()));
|
||||
|
||||
I = new AtomicRMWInst(Operation, Ptr, Val, *Alignment, Ordering, SSID);
|
||||
FullTy = getPointerElementFlatType(FullTy);
|
||||
cast<AtomicRMWInst>(I)->setVolatile(IsVol);
|
||||
|
||||
InstructionList.push_back(I);
|
||||
|
||||
@ -1602,9 +1602,9 @@ void AtomicRMWInst::Init(BinOp Operation, Value *Ptr, Value *Val,
|
||||
"All operands must be non-null!");
|
||||
assert(getOperand(0)->getType()->isPointerTy() &&
|
||||
"Ptr must have pointer type!");
|
||||
assert(getOperand(1)->getType() ==
|
||||
cast<PointerType>(getOperand(0)->getType())->getElementType()
|
||||
&& "Ptr must be a pointer to Val type!");
|
||||
assert(cast<PointerType>(getOperand(0)->getType())
|
||||
->isOpaqueOrPointeeTypeMatches(getOperand(1)->getType()) &&
|
||||
"Ptr must be a pointer to Val type!");
|
||||
assert(Ordering != AtomicOrdering::NotAtomic &&
|
||||
"AtomicRMW instructions must be atomic!");
|
||||
}
|
||||
|
||||
18
llvm/test/Assembler/atomicrmw.ll
Normal file
18
llvm/test/Assembler/atomicrmw.ll
Normal file
@ -0,0 +1,18 @@
|
||||
; RUN: llvm-as %s -o - | llvm-dis | FileCheck %s
|
||||
|
||||
; Make sure that we can parse an atomicrmw with an operand defined later in the function.
|
||||
|
||||
; CHECK: @f
|
||||
; CHECK: atomicrmw
|
||||
define void @f() {
|
||||
entry:
|
||||
br label %def
|
||||
|
||||
use:
|
||||
%x = atomicrmw add i32* undef, i32 %y monotonic
|
||||
ret void
|
||||
|
||||
def:
|
||||
%y = add i32 undef, undef
|
||||
br i1 undef, label %use, label %use
|
||||
}
|
||||
@ -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
|
||||
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
|
||||
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