Skip to content

Commit ad90a6b

Browse files
committed
[OpaquePtr] Create new bitcode encoding for atomicrmw
Since the opaque pointer type won't contain the pointee type, we need to separately encode the value type for an atomicrmw. Emit this new code for atomicrmw. Handle this new code and the old one in the bitcode reader. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D103123
1 parent e672595 commit ad90a6b

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

llvm/include/llvm/Bitcode/LLVMBitCodes.h

+12-9
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,15 @@ enum FunctionCodes {
547547

548548
FUNC_CODE_INST_CALL = 34, // CALL: [attr, cc, fnty, fnid, args...]
549549

550-
FUNC_CODE_DEBUG_LOC = 35, // DEBUG_LOC: [Line,Col,ScopeVal, IAVal]
551-
FUNC_CODE_INST_FENCE = 36, // FENCE: [ordering, synchscope]
552-
FUNC_CODE_INST_CMPXCHG_OLD = 37, // CMPXCHG: [ptrty, ptr, cmp, val, vol,
553-
// ordering, synchscope,
554-
// failure_ordering?, weak?]
555-
FUNC_CODE_INST_ATOMICRMW = 38, // ATOMICRMW: [ptrty,ptr,val, operation,
556-
// align, vol,
557-
// ordering, synchscope]
558-
FUNC_CODE_INST_RESUME = 39, // RESUME: [opval]
550+
FUNC_CODE_DEBUG_LOC = 35, // DEBUG_LOC: [Line,Col,ScopeVal, IAVal]
551+
FUNC_CODE_INST_FENCE = 36, // FENCE: [ordering, synchscope]
552+
FUNC_CODE_INST_CMPXCHG_OLD = 37, // CMPXCHG: [ptrty, ptr, cmp, val, vol,
553+
// ordering, synchscope,
554+
// failure_ordering?, weak?]
555+
FUNC_CODE_INST_ATOMICRMW_OLD = 38, // ATOMICRMW: [ptrty,ptr,val, operation,
556+
// align, vol,
557+
// ordering, synchscope]
558+
FUNC_CODE_INST_RESUME = 39, // RESUME: [opval]
559559
FUNC_CODE_INST_LANDINGPAD_OLD =
560560
40, // LANDINGPAD: [ty,val,val,num,id0,val0...]
561561
FUNC_CODE_INST_LOADATOMIC = 41, // LOAD: [opty, op, align, vol,
@@ -582,6 +582,9 @@ enum FunctionCodes {
582582
FUNC_CODE_INST_CALLBR = 57, // CALLBR: [attr, cc, norm, transfs,
583583
// fnty, fnid, args...]
584584
FUNC_CODE_INST_FREEZE = 58, // FREEZE: [opty, opval]
585+
FUNC_CODE_INST_ATOMICRMW = 59, // ATOMICRMW: [ptrty, ptr, valty, val,
586+
// operation, align, vol,
587+
// ordering, synchscope]
585588
};
586589

587590
enum UseListCodes {

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -5232,8 +5232,10 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
52325232
InstructionList.push_back(I);
52335233
break;
52345234
}
5235+
case bitc::FUNC_CODE_INST_ATOMICRMW_OLD:
52355236
case bitc::FUNC_CODE_INST_ATOMICRMW: {
5236-
// ATOMICRMW:[ptrty, ptr, val, op, vol, ordering, ssid, align?]
5237+
// ATOMICRMW_OLD: [ptrty, ptr, val, op, vol, ordering, ssid, align?]
5238+
// ATOMICRMW: [ptrty, ptr, valty, val, op, vol, ordering, ssid, align?]
52375239
const size_t NumRecords = Record.size();
52385240
unsigned OpNum = 0;
52395241

@@ -5245,9 +5247,14 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
52455247
return error("Invalid record");
52465248

52475249
Value *Val = nullptr;
5248-
if (popValue(Record, OpNum, NextValueNo,
5249-
getPointerElementFlatType(FullTy), Val))
5250-
return error("Invalid record");
5250+
if (BitCode == bitc::FUNC_CODE_INST_ATOMICRMW_OLD) {
5251+
if (popValue(Record, OpNum, NextValueNo,
5252+
getPointerElementFlatType(FullTy), Val))
5253+
return error("Invalid record");
5254+
} else {
5255+
if (getValueTypePair(Record, OpNum, NextValueNo, Val))
5256+
return error("Invalid record");
5257+
}
52515258

52525259
if (!(NumRecords == (OpNum + 4) || NumRecords == (OpNum + 5)))
52535260
return error("Invalid record");

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3103,7 +3103,7 @@ void ModuleBitcodeWriter::writeInstruction(const Instruction &I,
31033103
case Instruction::AtomicRMW:
31043104
Code = bitc::FUNC_CODE_INST_ATOMICRMW;
31053105
pushValueAndType(I.getOperand(0), InstID, Vals); // ptrty + ptr
3106-
pushValue(I.getOperand(1), InstID, Vals); // val.
3106+
pushValueAndType(I.getOperand(1), InstID, Vals); // valty + val
31073107
Vals.push_back(
31083108
getEncodedRMWOperation(cast<AtomicRMWInst>(I).getOperation()));
31093109
Vals.push_back(cast<AtomicRMWInst>(I).isVolatile());
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: llvm-dis < %s.bc | FileCheck %s
2+
; RUN: verify-uselistorder < %s.bc
3+
4+
; atomicrmw-upgrade.ll.bc was produced by running a version of llvm-as from just
5+
; before the IR change on this file.
6+
7+
; CHECK: @atomicrmw
8+
; CHECK: %b = atomicrmw add i32* %a, i32 %i acquire
9+
define void @atomicrmw(i32* %a, i32 %i) {
10+
%b = atomicrmw add i32* %a, i32 %i acquire
11+
ret void
12+
}
1.12 KB
Binary file not shown.

0 commit comments

Comments
 (0)