Skip to content

Commit 0675c04

Browse files
authored
Merge branch 'main' into main
2 parents 6407ae7 + af56fd0 commit 0675c04

35 files changed

+1003
-399
lines changed

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
#define CLANG_CIR_DIALECT_IR_CIRATTRS_TD
1515

1616
include "mlir/IR/BuiltinAttributeInterfaces.td"
17-
include "mlir/IR/EnumAttr.td"
1817

19-
include "clang/CIR/Dialect/IR/CIRDialect.td"
2018
include "clang/CIR/Dialect/IR/CIRAttrConstraints.td"
19+
include "clang/CIR/Dialect/IR/CIRDialect.td"
20+
include "clang/CIR/Dialect/IR/CIREnumAttr.td"
2121

2222
//===----------------------------------------------------------------------===//
2323
// CIR Attrs
@@ -42,21 +42,6 @@ class CIR_TypedAttr<string name, string attrMnemonic, list<Trait> traits = []>
4242
let assemblyFormat = [{}];
4343
}
4444

45-
class CIR_I32EnumAttr<string name, string summary, list<I32EnumAttrCase> cases>
46-
: I32EnumAttr<name, summary, cases> {
47-
let cppNamespace = "::cir";
48-
}
49-
50-
class CIR_I64EnumAttr<string name, string summary, list<I64EnumAttrCase> cases>
51-
: I64EnumAttr<name, summary, cases> {
52-
let cppNamespace = "::cir";
53-
}
54-
55-
class CIR_EnumAttr<EnumAttrInfo info, string name = "", list<Trait> traits = []>
56-
: EnumAttr<CIR_Dialect, info, name, traits> {
57-
let assemblyFormat = "`<` $value `>`";
58-
}
59-
6045
class CIRUnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
6146
: CIR_Attr<name, attrMnemonic, traits> {
6247
let returnType = "bool";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines the CIR dialect enum base classes
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef CLANG_CIR_DIALECT_IR_CIRENUMATTR_TD
14+
#define CLANG_CIR_DIALECT_IR_CIRENUMATTR_TD
15+
16+
include "mlir/IR/EnumAttr.td"
17+
18+
class CIR_I32EnumAttr<string name, string summary, list<I32EnumAttrCase> cases>
19+
: I32EnumAttr<name, summary, cases> {
20+
let cppNamespace = "::cir";
21+
}
22+
23+
class CIR_I64EnumAttr<string name, string summary, list<I64EnumAttrCase> cases>
24+
: I64EnumAttr<name, summary, cases> {
25+
let cppNamespace = "::cir";
26+
}
27+
28+
class CIR_EnumAttr<EnumAttrInfo info, string name = "", list<Trait> traits = []>
29+
: EnumAttr<CIR_Dialect, info, name, traits> {
30+
let assemblyFormat = "`<` $value `>`";
31+
}
32+
33+
class CIR_DefaultValuedEnumParameter<EnumAttrInfo info, string value = "">
34+
: EnumParameter<info> {
35+
let defaultValue = value;
36+
}
37+
38+
#endif // CLANG_CIR_DIALECT_IR_CIRENUMATTR_TD

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "llvm/ADT/ArrayRef.h"
1818
#include "llvm/ADT/Sequence.h"
19+
#include "llvm/ADT/StringTable.h"
1920
#include "llvm/IR/CallingConv.h"
2021
#include "llvm/IR/InstrTypes.h"
2122
#include "llvm/Support/AtomicOrdering.h"
@@ -77,12 +78,16 @@ struct RuntimeLibcallsInfo {
7778
/// Get the libcall routine name for the specified libcall.
7879
// FIXME: This should be removed. Only LibcallImpl should have a name.
7980
const char *getLibcallName(RTLIB::Libcall Call) const {
80-
return LibCallImplNames[LibcallImpls[Call]];
81+
return getLibcallImplName(LibcallImpls[Call]);
8182
}
8283

8384
/// Get the libcall routine name for the specified libcall implementation.
85+
// FIXME: Change to return StringRef
8486
static const char *getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
85-
return LibCallImplNames[CallImpl];
87+
if (CallImpl == RTLIB::Unsupported)
88+
return nullptr;
89+
return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]]
90+
.data();
8691
}
8792

8893
/// Return the lowering's selection of implementation call for \p Call
@@ -144,7 +149,9 @@ struct RuntimeLibcallsInfo {
144149

145150
/// Names of concrete implementations of runtime calls. e.g. __ashlsi3 for
146151
/// SHL_I32
147-
LLVM_ABI static const char *const LibCallImplNames[RTLIB::NumLibcallImpls];
152+
LLVM_ABI static const char RuntimeLibcallImplNameTableStorage[];
153+
LLVM_ABI static const StringTable RuntimeLibcallImplNameTable;
154+
LLVM_ABI static const uint16_t RuntimeLibcallNameOffsetTable[];
148155

149156
/// Map from a concrete LibcallImpl implementation to its RTLIB::Libcall kind.
150157
LLVM_ABI static const RTLIB::Libcall ImplToLibcall[RTLIB::NumLibcallImpls];

llvm/include/llvm/TableGen/StringToOffsetTable.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ namespace llvm {
2323
class StringToOffsetTable {
2424
StringMap<unsigned> StringOffset;
2525
std::string AggregateString;
26+
27+
/// If this is to be a static class member, the prefix to use (i.e. class name
28+
/// plus ::)
29+
const StringRef ClassPrefix;
2630
const bool AppendZero;
2731

2832
public:
29-
StringToOffsetTable(bool AppendZero = true) : AppendZero(AppendZero) {
33+
StringToOffsetTable(bool AppendZero = true, StringRef ClassPrefix = "")
34+
: ClassPrefix(ClassPrefix), AppendZero(AppendZero) {
3035
// Ensure we always put the empty string at offset zero. That lets empty
3136
// initialization also be zero initialization for offsets into the table.
3237
GetOrAddStringOffset("");

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/IR/RuntimeLibcalls.h"
10+
#include "llvm/ADT/StringTable.h"
1011

1112
using namespace llvm;
1213
using namespace RTLIB;

llvm/lib/TableGen/StringToOffsetTable.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ void StringToOffsetTable::EmitStringTableDef(raw_ostream &OS,
3838
#pragma GCC diagnostic push
3939
#pragma GCC diagnostic ignored "-Woverlength-strings"
4040
#endif
41-
static constexpr char {}Storage[] = )",
42-
Name);
41+
{} constexpr char {}{}Storage[] = )",
42+
ClassPrefix.empty() ? "static" : "", ClassPrefix, Name);
4343

4444
// MSVC silently miscompiles string literals longer than 64k in some
4545
// circumstances. The build system sets EmitLongStrLiterals to false when it
@@ -83,10 +83,10 @@ static constexpr char {}Storage[] = )",
8383
#pragma GCC diagnostic pop
8484
#endif
8585
86-
static constexpr llvm::StringTable
87-
{0} = {0}Storage;
86+
{1}constexpr llvm::StringTable
87+
{2}{0} = {0}Storage;
8888
)",
89-
Name);
89+
Name, ClassPrefix.empty() ? "static " : "", ClassPrefix);
9090
}
9191

9292
void StringToOffsetTable::EmitString(raw_ostream &O) const {

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3724,7 +3724,7 @@ InstructionCost AArch64TTIImpl::getCFInstrCost(unsigned Opcode,
37243724

37253725
InstructionCost AArch64TTIImpl::getVectorInstrCostHelper(
37263726
unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
3727-
bool HasRealUse, const Instruction *I, Value *Scalar,
3727+
const Instruction *I, Value *Scalar,
37283728
ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) const {
37293729
assert(Val->isVectorTy() && "This must be a vector type");
37303730

@@ -3744,12 +3744,10 @@ InstructionCost AArch64TTIImpl::getVectorInstrCostHelper(
37443744
}
37453745

37463746
// The element at index zero is already inside the vector.
3747-
// - For a physical (HasRealUse==true) insert-element or extract-element
3747+
// - For a insert-element or extract-element
37483748
// instruction that extracts integers, an explicit FPR -> GPR move is
37493749
// needed. So it has non-zero cost.
3750-
// - For the rest of cases (virtual instruction or element type is float),
3751-
// consider the instruction free.
3752-
if (Index == 0 && (!HasRealUse || !Val->getScalarType()->isIntegerTy()))
3750+
if (Index == 0 && !Val->getScalarType()->isIntegerTy())
37533751
return 0;
37543752

37553753
// This is recognising a LD1 single-element structure to one lane of one
@@ -3899,25 +3897,28 @@ InstructionCost AArch64TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
38993897
unsigned Index,
39003898
const Value *Op0,
39013899
const Value *Op1) const {
3902-
bool HasRealUse =
3903-
Opcode == Instruction::InsertElement && Op0 && !isa<UndefValue>(Op0);
3904-
return getVectorInstrCostHelper(Opcode, Val, CostKind, Index, HasRealUse);
3900+
// Treat insert at lane 0 into a poison vector as having zero cost. This
3901+
// ensures vector broadcasts via an insert + shuffle (and will be lowered to a
3902+
// single dup) are treated as cheap.
3903+
if (Opcode == Instruction::InsertElement && Index == 0 && Op0 &&
3904+
isa<PoisonValue>(Op0))
3905+
return 0;
3906+
return getVectorInstrCostHelper(Opcode, Val, CostKind, Index);
39053907
}
39063908

39073909
InstructionCost AArch64TTIImpl::getVectorInstrCost(
39083910
unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
39093911
Value *Scalar,
39103912
ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx) const {
3911-
return getVectorInstrCostHelper(Opcode, Val, CostKind, Index, false, nullptr,
3912-
Scalar, ScalarUserAndIdx);
3913+
return getVectorInstrCostHelper(Opcode, Val, CostKind, Index, nullptr, Scalar,
3914+
ScalarUserAndIdx);
39133915
}
39143916

39153917
InstructionCost AArch64TTIImpl::getVectorInstrCost(const Instruction &I,
39163918
Type *Val,
39173919
TTI::TargetCostKind CostKind,
39183920
unsigned Index) const {
3919-
return getVectorInstrCostHelper(I.getOpcode(), Val, CostKind, Index,
3920-
true /* HasRealUse */, &I);
3921+
return getVectorInstrCostHelper(I.getOpcode(), Val, CostKind, Index, &I);
39213922
}
39223923

39233924
InstructionCost AArch64TTIImpl::getScalarizationOverhead(

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ class AArch64TTIImpl final : public BasicTTIImplBase<AArch64TTIImpl> {
6565

6666
// A helper function called by 'getVectorInstrCost'.
6767
//
68-
// 'Val' and 'Index' are forwarded from 'getVectorInstrCost'; 'HasRealUse'
69-
// indicates whether the vector instruction is available in the input IR or
70-
// just imaginary in vectorizer passes.
71-
/// \param ScalarUserAndIdx encodes the information about extracts from a
68+
// 'Val' and 'Index' are forwarded from 'getVectorInstrCost';
69+
// \param ScalarUserAndIdx encodes the information about extracts from a
7270
/// vector with 'Scalar' being the value being extracted,'User' being the user
7371
/// of the extract(nullptr if user is not known before vectorization) and
7472
/// 'Idx' being the extract lane.
7573
InstructionCost getVectorInstrCostHelper(
7674
unsigned Opcode, Type *Val, TTI::TargetCostKind CostKind, unsigned Index,
77-
bool HasRealUse, const Instruction *I = nullptr, Value *Scalar = nullptr,
75+
const Instruction *I = nullptr, Value *Scalar = nullptr,
7876
ArrayRef<std::tuple<Value *, User *, int>> ScalarUserAndIdx = {}) const;
7977

8078
public:

llvm/test/Analysis/CostModel/AArch64/reduce-and.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ define void @reduce() {
1313
; CHECK-NEXT: Cost Model: Found costs of 3 for: %V32 = call i1 @llvm.vector.reduce.and.v32i1(<32 x i1> undef)
1414
; CHECK-NEXT: Cost Model: Found costs of 5 for: %V64 = call i1 @llvm.vector.reduce.and.v64i1(<64 x i1> undef)
1515
; CHECK-NEXT: Cost Model: Found costs of 9 for: %V128 = call i1 @llvm.vector.reduce.and.v128i1(<128 x i1> undef)
16-
; CHECK-NEXT: Cost Model: Found costs of 0 for: %V1i8 = call i8 @llvm.vector.reduce.and.v1i8(<1 x i8> undef)
17-
; CHECK-NEXT: Cost Model: Found costs of 4 for: %V3i8 = call i8 @llvm.vector.reduce.and.v3i8(<3 x i8> undef)
16+
; CHECK-NEXT: Cost Model: Found costs of RThru:2 CodeSize:1 Lat:2 SizeLat:2 for: %V1i8 = call i8 @llvm.vector.reduce.and.v1i8(<1 x i8> undef)
17+
; CHECK-NEXT: Cost Model: Found costs of RThru:6 CodeSize:5 Lat:6 SizeLat:6 for: %V3i8 = call i8 @llvm.vector.reduce.and.v3i8(<3 x i8> undef)
1818
; CHECK-NEXT: Cost Model: Found costs of 7 for: %V4i8 = call i8 @llvm.vector.reduce.and.v4i8(<4 x i8> undef)
1919
; CHECK-NEXT: Cost Model: Found costs of 15 for: %V8i8 = call i8 @llvm.vector.reduce.and.v8i8(<8 x i8> undef)
2020
; CHECK-NEXT: Cost Model: Found costs of 17 for: %V16i8 = call i8 @llvm.vector.reduce.and.v16i8(<16 x i8> undef)

llvm/test/Analysis/CostModel/AArch64/reduce-or.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ define void @reduce() {
1313
; CHECK-NEXT: Cost Model: Found costs of 3 for: %V32 = call i1 @llvm.vector.reduce.or.v32i1(<32 x i1> undef)
1414
; CHECK-NEXT: Cost Model: Found costs of 5 for: %V64 = call i1 @llvm.vector.reduce.or.v64i1(<64 x i1> undef)
1515
; CHECK-NEXT: Cost Model: Found costs of 9 for: %V128 = call i1 @llvm.vector.reduce.or.v128i1(<128 x i1> undef)
16-
; CHECK-NEXT: Cost Model: Found costs of 0 for: %V1i8 = call i8 @llvm.vector.reduce.or.v1i8(<1 x i8> undef)
17-
; CHECK-NEXT: Cost Model: Found costs of 4 for: %V3i8 = call i8 @llvm.vector.reduce.or.v3i8(<3 x i8> undef)
16+
; CHECK-NEXT: Cost Model: Found costs of RThru:2 CodeSize:1 Lat:2 SizeLat:2 for: %V1i8 = call i8 @llvm.vector.reduce.or.v1i8(<1 x i8> undef)
17+
; CHECK-NEXT: Cost Model: Found costs of RThru:6 CodeSize:5 Lat:6 SizeLat:6 for: %V3i8 = call i8 @llvm.vector.reduce.or.v3i8(<3 x i8> undef)
1818
; CHECK-NEXT: Cost Model: Found costs of 7 for: %V4i8 = call i8 @llvm.vector.reduce.or.v4i8(<4 x i8> undef)
1919
; CHECK-NEXT: Cost Model: Found costs of 15 for: %V8i8 = call i8 @llvm.vector.reduce.or.v8i8(<8 x i8> undef)
2020
; CHECK-NEXT: Cost Model: Found costs of 17 for: %V16i8 = call i8 @llvm.vector.reduce.or.v16i8(<16 x i8> undef)

0 commit comments

Comments
 (0)