/llvm/include/llvm/Support/ELF.h

Dear developers,

Hi! I’m trying to create a new backend for loongArcg 32 in LLVM-project 15.0.0.

I’m now on the stage of “Add target machine ID and name to the llvm file”. In a tutorial of llvm 12.0.0, it tell me to modify the file :llvm/include/llvm/Support/ELF.h to add some enum info. But I can’t find this file under the folder. Is it no longer used?

Could you please help me with this? Or where could I find about the correct steps of “how to add a new target info in llvm 15.0.0 (tell the project - oh! hei ! here is a new target)”

Thank you so much.

Tei ichiyo

UPdate : I found the file in : LLVM-Project\llvm-project-llvmorg-15.0.0\llvm\include\llvm\BinaryFormat\ELF.h

Do I need to modify /llvm/lib/MC/SubtargetFeature.cpp ? The SubtargetFeature.cpp in tutorial and LLVM-project are different. According to the tutorial I need to add code for my target as follows: :slight_smile:

extern bool LoongArchDisableUnreconginizedMessage; // For LoongArch
...
FeatureBitset
SubtargetFeatures::ToggleFeature(FeatureBitset Bits, StringRef Feature,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
...
if (!LoongArchDisableUnreconginizedMessage) // For LoongArch
...
}
FeatureBitset
SubtargetFeatures::ApplyFeatureFlag(FeatureBitset Bits, StringRef Feature,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
...
if (!LoongArchDisableUnreconginizedMessage) // For LoongArch
...
}
FeatureBitset
SubtargetFeatures::getFeatureBits(StringRef CPU,
ArrayRef<SubtargetFeatureKV> CPUTable,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
...
if (!LoongArchDisableUnreconginizedMessage) // For LoongArch
...
}

Subtarget features are defined in the .td file for your target (via SubtargetFeature class). You shouldn’t be getting “unrecognized feature” messages when compiling for your target, regardless of what features your target defines. If you are seeing them, it means that some features are applied incorrectly. This can happen when you’re using an older version of the compiler (that doesn’t support certain features), but use flags/attributes meant for a newer version. Still, this is a usage issue, and not a problem with the compiler.

Code in llvm/lib/CodeGen is meant to be target-independent and should not require any modifications when adding a new target (or working on an existing one).

1 Like