llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
307 stars 84 forks source link

[CIR][CIRGen] Add setNonAliasAttributes for GlobalOp and FuncOp #707

Closed ghehg closed 1 day ago

ghehg commented 4 days ago

In this PR: as title we added setNonAliasAttributes in the skeleton of OG's setNonAliasAttributes, and call this function in buildGlobalFunctionDefinition after code for FuncOP is generated. This is needed for CIR OG to know FuncOP is not declaration anymore, thus giving shouldAssumeDsoLocal another run to make dso_local right.

A couple of notes about test;

  1. having to changed driver.c, because in terms of dso_local for func, masOS is different from other targets as even in OG, as macOS is !isOSBinFormatELF(), thus even OG doesn't set dso_local for its functions.

  2. most of functions in existing tests still not getting dso_local in LLVM yet because they fall into case of (RM != llvm::Reloc::Static && !LOpts.PIE) , which is more complicated to implement as we need to get canBenefitFromLocalAlias right. So I treated it as a missing feature and default it to false. We gonna leave it to another PR to address. In this PR, I just added additional test with -fpie option to my test so we get dso_local for functions without having to deal with this case.

Next 2 PRs: PR1. call setNonAliasAttributes in buildGlobalVarDefinition, after initialization for GlobalOP is found, similar to FuncOp. didn't to it in this PR as there are many more test cases needed to be fixed/added for this case. PR2: try to implement canBenefitFromLocalAlias.