Skip to content

Commit e57835b

Browse files
committed
add new option to Heatmaps.md
Created using spr 1.3.4
2 parents 1833e09 + 86e9be0 commit e57835b

File tree

90 files changed

+4403
-953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+4403
-953
lines changed

.github/new-prs-labeler.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ mlgo:
702702
- llvm/unittests/CodeGen/ML*
703703
- llvm/test/CodeGen/MLRegAlloc/**
704704
- llvm/utils/mlgo-utils/**
705+
- llvm/docs/MLGO.rst
705706

706707
tools:llvm-exegesis:
707708
- llvm/tools/llvm-exegesis/**

bolt/docs/Heatmaps.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ For the generation, the default bucket size was used with a line size of 128.
8989
Some useful options are:
9090

9191
```
92+
-block-size=<uint> - heatmap bucket size in bytes (default 64)
9293
-line-size=<uint> - number of entries per line (default 256)
9394
-max-address=<uint> - maximum address considered valid for heatmap (default 4GB)
9495
-print-mappings - print mappings in the legend, between characters/blocks and text sections (default false)
96+
-heatmap-zoom-out=<uint>,... - print zoomed out heatmaps with given block sizes,
97+
must be multiples of block-size in ascending order
9598
```

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ Bug Fixes in This Version
615615
argument which contains a pragma. (#GH113722)
616616
- Fixed assertion failures when generating name lookup table in modules. (#GH61065, #GH134739)
617617
- Fixed an assertion failure in constant compound literal statements. (#GH139160)
618+
- Fix crash due to unknown references and pointer implementation and handling of
619+
base classes. (GH139452)
618620

619621
Bug Fixes to Compiler Builtins
620622
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/Attr.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4790,6 +4790,7 @@ def HLSLResourceBinding: InheritableAttr {
47904790
RegisterType RegType;
47914791
std::optional<unsigned> SlotNumber;
47924792
unsigned SpaceNumber;
4793+
std::optional<unsigned> ImplicitBindingOrderID;
47934794

47944795
public:
47954796
void setBinding(RegisterType RT, std::optional<unsigned> SlotNum, unsigned SpaceNum) {
@@ -4811,6 +4812,16 @@ def HLSLResourceBinding: InheritableAttr {
48114812
unsigned getSpaceNumber() const {
48124813
return SpaceNumber;
48134814
}
4815+
void setImplicitBindingOrderID(uint32_t Value) {
4816+
ImplicitBindingOrderID = Value;
4817+
}
4818+
bool hasImplicitBindingOrderID() const {
4819+
return ImplicitBindingOrderID.has_value();
4820+
}
4821+
uint32_t getImplicitBindingOrderID() const {
4822+
assert(hasImplicitBindingOrderID() && "attribute does not have implicit binding order id");
4823+
return ImplicitBindingOrderID.value();
4824+
}
48144825
}];
48154826
}
48164827

clang/lib/AST/ExprConstant.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3314,7 +3314,11 @@ static bool HandleLValueBase(EvalInfo &Info, const Expr *E, LValue &Obj,
33143314
return false;
33153315

33163316
// Extract most-derived object and corresponding type.
3317-
DerivedDecl = D.MostDerivedType->getAsCXXRecordDecl();
3317+
// FIXME: After implementing P2280R4 it became possible to get references
3318+
// here. We do MostDerivedType->getAsCXXRecordDecl() in several other
3319+
// locations and if we see crashes in those locations in the future
3320+
// it may make more sense to move this fix into Lvalue::set.
3321+
DerivedDecl = D.MostDerivedType.getNonReferenceType()->getAsCXXRecordDecl();
33183322
if (!CastToDerivedClass(Info, E, Obj, DerivedDecl, D.MostDerivedPathLength))
33193323
return false;
33203324

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ namespace direct {
5454
namespace {
5555
/// If the given type is a vector type, return the vector's element type.
5656
/// Otherwise return the given type unchanged.
57-
// TODO(cir): Return the vector element type once we have support for vectors
58-
// instead of the identity type.
5957
mlir::Type elementTypeIfVector(mlir::Type type) {
60-
assert(!cir::MissingFeatures::vectorType());
61-
return type;
58+
return llvm::TypeSwitch<mlir::Type, mlir::Type>(type)
59+
.Case<cir::VectorType, mlir::VectorType>(
60+
[](auto p) { return p.getElementType(); })
61+
.Default([](mlir::Type p) { return p; });
6262
}
6363
} // namespace
6464

clang/lib/CodeGen/CGClass.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,6 +2784,29 @@ void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD,
27842784
}
27852785
}
27862786

2787+
/// Converts the CFITypeCheckKind into SanitizerKind::SanitizerOrdinal and
2788+
/// llvm::SanitizerStatKind.
2789+
static std::pair<SanitizerKind::SanitizerOrdinal, llvm::SanitizerStatKind>
2790+
SanitizerInfoFromCFICheckKind(CodeGenFunction::CFITypeCheckKind TCK) {
2791+
switch (TCK) {
2792+
case CodeGenFunction::CFITCK_VCall:
2793+
return std::make_pair(SanitizerKind::SO_CFIVCall, llvm::SanStat_CFI_VCall);
2794+
case CodeGenFunction::CFITCK_NVCall:
2795+
return std::make_pair(SanitizerKind::SO_CFINVCall,
2796+
llvm::SanStat_CFI_NVCall);
2797+
case CodeGenFunction::CFITCK_DerivedCast:
2798+
return std::make_pair(SanitizerKind::SO_CFIDerivedCast,
2799+
llvm::SanStat_CFI_DerivedCast);
2800+
case CodeGenFunction::CFITCK_UnrelatedCast:
2801+
return std::make_pair(SanitizerKind::SO_CFIUnrelatedCast,
2802+
llvm::SanStat_CFI_UnrelatedCast);
2803+
case CodeGenFunction::CFITCK_ICall:
2804+
case CodeGenFunction::CFITCK_NVMFCall:
2805+
case CodeGenFunction::CFITCK_VMFCall:
2806+
llvm_unreachable("unexpected sanitizer kind");
2807+
}
2808+
}
2809+
27872810
void CodeGenFunction::EmitVTablePtrCheckForCall(const CXXRecordDecl *RD,
27882811
llvm::Value *VTable,
27892812
CFITypeCheckKind TCK,
@@ -2847,30 +2870,7 @@ void CodeGenFunction::EmitVTablePtrCheck(const CXXRecordDecl *RD,
28472870
!CGM.HasHiddenLTOVisibility(RD))
28482871
return;
28492872

2850-
SanitizerKind::SanitizerOrdinal M;
2851-
llvm::SanitizerStatKind SSK;
2852-
switch (TCK) {
2853-
case CFITCK_VCall:
2854-
M = SanitizerKind::SO_CFIVCall;
2855-
SSK = llvm::SanStat_CFI_VCall;
2856-
break;
2857-
case CFITCK_NVCall:
2858-
M = SanitizerKind::SO_CFINVCall;
2859-
SSK = llvm::SanStat_CFI_NVCall;
2860-
break;
2861-
case CFITCK_DerivedCast:
2862-
M = SanitizerKind::SO_CFIDerivedCast;
2863-
SSK = llvm::SanStat_CFI_DerivedCast;
2864-
break;
2865-
case CFITCK_UnrelatedCast:
2866-
M = SanitizerKind::SO_CFIUnrelatedCast;
2867-
SSK = llvm::SanStat_CFI_UnrelatedCast;
2868-
break;
2869-
case CFITCK_ICall:
2870-
case CFITCK_NVMFCall:
2871-
case CFITCK_VMFCall:
2872-
llvm_unreachable("unexpected sanitizer kind");
2873-
}
2873+
auto [M, SSK] = SanitizerInfoFromCFICheckKind(TCK);
28742874

28752875
std::string TypeName = RD->getQualifiedNameAsString();
28762876
if (getContext().getNoSanitizeList().containsType(

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "clang/AST/Type.h"
2424
#include "clang/Basic/TargetOptions.h"
2525
#include "llvm/ADT/SmallVector.h"
26+
#include "llvm/IR/Constants.h"
2627
#include "llvm/IR/DerivedTypes.h"
2728
#include "llvm/IR/GlobalVariable.h"
2829
#include "llvm/IR/LLVMContext.h"
@@ -42,8 +43,8 @@ using namespace llvm;
4243
using llvm::hlsl::CBufferRowSizeInBytes;
4344

4445
static void initializeBufferFromBinding(CodeGenModule &CGM,
45-
llvm::GlobalVariable *GV, unsigned Slot,
46-
unsigned Space);
46+
llvm::GlobalVariable *GV,
47+
HLSLResourceBindingAttr *RBA);
4748

4849
namespace {
4950

@@ -271,13 +272,10 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) {
271272
emitBufferGlobalsAndMetadata(BufDecl, BufGV);
272273

273274
// Initialize cbuffer from binding (implicit or explicit)
274-
const HLSLResourceBindingAttr *RBA =
275-
BufDecl->getAttr<HLSLResourceBindingAttr>();
276-
// FIXME: handle implicit binding if no binding attribute is found
277-
// (llvm/llvm-project#110722)
278-
if (RBA && RBA->hasRegisterSlot())
279-
initializeBufferFromBinding(CGM, BufGV, RBA->getSlotNumber(),
280-
RBA->getSpaceNumber());
275+
HLSLResourceBindingAttr *RBA = BufDecl->getAttr<HLSLResourceBindingAttr>();
276+
assert(RBA &&
277+
"cbuffer/tbuffer should always have resource binding attribute");
278+
initializeBufferFromBinding(CGM, BufGV, RBA);
281279
}
282280

283281
llvm::TargetExtType *
@@ -560,19 +558,29 @@ static void initializeBuffer(CodeGenModule &CGM, llvm::GlobalVariable *GV,
560558
}
561559

562560
static void initializeBufferFromBinding(CodeGenModule &CGM,
563-
llvm::GlobalVariable *GV, unsigned Slot,
564-
unsigned Space) {
561+
llvm::GlobalVariable *GV,
562+
HLSLResourceBindingAttr *RBA) {
565563
llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGM.getLLVMContext());
566-
llvm::Value *Args[] = {
567-
llvm::ConstantInt::get(CGM.IntTy, Space), /* reg_space */
568-
llvm::ConstantInt::get(CGM.IntTy, Slot), /* lower_bound */
569-
llvm::ConstantInt::get(CGM.IntTy, 1), /* range_size */
570-
llvm::ConstantInt::get(CGM.IntTy, 0), /* index */
571-
llvm::ConstantInt::get(Int1Ty, false) /* non-uniform */
572-
};
573-
initializeBuffer(CGM, GV,
574-
CGM.getHLSLRuntime().getCreateHandleFromBindingIntrinsic(),
575-
Args);
564+
auto *NonUniform = llvm::ConstantInt::get(Int1Ty, false);
565+
auto *Index = llvm::ConstantInt::get(CGM.IntTy, 0);
566+
auto *RangeSize = llvm::ConstantInt::get(CGM.IntTy, 1);
567+
auto *Space =
568+
llvm::ConstantInt::get(CGM.IntTy, RBA ? RBA->getSpaceNumber() : 0);
569+
570+
if (RBA->hasRegisterSlot()) {
571+
auto *RegSlot = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());
572+
Intrinsic::ID Intr =
573+
CGM.getHLSLRuntime().getCreateHandleFromBindingIntrinsic();
574+
initializeBuffer(CGM, GV, Intr,
575+
{Space, RegSlot, RangeSize, Index, NonUniform});
576+
} else {
577+
auto *OrderID =
578+
llvm::ConstantInt::get(CGM.IntTy, RBA->getImplicitBindingOrderID());
579+
Intrinsic::ID Intr =
580+
CGM.getHLSLRuntime().getCreateHandleFromImplicitBindingIntrinsic();
581+
initializeBuffer(CGM, GV, Intr,
582+
{OrderID, Space, RangeSize, Index, NonUniform});
583+
}
576584
}
577585

578586
llvm::Instruction *CGHLSLRuntime::getConvergenceToken(BasicBlock &BB) {

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,18 @@ void createHostLayoutStructForBuffer(Sema &S, HLSLBufferDecl *BufDecl) {
537537
BufDecl->addLayoutStruct(LS);
538538
}
539539

540+
static void addImplicitBindingAttrToBuffer(Sema &S, HLSLBufferDecl *BufDecl,
541+
uint32_t ImplicitBindingOrderID) {
542+
RegisterType RT =
543+
BufDecl->isCBuffer() ? RegisterType::CBuffer : RegisterType::SRV;
544+
auto *Attr =
545+
HLSLResourceBindingAttr::CreateImplicit(S.getASTContext(), "", "0", {});
546+
std::optional<unsigned> RegSlot;
547+
Attr->setBinding(RT, RegSlot, 0);
548+
Attr->setImplicitBindingOrderID(ImplicitBindingOrderID);
549+
BufDecl->addAttr(Attr);
550+
}
551+
540552
// Handle end of cbuffer/tbuffer declaration
541553
void SemaHLSL::ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace) {
542554
auto *BufDecl = cast<HLSLBufferDecl>(Dcl);
@@ -547,9 +559,17 @@ void SemaHLSL::ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace) {
547559
// create buffer layout struct
548560
createHostLayoutStructForBuffer(SemaRef, BufDecl);
549561

550-
if (std::none_of(Dcl->attr_begin(), Dcl->attr_end(),
551-
[](Attr *A) { return isa<HLSLResourceBindingAttr>(A); }))
562+
HLSLResourceBindingAttr *RBA = Dcl->getAttr<HLSLResourceBindingAttr>();
563+
if (!RBA || !RBA->hasRegisterSlot()) {
552564
SemaRef.Diag(Dcl->getLocation(), diag::warn_hlsl_implicit_binding);
565+
// Use HLSLResourceBindingAttr to transfer implicit binding order_ID
566+
// to codegen. If it does not exist, create an implicit attribute.
567+
uint32_t OrderID = getNextImplicitBindingOrderID();
568+
if (RBA)
569+
RBA->setImplicitBindingOrderID(OrderID);
570+
else
571+
addImplicitBindingAttrToBuffer(SemaRef, BufDecl, OrderID);
572+
}
553573

554574
SemaRef.PopDeclContext();
555575
}
@@ -2000,6 +2020,8 @@ void SemaHLSL::ActOnEndOfTranslationUnit(TranslationUnitDecl *TU) {
20002020
HLSLBufferDecl *DefaultCBuffer = HLSLBufferDecl::CreateDefaultCBuffer(
20012021
SemaRef.getASTContext(), SemaRef.getCurLexicalContext(),
20022022
DefaultCBufferDecls);
2023+
addImplicitBindingAttrToBuffer(SemaRef, DefaultCBuffer,
2024+
getNextImplicitBindingOrderID());
20032025
SemaRef.getCurLexicalContext()->addDecl(DefaultCBuffer);
20042026
createHostLayoutStructForBuffer(SemaRef, DefaultCBuffer);
20052027

clang/test/AST/HLSL/ast-dump-comment-cbuffer.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cbuffer A {
2121

2222
// AST: HLSLBufferDecl {{.*}} line:11:9 cbuffer A
2323
// AST-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
24+
// AST-NEXT: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
2425
// AST-NEXT: FullComment
2526
// AST-NEXT: ParagraphComment
2627
// AST-NEXT: TextComment {{.*}} Text=" CBuffer decl."

0 commit comments

Comments
 (0)