Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 3049e16

Browse files
committed
Revert commit r226784.
Accidentally modified file SemaType.cpp must be restored to its original state. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226785 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 515d33a commit 3049e16

File tree

4 files changed

+75
-603
lines changed

4 files changed

+75
-603
lines changed

lib/CodeGen/CGAtomic.cpp

Lines changed: 72 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include "CodeGenFunction.h"
1515
#include "CGCall.h"
16-
#include "CGRecordLayout.h"
1716
#include "CodeGenModule.h"
1817
#include "clang/AST/ASTContext.h"
1918
#include "clang/CodeGen/CGFunctionInfo.h"
@@ -37,69 +36,34 @@ namespace {
3736
CharUnits LValueAlign;
3837
TypeEvaluationKind EvaluationKind;
3938
bool UseLibcall;
40-
LValue LVal;
41-
CGBitFieldInfo BFI;
4239
public:
43-
AtomicInfo(CodeGenFunction &CGF, LValue &lvalue)
44-
: CGF(CGF), AtomicSizeInBits(0), ValueSizeInBits(0), UseLibcall(true) {
45-
assert(!lvalue.isGlobalReg());
40+
AtomicInfo(CodeGenFunction &CGF, LValue &lvalue) : CGF(CGF) {
41+
assert(lvalue.isSimple());
42+
43+
AtomicTy = lvalue.getType();
44+
ValueTy = AtomicTy->castAs<AtomicType>()->getValueType();
45+
EvaluationKind = CGF.getEvaluationKind(ValueTy);
46+
4647
ASTContext &C = CGF.getContext();
47-
if (lvalue.isSimple()) {
48-
AtomicTy = lvalue.getType();
49-
if (auto *ATy = AtomicTy->getAs<AtomicType>())
50-
ValueTy = ATy->getValueType();
51-
else
52-
ValueTy = AtomicTy;
53-
EvaluationKind = CGF.getEvaluationKind(ValueTy);
54-
55-
uint64_t ValueAlignInBits;
56-
uint64_t AtomicAlignInBits;
57-
TypeInfo ValueTI = C.getTypeInfo(ValueTy);
58-
ValueSizeInBits = ValueTI.Width;
59-
ValueAlignInBits = ValueTI.Align;
60-
61-
TypeInfo AtomicTI = C.getTypeInfo(AtomicTy);
62-
AtomicSizeInBits = AtomicTI.Width;
63-
AtomicAlignInBits = AtomicTI.Align;
64-
65-
assert(ValueSizeInBits <= AtomicSizeInBits);
66-
assert(ValueAlignInBits <= AtomicAlignInBits);
67-
68-
AtomicAlign = C.toCharUnitsFromBits(AtomicAlignInBits);
69-
ValueAlign = C.toCharUnitsFromBits(ValueAlignInBits);
70-
if (lvalue.getAlignment().isZero())
71-
lvalue.setAlignment(AtomicAlign);
72-
73-
LVal = lvalue;
74-
} else if (lvalue.isBitField()) {
75-
auto &OrigBFI = lvalue.getBitFieldInfo();
76-
auto Offset = OrigBFI.Offset % C.toBits(lvalue.getAlignment());
77-
AtomicSizeInBits = C.toBits(
78-
C.toCharUnitsFromBits(Offset + OrigBFI.Size + C.getCharWidth() - 1)
79-
.RoundUpToAlignment(lvalue.getAlignment()));
80-
auto VoidPtrAddr = CGF.EmitCastToVoidPtr(lvalue.getBitFieldAddr());
81-
auto OffsetInChars =
82-
(C.toCharUnitsFromBits(OrigBFI.Offset) / lvalue.getAlignment()) *
83-
lvalue.getAlignment();
84-
VoidPtrAddr = CGF.Builder.CreateConstGEP1_64(
85-
VoidPtrAddr, OffsetInChars.getQuantity());
86-
auto Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
87-
VoidPtrAddr,
88-
CGF.Builder.getIntNTy(AtomicSizeInBits)->getPointerTo(),
89-
"atomic_bitfield_base");
90-
BFI = OrigBFI;
91-
BFI.Offset = Offset;
92-
BFI.StorageSize = AtomicSizeInBits;
93-
LVal = LValue::MakeBitfield(Addr, BFI, lvalue.getType(),
94-
lvalue.getAlignment());
95-
} else if (lvalue.isVectorElt()) {
96-
AtomicSizeInBits = C.getTypeSize(lvalue.getType());
97-
LVal = lvalue;
98-
} else {
99-
assert(lvalue.isExtVectorElt());
100-
AtomicSizeInBits = C.getTypeSize(lvalue.getType());
101-
LVal = lvalue;
102-
}
48+
49+
uint64_t ValueAlignInBits;
50+
uint64_t AtomicAlignInBits;
51+
TypeInfo ValueTI = C.getTypeInfo(ValueTy);
52+
ValueSizeInBits = ValueTI.Width;
53+
ValueAlignInBits = ValueTI.Align;
54+
55+
TypeInfo AtomicTI = C.getTypeInfo(AtomicTy);
56+
AtomicSizeInBits = AtomicTI.Width;
57+
AtomicAlignInBits = AtomicTI.Align;
58+
59+
assert(ValueSizeInBits <= AtomicSizeInBits);
60+
assert(ValueAlignInBits <= AtomicAlignInBits);
61+
62+
AtomicAlign = C.toCharUnitsFromBits(AtomicAlignInBits);
63+
ValueAlign = C.toCharUnitsFromBits(ValueAlignInBits);
64+
if (lvalue.getAlignment().isZero())
65+
lvalue.setAlignment(AtomicAlign);
66+
10367
UseLibcall = !C.getTargetInfo().hasBuiltinAtomic(
10468
AtomicSizeInBits, C.toBits(lvalue.getAlignment()));
10569
}
@@ -112,7 +76,6 @@ namespace {
11276
uint64_t getValueSizeInBits() const { return ValueSizeInBits; }
11377
TypeEvaluationKind getEvaluationKind() const { return EvaluationKind; }
11478
bool shouldUseLibcall() const { return UseLibcall; }
115-
const LValue &getAtomicLValue() const { return LVal; }
11679

11780
/// Is the atomic size larger than the underlying value type?
11881
///
@@ -124,7 +87,7 @@ namespace {
12487
return (ValueSizeInBits != AtomicSizeInBits);
12588
}
12689

127-
bool emitMemSetZeroIfNecessary() const;
90+
bool emitMemSetZeroIfNecessary(LValue dest) const;
12891

12992
llvm::Value *getAtomicSizeValue() const {
13093
CharUnits size = CGF.getContext().toCharUnitsFromBits(AtomicSizeInBits);
@@ -147,17 +110,16 @@ namespace {
147110
SourceLocation Loc) const;
148111

149112
/// Copy an atomic r-value into atomic-layout memory.
150-
void emitCopyIntoMemory(RValue rvalue) const;
113+
void emitCopyIntoMemory(RValue rvalue, LValue lvalue) const;
151114

152115
/// Project an l-value down to the value field.
153-
LValue projectValue() const {
154-
assert(LVal.isSimple());
155-
llvm::Value *addr = LVal.getAddress();
116+
LValue projectValue(LValue lvalue) const {
117+
llvm::Value *addr = lvalue.getAddress();
156118
if (hasPadding())
157119
addr = CGF.Builder.CreateStructGEP(addr, 0);
158120

159-
return LValue::MakeAddr(addr, getValueType(), LVal.getAlignment(),
160-
CGF.getContext(), LVal.getTBAAInfo());
121+
return LValue::MakeAddr(addr, getValueType(), lvalue.getAlignment(),
122+
CGF.getContext(), lvalue.getTBAAInfo());
161123
}
162124

163125
/// Materialize an atomic r-value in atomic-layout memory.
@@ -210,15 +172,14 @@ bool AtomicInfo::requiresMemSetZero(llvm::Type *type) const {
210172
llvm_unreachable("bad evaluation kind");
211173
}
212174

213-
bool AtomicInfo::emitMemSetZeroIfNecessary() const {
214-
assert(LVal.isSimple());
215-
llvm::Value *addr = LVal.getAddress();
175+
bool AtomicInfo::emitMemSetZeroIfNecessary(LValue dest) const {
176+
llvm::Value *addr = dest.getAddress();
216177
if (!requiresMemSetZero(addr->getType()->getPointerElementType()))
217178
return false;
218179

219180
CGF.Builder.CreateMemSet(addr, llvm::ConstantInt::get(CGF.Int8Ty, 0),
220181
AtomicSizeInBits / 8,
221-
LVal.getAlignment().getQuantity());
182+
dest.getAlignment().getQuantity());
222183
return true;
223184
}
224185

@@ -941,34 +902,21 @@ llvm::Value *AtomicInfo::emitCastToAtomicIntPointer(llvm::Value *addr) const {
941902
RValue AtomicInfo::convertTempToRValue(llvm::Value *addr,
942903
AggValueSlot resultSlot,
943904
SourceLocation loc) const {
944-
if (LVal.isSimple()) {
945-
if (EvaluationKind == TEK_Aggregate)
946-
return resultSlot.asRValue();
947-
948-
// Drill into the padding structure if we have one.
949-
if (hasPadding())
950-
addr = CGF.Builder.CreateStructGEP(addr, 0);
951-
952-
// Otherwise, just convert the temporary to an r-value using the
953-
// normal conversion routine.
954-
return CGF.convertTempToRValue(addr, getValueType(), loc);
955-
} else if (LVal.isBitField())
956-
return CGF.EmitLoadOfBitfieldLValue(LValue::MakeBitfield(
957-
addr, LVal.getBitFieldInfo(), LVal.getType(), LVal.getAlignment()));
958-
else if (LVal.isVectorElt())
959-
return CGF.EmitLoadOfLValue(LValue::MakeVectorElt(addr, LVal.getVectorIdx(),
960-
LVal.getType(),
961-
LVal.getAlignment()),
962-
loc);
963-
assert(LVal.isExtVectorElt());
964-
return CGF.EmitLoadOfExtVectorElementLValue(LValue::MakeExtVectorElt(
965-
addr, LVal.getExtVectorElts(), LVal.getType(), LVal.getAlignment()));
905+
if (EvaluationKind == TEK_Aggregate)
906+
return resultSlot.asRValue();
907+
908+
// Drill into the padding structure if we have one.
909+
if (hasPadding())
910+
addr = CGF.Builder.CreateStructGEP(addr, 0);
911+
912+
// Otherwise, just convert the temporary to an r-value using the
913+
// normal conversion routine.
914+
return CGF.convertTempToRValue(addr, getValueType(), loc);
966915
}
967916

968917
RValue AtomicInfo::convertIntToValue(llvm::Value *IntVal,
969918
AggValueSlot ResultSlot,
970919
SourceLocation Loc) const {
971-
assert(LVal.isSimple());
972920
// Try not to in some easy cases.
973921
assert(IntVal->getType()->isIntegerTy() && "Expected integer value");
974922
if (getEvaluationKind() == TEK_Scalar && !hasPadding()) {
@@ -1010,43 +958,25 @@ RValue AtomicInfo::convertIntToValue(llvm::Value *IntVal,
1010958
RValue CodeGenFunction::EmitAtomicLoad(LValue src, SourceLocation loc,
1011959
AggValueSlot resultSlot) {
1012960
AtomicInfo atomics(*this, src);
1013-
LValue LVal = atomics.getAtomicLValue();
1014-
llvm::Value *SrcAddr = nullptr;
1015-
llvm::AllocaInst *NonSimpleTempAlloca = nullptr;
1016-
if (LVal.isSimple())
1017-
SrcAddr = LVal.getAddress();
1018-
else {
1019-
if (LVal.isBitField())
1020-
SrcAddr = LVal.getBitFieldAddr();
1021-
else if (LVal.isVectorElt())
1022-
SrcAddr = LVal.getVectorAddr();
1023-
else {
1024-
assert(LVal.isExtVectorElt());
1025-
SrcAddr = LVal.getExtVectorAddr();
1026-
}
1027-
NonSimpleTempAlloca = CreateTempAlloca(
1028-
SrcAddr->getType()->getPointerElementType(), "atomic-load-temp");
1029-
NonSimpleTempAlloca->setAlignment(getContext().toBits(src.getAlignment()));
1030-
}
1031961

1032962
// Check whether we should use a library call.
1033963
if (atomics.shouldUseLibcall()) {
1034964
llvm::Value *tempAddr;
1035-
if (LVal.isSimple()) {
1036-
if (!resultSlot.isIgnored()) {
1037-
assert(atomics.getEvaluationKind() == TEK_Aggregate);
1038-
tempAddr = resultSlot.getAddr();
1039-
} else
1040-
tempAddr = CreateMemTemp(atomics.getAtomicType(), "atomic-load-temp");
1041-
} else
1042-
tempAddr = NonSimpleTempAlloca;
965+
if (!resultSlot.isIgnored()) {
966+
assert(atomics.getEvaluationKind() == TEK_Aggregate);
967+
tempAddr = resultSlot.getAddr();
968+
} else {
969+
tempAddr = CreateMemTemp(atomics.getAtomicType(), "atomic-load-temp");
970+
}
1043971

1044972
// void __atomic_load(size_t size, void *mem, void *return, int order);
1045973
CallArgList args;
1046974
args.add(RValue::get(atomics.getAtomicSizeValue()),
1047975
getContext().getSizeType());
1048-
args.add(RValue::get(EmitCastToVoidPtr(SrcAddr)), getContext().VoidPtrTy);
1049-
args.add(RValue::get(EmitCastToVoidPtr(tempAddr)), getContext().VoidPtrTy);
976+
args.add(RValue::get(EmitCastToVoidPtr(src.getAddress())),
977+
getContext().VoidPtrTy);
978+
args.add(RValue::get(EmitCastToVoidPtr(tempAddr)),
979+
getContext().VoidPtrTy);
1050980
args.add(RValue::get(llvm::ConstantInt::get(
1051981
IntTy, AtomicExpr::AO_ABI_memory_order_seq_cst)),
1052982
getContext().IntTy);
@@ -1057,7 +987,7 @@ RValue CodeGenFunction::EmitAtomicLoad(LValue src, SourceLocation loc,
1057987
}
1058988

1059989
// Okay, we're doing this natively.
1060-
llvm::Value *addr = atomics.emitCastToAtomicIntPointer(SrcAddr);
990+
llvm::Value *addr = atomics.emitCastToAtomicIntPointer(src.getAddress());
1061991
llvm::LoadInst *load = Builder.CreateLoad(addr, "atomic-load");
1062992
load->setAtomic(llvm::SequentiallyConsistent);
1063993

@@ -1073,46 +1003,40 @@ RValue CodeGenFunction::EmitAtomicLoad(LValue src, SourceLocation loc,
10731003
return RValue::getAggregate(nullptr, false);
10741004

10751005
// Okay, turn that back into the original value type.
1076-
if (src.isSimple())
1077-
return atomics.convertIntToValue(load, resultSlot, loc);
1078-
1079-
auto *IntAddr = atomics.emitCastToAtomicIntPointer(NonSimpleTempAlloca);
1080-
Builder.CreateAlignedStore(load, IntAddr, src.getAlignment().getQuantity());
1081-
return atomics.convertTempToRValue(NonSimpleTempAlloca, resultSlot, loc);
1006+
return atomics.convertIntToValue(load, resultSlot, loc);
10821007
}
10831008

10841009

10851010

10861011
/// Copy an r-value into memory as part of storing to an atomic type.
10871012
/// This needs to create a bit-pattern suitable for atomic operations.
1088-
void AtomicInfo::emitCopyIntoMemory(RValue rvalue) const {
1089-
assert(LVal.isSimple());
1013+
void AtomicInfo::emitCopyIntoMemory(RValue rvalue, LValue dest) const {
10901014
// If we have an r-value, the rvalue should be of the atomic type,
10911015
// which means that the caller is responsible for having zeroed
10921016
// any padding. Just do an aggregate copy of that type.
10931017
if (rvalue.isAggregate()) {
1094-
CGF.EmitAggregateCopy(LVal.getAddress(),
1018+
CGF.EmitAggregateCopy(dest.getAddress(),
10951019
rvalue.getAggregateAddr(),
10961020
getAtomicType(),
10971021
(rvalue.isVolatileQualified()
1098-
|| LVal.isVolatileQualified()),
1099-
LVal.getAlignment());
1022+
|| dest.isVolatileQualified()),
1023+
dest.getAlignment());
11001024
return;
11011025
}
11021026

11031027
// Okay, otherwise we're copying stuff.
11041028

11051029
// Zero out the buffer if necessary.
1106-
emitMemSetZeroIfNecessary();
1030+
emitMemSetZeroIfNecessary(dest);
11071031

11081032
// Drill past the padding if present.
1109-
LValue TempLVal = projectValue();
1033+
dest = projectValue(dest);
11101034

11111035
// Okay, store the rvalue in.
11121036
if (rvalue.isScalar()) {
1113-
CGF.EmitStoreOfScalar(rvalue.getScalarVal(), TempLVal, /*init*/ true);
1037+
CGF.EmitStoreOfScalar(rvalue.getScalarVal(), dest, /*init*/ true);
11141038
} else {
1115-
CGF.EmitStoreOfComplex(rvalue.getComplexVal(), TempLVal, /*init*/ true);
1039+
CGF.EmitStoreOfComplex(rvalue.getComplexVal(), dest, /*init*/ true);
11161040
}
11171041
}
11181042

@@ -1127,10 +1051,8 @@ llvm::Value *AtomicInfo::materializeRValue(RValue rvalue) const {
11271051

11281052
// Otherwise, make a temporary and materialize into it.
11291053
llvm::Value *temp = CGF.CreateMemTemp(getAtomicType(), "atomic-store-temp");
1130-
LValue tempLV =
1131-
CGF.MakeAddrLValue(temp, getAtomicType(), getAtomicAlignment());
1132-
AtomicInfo Atomics(CGF, tempLV);
1133-
Atomics.emitCopyIntoMemory(rvalue);
1054+
LValue tempLV = CGF.MakeAddrLValue(temp, getAtomicType(), getAtomicAlignment());
1055+
emitCopyIntoMemory(rvalue, tempLV);
11341056
return temp;
11351057
}
11361058

@@ -1176,7 +1098,7 @@ void CodeGenFunction::EmitAtomicStore(RValue rvalue, LValue dest, bool isInit) {
11761098

11771099
// If this is an initialization, just put the value there normally.
11781100
if (isInit) {
1179-
atomics.emitCopyIntoMemory(rvalue);
1101+
atomics.emitCopyIntoMemory(rvalue, dest);
11801102
return;
11811103
}
11821104

@@ -1292,13 +1214,13 @@ void CodeGenFunction::EmitAtomicInit(Expr *init, LValue dest) {
12921214
switch (atomics.getEvaluationKind()) {
12931215
case TEK_Scalar: {
12941216
llvm::Value *value = EmitScalarExpr(init);
1295-
atomics.emitCopyIntoMemory(RValue::get(value));
1217+
atomics.emitCopyIntoMemory(RValue::get(value), dest);
12961218
return;
12971219
}
12981220

12991221
case TEK_Complex: {
13001222
ComplexPairTy value = EmitComplexExpr(init);
1301-
atomics.emitCopyIntoMemory(RValue::getComplex(value));
1223+
atomics.emitCopyIntoMemory(RValue::getComplex(value), dest);
13021224
return;
13031225
}
13041226

@@ -1307,8 +1229,8 @@ void CodeGenFunction::EmitAtomicInit(Expr *init, LValue dest) {
13071229
// of atomic type.
13081230
bool Zeroed = false;
13091231
if (!init->getType()->isAtomicType()) {
1310-
Zeroed = atomics.emitMemSetZeroIfNecessary();
1311-
dest = atomics.projectValue();
1232+
Zeroed = atomics.emitMemSetZeroIfNecessary(dest);
1233+
dest = atomics.projectValue(dest);
13121234
}
13131235

13141236
// Evaluate the expression directly into the destination.

0 commit comments

Comments
 (0)