Skip to content

Commit da62b70

Browse files
committed
[CIR] Attach hot attribute to CIR function
1 parent b626e81 commit da62b70

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,10 @@ def CIR_ConvergentAttr : CIR_UnitAttr<"Convergent", "convergent"> {
12011201
let storageType = [{ ConvergentAttr }];
12021202
}
12031203

1204+
def CIR_HotAttr : CIR_UnitAttr<"Hot", "hot"> {
1205+
let storageType = [{ HotAttr }];
1206+
}
1207+
12041208
//===----------------------------------------------------------------------===//
12051209
// UWTableAttr
12061210
//===----------------------------------------------------------------------===//

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,8 +2983,10 @@ void CIRGenModule::setCIRFunctionAttributesForDefinition(const Decl *decl,
29832983
if (decl->hasAttr<ColdAttr>()) {
29842984
llvm_unreachable("NYI");
29852985
}
2986-
if (decl->hasAttr<HotAttr>())
2987-
llvm_unreachable("NYI");
2986+
if (decl->hasAttr<HotAttr>()) {
2987+
auto attr = cir::HotAttr::get(&getMLIRContext());
2988+
attrs.set(attr.getMnemonic(), attr);
2989+
}
29882990
if (decl->hasAttr<MinSizeAttr>())
29892991
assert(!MissingFeatures::minSize());
29902992
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ class CIRDialectLLVMIRTranslationInterface
116116
llvmFunc->addFnAttr(llvm::Attribute::NoUnwind);
117117
} else if (mlir::dyn_cast<cir::ConvergentAttr>(attr.getValue())) {
118118
llvmFunc->addFnAttr(llvm::Attribute::Convergent);
119+
} else if (mlir::dyn_cast<cir::HotAttr>(attr.getValue())) {
120+
llvmFunc->addFnAttr(llvm::Attribute::Hot);
119121
} else if (mlir::dyn_cast<cir::OpenCLKernelAttr>(attr.getValue())) {
120122
const auto uniformAttrName =
121123
cir::OpenCLKernelUniformWorkGroupSizeAttr::getMnemonic();

clang/test/CIR/CodeGen/hot-attr.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -O2 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3+
// RUN: %clang_cc1 -O2 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
4+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
5+
6+
__attribute__((hot)) int s0(int a, int b) {
7+
int x = a + b;
8+
return x;
9+
}
10+
11+
// CIR: #[[ATTR0:.+]] = #cir<extra({{{.*}}hot = #cir.hot
12+
// CIR: cir.func dso_local @_Z2s0ii(
13+
// CIR-SAME: -> !s32i extra(#[[ATTR0]])
14+
15+
// LLVM: define dso_local i32 @_Z2s0ii({{.*}} #[[#ATTR1:]] {
16+
// LLVM: attributes #[[#ATTR1]] = {{.*}} hot

0 commit comments

Comments
 (0)