From 3e5909585139d11f4541ddeafd3314e9fb848da9 Mon Sep 17 00:00:00 2001 From: "C.Zhu" <113450928+ZyuN0cUka1@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:01:35 +0200 Subject: [PATCH] remove target fix format and typo --- llvm/CMakeLists.txt | 1 - llvm/CheerpCmakeConf.cmake | 2 +- llvm/lib/Target/CheerpBackend/CMakeLists.txt | 21 -- .../Target/CheerpBackend/CheerpBackend.cpp | 60 ---- .../CheerpBackend/CheerpTargetMachine.h | 82 ----- .../CheerpTargetTransformInfo.cpp | 145 --------- .../CheerpBackend/CheerpTargetTransformInfo.h | 66 ---- .../Target/CheerpBackend/CheerpWritePass.cpp | 292 ------------------ .../Target/CheerpBackend/CheerpWritePass.h | 25 -- llvm/lib/Target/CheerpBackend/LLVMBuild.txt | 31 -- .../Target/CheerpBackend/MC/CMakeLists.txt | 6 - .../CheerpBackend/MC/CheerpMCAsmInfo.cpp | 62 ---- .../lib/Target/CheerpBackend/MC/LLVMBuild.txt | 23 -- llvm/lib/Target/CheerpBackend/MC/Makefile | 13 - llvm/lib/Target/CheerpBackend/Makefile | 14 - .../CheerpBackend/TargetInfo/CMakeLists.txt | 5 - .../TargetInfo/CheerpBackendTargetInfo.cpp | 22 -- .../CheerpBackend/TargetInfo/LLVMBuild.txt | 25 -- .../Target/CheerpBackend/TargetInfo/Makefile | 15 - llvm/lib/Target/WebAssembly/CMakeLists.txt | 8 +- .../WebAssembly/WebAssemblyTargetMachine.cpp | 2 +- 21 files changed, 6 insertions(+), 914 deletions(-) delete mode 100644 llvm/lib/Target/CheerpBackend/CMakeLists.txt delete mode 100644 llvm/lib/Target/CheerpBackend/CheerpBackend.cpp delete mode 100644 llvm/lib/Target/CheerpBackend/CheerpTargetMachine.h delete mode 100644 llvm/lib/Target/CheerpBackend/CheerpTargetTransformInfo.cpp delete mode 100644 llvm/lib/Target/CheerpBackend/CheerpTargetTransformInfo.h delete mode 100644 llvm/lib/Target/CheerpBackend/CheerpWritePass.cpp delete mode 100644 llvm/lib/Target/CheerpBackend/CheerpWritePass.h delete mode 100644 llvm/lib/Target/CheerpBackend/LLVMBuild.txt delete mode 100644 llvm/lib/Target/CheerpBackend/MC/CMakeLists.txt delete mode 100644 llvm/lib/Target/CheerpBackend/MC/CheerpMCAsmInfo.cpp delete mode 100644 llvm/lib/Target/CheerpBackend/MC/LLVMBuild.txt delete mode 100644 llvm/lib/Target/CheerpBackend/MC/Makefile delete mode 100644 llvm/lib/Target/CheerpBackend/Makefile delete mode 100644 llvm/lib/Target/CheerpBackend/TargetInfo/CMakeLists.txt delete mode 100644 llvm/lib/Target/CheerpBackend/TargetInfo/CheerpBackendTargetInfo.cpp delete mode 100644 llvm/lib/Target/CheerpBackend/TargetInfo/LLVMBuild.txt delete mode 100644 llvm/lib/Target/CheerpBackend/TargetInfo/Makefile diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index dde2d6d75f88..5382cf68f075 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -418,7 +418,6 @@ set(LLVM_ALL_TARGETS ARM AVR BPF - CheerpBackend Hexagon Lanai Mips diff --git a/llvm/CheerpCmakeConf.cmake b/llvm/CheerpCmakeConf.cmake index 7695baee4725..99cc70bc8fe9 100644 --- a/llvm/CheerpCmakeConf.cmake +++ b/llvm/CheerpCmakeConf.cmake @@ -3,7 +3,7 @@ set(CMAKE_INSTALL_PREFIX /opt/cheerp CACHE STRING "") set(LLVM_DEFAULT_TARGET_TRIPLE cheerp-leaningtech-webbrowser-wasm CACHE STRING "") -set(LLVM_TARGETS_TO_BUILD X86;WebAssembly;CheerpBackend CACHE STRING "") +set(LLVM_TARGETS_TO_BUILD X86;WebAssembly CACHE STRING "") SET(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "") SET(CLANG_ENABLE_ARCMT OFF CACHE BOOL "") diff --git a/llvm/lib/Target/CheerpBackend/CMakeLists.txt b/llvm/lib/Target/CheerpBackend/CMakeLists.txt deleted file mode 100644 index 9548ebdd3afe..000000000000 --- a/llvm/lib/Target/CheerpBackend/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -add_llvm_component_group(CheerpBackend) - -add_llvm_target(CheerpBackendCodeGen - CheerpBackend.cpp - CheerpTargetTransformInfo.cpp - CheerpWritePass.cpp - - LINK_COMPONENTS - CheerpWriter - CheerpUtils - ExecutionEngine - Interpreter - SelectionDAG - Passes - - ADD_TO_COMPONENT - CheerpBackend - ) - -add_subdirectory(MC) -add_subdirectory(TargetInfo) diff --git a/llvm/lib/Target/CheerpBackend/CheerpBackend.cpp b/llvm/lib/Target/CheerpBackend/CheerpBackend.cpp deleted file mode 100644 index ba5650e8af64..000000000000 --- a/llvm/lib/Target/CheerpBackend/CheerpBackend.cpp +++ /dev/null @@ -1,60 +0,0 @@ -//===-- CheerpBackend.cpp - Backend wrapper for CheerpWriter---------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the Apache License v2.0 with LLVM Exceptions. -// See LICENSE.TXT for details. -// -// Copyright 2011-2023 Leaning Technologies -// -//===----------------------------------------------------------------------===// - -#include "llvm/Support/FileSystem.h" -#include "CheerpTargetMachine.h" -#include "CheerpTargetTransformInfo.h" -#include "CheerpWritePass.h" -#include "llvm/Cheerp/PassRegistry.h" -#include "llvm/IR/Function.h" -#include "llvm/IR/LegacyPassManager.h" -#include "llvm/MC/TargetRegistry.h" -#include "llvm/Passes/PassBuilder.h" -#include "llvm/Passes/StandardInstrumentations.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/Scalar.h" -using namespace llvm; - -extern "C" void LLVMInitializeCheerpBackendTarget() { - // Register the target. - RegisterTargetMachine X(TheCheerpBackendTarget); -} - -//===----------------------------------------------------------------------===// -// External Interface declaration -//===----------------------------------------------------------------------===// - -bool CheerpTargetMachine::addPassesToEmitFile(PassManagerBase &PM, - raw_pwrite_stream &o, - raw_pwrite_stream *DwoOut, - CodeGenFileType FileType, - bool DisableVerify, - MachineModuleInfoWrapperPass *MMIWP) { - - - PM.add(new CheerpWritePass(o, (TargetMachine*)this)); - return false; -} - -const CheerpTargetLowering* CheerpSubtarget::getTargetLowering() const -{ - return &targetLowering; -} - -const CheerpSubtarget* CheerpTargetMachine::getSubtargetImpl(const Function &F) const -{ - return &subTargetInfo; -} - -TargetTransformInfo CheerpTargetMachine::getTargetTransformInfo(const Function &F) const -{ - return TargetTransformInfo(CheerpTTIImpl(this, F)); -} diff --git a/llvm/lib/Target/CheerpBackend/CheerpTargetMachine.h b/llvm/lib/Target/CheerpBackend/CheerpTargetMachine.h deleted file mode 100644 index 77bfaa5afc83..000000000000 --- a/llvm/lib/Target/CheerpBackend/CheerpTargetMachine.h +++ /dev/null @@ -1,82 +0,0 @@ -//===-- CheerpTargetMachine.h - TargetMachine for the CheerpBackend -------===// -// -// Cheerp: The C++ compiler for the Web -// -// This file is distributed under the Apache License v2.0 with LLVM Exceptions. -// See LICENSE.TXT for details. -// -// Copyright 2011-2023 Leaning Technlogies -// -//===----------------------------------------------------------------------===// - -#ifndef _CHEERP_TARGETMACHINE_H -#define _CHEERP_TARGETMACHINE_H - -#include "llvm/ADT/Optional.h" -#include "llvm/IR/DataLayout.h" -#include "llvm/CodeGen/TargetLowering.h" -#include "llvm/CodeGen/TargetSubtargetInfo.h" -#include "llvm/MC/SectionKind.h" -#include "llvm/Target/TargetLoweringObjectFile.h" -#include "llvm/Target/TargetMachine.h" - -namespace llvm { - -class formatted_raw_ostream; - -class CheerpTargetLowering: public TargetLowering { -public: - CheerpTargetLowering(const TargetMachine &TM) : TargetLowering(TM) {} -}; - -class CheerpSubtarget: public TargetSubtargetInfo { -private: - CheerpTargetLowering targetLowering; -public: - CheerpSubtarget(const TargetMachine &TM, const Target &T, const Triple& TT, StringRef CPU, StringRef FS) : - TargetSubtargetInfo(TT, CPU, CPU, FS, None, None, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr), - targetLowering(TM) { } - virtual const CheerpTargetLowering *getTargetLowering() const override; -}; - -class CheerpTargetLoweringObjectFile: public TargetLoweringObjectFile { - MCSection* getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override { - return nullptr; - } - MCSection* SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override { - return nullptr; - } -}; - -struct CheerpTargetMachine : public LLVMTargetMachine { - CheerpTargetMachine(const Target &T, const Triple& TT, - StringRef CPU, StringRef FS, const TargetOptions &Options, - Optional RM, Optional CM, - CodeGenOpt::Level OL, bool JIT) - : LLVMTargetMachine(T, "b-e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i24:8:8-i32:32:32-" - "i64:64:64-f32:32:32-f64:64:64-" - "a:0:32-f16:16:16-f32:32:32-f64:64:64-n8:16:32-S64", - TT, CPU, FS, Options, Reloc::PIC_, CM ? *CM : CodeModel::Medium, OL), - subTargetInfo(*this, T, TT, CPU, FS), targetLoweringObjectFile(new CheerpTargetLoweringObjectFile()) { initAsmInfo(); } - CheerpSubtarget subTargetInfo; - CheerpTargetLoweringObjectFile* targetLoweringObjectFile; - -public: - virtual bool addPassesToEmitFile(PassManagerBase &PM, - raw_pwrite_stream &Out, - raw_pwrite_stream *DwoOut, - CodeGenFileType FileType, - bool DisableVerify, - MachineModuleInfoWrapperPass *MMIWP = nullptr) override; - virtual const CheerpSubtarget* getSubtargetImpl(const Function &F) const override; - virtual TargetLoweringObjectFile *getObjFileLowering() const override { - return targetLoweringObjectFile; - } - TargetTransformInfo getTargetTransformInfo(const Function &F) const override; -}; - -extern Target TheCheerpBackendTarget; - -} // End llvm namespace - -#endif diff --git a/llvm/lib/Target/CheerpBackend/CheerpTargetTransformInfo.cpp b/llvm/lib/Target/CheerpBackend/CheerpTargetTransformInfo.cpp deleted file mode 100644 index 5e9e8ce1bdd7..000000000000 --- a/llvm/lib/Target/CheerpBackend/CheerpTargetTransformInfo.cpp +++ /dev/null @@ -1,145 +0,0 @@ -//===-- CheerpTargetTransformInfo.cpp - Cheerp helper --------------------===// -// -// Cheerp: The C++ compiler for the Web -// -// This file is distributed under the Apache License v2.0 with LLVM Exceptions. -// See LICENSE.TXT for details. -// -// Copyright 2022-2023 Leaning Technologies -// -//===----------------------------------------------------------------------===// - -#include "CheerpTargetTransformInfo.h" -#include "llvm/CodeGen/CostTable.h" -#include "llvm/Support/Debug.h" -#include "llvm/Cheerp/CommandLine.h" -using namespace llvm; - -#define DEBUG_TYPE "wasmtti" - -unsigned CheerpTTIImpl::getNumberOfRegisters(unsigned ClassID) const { - unsigned Result = BaseT::getNumberOfRegisters(ClassID); - - // For SIMD, use at least 16 registers, as a rough guess. - bool Vector = (ClassID == 1); - if (Vector) - { - if (!SIMD) - return 0; - if (LinearOutput == LinearOutputTy::AsmJs) - return 0; - Result = std::max(Result, 16u); - } - - return Result; -} - -TypeSize CheerpTTIImpl::getRegisterBitWidth( - TargetTransformInfo::RegisterKind K) const { - switch (K) { - case TargetTransformInfo::RGK_Scalar: - return TypeSize::getFixed(64); - case TargetTransformInfo::RGK_FixedWidthVector: - return TypeSize::getFixed(128); - case TargetTransformInfo::RGK_ScalableVector: - return TypeSize::getScalable(0); - } - - llvm_unreachable("Unsupported register kind"); -} - -InstructionCost CheerpTTIImpl::getArithmeticInstrCost( - unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, - TTI::OperandValueInfo Opd1Info, - TTI::OperandValueInfo Opd2Info, - ArrayRef Args, - const Instruction *CxtI) { - - InstructionCost Cost = - BasicTTIImplBase::getArithmeticInstrCost( - Opcode, Ty, CostKind, Opd1Info, Opd2Info); - - if (auto *VTy = dyn_cast(Ty)) { - switch (Opcode) { - case Instruction::LShr: - case Instruction::AShr: - case Instruction::Shl: - // SIMD128's shifts currently only accept a scalar shift count. For each - // element, we'll need to extract, op, insert. The following is a rough - // approxmation. - if (!Opd2Info.isUniform()) - Cost = - cast(VTy)->getNumElements() * - (TargetTransformInfo::TCC_Basic + - getArithmeticInstrCost(Opcode, VTy->getElementType(), CostKind) + - TargetTransformInfo::TCC_Basic); - break; - } - } - return Cost; -} - -InstructionCost CheerpTTIImpl::getVectorInstrCost(unsigned Opcode, - Type *Val, - unsigned Index) { - std::pair LT = getTypeLegalizationCost(Val->getScalarType()); - InstructionCost Cost = LT.first; - - // SIMD128's insert/extract currently only take constant indices. - if (Index == -1u) - return Cost + 25 * TargetTransformInfo::TCC_Expensive; - - return Cost; -} - -InstructionCost CheerpTTIImpl::getVectorInstrCost(const Instruction& I, - Type *Val, - unsigned Index) { - return getVectorInstrCost(I.getOpcode(), Val, Index); -} - -void CheerpTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE, - TTI::UnrollingPreferences &UP, - OptimizationRemarkEmitter *ORE) { - // Scan the loop: don't unroll loops with calls. This is a standard approach - // for most (all?) targets. - for (BasicBlock *BB : L->blocks()) - for (Instruction &I : *BB) - if (isa(I) || isa(I)) - if (const Function *F = cast(I).getCalledFunction()) - if (isLoweredToCall(F)) - return; - - // The chosen threshold is within the range of 'LoopMicroOpBufferSize' of - // the various microarchitectures that use the BasicTTI implementation and - // has been selected through heuristics across multiple cores and runtimes. - UP.Partial = UP.Runtime = UP.UpperBound = true; - UP.PartialThreshold = 18; - - // Avoid unrolling when optimizing for size. - UP.OptSizeThreshold = 0; - UP.PartialOptSizeThreshold = 0; - - // Set number of instructions optimized when "back edge" - // becomes "fall through" to default value of 2. - UP.BEInsns = 2; -} - -bool CheerpTTIImpl::areInlineCompatible(const Function *Caller, - const Function *Callee) const { - // Allow inlining only when the Callee has a subset of the Caller's - // features. In principle, we should be able to inline regardless of any - // features because WebAssembly supports features at module granularity, not - // function granularity, but without this restriction it would be possible for - // a module to "forget" about features if all the functions that used them - // were inlined. - const TargetMachine &TM = getTLI()->getTargetMachine(); - - const FeatureBitset &CallerBits = - TM.getSubtargetImpl(*Caller)->getFeatureBits(); - const FeatureBitset &CalleeBits = - TM.getSubtargetImpl(*Callee)->getFeatureBits(); - - return (CallerBits & CalleeBits) == CalleeBits; -} - diff --git a/llvm/lib/Target/CheerpBackend/CheerpTargetTransformInfo.h b/llvm/lib/Target/CheerpBackend/CheerpTargetTransformInfo.h deleted file mode 100644 index 1efa9a806541..000000000000 --- a/llvm/lib/Target/CheerpBackend/CheerpTargetTransformInfo.h +++ /dev/null @@ -1,66 +0,0 @@ -//===-- CheerpTargetTransformInfo.h - TargetTransformInfo for the CheerpBackend -------===// -// -// Cheerp: The C++ compiler for the Web -// -// This file is distributed under the Apache License v2.0 with LLVM Exceptions. -// See LICENSE.TXT for details. -// -// Copyright 2022-2023 Leaning Technlogies -// -//===----------------------------------------------------------------------===// - -#ifndef _CHEERP_TARGETTRANSFORMINFO_H -#define _CHEERP_TARGETTRANSFORMINFO_H - -#include "CheerpTargetMachine.h" -#include "llvm/CodeGen/BasicTTIImpl.h" -#include "llvm/CodeGen/TargetLowering.h" -#include "llvm/CodeGen/TargetSubtargetInfo.h" -#include "llvm/Cheerp/Utility.h" -#include - -namespace llvm { - -class CheerpTTIImpl final : public BasicTTIImplBase { - typedef BasicTTIImplBase BaseT; - typedef TargetTransformInfo TTI; - friend BaseT; - - const CheerpSubtarget *ST; - const CheerpTargetLowering *TLI; - - const CheerpSubtarget *getST() const { return ST; } - const CheerpTargetLowering *getTLI() const { return TLI; } - - bool SIMD; - -public: - CheerpTTIImpl(const CheerpTargetMachine *TM, const Function &F) - : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), - TLI(ST->getTargetLowering()), SIMD(false) { - if (cheerp::hasSIMDAttribute(&F)) - SIMD = true; - } - - unsigned getNumberOfRegisters(unsigned ClassID) const; - TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const; - InstructionCost getArithmeticInstrCost( - unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind, - TTI::OperandValueInfo Opd1Info = {TTI::OK_AnyValue, TTI::OP_None}, - TTI::OperandValueInfo Opd2Info = {TTI::OK_AnyValue, TTI::OP_None}, - ArrayRef Args = ArrayRef(), - const Instruction *CxtI = nullptr); - InstructionCost getVectorInstrCost(unsigned Opcode, Type *Val, - unsigned Index); - InstructionCost getVectorInstrCost(const Instruction& I, Type *Val, - unsigned Index); - void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, - TTI::UnrollingPreferences &UP, - OptimizationRemarkEmitter *ORE); - bool areInlineCompatible(const Function *Caller, - const Function *Callee) const; -}; - -} // end namespace llvm - -#endif diff --git a/llvm/lib/Target/CheerpBackend/CheerpWritePass.cpp b/llvm/lib/Target/CheerpBackend/CheerpWritePass.cpp deleted file mode 100644 index 38a0703efb0e..000000000000 --- a/llvm/lib/Target/CheerpBackend/CheerpWritePass.cpp +++ /dev/null @@ -1,292 +0,0 @@ -//===-- CheerpWritePass.cpp - Pass writer for CheerpWriter ----------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the Apache License v2.0 with LLVM Exceptions. -// See LICENSE.TXT for details. -// -// Copyright 2011-2023 Leaning Technologies -// -//===----------------------------------------------------------------------===// - -#include "llvm/Support/ToolOutputFile.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/Path.h" -#include "llvm/IR/LegacyPassManager.h" -#include "llvm/IR/PassManager.h" -#include "llvm/IR/Function.h" -#include "llvm/MC/TargetRegistry.h" -#include "llvm/Cheerp/Writer.h" -#include "llvm/Cheerp/WasmWriter.h" -#include "llvm/Cheerp/DTSWriter.h" -#include "llvm/Cheerp/PassRegistry.h" -#include "llvm/Cheerp/PassUtility.h" -#include "llvm/Cheerp/I64Lowering.h" -#include "llvm/Cheerp/SIMDLowering.h" -#include "llvm/Cheerp/SIMDTransform.h" -#include "llvm/Cheerp/BitCastLowering.h" -#include "llvm/Cheerp/JSStringLiteralLowering.h" -#include "llvm/Cheerp/MemoryInit.h" -#include "llvm/Transforms/Scalar/EarlyCSE.h" -#include "llvm/Passes/PassBuilder.h" -#include "llvm/Passes/StandardInstrumentations.h" -#include "llvm/Support/PrettyStackTrace.h" -#include "llvm/Transforms/Scalar/DCE.h" - -#include "CheerpWritePass.h" - - -using namespace llvm; - -cl::opt VerbosePassManager("cheerp-verbose-pm", cl::init(false), cl::Hidden, - cl::desc("Emit verbose informations")); - -PreservedAnalyses cheerp::CheerpWritePassImpl::run(Module& M, ModuleAnalysisManager& MAM) -{ - cheerp::Registerize ®isterize = MAM.getResult(M); - cheerp::GlobalDepsAnalyzer &GDA = MAM.getResult(M); - cheerp::PointerAnalyzer &PA = MAM.getResult(M); - cheerp::InvokeWrapping &IW = MAM.getResult(M); - cheerp::AllocaStoresExtractor &allocaStoresExtractor = MAM.getResult(M); - cheerp::LinearMemoryHelper &linearHelper = MAM.getResult(M); - std::unique_ptr sourceMapGenerator; - GDA.forceTypedArrays = ForceTypedArrays; - if (!SourceMap.empty()) - { - std::error_code ErrorCode; - sourceMapGenerator.reset(new cheerp::SourceMapGenerator(SourceMap, SourceMapPrefix, SourceMapStandAlone, ErrorCode)); - if (ErrorCode) - { - // An error occurred opening the source map file, bail out - llvm::report_fatal_error(StringRef(ErrorCode.message()), false); - return PreservedAnalyses::none(); - } - } - PA.fullResolve(); - PA.computeConstantOffsets(M); - // Destroy the stores here, we need them to properly compute the pointer kinds, but we want to optimize them away before registerize - allocaStoresExtractor.unlinkStores(); - - registerize.assignRegisters(M, PA); -#ifdef REGISTERIZE_STATS - cheerp::reportRegisterizeStatistics(); -#endif - - Triple TargetTriple(M.getTargetTriple()); - bool WasmOnly = TargetTriple.getOS() == Triple::WASI; - std::error_code ErrorCode; - llvm::ToolOutputFile secondaryFile(SecondaryOutputFile, ErrorCode, sys::fs::OF_None); - std::unique_ptr secondaryOut; - if (!SecondaryOutputFile.empty()) - { - secondaryOut.reset(new formatted_raw_ostream(secondaryFile.os())); - } - else if (WasmOnly && LinearOutput != AsmJs) - { - secondaryOut.reset(new formatted_raw_ostream(Out)); - } - - std::error_code dtsErrorCode; - llvm::ToolOutputFile dtsFile(DTSOutputFile, dtsErrorCode, sys::fs::OF_None); - std::unique_ptr dtsOut; - if (!DTSOutputFile.empty()) - { - dtsOut.reset(new formatted_raw_ostream(dtsFile.os())); - } - - // Build the ordered list of reserved names - std::vector reservedNames(ReservedNames.begin(), ReservedNames.end()); - std::sort(reservedNames.begin(), reservedNames.end()); - - cheerp::NameGenerator namegen(M, GDA, registerize, PA, linearHelper, reservedNames, PrettyCode, WasmExportedMemory); - - std::string wasmFile; - std::string asmjsMemFile; - llvm::formatted_raw_ostream* memOut = nullptr; - switch (LinearOutput) - { - case Wasm: - if (!SecondaryOutputPath.empty()) - wasmFile = SecondaryOutputPath.getValue(); - else if (!SecondaryOutputFile.empty()) - wasmFile = std::string(llvm::sys::path::filename(SecondaryOutputFile.getValue())); - break; - case AsmJs: - if (!SecondaryOutputPath.empty()) - asmjsMemFile = SecondaryOutputPath.getValue(); - else if (!SecondaryOutputFile.empty()) - asmjsMemFile = std::string(llvm::sys::path::filename(SecondaryOutputFile.getValue())); - memOut = secondaryOut.get(); - break; - } - - MODULE_TYPE makeModule = getModuleType(MakeModule); - - if (MakeDTS && dtsOut) - { - cheerp::CheerpDTSWriter dtsWriter(M, *dtsOut, sourceMapGenerator.get(), PrettyCode, makeModule); - dtsWriter.makeDTS(); - } - - if (!WasmOnly) - { - cheerp::CheerpWriter writer(M, MAM, Out, PA, registerize, GDA, linearHelper, namegen, allocaStoresExtractor, IW.getLandingPadTable(), memOut, asmjsMemFile, - sourceMapGenerator.get(), PrettyCode, makeModule, !NoNativeJavaScriptMath, - !NoJavaScriptMathImul, !NoJavaScriptMathFround, !NoCredits, MeasureTimeToMain, CheerpHeapSize, - BoundsCheck, SymbolicGlobalsAsmJS, wasmFile, ForceTypedArrays); - writer.makeJS(); - } - - if (LinearOutput != AsmJs && secondaryOut) - { - cheerp::CheerpWasmWriter wasmWriter(M, MAM, *secondaryOut, PA, registerize, GDA, linearHelper, IW.getLandingPadTable(), namegen, - M.getContext(), CheerpHeapSize, !WasmOnly, - PrettyCode, WasmSharedMemory, - WasmExportedTable); - wasmWriter.makeWasm(); - } - - allocaStoresExtractor.destroyStores(); - - if (!SecondaryOutputFile.empty() && ErrorCode) - { - // An error occurred opening the asm.js memory file, bail out - llvm::report_fatal_error(StringRef(ErrorCode.message()), false); - return PreservedAnalyses::none(); - } - if (!DTSOutputFile.empty() && dtsErrorCode) - { - llvm::report_fatal_error(StringRef(dtsErrorCode.message()), false); - return PreservedAnalyses::none(); - } - if (!WasmOnly) - secondaryFile.keep(); - if (MakeDTS) - dtsFile.keep(); - - - return PreservedAnalyses::none(); -} - -bool CheerpWritePass::runOnModule(Module& M) -{ - LoopAnalysisManager LAM; - FunctionAnalysisManager FAM; - CGSCCAnalysisManager CGAM; - ModuleAnalysisManager MAM; - - PassInstrumentationCallbacks PIC; - PrintPassOptions PrintPassOpts; - PrintPassOpts.Indent = VerbosePassManager; - PrintPassOpts.SkipAnalyses = false; - StandardInstrumentations SI(M.getContext(), VerbosePassManager, - /*VerifyEach*/ false, PrintPassOpts); - SI.registerCallbacks(PIC, &FAM); - - llvm::PipelineTuningOptions PTO; - Optional PGOOpt; - PassBuilder PB(TM, PTO, PGOOpt, &PIC); - -#define HANDLE_EXTENSION(Ext) \ - get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB); -#include "llvm/Support/Extension.def" - - Triple TargetTriple(M.getTargetTriple()); - std::unique_ptr TLII( - new TargetLibraryInfoImpl(TargetTriple)); - FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); }); - - // Register all the basic analyses with the managers. - PB.registerModuleAnalyses(MAM); - PB.registerCGSCCAnalyses(CGAM); - PB.registerFunctionAnalyses(FAM); - PB.registerLoopAnalyses(LAM); - PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); - - ModulePassManager MPM; - bool isWasmTarget = Triple(M.getTargetTriple()).isCheerpWasm(); - cheerp::GlobalDepsAnalyzer::MATH_MODE mathMode; - if (NoNativeJavaScriptMath) - mathMode = cheerp::GlobalDepsAnalyzer::NO_BUILTINS; - else if(isWasmTarget && LinearOutput != AsmJs) - - mathMode = cheerp::GlobalDepsAnalyzer::WASM_BUILTINS; - else - mathMode = cheerp::GlobalDepsAnalyzer::JS_BUILTINS; - - auto functionAddressMode = LinearOutput == LinearOutputTy::AsmJs - ? cheerp::LinearMemoryHelperInitializer::FunctionAddressMode::AsmJS - : cheerp::LinearMemoryHelperInitializer::FunctionAddressMode::Wasm; - bool growMem = !WasmNoGrowMemory && - functionAddressMode == cheerp::LinearMemoryHelperInitializer::FunctionAddressMode::Wasm && - // NOTE: this is not actually required by the spec, but for now chrome - // doesn't like growing shared memory - !WasmSharedMemory; - bool hasAsmjsMem = functionAddressMode == cheerp::LinearMemoryHelperInitializer::FunctionAddressMode::AsmJS && - (!SecondaryOutputFile.empty() || !SecondaryOutputPath.empty()); - - if (FixWrongFuncCasts) - MPM.addPass(cheerp::FixFunctionCastsPass()); - - { - //Wrap these in a FunctionPassManager - FunctionPassManager FPM; - - FPM.addPass(cheerp::I64LoweringPass()); - // Run a simple constant elimination pass to clean up suboptimal code left - // by I64Lowering. - FPM.addPass(EarlyCSEPass()); - FPM.addPass(cheerp::JSStringLiteralLoweringPass()); - FPM.addPass(cheerp::BitCastLoweringPass()); - FPM.addPass(cheerp::SIMDTransformPass()); - FPM.addPass(cheerp::SIMDLoweringPass()); - FPM.addPass(cheerp::CheerpLowerSwitchPass(/*onlyLowerI64*/false)); - FPM.addPass(cheerp::LowerAndOrBranchesPass()); - FPM.addPass(cheerp::StructMemFuncLoweringPass()); - - MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); - } - - MPM.addPass(cheerp::FreeAndDeleteRemovalPass()); - MPM.addPass(cheerp::GlobalDepsAnalyzerPass(mathMode, /*resolveAliases*/true)); - if (isWasmTarget) - MPM.addPass(cheerp::AllocaLoweringPass()); - MPM.addPass(cheerp::InvokeWrappingPass()); - MPM.addPass(cheerp::FFIWrappingPass()); - MPM.addPass(createModuleToFunctionPassAdaptor(cheerp::FixIrreducibleControlFlowPass())); - MPM.addPass(createModuleToFunctionPassAdaptor(cheerp::PointerArithmeticToArrayIndexingPass())); - MPM.addPass(createModuleToFunctionPassAdaptor(cheerp::PointerToImmutablePHIRemovalPass())); - MPM.addPass(createModuleToFunctionPassAdaptor(cheerp::GEPOptimizerPass())); - MPM.addPass(createModuleToFunctionPassAdaptor(cheerp::StoreMergingPass(LinearOutput == Wasm && !WasmNoUnalignedMem))); - // Remove obviously dead instruction, this avoids problems caused by inlining of effectfull instructions - // inside not used instructions which are then not rendered. - MPM.addPass(createModuleToFunctionPassAdaptor(cheerp::PreserveCheerpAnalysisPassWrapper())); - MPM.addPass(cheerp::RegisterizePass(!NoJavaScriptMathFround, LinearOutput == Wasm)); - MPM.addPass(cheerp::LinearMemoryHelperPass(cheerp::LinearMemoryHelperInitializer({functionAddressMode, CheerpHeapSize, CheerpStackSize, CheerpStackOffset, growMem, hasAsmjsMem}))); - if (LinearOutput == LinearOutputTy::Wasm) - MPM.addPass(cheerp::MemoryInitPass()); - MPM.addPass(cheerp::ConstantExprLoweringPass()); - MPM.addPass(cheerp::PointerAnalyzerPass()); - MPM.addPass(cheerp::DelayInstsPass()); - - MPM.addPass(cheerp::AllocaMergingPass()); - MPM.addPass(cheerp::AllocaArraysPass()); - MPM.addPass(cheerp::AllocaArraysMergingPass()); - - MPM.addPass(createModuleToFunctionPassAdaptor(cheerp::RemoveFwdBlocksPass())); - // Keep this pass last, it is going to remove stores to memory from the LLVM visible code, so further optimizing afterwards will break - MPM.addPass(cheerp::AllocaStoresExtractorPass()); - - MPM.addPass(cheerp::CheerpWritePassImpl(Out, TM)); - - // Now that we have all of the passes ready, run them. - { - PrettyStackTraceString CrashInfo("Optimizer"); - llvm::TimeTraceScope TimeScope("Optimizer"); - MPM.run(M, MAM); - } - - return false; -} - -char CheerpWritePass::ID = 0; diff --git a/llvm/lib/Target/CheerpBackend/CheerpWritePass.h b/llvm/lib/Target/CheerpBackend/CheerpWritePass.h deleted file mode 100644 index 9ac1356e73db..000000000000 --- a/llvm/lib/Target/CheerpBackend/CheerpWritePass.h +++ /dev/null @@ -1,25 +0,0 @@ -//===-- CheerpWritePass.h - Pass writer for CheerpWriter ------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the Apache License v2.0 with LLVM Exceptions. -// See LICENSE.TXT for details. -// -// Copyright 2011-2023 Leaning Technologies -// -//===----------------------------------------------------------------------===// - -#include "llvm/Pass.h" -using namespace llvm; - -class CheerpWritePass : public ModulePass { -private: - raw_ostream &Out; - static char ID; - void getAnalysisUsage(AnalysisUsage& AU) const override { } - TargetMachine* TM; -public: - explicit CheerpWritePass(raw_ostream &o, TargetMachine* TM) :ModulePass(ID), Out(o), TM(TM) { } - bool runOnModule(Module &M) override; - StringRef getPassName() const override { return "CheerpWritePass"; } -}; diff --git a/llvm/lib/Target/CheerpBackend/LLVMBuild.txt b/llvm/lib/Target/CheerpBackend/LLVMBuild.txt deleted file mode 100644 index 9d0821da37c5..000000000000 --- a/llvm/lib/Target/CheerpBackend/LLVMBuild.txt +++ /dev/null @@ -1,31 +0,0 @@ -;===- ./lib/Target/CheerpBackend/LLVMBuild.txt --------------------*- Conf -*--===; -; -; The LLVM Compiler Infrastructure -; -; This file is distributed under the University of Illinois Open Source -; License. See LICENSE.TXT for details. -; -;===------------------------------------------------------------------------===; -; -; This is an LLVMBuild description file for the components in this subdirectory. -; -; For more information on the LLVMBuild system, please see: -; -; http://llvm.org/docs/LLVMBuild.html -; -;===------------------------------------------------------------------------===; - -[common] -subdirectories = TargetInfo MC - -[component_0] -type = TargetGroup -name = CheerpBackend -parent = Target - -[component_1] -type = Library -name = CheerpBackendCodeGen -parent = CheerpBackend -required_libraries = Core CheerpBackendInfo CheerpBackendDesc SelectionDAG Support Target CheerpWriter -add_to_library_groups = CheerpBackend diff --git a/llvm/lib/Target/CheerpBackend/MC/CMakeLists.txt b/llvm/lib/Target/CheerpBackend/MC/CMakeLists.txt deleted file mode 100644 index 26e31bc2f8a5..000000000000 --- a/llvm/lib/Target/CheerpBackend/MC/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -add_llvm_library(LLVMCheerpBackendDesc - CheerpMCAsmInfo.cpp - - LINK_COMPONENTS - MC - ) diff --git a/llvm/lib/Target/CheerpBackend/MC/CheerpMCAsmInfo.cpp b/llvm/lib/Target/CheerpBackend/MC/CheerpMCAsmInfo.cpp deleted file mode 100644 index db92929b8780..000000000000 --- a/llvm/lib/Target/CheerpBackend/MC/CheerpMCAsmInfo.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===-- CheerpBackend.cpp - MCAsmInfo for Cheerp ---------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -// Copyright 2013 Leaning Technologies -// -//===----------------------------------------------------------------------===// - -#include "CheerpTargetMachine.h" -#include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCInstrInfo.h" -#include "llvm/MC/MCRegisterInfo.h" -#include "llvm/MC/TargetRegistry.h" -#include "llvm/ADT/Triple.h" - -namespace llvm { - class Triple; - - class CheerpMCAsmInfo : public MCAsmInfo { - virtual void anchor(); - public: - explicit CheerpMCAsmInfo(const Triple &Triple); - }; - -void CheerpMCAsmInfo::anchor() { } - -CheerpMCAsmInfo::CheerpMCAsmInfo(const Triple &T) { - - // Debug Information - SupportsDebugInformation = false; -} - -static MCAsmInfo *createCheerpMCAsmInfo(const MCRegisterInfo &T, const Triple& TheTriple, const llvm::MCTargetOptions&) { - return new CheerpMCAsmInfo(TheTriple); -} - -static MCRegisterInfo *createCheerpMCRegInfo(const Triple& TheTriple) { - return new MCRegisterInfo(); -} - -static MCInstrInfo *createCheerpMCInstrInfo() { - return new MCInstrInfo(); -} - -static MCSubtargetInfo *createCheerpMCSubtargetInfo(const Triple& TheTriple, StringRef a, StringRef b) { - // We do not pass b on to the MCSubtargetInfo, but an empty string, to make the compiler stop giving a message - // about +simd128 not being a recognized processor. - return new MCSubtargetInfo(TheTriple, a, "", "", {}, {}, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); -} - -extern "C" void LLVMInitializeCheerpBackendTargetMC() { - // Register the MC asm info. - RegisterMCAsmInfoFn A(TheCheerpBackendTarget, createCheerpMCAsmInfo); - RegisterMCInstrInfoFn I(TheCheerpBackendTarget, createCheerpMCInstrInfo); - RegisterMCRegInfoFn R(TheCheerpBackendTarget, createCheerpMCRegInfo); - RegisterMCSubtargetInfoFn S(TheCheerpBackendTarget, createCheerpMCSubtargetInfo); -} - -} // namespace llvm diff --git a/llvm/lib/Target/CheerpBackend/MC/LLVMBuild.txt b/llvm/lib/Target/CheerpBackend/MC/LLVMBuild.txt deleted file mode 100644 index 239f6c9c67c3..000000000000 --- a/llvm/lib/Target/CheerpBackend/MC/LLVMBuild.txt +++ /dev/null @@ -1,23 +0,0 @@ -;===- ./lib/Target/CheerpBackend/MC/LLVMBuild.txt --------------*- Conf -*--===; -; -; The LLVM Compiler Infrastructure -; -; This file is distributed under the University of Illinois Open Source -; License. See LICENSE.TXT for details. -; -;===------------------------------------------------------------------------===; -; -; This is an LLVMBuild description file for the components in this subdirectory. -; -; For more information on the LLVMBuild system, please see: -; -; http://llvm.org/docs/LLVMBuild.html -; -;===------------------------------------------------------------------------===; - -[component_0] -type = Library -name = CheerpBackendDesc -parent = CheerpBackend -required_libraries = MC CheerpBackendInfo Support -add_to_library_groups = CheerpBackend diff --git a/llvm/lib/Target/CheerpBackend/MC/Makefile b/llvm/lib/Target/CheerpBackend/MC/Makefile deleted file mode 100644 index c369e279f593..000000000000 --- a/llvm/lib/Target/CheerpBackend/MC/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -##===- lib/Target/CheerpBackend/MC/Makefile --- ------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LEVEL = ../../.. -LIBRARYNAME = LLVMCheerpBackendDesc - -include $(LEVEL)/Makefile.common diff --git a/llvm/lib/Target/CheerpBackend/Makefile b/llvm/lib/Target/CheerpBackend/Makefile deleted file mode 100644 index 36b43e913336..000000000000 --- a/llvm/lib/Target/CheerpBackend/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -##===- lib/Target/CheerpBackend/Makefile --- ---------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LEVEL = ../../.. -LIBRARYNAME = LLVMCheerpBackendCodeGen -DIRS = TargetInfo MC - -include $(LEVEL)/Makefile.common diff --git a/llvm/lib/Target/CheerpBackend/TargetInfo/CMakeLists.txt b/llvm/lib/Target/CheerpBackend/TargetInfo/CMakeLists.txt deleted file mode 100644 index bef1fa832a80..000000000000 --- a/llvm/lib/Target/CheerpBackend/TargetInfo/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/.. ) - -add_llvm_library(LLVMCheerpBackendInfo - CheerpBackendTargetInfo.cpp - ) diff --git a/llvm/lib/Target/CheerpBackend/TargetInfo/CheerpBackendTargetInfo.cpp b/llvm/lib/Target/CheerpBackend/TargetInfo/CheerpBackendTargetInfo.cpp deleted file mode 100644 index cf0da7eecbd7..000000000000 --- a/llvm/lib/Target/CheerpBackend/TargetInfo/CheerpBackendTargetInfo.cpp +++ /dev/null @@ -1,22 +0,0 @@ -//===-- CheerpBackendTargetInfo.cpp - TargetInfo for the CheerpBackend ----===// -// -// Cheerp: The C++ compiler for the Web -// -// This file is distributed under the Apache License v2.0 with LLVM Exceptions. -// See LICENSE.TXT for details. -// -// Copyright 2011-2023 Leaning Technlogies -// -//===----------------------------------------------------------------------===// - -#include "CheerpTargetMachine.h" -#include "llvm/MC/TargetRegistry.h" - -using namespace llvm; - -Target llvm::TheCheerpBackendTarget; - -extern "C" void LLVMInitializeCheerpBackendTargetInfo() { - RegisterTarget - X(TheCheerpBackendTarget, "cheerp", "Cheerp client side backend", "Cheerp"); -} diff --git a/llvm/lib/Target/CheerpBackend/TargetInfo/LLVMBuild.txt b/llvm/lib/Target/CheerpBackend/TargetInfo/LLVMBuild.txt deleted file mode 100644 index a4ff8b73a3dd..000000000000 --- a/llvm/lib/Target/CheerpBackend/TargetInfo/LLVMBuild.txt +++ /dev/null @@ -1,25 +0,0 @@ -;===- ./lib/Target/CheerpBackend/TargetInfo/LLVMBuild.txt ---------*- Conf -*--===; -; -; Cheerp: The C++ compiler for the Web -; -; This file is distributed under the Apache License v2.0 with LLVM Exceptions. -; See LICENSE.TXT for details. -; -; Copyright 2011-2023 Leaning Technlogies -; -;===------------------------------------------------------------------------===; -; -; This is an LLVMBuild description file for the components in this subdirectory. -; -; For more information on the LLVMBuild system, please see: -; -; http://llvm.org/docs/LLVMBuild.html -; -;===------------------------------------------------------------------------===; - -[component_0] -type = Library -name = CheerpBackendInfo -parent = CheerpBackend -required_libraries = MC Support Target -add_to_library_groups = CheerpBackend diff --git a/llvm/lib/Target/CheerpBackend/TargetInfo/Makefile b/llvm/lib/Target/CheerpBackend/TargetInfo/Makefile deleted file mode 100644 index c5f00002aabd..000000000000 --- a/llvm/lib/Target/CheerpBackend/TargetInfo/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -##===- lib/Target/CheerpBackend/TargetInfo/Makefile --------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## -LEVEL = ../../../.. -LIBRARYNAME = LLVMCheerpBackendInfo - -# Hack: we need to include 'main' target directory to grab private headers -CPPFLAGS = -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/.. - -include $(LEVEL)/Makefile.common diff --git a/llvm/lib/Target/WebAssembly/CMakeLists.txt b/llvm/lib/Target/WebAssembly/CMakeLists.txt index 95055f0ff0ca..ce4178951867 100644 --- a/llvm/lib/Target/WebAssembly/CMakeLists.txt +++ b/llvm/lib/Target/WebAssembly/CMakeLists.txt @@ -15,7 +15,7 @@ tablegen(LLVM WebAssemblyGenSubtargetInfo.inc -gen-subtarget) add_public_tablegen_target(WebAssemblyCommonTableGen) add_llvm_target(WebAssemblyCodeGen - CheerpWritePass.cpp + CheerpWritePass.cpp WebAssemblyAddMissingPrototypes.cpp WebAssemblyArgumentMove.cpp WebAssemblyAsmPrinter.cpp @@ -70,13 +70,13 @@ add_llvm_target(WebAssemblyCodeGen Core CheerpWriter CheerpUtils - ExecutionEngine - Interpreter + ExecutionEngine + Interpreter MC Scalar SelectionDAG Support - Passes + Passes Target TransformUtils WebAssemblyDesc diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index d6a52dea4fb2..f6cbc913003d 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -150,7 +150,7 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine( : "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-" "n32:64-S128-ni:1:10:20")), TT, CPU, FS, Options, getEffectiveRelocModel(RM, TT), - TT.isCheerpWasm()? (CM ? *CM : CodeModel::Medium) + TT.isCheerp()? (CM ? *CM : CodeModel::Medium) :getEffectiveCodeModel(CM, CodeModel::Large), OL), TLOF(new WebAssemblyTargetObjectFile()) { // WebAssembly type-checks instructions, but a noreturn function with a return