Skip to content

Commit 2147703

Browse files
author
Diogo Sampaio
committed
Revert "[ARM] Follow AACPS standard for volatile bit-fields access width"
This reverts commit 6a24339. Submitted using ide button by mistake
1 parent 6a24339 commit 2147703

File tree

4 files changed

+134
-350
lines changed

4 files changed

+134
-350
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 5 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,6 @@ llvm::Value *CodeGenFunction::EvaluateExprAsBool(const Expr *E) {
177177
Loc);
178178
}
179179

180-
// Helper method to check if the underlying ABI is AAPCS
181-
static bool isAAPCS(const TargetInfo &TargetInfo) {
182-
return TargetInfo.getABI().startswith("aapcs");
183-
}
184-
185180
/// EmitIgnoredExpr - Emit code to compute the specified expression,
186181
/// ignoring the result.
187182
void CodeGenFunction::EmitIgnoredExpr(const Expr *E) {
@@ -4057,120 +4052,15 @@ static bool hasAnyVptr(const QualType Type, const ASTContext &Context) {
40574052
return false;
40584053
}
40594054

4060-
// AAPCS requires volatile bitfield accesses to be performed using the
4061-
// natural alignment / width of the bitfield declarative type, if that
4062-
// won't cause overlap over a non-bitfield member nor access outside the
4063-
// the data structure.
4064-
bool CodeGenFunction::AdjustAAPCSBitfieldLValue(Address &Base,
4065-
CGBitFieldInfo &Info,
4066-
const FieldDecl *Field,
4067-
const QualType FieldType,
4068-
const CGRecordLayout &RL) {
4069-
llvm::Type *ResLTy = ConvertTypeForMem(FieldType);
4070-
// CGRecordLowering::setBitFieldInfo() pre-adjusts the bitfield offsets for
4071-
// big-endian targets, but it assumes a container of width Info.StorageSize.
4072-
// Since AAPCS uses a different container size (width of the type), we first
4073-
// undo that calculation here and redo it once the bitfield offset within the
4074-
// new container is calculated
4075-
const bool BE = CGM.getTypes().getDataLayout().isBigEndian();
4076-
const unsigned OldOffset =
4077-
BE ? Info.StorageSize - (Info.Offset + Info.Size) : Info.Offset;
4078-
// Offset to the bitfield from the beginning of the struct
4079-
const unsigned AbsoluteOffset =
4080-
getContext().toBits(Info.StorageOffset) + OldOffset;
4081-
4082-
// Container size is the width of the bitfield type
4083-
const unsigned ContainerSize = ResLTy->getPrimitiveSizeInBits();
4084-
// Nothing to do if the access uses the desired
4085-
// container width and is naturally aligned
4086-
if (Info.StorageSize == ContainerSize && (OldOffset % ContainerSize == 0))
4087-
return false;
4088-
4089-
// Offset within the container
4090-
unsigned MemberOffset = AbsoluteOffset & (ContainerSize - 1);
4091-
4092-
// Bail out if an aligned load of the container cannot cover the entire
4093-
// bitfield. This can happen for example, if the bitfield is part of a packed
4094-
// struct. AAPCS does not define access rules for such cases, we let clang to
4095-
// follow its own rules.
4096-
if (MemberOffset + Info.Size > ContainerSize) {
4097-
return false;
4098-
}
4099-
// Re-adjust offsets for big-endian targets
4100-
if (BE)
4101-
MemberOffset = ContainerSize - (MemberOffset + Info.Size);
4102-
4103-
const CharUnits NewOffset =
4104-
getContext().toCharUnitsFromBits(AbsoluteOffset & ~(ContainerSize - 1));
4105-
const CharUnits End = NewOffset +
4106-
getContext().toCharUnitsFromBits(ContainerSize) -
4107-
CharUnits::One();
4108-
4109-
const ASTRecordLayout &Layout =
4110-
getContext().getASTRecordLayout(Field->getParent());
4111-
// If we access outside memory outside the record, than bail out
4112-
const CharUnits RecordSize = Layout.getSize();
4113-
if (End >= RecordSize) {
4114-
return false;
4115-
}
4116-
4117-
// Bail out if performing this load would access non-bitfields members
4118-
4119-
for (auto it : Field->getParent()->fields()) {
4120-
const FieldDecl &F = *it;
4121-
// We distinct allow bitfields overlaps
4122-
if (F.isBitField())
4123-
continue;
4124-
const CharUnits FOffset = getContext().toCharUnitsFromBits(
4125-
Layout.getFieldOffset(F.getFieldIndex()));
4126-
const CharUnits FEnd =
4127-
FOffset +
4128-
getContext().toCharUnitsFromBits(
4129-
ConvertTypeForMem(F.getType())->getPrimitiveSizeInBits()) -
4130-
CharUnits::One();
4131-
if (End < FOffset) {
4132-
// The other field starts after the desired load end.
4133-
break;
4134-
}
4135-
if (FEnd < NewOffset) {
4136-
// The other field ends before the desired load offset.
4137-
continue;
4138-
}
4139-
// The desired load overlaps a non-bitfiel member, bail out.
4140-
return false;
4141-
}
4142-
4143-
// Write the new bitfield access parameters
4144-
Info.StorageOffset = NewOffset;
4145-
Info.StorageSize = ContainerSize;
4146-
Info.Offset = MemberOffset;
4147-
// GEP into the bitfield container. Here we essentially treat the Base as a
4148-
// pointer to a block of containers and index into it appropriately
4149-
Base =
4150-
Builder.CreateConstInBoundsGEP(Builder.CreateElementBitCast(Base, ResLTy),
4151-
AbsoluteOffset / ContainerSize);
4152-
return true;
4153-
}
4154-
41554055
LValue CodeGenFunction::EmitLValueForField(LValue base,
41564056
const FieldDecl *field) {
41574057
LValueBaseInfo BaseInfo = base.getBaseInfo();
41584058

41594059
if (field->isBitField()) {
41604060
const CGRecordLayout &RL =
4161-
CGM.getTypes().getCGRecordLayout(field->getParent());
4162-
CGBitFieldInfo Info = RL.getBitFieldInfo(field);
4061+
CGM.getTypes().getCGRecordLayout(field->getParent());
4062+
const CGBitFieldInfo &Info = RL.getBitFieldInfo(field);
41634063
Address Addr = base.getAddress(*this);
4164-
const QualType FieldType =
4165-
field->getType().withCVRQualifiers(base.getVRQualifiers());
4166-
4167-
if (isAAPCS(CGM.getTarget()) && FieldType.isVolatileQualified()) {
4168-
if (AdjustAAPCSBitfieldLValue(Addr, Info, field, FieldType, RL)) {
4169-
return LValue::MakeBitfield(Addr, Info, FieldType, BaseInfo,
4170-
TBAAAccessInfo());
4171-
}
4172-
}
4173-
41744064
unsigned Idx = RL.getLLVMFieldNo(field);
41754065
const RecordDecl *rec = field->getParent();
41764066
if (!IsInPreservedAIRegion &&
@@ -4192,9 +4082,11 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
41924082
if (Addr.getElementType() != FieldIntTy)
41934083
Addr = Builder.CreateElementBitCast(Addr, FieldIntTy);
41944084

4085+
QualType fieldType =
4086+
field->getType().withCVRQualifiers(base.getVRQualifiers());
41954087
// TODO: Support TBAA for bit fields.
41964088
LValueBaseInfo FieldBaseInfo(BaseInfo.getAlignmentSource());
4197-
return LValue::MakeBitfield(Addr, Info, FieldType, FieldBaseInfo,
4089+
return LValue::MakeBitfield(Addr, Info, fieldType, FieldBaseInfo,
41984090
TBAAAccessInfo());
41994091
}
42004092

clang/lib/CodeGen/CGValue.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
#ifndef LLVM_CLANG_LIB_CODEGEN_CGVALUE_H
1515
#define LLVM_CLANG_LIB_CODEGEN_CGVALUE_H
1616

17-
#include "Address.h"
18-
#include "CGRecordLayout.h"
19-
#include "CodeGenTBAA.h"
2017
#include "clang/AST/ASTContext.h"
2118
#include "clang/AST/Type.h"
22-
#include "llvm/IR/Type.h"
2319
#include "llvm/IR/Value.h"
20+
#include "llvm/IR/Type.h"
21+
#include "Address.h"
22+
#include "CodeGenTBAA.h"
2423

2524
namespace llvm {
2625
class Constant;
@@ -182,10 +181,10 @@ class LValue {
182181

183182
// ExtVector element subset: V.xyx
184183
llvm::Constant *VectorElts;
185-
};
186184

187-
// BitField start bit and size
188-
CGBitFieldInfo BitFieldInfo;
185+
// BitField start bit and size
186+
const CGBitFieldInfo *BitFieldInfo;
187+
};
189188

190189
QualType Type;
191190

@@ -358,13 +357,10 @@ class LValue {
358357
Address getBitFieldAddress() const {
359358
return Address(getBitFieldPointer(), getAlignment());
360359
}
361-
llvm::Value *getBitFieldPointer() const {
362-
assert(isBitField());
363-
return V;
364-
}
360+
llvm::Value *getBitFieldPointer() const { assert(isBitField()); return V; }
365361
const CGBitFieldInfo &getBitFieldInfo() const {
366362
assert(isBitField());
367-
return BitFieldInfo;
363+
return *BitFieldInfo;
368364
}
369365

370366
// global register lvalue
@@ -419,7 +415,7 @@ class LValue {
419415
LValue R;
420416
R.LVType = BitField;
421417
R.V = Addr.getPointer();
422-
R.BitFieldInfo = Info;
418+
R.BitFieldInfo = &Info;
423419
R.Initialize(type, type.getQualifiers(), Addr.getAlignment(), BaseInfo,
424420
TBAAInfo);
425421
return R;

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,14 +1619,8 @@ class CodeGenFunction : public CodeGenTypeCache {
16191619
void EmitOpenCLKernelMetadata(const FunctionDecl *FD,
16201620
llvm::Function *Fn);
16211621

1622-
/// Perform AAPCS specific tweaks on volatile bitfield accesses.
1623-
bool AdjustAAPCSBitfieldLValue(Address &Base, CGBitFieldInfo &Info,
1624-
const FieldDecl *Field,
1625-
const QualType FieldType,
1626-
const CGRecordLayout &RL);
1627-
16281622
public:
1629-
CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext = false);
1623+
CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext=false);
16301624
~CodeGenFunction();
16311625

16321626
CodeGenTypes &getTypes() const { return CGM.getTypes(); }

0 commit comments

Comments
 (0)