Skip to content

Many target MCTargetDesc libraries still include headers from the target CodeGen library #64166

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

Closed
rnk opened this issue Jul 27, 2023 · 1 comment
Assignees
Labels
bazel "Peripheral" support tier build system: utils/bazel llvm Umbrella label for LLVM issues

Comments

@rnk
Copy link
Collaborator

rnk commented Jul 27, 2023

Every LLVM target is composed of several libraries. The primary library, the one called LLVM${TGT}CodeGen, is responsible for translating IR to MachineInstrs, and ultimately "printing" (or producing) MCInstrs, which is our representation of assembly. Below that, we have the MCTargetDesc library, which is intended to contain data about the ISA. This should not depend on CodeGen. The intention is that we can link llvm-mc for all targets without linking in either the target-independent library (LLVMCodeGen) or the target-specific codegen library (LLVMX86CodeGen).

This is how things are linked together in CMake. The problem is that our headers are not well organized, and we still reference headers from llvm/CodeGen/ from files in MCTargetDesc. This problem is detected by Bazel, which sandboxes each action and stages the necessary inputs to every action. If you apply this patch to remove the dep on CodeGen from all the MCTargetDesc libraries, you can observe compilation failures.

I have a stack of patches in a github branch to fix this issue. I'm filing this issue to describe the problem well once so I can link to it from the commit messages.

The error message from Bazel typically looks like a file-not-found error on an include, something like this:

In file included from external/llvm-project/llvm/lib/Target/AMDGPU/MCA/AMDGPUCustomBehaviour.cpp:16:                                                                                                                                                                                      
In file included from bazel-out/k8-fastbuild/bin/external/llvm-project/llvm/_virtual_includes/AMDGPUUtilsAndDesc/SIInstrInfo.h:17:                                                                                                                                                        
bazel-out/k8-fastbuild/bin/external/llvm-project/llvm/_virtual_includes/AMDGPUUtilsAndDesc/AMDGPUMIRFormatter.h:19:10: fatal error: 'llvm/CodeGen/MIRFormatter.h' file not found                                                                                                          
#include "llvm/CodeGen/MIRFormatter.h"                                                                                                                                                                                                                                                    
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                       
1 error generated.                                                                                                                           

Aside from Bazel, we should fix these issues because it makes our code fragile. We reference these CodeGen headers but do not link against the corresponding cpp file, so the link will fail if someone decides to move an inline function out of line or to call a non-inline method.

@rnk rnk added llvm Umbrella label for LLVM issues bazel "Peripheral" support tier build system: utils/bazel labels Jul 27, 2023
@rnk rnk self-assigned this Jul 27, 2023
rnk added a commit that referenced this issue Jul 27, 2023
These are small include-only changes in the X86, Mips, and SystemZ
backend that seem sufficiently small to commit separately without
review.

See issue #64166 for more information about layering.
rnk added a commit that referenced this issue Jul 27, 2023
These are small include-only changes in the AArch64 and ARM backends
that seem sufficiently small to commit separately without review.

See issue #64166 for more information about layering.
rnk added a commit that referenced this issue Jul 27, 2023
This required two substantial changes:
1. Moving a `getRegBitWidth(TargetRegisterClass)` overload out of Utils
   and into CodeGen
2. Passing the string function name to AMDGPUPALMetadata instead of the
   MachineFunction

Other changes are minor or updates to accommodate the first two.

See issue #64166 for more information on the layering issue.

Differential Revision: https://reviews.llvm.org/D156486
eymay pushed a commit to eymay/llvm-project that referenced this issue Jul 28, 2023
These are small include-only changes in the X86, Mips, and SystemZ
backend that seem sufficiently small to commit separately without
review.

See issue llvm#64166 for more information about layering.
eymay pushed a commit to eymay/llvm-project that referenced this issue Jul 28, 2023
These are small include-only changes in the AArch64 and ARM backends
that seem sufficiently small to commit separately without review.

See issue llvm#64166 for more information about layering.
eymay pushed a commit to eymay/llvm-project that referenced this issue Jul 28, 2023
This required two substantial changes:
1. Moving a `getRegBitWidth(TargetRegisterClass)` overload out of Utils
   and into CodeGen
2. Passing the string function name to AMDGPUPALMetadata instead of the
   MachineFunction

Other changes are minor or updates to accommodate the first two.

See issue llvm#64166 for more information on the layering issue.

Differential Revision: https://reviews.llvm.org/D156486
rnk added a commit that referenced this issue Aug 18, 2023
Move WebAssemblyUtilities from Utils to the CodeGen library. It
primarily deals in MIR layer types, so it really lives in the CodeGen
library.

Move a variety of other things around to try create better separation.

See issue #64166 for more info on layering.

Move llvm/include/CodeGen/WasmAddressSpaces.h back to
llvm/lib/Target/WebAssembly/Utils.

Differential Revision: https://reviews.llvm.org/D156472
@MaskRay
Copy link
Member

MaskRay commented Aug 18, 2023

Thank you for working on this!

My f406db9 added -layering_check to name = target["name"] + "UtilsAndDesc" so that I can enable layering_check for llvm/. There are other related issues here...

MaskRay added a commit that referenced this issue Aug 22, 2023
…eps, NFC

See issue #64166 for more information about layering.
rnk added a commit that referenced this issue Aug 30, 2023
See issue #64166 for more information about the layering issue.

The PPCMCTargetDesc library was including CodeGen headers such as
PPCInstrInfo.h and calling inline functions in them. This doesn't work
in the Bazel build, and is error-prone. If the inline function moves to
a cpp file, it will result in linker errors.

To address the issue, I moved several inline functions to
PPCMCTargetDesc.cpp, and declared them in the PPC namespace in
PPCMCTargetDesc.h, which seemed like the most straightforward fix.

Differential Revision: https://reviews.llvm.org/D156488
rnk added a commit that referenced this issue Aug 30, 2023
See issue #64166 for more information about the layering issue.
rnk added a commit that referenced this issue Aug 30, 2023
See issue #64166 for more information about the layering issue.
@rnk rnk closed this as completed in 5bc514b Aug 31, 2023
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
Move WebAssemblyUtilities from Utils to the CodeGen library. It
primarily deals in MIR layer types, so it really lives in the CodeGen
library.

Move a variety of other things around to try create better separation.

See issue llvm#64166 for more info on layering.

Move llvm/include/CodeGen/WasmAddressSpaces.h back to
llvm/lib/Target/WebAssembly/Utils.

Differential Revision: https://reviews.llvm.org/D156472
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
…eps, NFC

See issue llvm#64166 for more information about layering.
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
Move WebAssemblyUtilities from Utils to the CodeGen library. It
primarily deals in MIR layer types, so it really lives in the CodeGen
library.

Move a variety of other things around to try create better separation.

See issue llvm#64166 for more info on layering.

Move llvm/include/CodeGen/WasmAddressSpaces.h back to
llvm/lib/Target/WebAssembly/Utils.

Differential Revision: https://reviews.llvm.org/D156472
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
…eps, NFC

See issue llvm#64166 for more information about layering.
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
Move WebAssemblyUtilities from Utils to the CodeGen library. It
primarily deals in MIR layer types, so it really lives in the CodeGen
library.

Move a variety of other things around to try create better separation.

See issue llvm#64166 for more info on layering.

Move llvm/include/CodeGen/WasmAddressSpaces.h back to
llvm/lib/Target/WebAssembly/Utils.

Differential Revision: https://reviews.llvm.org/D156472
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
…eps, NFC

See issue llvm#64166 for more information about layering.
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 3, 2023
Move WebAssemblyUtilities from Utils to the CodeGen library. It
primarily deals in MIR layer types, so it really lives in the CodeGen
library.

Move a variety of other things around to try create better separation.

See issue llvm#64166 for more info on layering.

Move llvm/include/CodeGen/WasmAddressSpaces.h back to
llvm/lib/Target/WebAssembly/Utils.

Differential Revision: https://reviews.llvm.org/D156472
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 3, 2023
…eps, NFC

See issue llvm#64166 for more information about layering.
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 3, 2023
Move WebAssemblyUtilities from Utils to the CodeGen library. It
primarily deals in MIR layer types, so it really lives in the CodeGen
library.

Move a variety of other things around to try create better separation.

See issue llvm#64166 for more info on layering.

Move llvm/include/CodeGen/WasmAddressSpaces.h back to
llvm/lib/Target/WebAssembly/Utils.

Differential Revision: https://reviews.llvm.org/D156472
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 3, 2023
…eps, NFC

See issue llvm#64166 for more information about layering.
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 6, 2023
Move WebAssemblyUtilities from Utils to the CodeGen library. It
primarily deals in MIR layer types, so it really lives in the CodeGen
library.

Move a variety of other things around to try create better separation.

See issue llvm#64166 for more info on layering.

Move llvm/include/CodeGen/WasmAddressSpaces.h back to
llvm/lib/Target/WebAssembly/Utils.

Differential Revision: https://reviews.llvm.org/D156472
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 6, 2023
…eps, NFC

See issue llvm#64166 for more information about layering.
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 11, 2023
Move WebAssemblyUtilities from Utils to the CodeGen library. It
primarily deals in MIR layer types, so it really lives in the CodeGen
library.

Move a variety of other things around to try create better separation.

See issue llvm#64166 for more info on layering.

Move llvm/include/CodeGen/WasmAddressSpaces.h back to
llvm/lib/Target/WebAssembly/Utils.

Differential Revision: https://reviews.llvm.org/D156472
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 11, 2023
…eps, NFC

See issue llvm#64166 for more information about layering.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bazel "Peripheral" support tier build system: utils/bazel llvm Umbrella label for LLVM issues
Projects
None yet
Development

No branches or pull requests

2 participants