diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h @@ -21,6 +21,7 @@ #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h" #include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h" #include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" +#include "llvm/MC/SubtargetFeature.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/BinaryStreamReader.h" #include "llvm/Support/BinaryStreamWriter.h" @@ -984,11 +985,12 @@ using GetEdgeKindNameFunction = const char *(*)(Edge::Kind); + LinkGraph(std::string Name, const Triple &TT, SubtargetFeatures Features, + unsigned PointerSize, support::endianness Endianness, + GetEdgeKindNameFunction GetEdgeKindName); LinkGraph(std::string Name, const Triple &TT, unsigned PointerSize, support::endianness Endianness, - GetEdgeKindNameFunction GetEdgeKindName) - : Name(std::move(Name)), TT(TT), PointerSize(PointerSize), - Endianness(Endianness), GetEdgeKindName(std::move(GetEdgeKindName)) {} + GetEdgeKindNameFunction GetEdgeKindName); LinkGraph(const LinkGraph &) = delete; LinkGraph &operator=(const LinkGraph &) = delete; @@ -1002,6 +1004,9 @@ /// Returns the target triple for this Graph. const Triple &getTargetTriple() const { return TT; } + /// Return the subtarget features for this Graph. + const SubtargetFeatures &getFeatures() const { return Features; } + /// Returns the pointer size for use in this graph. unsigned getPointerSize() const { return PointerSize; } @@ -1507,6 +1512,7 @@ std::string Name; Triple TT; + SubtargetFeatures Features; unsigned PointerSize; support::endianness Endianness; GetEdgeKindNameFunction GetEdgeKindName = nullptr; diff --git a/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt b/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt --- a/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt +++ b/llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt @@ -50,6 +50,7 @@ LINK_COMPONENTS BinaryFormat + MC Object Option OrcTargetProcess diff --git a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp --- a/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.cpp @@ -26,11 +26,10 @@ COFFLinkGraphBuilder::COFFLinkGraphBuilder( const object::COFFObjectFile &Obj, Triple TT, LinkGraph::GetEdgeKindNameFunction GetEdgeKindName) - : Obj(Obj), - G(std::make_unique(Obj.getFileName().str(), - createTripleWithCOFFFormat(TT), - getPointerSize(Obj), getEndianness(Obj), - std::move(GetEdgeKindName))) { + : Obj(Obj), G(std::make_unique( + Obj.getFileName().str(), createTripleWithCOFFFormat(TT), + cantFail(Obj.getFeatures()), getPointerSize(Obj), + getEndianness(Obj), std::move(GetEdgeKindName))) { LLVM_DEBUG({ dbgs() << "Created COFFLinkGraphBuilder for \"" << Obj.getFileName() << "\"\n"; diff --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h --- a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h @@ -59,7 +59,7 @@ public: ELFLinkGraphBuilder(const object::ELFFile &Obj, Triple TT, - StringRef FileName, + SubtargetFeatures Features, StringRef FileName, LinkGraph::GetEdgeKindNameFunction GetEdgeKindName); /// Debug sections are included in the graph by default. Use @@ -195,11 +195,11 @@ template ELFLinkGraphBuilder::ELFLinkGraphBuilder( - const ELFFile &Obj, Triple TT, StringRef FileName, - LinkGraph::GetEdgeKindNameFunction GetEdgeKindName) + const ELFFile &Obj, Triple TT, SubtargetFeatures Features, + StringRef FileName, LinkGraph::GetEdgeKindNameFunction GetEdgeKindName) : ELFLinkGraphBuilderBase(std::make_unique( - FileName.str(), Triple(std::move(TT)), ELFT::Is64Bits ? 8 : 4, - support::endianness(ELFT::TargetEndianness), + FileName.str(), Triple(std::move(TT)), std::move(Features), + ELFT::Is64Bits ? 8 : 4, support::endianness(ELFT::TargetEndianness), std::move(GetEdgeKindName))), Obj(Obj) { LLVM_DEBUG( diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch32.cpp @@ -191,9 +191,10 @@ public: ELFLinkGraphBuilder_aarch32(StringRef FileName, const llvm::object::ELFFile &Obj, Triple TT, + SubtargetFeatures Features, aarch32::ArmConfig ArmCfg) - : ELFLinkGraphBuilder(Obj, std::move(TT), FileName, - getELFAArch32EdgeKindName), + : ELFLinkGraphBuilder(Obj, std::move(TT), std::move(Features), + FileName, getELFAArch32EdgeKindName), ArmCfg(std::move(ArmCfg)) {} }; @@ -249,14 +250,16 @@ case Triple::thumb: { auto &ELFFile = cast>(**ELFObj).getELFFile(); return ELFLinkGraphBuilder_aarch32( - (*ELFObj)->getFileName(), ELFFile, TT, ArmCfg) + (*ELFObj)->getFileName(), ELFFile, TT, + cantFail((*ELFObj)->getFeatures()), ArmCfg) .buildGraph(); } case Triple::armeb: case Triple::thumbeb: { auto &ELFFile = cast>(**ELFObj).getELFFile(); - return ELFLinkGraphBuilder_aarch32((*ELFObj)->getFileName(), - ELFFile, TT, ArmCfg) + return ELFLinkGraphBuilder_aarch32( + (*ELFObj)->getFileName(), ELFFile, TT, + cantFail((*ELFObj)->getFeatures()), ArmCfg) .buildGraph(); } default: diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp @@ -404,9 +404,10 @@ public: ELFLinkGraphBuilder_aarch64(StringRef FileName, - const object::ELFFile &Obj, Triple TT) - : ELFLinkGraphBuilder(Obj, std::move(TT), FileName, - aarch64::getEdgeKindName) {} + const object::ELFFile &Obj, Triple TT, + SubtargetFeatures Features) + : ELFLinkGraphBuilder(Obj, std::move(TT), std::move(Features), + FileName, aarch64::getEdgeKindName) {} }; // TLS Info Builder. @@ -558,9 +559,9 @@ "Only AArch64 (little endian) is supported for now"); auto &ELFObjFile = cast>(**ELFObj); - return ELFLinkGraphBuilder_aarch64((*ELFObj)->getFileName(), - ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + return ELFLinkGraphBuilder_aarch64( + (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), + (*ELFObj)->makeTriple(), cantFail((*ELFObj)->getFeatures())) .buildGraph(); } diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_i386.cpp @@ -210,9 +210,9 @@ public: ELFLinkGraphBuilder_i386(StringRef FileName, const object::ELFFile &Obj, - Triple TT) - : ELFLinkGraphBuilder(Obj, std::move(TT), FileName, - i386::getEdgeKindName) {} + Triple TT, SubtargetFeatures Features) + : ELFLinkGraphBuilder(Obj, std::move(TT), std::move(Features), + FileName, i386::getEdgeKindName) {} }; Expected> @@ -230,9 +230,9 @@ "Only i386 (little endian) is supported for now"); auto &ELFObjFile = cast>(**ELFObj); - return ELFLinkGraphBuilder_i386((*ELFObj)->getFileName(), - ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + return ELFLinkGraphBuilder_i386( + (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), + (*ELFObj)->makeTriple(), cantFail((*ELFObj)->getFeatures())) .buildGraph(); } diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp @@ -129,9 +129,10 @@ public: ELFLinkGraphBuilder_loongarch(StringRef FileName, - const object::ELFFile &Obj, Triple TT) - : ELFLinkGraphBuilder(Obj, std::move(TT), FileName, - loongarch::getEdgeKindName) {} + const object::ELFFile &Obj, Triple TT, + SubtargetFeatures Features) + : ELFLinkGraphBuilder(Obj, std::move(TT), std::move(Features), + FileName, loongarch::getEdgeKindName) {} }; Error buildTables_ELF_loongarch(LinkGraph &G) { @@ -163,7 +164,7 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_loongarch( (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + (*ELFObj)->makeTriple(), cantFail((*ELFObj)->getFeatures())) .buildGraph(); } @@ -172,7 +173,7 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_loongarch( (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + (*ELFObj)->makeTriple(), cantFail((*ELFObj)->getFeatures())) .buildGraph(); } diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp @@ -595,9 +595,10 @@ public: ELFLinkGraphBuilder_riscv(StringRef FileName, - const object::ELFFile &Obj, Triple TT) - : ELFLinkGraphBuilder(Obj, std::move(TT), FileName, - riscv::getEdgeKindName) {} + const object::ELFFile &Obj, Triple TT, + SubtargetFeatures Features) + : ELFLinkGraphBuilder(Obj, std::move(TT), std::move(Features), + FileName, riscv::getEdgeKindName) {} }; Expected> @@ -615,7 +616,7 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_riscv( (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + (*ELFObj)->makeTriple(), cantFail((*ELFObj)->getFeatures())) .buildGraph(); } else { assert((*ELFObj)->getArch() == Triple::riscv32 && @@ -623,7 +624,7 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_riscv( (*ELFObj)->getFileName(), ELFObjFile.getELFFile(), - (*ELFObj)->makeTriple()) + (*ELFObj)->makeTriple(), cantFail((*ELFObj)->getFeatures())) .buildGraph(); } } diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp @@ -227,8 +227,10 @@ public: ELFLinkGraphBuilder_x86_64(StringRef FileName, - const object::ELFFile &Obj) - : ELFLinkGraphBuilder(Obj, Triple("x86_64-unknown-linux"), FileName, + const object::ELFFile &Obj, + SubtargetFeatures Features) + : ELFLinkGraphBuilder(Obj, Triple("x86_64-unknown-linux"), + std::move(Features), FileName, x86_64::getEdgeKindName) {} }; @@ -331,7 +333,8 @@ auto &ELFObjFile = cast>(**ELFObj); return ELFLinkGraphBuilder_x86_64((*ELFObj)->getFileName(), - ELFObjFile.getELFFile()) + ELFObjFile.getELFFile(), + cantFail(ELFObjFile.getFeatures())) .buildGraph(); } diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp --- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp @@ -162,6 +162,20 @@ B->~Block(); } +LinkGraph::LinkGraph(std::string Name, const Triple &TT, + SubtargetFeatures Features, unsigned PointerSize, + support::endianness Endianness, + GetEdgeKindNameFunction GetEdgeKindName) + : Name(std::move(Name)), TT(TT), Features(std::move(Features)), + PointerSize(PointerSize), Endianness(Endianness), + GetEdgeKindName(std::move(GetEdgeKindName)) {} + +LinkGraph::LinkGraph(std::string Name, const Triple &TT, unsigned PointerSize, + support::endianness Endianness, + GetEdgeKindNameFunction GetEdgeKindName) + : LinkGraph(std::move(Name), TT, SubtargetFeatures(), PointerSize, + Endianness, GetEdgeKindName) {} + Block &LinkGraph::splitBlock(Block &B, size_t SplitIndex, SplitBlockCache *Cache) { diff --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp --- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp @@ -50,9 +50,10 @@ const object::MachOObjectFile &Obj, Triple TT, LinkGraph::GetEdgeKindNameFunction GetEdgeKindName) : Obj(Obj), - G(std::make_unique( - std::string(Obj.getFileName()), std::move(TT), getPointerSize(Obj), - getEndianness(Obj), std::move(GetEdgeKindName))) { + G(std::make_unique(std::string(Obj.getFileName()), + std::move(TT), cantFail(Obj.getFeatures()), + getPointerSize(Obj), getEndianness(Obj), + std::move(GetEdgeKindName))) { auto &MachHeader = Obj.getHeader64(); SubsectionsViaSymbols = MachHeader.flags & MachO::MH_SUBSECTIONS_VIA_SYMBOLS; }