Skip to content

Commit 6d13aef

Browse files
authored
[FPGA] [CodeGen][NFC] Enhance Intel FPGA annotation function and optimize code (#14577)
This commit makes several improvements to the `CodeGenModule::addGlobalIntelFPGAAnnotation` method: - Updating the comment style to be Doxygen compliant for the `addGlobalIntelFPGAAnnotation` function. - Replaced `getAs<RecordType>()` with `castAs<RecordType>()` after confirming that the variable declaration type is guaranteed to be a `RecordType`. This change removes the need for a null check and streamlines the code. - Modified the base class iteration loop to use a reference (`const auto &Base`) to avoid unnecessary copies of `CXXBaseSpecifier` objects. These changes enhance code readability, improve code documentation and potentially increase performance by avoiding unnecessary dynamic type checks and copies. --------- Signed-off-by: Soumi Manna <[email protected]>
1 parent 6a93147 commit 6d13aef

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5907,22 +5907,19 @@ void CodeGenModule::generateIntelFPGAAnnotation(
59075907
}
59085908
}
59095909

5910-
/**
5911-
* Adds global Intel FPGA annotations for a given variable declaration.
5912-
* This function handles both simple global variables and fields within
5913-
* structs that are annotated with Intel FPGA attributes. For structs,
5914-
* it recursively visits all fields and base classes to collect annotations.
5915-
*
5916-
* @param VD The variable declaration to annotate.
5917-
* @param GV The LLVM GlobalValue corresponding to the variable declaration.
5918-
*/
5910+
/// Adds global Intel FPGA annotations for a given variable declaration.
5911+
/// This function handles both simple global variables and fields within
5912+
/// structs that are annotated with Intel FPGA attributes. For structs,
5913+
/// it recursively visits all fields and base classes to collect annotations.
5914+
/// \param VD The variable declaration to annotate.
5915+
/// \param GV The LLVM GlobalValue corresponding to the variable declaration.
59195916
void CodeGenModule::addGlobalIntelFPGAAnnotation(const VarDecl *VD,
59205917
llvm::GlobalValue *GV) {
59215918
SmallString<256> AnnotStr;
59225919

59235920
// Handle annotations for fields within a device_global struct.
59245921
if (getLangOpts().IntelFPGA && VD->getType()->isRecordType()) {
5925-
auto RT = VD->getType()->getAs<RecordType>();
5922+
auto RT = VD->getType()->castAs<RecordType>();
59265923

59275924
auto Gen = [&AnnotStr, this](const RecordType *Ty, auto &&Gen) -> void {
59285925
const CXXRecordDecl *RD = cast<CXXRecordDecl>(Ty->getDecl());
@@ -5939,11 +5936,11 @@ void CodeGenModule::addGlobalIntelFPGAAnnotation(const VarDecl *VD,
59395936
}
59405937

59415938
// Iterate over the base classes of the struct.
5942-
for (const auto Base : RD->bases()) {
5939+
for (const auto &Base : RD->bases()) {
59435940
QualType BaseTy = Base.getType();
59445941

5945-
if (const auto *BRT = BaseTy->getAs<RecordType>())
5946-
Gen(BRT, Gen);
5942+
const auto *BRT = BaseTy->castAs<RecordType>();
5943+
Gen(BRT, Gen);
59475944
}
59485945
};
59495946
Gen(RT, Gen);

0 commit comments

Comments
 (0)