Skip to content

[CIR][CodeGen] Attach hot attribute to CIR function #1826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,10 @@ def CIR_ConvergentAttr : CIR_UnitAttr<"Convergent", "convergent"> {
let storageType = [{ ConvergentAttr }];
}

def CIR_HotAttr : CIR_UnitAttr<"Hot", "hot"> {
let storageType = [{ HotAttr }];
}

//===----------------------------------------------------------------------===//
// UWTableAttr
//===----------------------------------------------------------------------===//
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2983,8 +2983,10 @@ void CIRGenModule::setCIRFunctionAttributesForDefinition(const Decl *decl,
if (decl->hasAttr<ColdAttr>()) {
llvm_unreachable("NYI");
}
if (decl->hasAttr<HotAttr>())
llvm_unreachable("NYI");
if (decl->hasAttr<HotAttr>()) {
auto attr = cir::HotAttr::get(&getMLIRContext());
attrs.set(attr.getMnemonic(), attr);
}
if (decl->hasAttr<MinSizeAttr>())
assert(!MissingFeatures::minSize());
}
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class CIRDialectLLVMIRTranslationInterface
llvmFunc->addFnAttr(llvm::Attribute::NoUnwind);
} else if (mlir::dyn_cast<cir::ConvergentAttr>(attr.getValue())) {
llvmFunc->addFnAttr(llvm::Attribute::Convergent);
} else if (mlir::dyn_cast<cir::HotAttr>(attr.getValue())) {
llvmFunc->addFnAttr(llvm::Attribute::Hot);
} else if (mlir::dyn_cast<cir::OpenCLKernelAttr>(attr.getValue())) {
const auto uniformAttrName =
cir::OpenCLKernelUniformWorkGroupSizeAttr::getMnemonic();
Expand Down
16 changes: 16 additions & 0 deletions clang/test/CIR/CodeGen/hot-attr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_cc1 -O2 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
// RUN: %clang_cc1 -O2 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM

__attribute__((hot)) int s0(int a, int b) {
int x = a + b;
return x;
}

// CIR: #[[ATTR0:.+]] = #cir<extra({{{.*}}hot = #cir.hot
// CIR: cir.func dso_local @_Z2s0ii(
// CIR-SAME: -> !s32i extra(#[[ATTR0]])

// LLVM: define dso_local i32 @_Z2s0ii({{.*}} #[[#ATTR1:]] {
// LLVM: attributes #[[#ATTR1]] = {{.*}} hot
Loading