Skip to content
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

[FPGA] [CodeGen][NFC] Enhance Intel FPGA annotation function and optimize code #14577

Merged
merged 9 commits into from
Jul 16, 2024
23 changes: 10 additions & 13 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5907,22 +5907,19 @@ void CodeGenModule::generateIntelFPGAAnnotation(
}
}

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

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

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

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

if (const auto *BRT = BaseTy->getAs<RecordType>())
Gen(BRT, Gen);
const auto *BRT = BaseTy->castAs<RecordType>();
Gen(BRT, Gen);
}
};
Gen(RT, Gen);
Expand Down
Loading