[clang] [llvm] [AIX][TOC] Add -mtocdata/-mno-tocdata options on AIX (PR #67999)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 31 13:19:29 PDT 2023
================
@@ -265,6 +269,63 @@ bool AIXTargetCodeGenInfo::initDwarfEHRegSizeTable(
return PPC_initDwarfEHRegSizeTable(CGF, Address, Is64Bit, /*IsAIX*/ true);
}
+void AIXTargetCodeGenInfo::setTargetAttributes(
+ const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+ if (auto *GVar = dyn_cast<llvm::GlobalVariable>(GV)) {
+ auto GVId = M.getMangledName(dyn_cast<NamedDecl>(D));
+
+ // Is this a global variable specified by the user as toc-data?
+ bool UserSpecifiedTOC =
+ llvm::binary_search(M.getCodeGenOpts().TocDataVarsUserSpecified, GVId);
+ // Assumes the same variable cannot be in both TocVarsUserSpecified and
+ // NoTocVars.
+ if (UserSpecifiedTOC ||
+ ((M.getCodeGenOpts().AllTocData) &&
+ !llvm::binary_search(M.getCodeGenOpts().NoTocDataVars, GVId))) {
+ const unsigned long PointerSize =
+ GV->getParent()->getDataLayout().getPointerSizeInBits() / 8;
+ ASTContext &Context = D->getASTContext();
+ auto *VarD = dyn_cast<VarDecl>(D);
+ assert(VarD && "Invalid declaration of global variable.");
+
+ unsigned Alignment = Context.toBits(Context.getDeclAlign(D)) / 8;
----------------
diggerlin wrote:
we can delete the code
`ASTContext &Context = D->getASTContext();`
and change the code to
`unsigned Alignment = D->getASTContext().toBits(Context.getDeclAlign(D)) / 8;`
https://github.com/llvm/llvm-project/pull/67999
More information about the cfe-commits
mailing list