Skip to content

Commit

Permalink
Manually merged master:f4257c5832aa into amd-gfx:e7bf03cf04ed
Browse files Browse the repository at this point in the history
Local branch amd-gfx e7bf03c Merged master:dce72dc87040 into amd-gfx:5c7b2b0373fd
Remote branch master f4257c5 [SVE] Make ElementCount members private

Change-Id: I1fbf5f483cd0663eecfc878d3bf37729e59926dc
  • Loading branch information
dstutt committed Aug 28, 2020
2 parents e7bf03c + f4257c5 commit 59c5004
Show file tree
Hide file tree
Showing 61 changed files with 1,820 additions and 838 deletions.
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8457,7 +8457,8 @@ Value *CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID,
case SVE::BI__builtin_sve_svlen_u64: {
SVETypeFlags TF(Builtin->TypeModifier);
auto VTy = cast<llvm::VectorType>(getSVEType(TF));
auto NumEls = llvm::ConstantInt::get(Ty, VTy->getElementCount().Min);
auto *NumEls =
llvm::ConstantInt::get(Ty, VTy->getElementCount().getKnownMinValue());

Function *F = CGM.getIntrinsic(Intrinsic::vscale, Ty);
return Builder.CreateMul(NumEls, Builder.CreateCall(F));
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
{
ASTContext::BuiltinVectorTypeInfo Info =
CGM.getContext().getBuiltinVectorTypeInfo(BT);
unsigned NumElemsPerVG = (Info.EC.Min * Info.NumVectors) / 2;
unsigned NumElemsPerVG = (Info.EC.getKnownMinValue() * Info.NumVectors) / 2;

// Debuggers can't extract 1bit from a vector, so will display a
// bitpattern for svbool_t instead.
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CodeGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,8 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
ASTContext::BuiltinVectorTypeInfo Info =
Context.getBuiltinVectorTypeInfo(cast<BuiltinType>(Ty));
return llvm::ScalableVectorType::get(ConvertType(Info.ElementType),
Info.EC.Min * Info.NumVectors);
Info.EC.getKnownMinValue() *
Info.NumVectors);
}
case BuiltinType::Dependent:
#define BUILTIN_TYPE(Id, SingletonId)
Expand Down
100 changes: 52 additions & 48 deletions clang/lib/Tooling/Syntax/BuildTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,58 @@ static syntax::NodeKind getOperatorNodeKind(const CXXOperatorCallExpr &E) {
llvm_unreachable("Unknown OverloadedOperatorKind enum");
}

/// Get the start of the qualified name. In the examples below it gives the
/// location of the `^`:
/// `int ^a;`
/// `int *^a;`
/// `int ^a::S::f(){}`
static SourceLocation getQualifiedNameStart(NamedDecl *D) {
assert((isa<DeclaratorDecl, TypedefNameDecl>(D)) &&
"only DeclaratorDecl and TypedefNameDecl are supported.");

auto DN = D->getDeclName();
bool IsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo();
if (IsAnonymous)
return SourceLocation();

if (const auto *DD = dyn_cast<DeclaratorDecl>(D)) {
if (DD->getQualifierLoc()) {
return DD->getQualifierLoc().getBeginLoc();
}
}

return D->getLocation();
}

/// Gets the range of the initializer inside an init-declarator C++ [dcl.decl].
/// `int a;` -> range of ``,
/// `int *a = nullptr` -> range of `= nullptr`.
/// `int a{}` -> range of `{}`.
/// `int a()` -> range of `()`.
static SourceRange getInitializerRange(Decl *D) {
if (auto *V = dyn_cast<VarDecl>(D)) {
auto *I = V->getInit();
// Initializers in range-based-for are not part of the declarator
if (I && !V->isCXXForRangeDecl())
return I->getSourceRange();
}

return SourceRange();
}

/// Gets the range of declarator as defined by the C++ grammar. E.g.
/// `int a;` -> range of `a`,
/// `int *a;` -> range of `*a`,
/// `int a[10];` -> range of `a[10]`,
/// `int a[1][2][3];` -> range of `a[1][2][3]`,
/// `int *a = nullptr` -> range of `*a = nullptr`.
/// FIMXE: \p Name must be a source range, e.g. for `operator+`.
/// `int S::f(){}` -> range of `S::f()`.
/// FIXME: \p Name must be a source range.
static SourceRange getDeclaratorRange(const SourceManager &SM, TypeLoc T,
SourceLocation Name,
SourceRange Initializer) {
SourceLocation Start = GetStartLoc().Visit(T);
SourceLocation End = T.getSourceRange().getEnd();
SourceLocation End = T.getEndLoc();
assert(End.isValid());
if (Name.isValid()) {
if (Start.isInvalid())
Expand Down Expand Up @@ -378,27 +418,24 @@ class syntax::TreeBuilder {

/// Returns true if \p D is the last declarator in a chain and is thus
/// reponsible for creating SimpleDeclaration for the whole chain.
template <class T>
bool isResponsibleForCreatingDeclaration(const T *D) const {
static_assert((std::is_base_of<DeclaratorDecl, T>::value ||
std::is_base_of<TypedefNameDecl, T>::value),
"only DeclaratorDecl and TypedefNameDecl are supported.");
bool isResponsibleForCreatingDeclaration(const Decl *D) const {
assert((isa<DeclaratorDecl, TypedefNameDecl>(D)) &&
"only DeclaratorDecl and TypedefNameDecl are supported.");

const Decl *Next = D->getNextDeclInContext();

// There's no next sibling, this one is responsible.
if (Next == nullptr) {
return true;
}
const auto *NextT = dyn_cast<T>(Next);

// Next sibling is not the same type, this one is responsible.
if (NextT == nullptr) {
if (D->getKind() != Next->getKind()) {
return true;
}
// Next sibling doesn't begin at the same loc, it must be a different
// declaration, so this declarator is responsible.
if (NextT->getBeginLoc() != D->getBeginLoc()) {
if (Next->getBeginLoc() != D->getBeginLoc()) {
return true;
}

Expand Down Expand Up @@ -1405,43 +1442,12 @@ class BuildTreeVisitor : public RecursiveASTVisitor<BuildTreeVisitor> {
}

private:
template <class T> SourceLocation getQualifiedNameStart(T *D) {
static_assert((std::is_base_of<DeclaratorDecl, T>::value ||
std::is_base_of<TypedefNameDecl, T>::value),
"only DeclaratorDecl and TypedefNameDecl are supported.");

auto DN = D->getDeclName();
bool IsAnonymous = DN.isIdentifier() && !DN.getAsIdentifierInfo();
if (IsAnonymous)
return SourceLocation();

if (const auto *DD = dyn_cast<DeclaratorDecl>(D)) {
if (DD->getQualifierLoc()) {
return DD->getQualifierLoc().getBeginLoc();
}
}

return D->getLocation();
}

SourceRange getInitializerRange(Decl *D) {
if (auto *V = dyn_cast<VarDecl>(D)) {
auto *I = V->getInit();
// Initializers in range-based-for are not part of the declarator
if (I && !V->isCXXForRangeDecl())
return I->getSourceRange();
}

return SourceRange();
}

/// Folds SimpleDeclarator node (if present) and in case this is the last
/// declarator in the chain it also folds SimpleDeclaration node.
template <class T> bool processDeclaratorAndDeclaration(T *D) {
SourceRange Initializer = getInitializerRange(D);
auto Range = getDeclaratorRange(Builder.sourceManager(),
D->getTypeSourceInfo()->getTypeLoc(),
getQualifiedNameStart(D), Initializer);
auto Range = getDeclaratorRange(
Builder.sourceManager(), D->getTypeSourceInfo()->getTypeLoc(),
getQualifiedNameStart(D), getInitializerRange(D));

// There doesn't have to be a declarator (e.g. `void foo(int)` only has
// declaration, but no declarator).
Expand All @@ -1464,10 +1470,8 @@ class BuildTreeVisitor : public RecursiveASTVisitor<BuildTreeVisitor> {

auto ReturnedType = L.getReturnLoc();
// Build node for the declarator, if any.
auto ReturnDeclaratorRange =
getDeclaratorRange(this->Builder.sourceManager(), ReturnedType,
/*Name=*/SourceLocation(),
/*Initializer=*/SourceLocation());
auto ReturnDeclaratorRange = SourceRange(GetStartLoc().Visit(ReturnedType),
ReturnedType.getEndLoc());
syntax::SimpleDeclarator *ReturnDeclarator = nullptr;
if (ReturnDeclaratorRange.isValid()) {
ReturnDeclarator = new (allocator()) syntax::SimpleDeclarator;
Expand Down
76 changes: 76 additions & 0 deletions clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3123,6 +3123,35 @@ SimpleDeclaration
)txt"}));
}

TEST_P(SyntaxTreeTest, OutOfLineMemberFunctionDefinition) {
if (!GetParam().isCXX11OrLater()) {
return;
}
EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
struct S {
void f();
};
[[void S::f(){}]]
)cpp",
{R"txt(
SimpleDeclaration
|-'void'
|-SimpleDeclarator Declarator
| |-NestedNameSpecifier
| | |-IdentifierNameSpecifier ListElement
| | | `-'S'
| | `-'::' ListDelimiter
| |-'f'
| `-ParametersAndQualifiers
| |-'(' OpenParen
| `-')' CloseParen
`-CompoundStatement
|-'{' OpenParen
`-'}' CloseParen
)txt"}));
}

TEST_P(SyntaxTreeTest, ConversionMemberFunction) {
if (!GetParam().isCXX()) {
return;
Expand Down Expand Up @@ -3792,6 +3821,53 @@ TranslationUnit Detached
)txt"));
}

TEST_P(SyntaxTreeTest, InitDeclarator_Brace) {
if (!GetParam().isCXX11OrLater()) {
return;
}
EXPECT_TRUE(treeDumpEqual(
R"cpp(
int a {};
)cpp",
R"txt(
TranslationUnit Detached
`-SimpleDeclaration
|-'int'
|-SimpleDeclarator Declarator
| |-'a'
| `-UnknownExpression
| `-UnknownExpression
| |-'{'
| `-'}'
`-';'
)txt"));
}

TEST_P(SyntaxTreeTest, InitDeclarator_Paren) {
if (!GetParam().isCXX()) {
return;
}
EXPECT_TRUE(treeDumpEqualOnAnnotations(
R"cpp(
struct S {
S(int);
};
[[S s(1);]]
)cpp",
{R"txt(
SimpleDeclaration
|-'S'
|-SimpleDeclarator Declarator
| `-UnknownExpression
| |-'s'
| |-'('
| |-IntegerLiteralExpression
| | `-'1' LiteralToken
| `-')'
`-';'
)txt"}));
}

TEST_P(SyntaxTreeTest, ArrayDeclarator_Simple) {
EXPECT_TRUE(treeDumpEqual(
R"cpp(
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Analysis/TargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ class IntrinsicCostAttributes {
unsigned Factor);
IntrinsicCostAttributes(Intrinsic::ID Id, const CallBase &CI,
ElementCount Factor)
: IntrinsicCostAttributes(Id, CI, Factor.Min) {
assert(!Factor.Scalable);
: IntrinsicCostAttributes(Id, CI, Factor.getKnownMinValue()) {
assert(!Factor.isScalable());
}

IntrinsicCostAttributes(Intrinsic::ID Id, const CallBase &CI,
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/VectorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct VFShape {
Parameters.push_back(
VFParameter({CI.arg_size(), VFParamKind::GlobalPredicate}));

return {EC.Min, EC.Scalable, Parameters};
return {EC.getKnownMinValue(), EC.isScalable(), Parameters};
}
/// Sanity check on the Parameters in the VFShape.
bool hasValidParameterList() const;
Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ class ReachingDefAnalysis : public MachineFunctionPass {
void getGlobalUses(MachineInstr *MI, int PhysReg,
InstSet &Uses) const;

/// Collect all possible definitions of the value stored in PhysReg, which is
/// used by MI.
void getGlobalReachingDefs(MachineInstr *MI, int PhysReg,
InstSet &Defs) const;

/// Return whether From can be moved forwards to just before To.
bool isSafeToMoveForwards(MachineInstr *From, MachineInstr *To) const;

Expand Down
7 changes: 4 additions & 3 deletions llvm/include/llvm/CodeGen/ValueTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ namespace llvm {

/// Given a vector type, return the minimum number of elements it contains.
unsigned getVectorMinNumElements() const {
return getVectorElementCount().Min;
return getVectorElementCount().getKnownMinValue();
}

/// Return the size of the specified value type in bits.
Expand Down Expand Up @@ -383,7 +383,7 @@ namespace llvm {
EVT getHalfNumVectorElementsVT(LLVMContext &Context) const {
EVT EltVT = getVectorElementType();
auto EltCnt = getVectorElementCount();
assert(!(EltCnt.Min & 1) && "Splitting vector, but not in half!");
assert(EltCnt.isKnownEven() && "Splitting vector, but not in half!");
return EVT::getVectorVT(Context, EltVT, EltCnt / 2);
}

Expand All @@ -398,7 +398,8 @@ namespace llvm {
EVT getPow2VectorType(LLVMContext &Context) const {
if (!isPow2VectorType()) {
ElementCount NElts = getVectorElementCount();
NElts.Min = 1 << Log2_32_Ceil(NElts.Min);
unsigned NewMinCount = 1 << Log2_32_Ceil(NElts.getKnownMinValue());
NElts = ElementCount::get(NewMinCount, NElts.isScalable());
return EVT::getVectorVT(Context, getVectorElementType(), NElts);
}
else {
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/IR/DataLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,9 @@ inline TypeSize DataLayout::getTypeSizeInBits(Type *Ty) const {
case Type::ScalableVectorTyID: {
VectorType *VTy = cast<VectorType>(Ty);
auto EltCnt = VTy->getElementCount();
uint64_t MinBits = EltCnt.Min *
getTypeSizeInBits(VTy->getElementType()).getFixedSize();
return TypeSize(MinBits, EltCnt.Scalable);
uint64_t MinBits = EltCnt.getKnownMinValue() *
getTypeSizeInBits(VTy->getElementType()).getFixedSize();
return TypeSize(MinBits, EltCnt.isScalable());
}
default:
llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");
Expand Down
15 changes: 8 additions & 7 deletions llvm/include/llvm/IR/DerivedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,16 @@ class VectorType : public Type {
unsigned getNumElements() const {
ElementCount EC = getElementCount();
#ifdef STRICT_FIXED_SIZE_VECTORS
assert(!EC.Scalable &&
assert(!EC.isScalable() &&
"Request for fixed number of elements from scalable vector");
return EC.Min;
return EC.getKnownMinValue();
#else
if (EC.Scalable)
if (EC.isScalable())
WithColor::warning()
<< "The code that requested the fixed number of elements has made "
"the assumption that this vector is not scalable. This assumption "
"was not correct, and this may lead to broken code\n";
return EC.Min;
return EC.getKnownMinValue();
#endif
}

Expand Down Expand Up @@ -512,16 +512,17 @@ class VectorType : public Type {
/// input type and the same element type.
static VectorType *getHalfElementsVectorType(VectorType *VTy) {
auto EltCnt = VTy->getElementCount();
assert ((EltCnt.Min & 1) == 0 &&
"Cannot halve vector with odd number of elements.");
assert(EltCnt.isKnownEven() &&
"Cannot halve vector with odd number of elements.");
return VectorType::get(VTy->getElementType(), EltCnt/2);
}

/// This static method returns a VectorType with twice as many elements as the
/// input type and the same element type.
static VectorType *getDoubleElementsVectorType(VectorType *VTy) {
auto EltCnt = VTy->getElementCount();
assert((EltCnt.Min * 2ull) <= UINT_MAX && "Too many elements in vector");
assert((EltCnt.getKnownMinValue() * 2ull) <= UINT_MAX &&
"Too many elements in vector");
return VectorType::get(VTy->getElementType(), EltCnt * 2);
}

Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2046,8 +2046,9 @@ class ShuffleVectorInst : public Instruction {
/// Examples: shufflevector <4 x n> A, <4 x n> B, <1,2,3>
/// shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5>
bool changesLength() const {
unsigned NumSourceElts =
cast<VectorType>(Op<0>()->getType())->getElementCount().Min;
unsigned NumSourceElts = cast<VectorType>(Op<0>()->getType())
->getElementCount()
.getKnownMinValue();
unsigned NumMaskElts = ShuffleMask.size();
return NumSourceElts != NumMaskElts;
}
Expand Down
Loading

0 comments on commit 59c5004

Please sign in to comment.