From 6b2b22935bba1144fae826197372522551b0a064 Mon Sep 17 00:00:00 2001 From: Theo Paris Date: Thu, 1 Oct 2026 19:46:13 -0700 Subject: [PATCH] Update to LLVM 23 --- .../workflows/cmake-test-release-linux.yml | 2 +- .github/workflows/cmake-test-release-win.yml | 4 +- scripts/install_llvm_prebuilt_release.sh | 10 ++-- scripts/llvm_prebuilt_common.ps1 | 6 +- tslang/include/TypeScript/Defines.h | 4 +- .../TypeScript/LowerToLLVM/LLVMDebugInfo.h | 33 +++++------ .../LowerToLLVM/LLVMDebugInfoFixer.h | 2 +- .../LowerToLLVM/LLVMRTTIHelperVCLinux.h | 2 +- .../MLIRLogic/MLIRDebugInfoHelper.h | 5 +- tslang/include/TypeScript/TypeScriptOps.td | 8 +-- tslang/lib/TypeScript/LowerToLLVM.cpp | 48 +++++++-------- tslang/lib/TypeScript/MLIRGenModule.cpp | 2 +- tslang/lib/TypeScript/MLIRGenTypes.cpp | 8 +-- .../TypeScriptDialectTranslation.cpp | 3 +- tslang/lib/TypeScript/TypeScriptOps.cpp | 59 +++++++++++++------ tslang/tslang/TextDiagnosticPrinter.cpp | 4 +- tslang/tslang/exe.cpp | 1 - tslang/tslang/jit.cpp | 2 +- tslang/tslang/obj.cpp | 2 +- tslang/tslang/transform.cpp | 16 ++++- 20 files changed, 126 insertions(+), 95 deletions(-) diff --git a/.github/workflows/cmake-test-release-linux.yml b/.github/workflows/cmake-test-release-linux.yml index 836b1888e..0cab11dda 100644 --- a/.github/workflows/cmake-test-release-linux.yml +++ b/.github/workflows/cmake-test-release-linux.yml @@ -15,7 +15,7 @@ env: BUILD_TYPE: Release # The official LLVM release package, installed where a custom LLVM build would be - see # scripts/install_llvm_prebuilt_release.sh. - LLVM_FULL_VERSION: "22.1.8" + LLVM_FULL_VERSION: "23.1.2" GC_VERSION: "8.2.12" LIBATOMIC_OPS_VERSION: "7.10.0" diff --git a/.github/workflows/cmake-test-release-win.yml b/.github/workflows/cmake-test-release-win.yml index 60f987bd2..b565359c0 100644 --- a/.github/workflows/cmake-test-release-win.yml +++ b/.github/workflows/cmake-test-release-win.yml @@ -14,10 +14,10 @@ env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release CACHE_VERSION: v11 - LLVM_VERSION: 22 + LLVM_VERSION: 23 # The official LLVM release package plus a prebuilt MLIR archive, installed where a custom LLVM # build would be - see scripts/install_llvm_prebuilt_release.ps1. - LLVM_FULL_VERSION: "22.1.8" + LLVM_FULL_VERSION: "23.1.2" GC_VERSION: "8.2.12" LIBATOMIC_OPS_VERSION: "7.10.0" diff --git a/scripts/install_llvm_prebuilt_release.sh b/scripts/install_llvm_prebuilt_release.sh index 8b531ed25..c591e93f5 100755 --- a/scripts/install_llvm_prebuilt_release.sh +++ b/scripts/install_llvm_prebuilt_release.sh @@ -17,7 +17,7 @@ # Skips everything when the prefix already has MLIR, so it never overwrites a custom build. set -e -VERSION=${1:-22.1.8} +VERSION=${1:-23.1.2} ROOT=$(cd "$(dirname "$0")/.." && pwd) PREFIX=${PREFIX:-$ROOT/3rdParty/llvm/release} WORK_DIR=${WORK_DIR:-$ROOT/__build/llvm-prebuilt} @@ -28,17 +28,17 @@ if [ -f "$PREFIX/lib/cmake/mlir/MLIRConfig.cmake" ]; then fi NAME=LLVM-$VERSION-Linux-X64 -PACKAGE=$WORK_DIR/$NAME.tar.xz +PACKAGE=$WORK_DIR/$NAME.tar.zst mkdir -p "$WORK_DIR" "$PREFIX" if [ ! -f "$PACKAGE" ]; then - echo "Downloading $NAME.tar.xz" + echo "Downloading $NAME.tar.zst" curl -fsSL --retry 3 -o "$PACKAGE.part" \ - "https://github.com/llvm/llvm-project/releases/download/llvmorg-$VERSION/$NAME.tar.xz" + "https://github.com/llvm/llvm-project/releases/download/llvmorg-$VERSION/$NAME.tar.zst" mv "$PACKAGE.part" "$PACKAGE" fi echo "Unpacking $PACKAGE into $PREFIX" -xz -T0 -dc "$PACKAGE" | tar -x -C "$PREFIX" --strip-components=1 \ +zstd --long=31 -T0 -dc "$PACKAGE" | tar -x -C "$PREFIX" --strip-components=1 \ --exclude='*/bin/flang*' --exclude='*/bin/bbc' --exclude='*/bin/tco' \ --exclude='*/bin/fir-*' --exclude='*/bin/f18-*' --exclude='*/bin/lldb*' \ --exclude='*/bin/llvm-bolt*' --exclude='*/bin/*bolt*' --exclude='*/bin/merge-fdata' \ diff --git a/scripts/llvm_prebuilt_common.ps1 b/scripts/llvm_prebuilt_common.ps1 index fa6369101..218c35bfc 100644 --- a/scripts/llvm_prebuilt_common.ps1 +++ b/scripts/llvm_prebuilt_common.ps1 @@ -1,6 +1,6 @@ # Shared by build_mlir_prebuilt_release.ps1 and install_llvm_prebuilt_release.ps1 (dot-sourced). # -# The official LLVM Windows package (clang+llvm--x86_64-pc-windows-msvc.tar.xz, a GitHub +# The official LLVM Windows package (clang+llvm--x86_64-pc-windows-msvc.tar.zst, a GitHub # release asset of llvm/llvm-project) carries the LLVM, Clang and LLD libraries with their CMake # packages, lld/wasm-ld, clang and clang's resource directory, built with the static CRT (/MT) the # project needs. It has no MLIR at all. build_mlir_prebuilt_release.ps1 builds MLIR standalone @@ -16,7 +16,7 @@ $ErrorActionPreference = "Stop" $ProgressPreference = "SilentlyContinue" -# Windows' own bsdtar reads and writes .tar.xz; a Git for Windows tar earlier on PATH would need xz +# Windows' own bsdtar reads and writes .tar.zst; a Git for Windows tar earlier on PATH would need zst # beside it. $script:tar = Join-Path $env:SystemRoot "System32\tar.exe" @@ -44,7 +44,7 @@ function Get-LlvmAsset([string]$version, [string]$name, [string]$dir) { function Install-OfficialLlvm([string]$version, [string]$prefix, [string]$workDir) { $llvmConfig = Join-Path $prefix "lib\cmake\llvm\LLVMConfig.cmake" if (-not (Test-Path $llvmConfig)) { - $package = Get-LlvmAsset $version "clang+llvm-$version-x86_64-pc-windows-msvc.tar.xz" $workDir + $package = Get-LlvmAsset $version "clang+llvm-$version-x86_64-pc-windows-msvc.tar.zst" $workDir New-Item -ItemType Directory -Force -Path $prefix | Out-Null Write-Host "Unpacking $package into $prefix" Invoke-Checked "Unpacking the LLVM package" { & $script:tar -xf $package -C $prefix --strip-components=1 } diff --git a/tslang/include/TypeScript/Defines.h b/tslang/include/TypeScript/Defines.h index ddab22dfb..5b232d914 100644 --- a/tslang/include/TypeScript/Defines.h +++ b/tslang/include/TypeScript/Defines.h @@ -194,9 +194,9 @@ #define TRAMPOLINE_SIZE 40 #endif -#define ATTR(attr) mlir::StringAttr::get(rewriter.getContext(), attr) +#define TS_ATTR(attr) mlir::StringAttr::get(rewriter.getContext(), attr) #define IDENT(name) mlir::Identifier::get(name, rewriter.getContext()) -#define NAMED_ATTR(name, attr) mlir::ArrayAttr::get(rewriter.getContext(), {ATTR(name), ATTR(attr)}) +#define NAMED_TS_ATTR(name, attr) mlir::ArrayAttr::get(rewriter.getContext(), {TS_ATTR(name), TS_ATTR(attr)}) #define DATA_VALUE_INDEX 0 #define THIS_VALUE_INDEX 1 diff --git a/tslang/include/TypeScript/LowerToLLVM/LLVMDebugInfo.h b/tslang/include/TypeScript/LowerToLLVM/LLVMDebugInfo.h index d4ad68f65..2886b0a60 100644 --- a/tslang/include/TypeScript/LowerToLLVM/LLVMDebugInfo.h +++ b/tslang/include/TypeScript/LowerToLLVM/LLVMDebugInfo.h @@ -489,7 +489,7 @@ class LLVMDebugInfoHelper emptyDIExpr, emptyDIExpr, emptyDIExpr, - {}); + StringAttr(), LLVM::DIDerivedTypeAttr(), {}); return fwdCompositeType; } @@ -530,15 +530,15 @@ class LLVMDebugInfoHelper auto elementOffsetInBits = structLaytout->getElementOffsetInBits(index); auto elementDiType = getDITypeScriptType(location, elementType, file, line, scope); - auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, name, elementDiType, - sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, elementOffsetInBits/*sizesTrack.offsetInBits*/, {}, {}); + auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, name, file, line, scope, elementDiType, + sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, elementOffsetInBits, {}, LLVM::DIFlags::Zero, {}); elements.push_back(wrapperDiType); } LLVM::DIExpressionAttr emptyDIExpr; auto compositeType = LLVM::DICompositeTypeAttr::get(context, dwarf::DW_TAG_structure_type, StringAttr::get(context, isNamePrefix ? MLIRHelper::getAnonymousName(typeWithFields, name.data()) : name), - file, line, scope, LLVM::DITypeAttr(), LLVM::DIFlags::TypePassByValue, sizesTrack.sizeInBits, sizesTrack.alignInBits, emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, elements); + file, line, scope, LLVM::DITypeAttr(), LLVM::DIFlags::TypePassByValue, sizesTrack.sizeInBits, sizesTrack.alignInBits, emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, StringAttr(), LLVM::DIDerivedTypeAttr(), elements); if (!isNamePrefix) { @@ -555,8 +555,8 @@ class LLVMDebugInfoHelper auto offsetInBits = 0; return LLVM::DIDerivedTypeAttr::get( - context, dwarf::DW_TAG_pointer_type, StringAttr::get(context, "pointer"), diElementType, - sizeInBits, alignInBits, offsetInBits, {}, {}); + context, dwarf::DW_TAG_pointer_type, StringAttr::get(context, "pointer"), file, line, LLVM::DIScopeAttr(), diElementType, + sizeInBits, alignInBits, offsetInBits, {}, LLVM::DIFlags::Zero, {}); } LLVM::DISubroutineTypeAttr getDISubroutineType(mlir::Location location, LLVM::LLVMFunctionType funcType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope) @@ -597,7 +597,7 @@ class LLVMDebugInfoHelper // create forward declaration auto fwdCompositeType = LLVM::DICompositeTypeAttr::get(context, dwarf::DW_TAG_structure_type, StringAttr::get(context, structType.getName()), - file, line, scope, LLVM::DITypeAttr(), LLVM::DIFlags::FwdDecl, 0, 0, emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, {}); + file, line, scope, LLVM::DITypeAttr(), LLVM::DIFlags::FwdDecl, 0, 0, emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, StringAttr(), LLVM::DIDerivedTypeAttr(), {}); return fwdCompositeType; } @@ -624,7 +624,7 @@ class LLVMDebugInfoHelper auto elementDiType = getDILLVMType(location, llvmElementType, file, line, scope); auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, - elementName, elementDiType, sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, elementOffsetInBits/*sizesTrack.offsetInBits*/, {}, {}); + elementName, file, line, scope, elementDiType, sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, elementOffsetInBits, {}, LLVM::DIFlags::Zero, {}); elements.push_back(wrapperDiType); } @@ -633,7 +633,7 @@ class LLVMDebugInfoHelper : MLIRHelper::getAnonymousName(structType, "struct")); auto compositeType = LLVM::DICompositeTypeAttr::get(context, dwarf::DW_TAG_structure_type, name, file, line, scope, LLVM::DITypeAttr(), LLVM::DIFlags::TypePassByValue, sizesTrack.sizeInBits, sizesTrack.alignInBits, - emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, elements); + emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, StringAttr(), LLVM::DIDerivedTypeAttr(), elements); if (structType.isIdentified()) { @@ -674,15 +674,15 @@ class LLVMDebugInfoHelper auto elementOffsetInBits = structLayout->getElementOffsetInBits(index); auto elementDiType = getDIType(location, llvmElementType, elementType, file, line, scope); - auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, name, elementDiType, - sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, elementOffsetInBits/*sizesTrack.offsetInBits*/, {}, {}); + auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, name, file, line, scope, elementDiType, + sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, elementOffsetInBits, {}, LLVM::DIFlags::Zero, {}); elements.push_back(wrapperDiType); } LLVM::DIExpressionAttr emptyDIExpr; return LLVM::DICompositeTypeAttr::get(context, dwarf::DW_TAG_structure_type, StringAttr::get(context, name), file, line, scope, LLVM::DITypeAttr(), - LLVM::DIFlags::TypePassByValue, sizesTrack.sizeInBits, sizesTrack.alignInBits, emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, elements); + LLVM::DIFlags::TypePassByValue, sizesTrack.sizeInBits, sizesTrack.alignInBits, emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, StringAttr(), LLVM::DIDerivedTypeAttr(), elements); } LLVM::DICompositeTypeAttr getDIStructType(StringRef name, ArrayRef> fields, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope) @@ -701,14 +701,13 @@ class LLVMDebugInfoHelper sizesTrack.nextElementType(elementDiType); - auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, name, elementDiType, - sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, sizesTrack.offsetInBits, {}, {}); + auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, name, file, line, scope, elementDiType, sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, sizesTrack.offsetInBits, {}, LLVM::DIFlags::Zero, {}); elements.push_back(wrapperDiType); } LLVM::DIExpressionAttr emptyDIExpr; return LLVM::DICompositeTypeAttr::get(context, dwarf::DW_TAG_structure_type, StringAttr::get(context, name), - file, line, scope, LLVM::DITypeAttr(), LLVM::DIFlags::TypePassByValue, sizesTrack.sizeInBits, sizesTrack.alignInBits, emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, elements); + file, line, scope, LLVM::DITypeAttr(), LLVM::DIFlags::TypePassByValue, sizesTrack.sizeInBits, sizesTrack.alignInBits, emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, StringAttr(), LLVM::DIDerivedTypeAttr(), elements); } LLVM::DICompositeTypeAttr getDIUnionType(mlir::Location location, mlir_ts::UnionType unionType, LLVM::DIFileAttr file, uint32_t line, LLVM::DIScopeAttr scope) @@ -731,14 +730,14 @@ class LLVMDebugInfoHelper auto elementDiType = getDITypeScriptType(location, elementType, file, line, scope); auto wrapperDiType = LLVM::DIDerivedTypeAttr::get(context, dwarf::DW_TAG_member, name, - elementDiType, sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, 0, {}, {}); + file, line, scope, elementDiType, sizesTrack.elementSizeInBits, sizesTrack.elementAlignInBits, 0, {}, LLVM::DIFlags::Zero, {}); elements.push_back(wrapperDiType); } LLVM::DIExpressionAttr emptyDIExpr; return LLVM::DICompositeTypeAttr::get(context, dwarf::DW_TAG_union_type, StringAttr::get(context, MLIRHelper::getAnonymousName(unionType, "union")), file, line, scope, LLVM::DITypeAttr(), LLVM::DIFlags::TypePassByValue, - sizeInBits, sizesTrack.alignInBits, emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, elements); + sizeInBits, sizesTrack.alignInBits, emptyDIExpr, emptyDIExpr, emptyDIExpr, emptyDIExpr, StringAttr(), LLVM::DIDerivedTypeAttr(), elements); } }; diff --git a/tslang/include/TypeScript/LowerToLLVM/LLVMDebugInfoFixer.h b/tslang/include/TypeScript/LowerToLLVM/LLVMDebugInfoFixer.h index 01dc44854..359359e98 100644 --- a/tslang/include/TypeScript/LowerToLLVM/LLVMDebugInfoFixer.h +++ b/tslang/include/TypeScript/LowerToLLVM/LLVMDebugInfoFixer.h @@ -78,7 +78,7 @@ class LLVMDebugInfoHelperFixer } auto subroutineTypeAttr = mlir::LLVM::DISubroutineTypeAttr::get(context, llvm::dwarf::DW_CC_normal, resultTypes); - SmallVector retainedNodes; // TODO: review usage of it + SmallVector retainedNodes; // TODO: review usage of it SmallVector annotations; // TODO: review usage of it // a fresh DistinctAttr id: references to the old subprogram outside this // function (if any) keep the old identity instead of colliding with the diff --git a/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinux.h b/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinux.h index 04ef403f9..7edc71c17 100644 --- a/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinux.h +++ b/tslang/include/TypeScript/LowerToLLVM/LLVMRTTIHelperVCLinux.h @@ -105,7 +105,7 @@ class LLVMRTTIHelperVCLinux auto name = "__gxx_personality_v0"; auto cxxFrameHandler3 = ch.getOrInsertFunction(name, th.getFunctionType(th.getI32Type(), {}, true)); - newFuncOp->setAttr(ATTR("personality"), FlatSymbolRefAttr::get(rewriter.getContext(), name)); + newFuncOp->setAttr(TS_ATTR("personality"), FlatSymbolRefAttr::get(rewriter.getContext(), name)); return success(); } diff --git a/tslang/include/TypeScript/MLIRLogic/MLIRDebugInfoHelper.h b/tslang/include/TypeScript/MLIRLogic/MLIRDebugInfoHelper.h index 9d1111841..abacc1f17 100644 --- a/tslang/include/TypeScript/MLIRLogic/MLIRDebugInfoHelper.h +++ b/tslang/include/TypeScript/MLIRLogic/MLIRDebugInfoHelper.h @@ -189,12 +189,13 @@ class MLIRDebugInfoHelper auto funcNameAttr = builder.getStringAttr(functionName); auto linkageNameAttr = builder.getStringAttr(linkageName); - SmallVector retainedNodes; // TODO: review usage of it + SmallVector retainedNodes; // TODO: review usage of it SmallVector annotations; // TODO: review usage of it auto subprogramAttr = mlir::LLVM::DISubprogramAttr::get( builder.getContext(), DistinctAttr::create(builder.getUnitAttr()), compileUnitAttr, isAcceptableSubProgramScope(scopeAttr) ? scopeAttr : compileUnitAttr, funcNameAttr, linkageNameAttr, - file/*compileUnitAttr.getFile()*/, line, scopeLine, subprogramFlags, type, retainedNodes, annotations); + file/*compileUnitAttr.getFile()*/, line, scopeLine, subprogramFlags, type, + retainedNodes, annotations); debugScope.insert(SUBPROGRAM_DEBUG_SCOPE, subprogramAttr); debugScope.insert(DEBUG_SCOPE, subprogramAttr); diff --git a/tslang/include/TypeScript/TypeScriptOps.td b/tslang/include/TypeScript/TypeScriptOps.td index 0da880b31..677160a22 100644 --- a/tslang/include/TypeScript/TypeScriptOps.td +++ b/tslang/include/TypeScript/TypeScriptOps.td @@ -1812,7 +1812,7 @@ def TypeScript_ReturnInternalOp : TypeScript_Op<"ReturnInternal", [Pure, HasPare } def TypeScript_IfOp : TypeScript_Op<"If", - [DeclareOpInterfaceMethods, SingleBlockImplicitTerminator<"typescript::ResultOp">, + [DeclareOpInterfaceMethods, SingleBlockImplicitTerminator<"typescript::ResultOp">, NoRegionArguments]> { let summary = "if-then-else operation"; @@ -1870,7 +1870,7 @@ def TypeScript_WhileOp : TypeScript_Op<"While", [ LoopLikeOpInterface, ConditionallySpeculatable, - DeclareOpInterfaceMethods + DeclareOpInterfaceMethods ]> { let summary = "a generic 'while' loop"; let description = [{ @@ -1915,7 +1915,7 @@ def TypeScript_DoWhileOp : TypeScript_Op<"DoWhile", [ LoopLikeOpInterface, ConditionallySpeculatable, - DeclareOpInterfaceMethods + DeclareOpInterfaceMethods ]> { let summary = "a generic 'do-while' loop"; let description = [{ @@ -1943,7 +1943,7 @@ def TypeScript_ForOp : TypeScript_Op<"For", [ LoopLikeOpInterface, ConditionallySpeculatable, - DeclareOpInterfaceMethods + DeclareOpInterfaceMethods ]> { let summary = "a generic 'for' loop"; diff --git a/tslang/lib/TypeScript/LowerToLLVM.cpp b/tslang/lib/TypeScript/LowerToLLVM.cpp index d3c0273e0..3077c8efb 100644 --- a/tslang/lib/TypeScript/LowerToLLVM.cpp +++ b/tslang/lib/TypeScript/LowerToLLVM.cpp @@ -1814,14 +1814,14 @@ struct FuncOpLowering : public TsLlvmPattern // ts loop with a call/store in its body already satisfies the (weaker) // mustprogress contract; a body-less `while(true){}` is the only case this // attribute changes the meaning of, same as in C/C++/Rust. - funcAttrs.push_back(ATTR("mustprogress")); + funcAttrs.push_back(TS_ATTR("mustprogress")); if (funcOp.getPersonality().has_value() && funcOp.getPersonality().value()) { LLVMRTTIHelperVC rttih(funcOp, rewriter, typeConverter, tsLlvmContext->compileOptions); rttih.setPersonality(newFuncOp); - funcAttrs.push_back(ATTR("noinline")); + funcAttrs.push_back(TS_ATTR("noinline")); } // copy attributes over @@ -1858,27 +1858,27 @@ struct FuncOpLowering : public TsLlvmPattern #ifdef DISABLE_OPT // add LLVM attributes to fix issue with shift >> 32 funcAttrs.append({ - ATTR("noinline"), - // ATTR("norecurse"), - // ATTR("nounwind"), - ATTR("optnone"), - // ATTR("uwtable"), - // NAMED_ATTR("correctly-rounded-divide-sqrt-fp-math","false"), - // NAMED_ATTR("disable-tail-calls","false"), - // NAMED_ATTR("frame-pointer","none"), - // NAMED_ATTR("less-precise-fpmad","false"), - // NAMED_ATTR("min-legal-vector-width","0"), - // NAMED_ATTR("no-infs-fp-math","false"), - // NAMED_ATTR("no-jump-tables","false"), - // NAMED_ATTR("no-nans-fp-math","false"), - // NAMED_ATTR("no-signed-zeros-fp-math","false"), - // NAMED_ATTR("no-trapping-math","true"), - // NAMED_ATTR("stack-protector-buffer-size","8"), - // NAMED_ATTR("target-cpu","x86-64"), - // NAMED_ATTR("target-features","+cx8,+fxsr,+mmx,+sse,+sse2,+x87"), - // NAMED_ATTR("tune-cpu","generic"), - // NAMED_ATTR("unsafe-fp-math","false"), - // NAMED_ATTR("use-soft-float","false"), + TS_ATTR("noinline"), + // TS_ATTR("norecurse"), + // TS_ATTR("nounwind"), + TS_ATTR("optnone"), + // TS_ATTR("uwtable"), + // NAMED_TS_ATTR("correctly-rounded-divide-sqrt-fp-math","false"), + // NAMED_TS_ATTR("disable-tail-calls","false"), + // NAMED_TS_ATTR("frame-pointer","none"), + // NAMED_TS_ATTR("less-precise-fpmad","false"), + // NAMED_TS_ATTR("min-legal-vector-width","0"), + // NAMED_TS_ATTR("no-infs-fp-math","false"), + // NAMED_TS_ATTR("no-jump-tables","false"), + // NAMED_TS_ATTR("no-nans-fp-math","false"), + // NAMED_TS_ATTR("no-signed-zeros-fp-math","false"), + // NAMED_TS_ATTR("no-trapping-math","true"), + // NAMED_TS_ATTR("stack-protector-buffer-size","8"), + // NAMED_TS_ATTR("target-cpu","x86-64"), + // NAMED_TS_ATTR("target-features","+cx8,+fxsr,+mmx,+sse,+sse2,+x87"), + // NAMED_TS_ATTR("tune-cpu","generic"), + // NAMED_TS_ATTR("unsafe-fp-math","false"), + // NAMED_TS_ATTR("use-soft-float","false"), })); #endif @@ -6651,7 +6651,7 @@ struct GlobalConstructorOpLowering : public TsLlvmPatterncompileOptions.isDLL) { SmallVector funcAttrs; - funcAttrs.push_back(ATTR("export")); + funcAttrs.push_back(TS_ATTR("export")); initFunc->setAttr("passthrough", ArrayAttr::get(rewriter.getContext(), funcAttrs)); } diff --git a/tslang/lib/TypeScript/MLIRGenModule.cpp b/tslang/lib/TypeScript/MLIRGenModule.cpp index 2701423d3..d7bfde375 100644 --- a/tslang/lib/TypeScript/MLIRGenModule.cpp +++ b/tslang/lib/TypeScript/MLIRGenModule.cpp @@ -105,7 +105,7 @@ namespace mlirgen { std::string suffix(llvm::sys::path::stem(llvm::sys::path::filename(filePath))); suffix.append("_"); - suffix.append(to_string(llvm::xxh3_64bits(canonicalFilePath(filePath)))); + suffix.append(std::to_string(llvm::xxh3_64bits(canonicalFilePath(filePath)))); return suffix; } diff --git a/tslang/lib/TypeScript/MLIRGenTypes.cpp b/tslang/lib/TypeScript/MLIRGenTypes.cpp index d5febf363..fcf9bfd69 100644 --- a/tslang/lib/TypeScript/MLIRGenTypes.cpp +++ b/tslang/lib/TypeScript/MLIRGenTypes.cpp @@ -1167,16 +1167,16 @@ namespace mlirgen auto kind = llvm::StringSwitch(name) .Case("TypeOf", EmbeddedType::TypeOf) - .Cases("Reference", "Ref", EmbeddedType::Reference) + .Cases({"Reference", "Ref"}, EmbeddedType::Reference) .Case("BoxedObject", EmbeddedType::BoxedObject) - .Cases("Readonly", "Partial", "Required", "ThisType", EmbeddedType::FirstTypeArgument) + .Cases({"Readonly", "Partial", "Required", "ThisType"}, EmbeddedType::FirstTypeArgument) .Case("NonNullable", EmbeddedType::NonNullable) #ifdef ARRAY_TYPE_AS_ARRAY_CLASS .Case("Array", EmbeddedType::Array) #endif .Case("ReadonlyArray", EmbeddedType::ReadonlyArray) .Case("ReturnType", EmbeddedType::ReturnType) - .Cases("Parameters", "ConstructorParameters", EmbeddedType::Parameters) + .Cases({"Parameters", "ConstructorParameters"}, EmbeddedType::Parameters) .Case("ThisParameterType", EmbeddedType::ThisParameterType) .Case("OmitThisParameter", EmbeddedType::OmitThisParameter) .Case("Uppercase", EmbeddedType::Uppercase) @@ -1265,7 +1265,7 @@ namespace mlirgen auto kind = llvm::StringSwitch(name) .Case("TypeOf", EmbeddedType::TypeOf) - .Cases("Reference", "Ref", EmbeddedType::Reference) + .Cases({"Reference", "Ref"}, EmbeddedType::Reference) .Case("BoxedObject", EmbeddedType::BoxedObject) .Case("ThisType", EmbeddedType::ThisType) #ifdef ARRAY_TYPE_AS_ARRAY_CLASS diff --git a/tslang/lib/TypeScript/TypeScriptDialectTranslation.cpp b/tslang/lib/TypeScript/TypeScriptDialectTranslation.cpp index d630ba84b..cea79eac7 100644 --- a/tslang/lib/TypeScript/TypeScriptDialectTranslation.cpp +++ b/tslang/lib/TypeScript/TypeScriptDialectTranslation.cpp @@ -1,5 +1,6 @@ #include "TypeScript/TypeScriptDialectTranslation.h" #include "TypeScript/Defines.h" +#undef ATTR #include "TypeScript/TypeScriptDialect.h" #include "TypeScript/TypeScriptOps.h" @@ -77,7 +78,7 @@ class TypeScriptDialectLLVMIRTranslationInterface : public LLVMTranslationDialec /// Attaches module-level metadata for functions marked as kernels. virtual LogicalResult - amendOperation(Operation *op, NamedAttribute attribute, LLVM::ModuleTranslation &moduleTranslation) const final + amendOperation(Operation *op, ArrayRef instructions, NamedAttribute attribute, LLVM::ModuleTranslation &moduleTranslation) const final { LLVM_DEBUG(llvm::dbgs() << "\n === amendOperation === \n"); LLVM_DEBUG(llvm::dbgs() << "attribute: " << attribute.getName() << " val: " << attribute.getValue() << "\n"); diff --git a/tslang/lib/TypeScript/TypeScriptOps.cpp b/tslang/lib/TypeScript/TypeScriptOps.cpp index 017b81fd2..dc4ddfac2 100644 --- a/tslang/lib/TypeScript/TypeScriptOps.cpp +++ b/tslang/lib/TypeScript/TypeScriptOps.cpp @@ -1512,11 +1512,14 @@ static void replaceOpWithRegion(PatternRewriter &rewriter, Operation *op, Region rewriter.eraseOp(terminator); } -/// Given the region at `index`, or the parent operation if `index` is None, -/// return the successor regions. These are the regions that may be selected -/// during the flow of control. `operands` is a set of optional attributes that -/// correspond to a constant value for each operand, or null if that operand is -/// not a constant. +ValueRange mlir_ts::IfOp::getSuccessorInputs(RegionSuccessor successor) +{ + // LLVM 23 queries successor inputs separately from the control-flow edges. + return successor.isOperation() ? ValueRange(getResults()) : ValueRange(); +} + +/// Return the possible successor regions from the parent operation or a +/// terminator in one of its regions. void mlir_ts::IfOp::getSuccessorRegions(RegionBranchPoint point, SmallVectorImpl ®ions) { // If the predecessor is an IfOp, then branching into both `then` and @@ -1524,26 +1527,32 @@ void mlir_ts::IfOp::getSuccessorRegions(RegionBranchPoint point, SmallVectorImpl if (point.isParent()) { regions.reserve(2); regions.push_back( - RegionSuccessor(&getThenRegion(), getThenRegion().getArguments())); + RegionSuccessor(&getThenRegion())); // If the "else" region is empty, branch back into parent. if (getElseRegion().empty()) { - regions.push_back(RegionSuccessor(getOperation(), getResults())); + regions.push_back(RegionSuccessor(getOperation())); } else { regions.push_back( - RegionSuccessor(&getElseRegion(), getElseRegion().getArguments())); + RegionSuccessor(&getElseRegion())); } return; } // If the predecessor is the `else`/`then` region, then branching into parent // op is valid. - regions.push_back(RegionSuccessor(getOperation(), getResults())); + regions.push_back(RegionSuccessor(getOperation())); } //===----------------------------------------------------------------------===// // WhileOp //===----------------------------------------------------------------------===// +ValueRange mlir_ts::WhileOp::getSuccessorInputs(RegionSuccessor successor) +{ + return successor.isOperation() ? ValueRange(getResults()) + : ValueRange(successor.getSuccessor()->getArguments()); +} + OperandRange mlir_ts::WhileOp::getEntrySuccessorOperands(RegionSuccessor successor) { return getInits(); @@ -1553,24 +1562,30 @@ void mlir_ts::WhileOp::getSuccessorRegions(RegionBranchPoint point, SmallVectorI { // The parent op always branches to the condition region. if (point.isParent()) { - regions.emplace_back(&getCond(), getCond().getArguments()); + regions.emplace_back(&getCond()); return; } // The body region always branches back to the condition region. if (point.getTerminatorPredecessorOrNull()->getParentRegion() == &getBody()) { - regions.emplace_back(&getCond(), getCond().getArguments()); + regions.emplace_back(&getCond()); return; } - regions.emplace_back(getOperation(), getResults()); - regions.emplace_back(&getBody(), getBody().getArguments()); + regions.emplace_back(getOperation()); + regions.emplace_back(&getBody()); } //===----------------------------------------------------------------------===// // DoWhileOp //===----------------------------------------------------------------------===// +ValueRange mlir_ts::DoWhileOp::getSuccessorInputs(RegionSuccessor successor) +{ + return successor.isOperation() ? ValueRange(getResults()) + : ValueRange(successor.getSuccessor()->getArguments()); +} + OperandRange mlir_ts::DoWhileOp::getEntrySuccessorOperands(RegionSuccessor successor) { return getInits(); @@ -1580,24 +1595,30 @@ void mlir_ts::DoWhileOp::getSuccessorRegions(RegionBranchPoint point, SmallVecto { // The parent op always branches to the condition region. if (point.isParent()) { - regions.emplace_back(&getBody(), getBody().getArguments()); + regions.emplace_back(&getBody()); return; } // The body region always branches back to the condition region. if (point.getTerminatorPredecessorOrNull()->getParentRegion() == &getCond()) { - regions.emplace_back(&getBody(), getBody().getArguments()); + regions.emplace_back(&getBody()); return; } - regions.emplace_back(getOperation(), getResults()); - regions.emplace_back(&getCond(), getCond().getArguments()); + regions.emplace_back(getOperation()); + regions.emplace_back(&getCond()); } //===----------------------------------------------------------------------===// // ForOp //===----------------------------------------------------------------------===// +ValueRange mlir_ts::ForOp::getSuccessorInputs(RegionSuccessor successor) +{ + return successor.isOperation() ? ValueRange(getResults()) + : ValueRange(successor.getSuccessor()->getArguments()); +} + OperandRange mlir_ts::ForOp::getEntrySuccessorOperands(RegionSuccessor successor) { return getInits(); @@ -1608,8 +1629,8 @@ void mlir_ts::ForOp::getSuccessorRegions(RegionBranchPoint point, SmallVectorImp // Both the operation itself and the region may be branching into the body or // back into the operation itself. It is possible for loop not to enter the // body. - regions.push_back(RegionSuccessor(&getRegion(0), getRegionIterArgs())); - regions.push_back(RegionSuccessor(getOperation(), getResults())); + regions.push_back(RegionSuccessor(&getRegion(0))); + regions.push_back(RegionSuccessor(getOperation())); } //===----------------------------------------------------------------------===// diff --git a/tslang/tslang/TextDiagnosticPrinter.cpp b/tslang/tslang/TextDiagnosticPrinter.cpp index b1eb1606e..d6fe57e83 100644 --- a/tslang/tslang/TextDiagnosticPrinter.cpp +++ b/tslang/tslang/TextDiagnosticPrinter.cpp @@ -34,11 +34,11 @@ void TextDiagnosticPrinter::HandleDiagnostic( "Diagnostics with valid source location are not supported"); typescript::tslang::TextDiagnostic::printDiagnosticLevel(os, level, - diagOpts->ShowColors); + diagOpts->showColors(os.has_colors())); typescript::tslang::TextDiagnostic::printDiagnosticMessage( os, /*IsSupplemental=*/level == clang::DiagnosticsEngine::Note, - diagMessageStream.str(), diagOpts->ShowColors); + diagMessageStream.str(), diagOpts->showColors(os.has_colors())); os.flush(); } diff --git a/tslang/tslang/exe.cpp b/tslang/tslang/exe.cpp index 3c8c78031..d52160da0 100644 --- a/tslang/tslang/exe.cpp +++ b/tslang/tslang/exe.cpp @@ -1036,7 +1036,6 @@ int buildExe(int argc, char **argv, std::string objFileName, std::string additio } } - diags.getClient()->finish(); // A binary linked against gc.dll does not start without it, so put it beside the output. if (res == 0 && useSharedGC) diff --git a/tslang/tslang/jit.cpp b/tslang/tslang/jit.cpp index ecc2bc661..5c6534d28 100644 --- a/tslang/tslang/jit.cpp +++ b/tslang/tslang/jit.cpp @@ -799,7 +799,7 @@ static std::unique_ptr createJit(llvm::orc::JITTargetMachineBu llvm::orc::LLJITBuilder() .setJITTargetMachineBuilder(std::move(tmBuilder)) .setObjectLinkingLayerCreator( - [targetTriple](llvm::orc::ExecutionSession &session) + [targetTriple](llvm::orc::ExecutionSession &session, llvm::jitlink::JITLinkMemoryManager &memoryManager) -> llvm::Expected> { auto objectLayer = std::make_unique( session, [](const llvm::MemoryBuffer &) { return std::make_unique(); }); diff --git a/tslang/tslang/obj.cpp b/tslang/tslang/obj.cpp index 560fe8dd1..7a71d5244 100644 --- a/tslang/tslang/obj.cpp +++ b/tslang/tslang/obj.cpp @@ -249,7 +249,7 @@ int setupTargetTriple(llvm::Module *llvmModule, std::unique_ptrsetTargetTriple(TheTriple); // Override function attributes based on CPUStr, FeaturesStr, and command line flags. - llvm::codegen::setFunctionAttributes(CPUStr, FeaturesStr, *llvmModule); + llvm::codegen::setFunctionAttributes(*llvmModule, CPUStr, FeaturesStr); return 0; } diff --git a/tslang/tslang/transform.cpp b/tslang/tslang/transform.cpp index 2d6195061..e180de1ba 100644 --- a/tslang/tslang/transform.cpp +++ b/tslang/tslang/transform.cpp @@ -275,10 +275,8 @@ static std::optional mapToLevel(unsigned optLevel, unsi return llvm::OptimizationLevel::O2; case 1: - return llvm::OptimizationLevel::Os; - case 2: - return llvm::OptimizationLevel::Oz; + return llvm::OptimizationLevel::O2; } break; case 3: @@ -343,6 +341,18 @@ std::function makeCustomPassesWithOptimizingTransfo applyFastMathFlags(*m); } + if (mbOptLevel && *mbOptLevel == 2 && mbSizeLevel && *mbSizeLevel > 0) + { + llvm::Attribute::AttrKind sizeAttr = *mbSizeLevel == 1 + ? llvm::Attribute::OptimizeForSize + : llvm::Attribute::MinSize; + for (llvm::Function &function : *m) + { + if (!function.isDeclaration()) + function.addFnAttr(sizeAttr); + } + } + // Every caller hands in a null TargetMachine, which leaves the -O2/-O3 // cost model without target information: no vector registers are known, // so LoopVectorize/SLP never consider vectorization profitable. Build a