|
5 | 5 |
|
6 | 6 | // target support
|
7 | 7 | #include <llvm/ADT/Triple.h>
|
| 8 | +#include <llvm/Analysis/TargetLibraryInfo.h> |
| 9 | +#include <llvm/Analysis/TargetTransformInfo.h> |
| 10 | +#include <llvm/IR/DataLayout.h> |
8 | 11 | #include <llvm/Support/TargetRegistry.h>
|
9 | 12 | #include <llvm/Target/TargetMachine.h>
|
10 |
| -#include <llvm/IR/DataLayout.h> |
11 |
| -#include <llvm/Analysis/TargetTransformInfo.h> |
12 |
| -#include <llvm/Analysis/TargetLibraryInfo.h> |
13 | 13 |
|
14 | 14 | // analysis passes
|
15 | 15 | #include <llvm/Analysis/Passes.h>
|
|
36 | 36 | #endif
|
37 | 37 | #endif
|
38 | 38 |
|
39 |
| -// for outputting assembly |
| 39 | +// for outputting code |
40 | 40 | #include <llvm/Bitcode/BitcodeWriter.h>
|
41 | 41 | #include <llvm/Bitcode/BitcodeWriterPass.h>
|
42 | 42 | #include "llvm/Object/ArchiveWriter.h"
|
43 | 43 | #include <llvm/IR/IRPrintingPasses.h>
|
44 |
| -#include <llvm/CodeGen/AsmPrinter.h> |
45 |
| -#include <llvm/CodeGen/MachineModuleInfo.h> |
46 |
| -#include <llvm/CodeGen/TargetPassConfig.h> |
47 |
| -#include <llvm/MC/MCAsmInfo.h> |
48 |
| -#include <llvm/MC/MCStreamer.h> |
49 |
| -#include <llvm/MC/MCAsmBackend.h> |
50 |
| -#include <llvm/MC/MCCodeEmitter.h> |
51 |
| -#include <llvm/Support/CodeGen.h> |
52 | 44 |
|
53 | 45 | #include <llvm/IR/LegacyPassManagers.h>
|
54 | 46 | #include <llvm/Transforms/Utils/Cloning.h>
|
@@ -494,10 +486,10 @@ void jl_dump_native(void *native_code,
|
494 | 486 | addTargetPasses(&PM, TM.get());
|
495 | 487 |
|
496 | 488 | // set up optimization passes
|
497 |
| - SmallVector<char, 128> bc_Buffer; |
498 |
| - SmallVector<char, 128> obj_Buffer; |
499 |
| - SmallVector<char, 128> asm_Buffer; |
500 |
| - SmallVector<char, 128> unopt_bc_Buffer; |
| 489 | + SmallVector<char, 0> bc_Buffer; |
| 490 | + SmallVector<char, 0> obj_Buffer; |
| 491 | + SmallVector<char, 0> asm_Buffer; |
| 492 | + SmallVector<char, 0> unopt_bc_Buffer; |
501 | 493 | raw_svector_ostream bc_OS(bc_Buffer);
|
502 | 494 | raw_svector_ostream obj_OS(obj_Buffer);
|
503 | 495 | raw_svector_ostream asm_OS(asm_Buffer);
|
@@ -864,7 +856,7 @@ void jl_add_optimization_passes(LLVMPassManagerRef PM, int opt_level, int lower_
|
864 | 856 | // --- native code info, and dump function to IR and ASM ---
|
865 | 857 | // Get pointer to llvm::Function instance, compiling if necessary
|
866 | 858 | // for use in reflection from Julia.
|
867 |
| -// this is paired with jl_dump_function_ir, jl_dump_method_asm, jl_dump_llvm_asm in particular ways: |
| 859 | +// this is paired with jl_dump_function_ir, jl_dump_function_asm, jl_dump_method_asm in particular ways: |
868 | 860 | // misuse will leak memory or cause read-after-free
|
869 | 861 | extern "C" JL_DLLEXPORT
|
870 | 862 | void *jl_get_llvmf_defn(jl_method_instance_t *mi, size_t world, char getwrapper, char optimize, const jl_cgparams_t params)
|
@@ -952,74 +944,3 @@ void *jl_get_llvmf_defn(jl_method_instance_t *mi, size_t world, char getwrapper,
|
952 | 944 | const char *mname = name_from_method_instance(mi);
|
953 | 945 | jl_errorf("unable to compile source for function %s", mname);
|
954 | 946 | }
|
955 |
| - |
956 |
| -/// addPassesToX helper drives creation and initialization of TargetPassConfig. |
957 |
| -static MCContext * |
958 |
| -addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM) { |
959 |
| - TargetPassConfig *PassConfig = TM->createPassConfig(PM); |
960 |
| - PassConfig->setDisableVerify(false); |
961 |
| - PM.add(PassConfig); |
962 |
| - MachineModuleInfoWrapperPass *MMIWP = |
963 |
| - new MachineModuleInfoWrapperPass(TM); |
964 |
| - PM.add(MMIWP); |
965 |
| - if (PassConfig->addISelPasses()) |
966 |
| - return NULL; |
967 |
| - PassConfig->addMachinePasses(); |
968 |
| - PassConfig->setInitialized(); |
969 |
| - return &MMIWP->getMMI().getContext(); |
970 |
| -} |
971 |
| - |
972 |
| -void jl_strip_llvm_debug(Module *m); |
973 |
| - |
974 |
| - |
975 |
| -// get a native assembly for llvm::Function |
976 |
| -// TODO: implement debuginfo handling |
977 |
| -extern "C" JL_DLLEXPORT |
978 |
| -jl_value_t *jl_dump_llvm_asm(void *F, const char* asm_variant, const char *debuginfo) |
979 |
| -{ |
980 |
| - // precise printing via IR assembler |
981 |
| - SmallVector<char, 4096> ObjBufferSV; |
982 |
| - { // scope block |
983 |
| - Function *f = (Function*)F; |
984 |
| - llvm::raw_svector_ostream asmfile(ObjBufferSV); |
985 |
| - assert(!f->isDeclaration()); |
986 |
| - std::unique_ptr<Module> m(f->getParent()); |
987 |
| - for (auto &f2 : m->functions()) { |
988 |
| - if (f != &f2 && !f->isDeclaration()) |
989 |
| - f2.deleteBody(); |
990 |
| - } |
991 |
| - jl_strip_llvm_debug(m.get()); |
992 |
| - legacy::PassManager PM; |
993 |
| - LLVMTargetMachine *TM = static_cast<LLVMTargetMachine*>(jl_TargetMachine); |
994 |
| - MCContext *Context = addPassesToGenerateCode(TM, PM); |
995 |
| - if (Context) { |
996 |
| - const MCSubtargetInfo &STI = *TM->getMCSubtargetInfo(); |
997 |
| - const MCAsmInfo &MAI = *TM->getMCAsmInfo(); |
998 |
| - const MCRegisterInfo &MRI = *TM->getMCRegisterInfo(); |
999 |
| - const MCInstrInfo &MII = *TM->getMCInstrInfo(); |
1000 |
| - unsigned OutputAsmDialect = MAI.getAssemblerDialect(); |
1001 |
| - if (!strcmp(asm_variant, "att")) |
1002 |
| - OutputAsmDialect = 0; |
1003 |
| - if (!strcmp(asm_variant, "intel")) |
1004 |
| - OutputAsmDialect = 1; |
1005 |
| - MCInstPrinter *InstPrinter = TM->getTarget().createMCInstPrinter( |
1006 |
| - TM->getTargetTriple(), OutputAsmDialect, MAI, MII, MRI); |
1007 |
| - std::unique_ptr<MCAsmBackend> MAB(TM->getTarget().createMCAsmBackend( |
1008 |
| - STI, MRI, TM->Options.MCOptions)); |
1009 |
| - std::unique_ptr<MCCodeEmitter> MCE; |
1010 |
| - auto FOut = std::make_unique<formatted_raw_ostream>(asmfile); |
1011 |
| - std::unique_ptr<MCStreamer> S(TM->getTarget().createAsmStreamer( |
1012 |
| - *Context, std::move(FOut), true, |
1013 |
| - true, InstPrinter, |
1014 |
| - std::move(MCE), std::move(MAB), |
1015 |
| - false)); |
1016 |
| - std::unique_ptr<AsmPrinter> Printer( |
1017 |
| - TM->getTarget().createAsmPrinter(*TM, std::move(S))); |
1018 |
| - if (Printer) { |
1019 |
| - PM.add(Printer.release()); |
1020 |
| - PM.run(*m); |
1021 |
| - } |
1022 |
| - } |
1023 |
| - } |
1024 |
| - return jl_pchar_to_string(ObjBufferSV.data(), ObjBufferSV.size()); |
1025 |
| -} |
0 commit comments