[llvm-branch-commits] [NFC][asan] Better `___asan_gen_` names (PR #104728)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/104728 Use different suffixes for each of 3 types of objects using `___asan_gen_`. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][asan] Create `ModuleName` lazily (PR #104729)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/104729 Avoids tracking conditions when it's needed. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][asan] Don't `cd` after `split-file` (PR #104727)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/104727 Helps with copy-pasting of command line with error. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Reland "[asan] Catch `initialization-order-fiasco` in modules without…" (PR #104730)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/104730 This reverts commit 34f941a2f96b804dd24c2a25770d899b018339ff. ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][asan] Better `___asan_gen_` names (PR #104728)
llvmbot wrote: @llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes Use different suffixes for each of 3 types of objects using `___asan_gen_`. --- Patch is 23.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/104728.diff 11 Files Affected: - (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+11-7) - (modified) llvm/test/Instrumentation/AddressSanitizer/asan-funclet.ll (+9-9) - (modified) llvm/test/Instrumentation/AddressSanitizer/fake-stack.ll (+4-4) - (modified) llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll (+1-1) - (modified) llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll (+1-1) - (modified) llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll (+2-2) - (modified) llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll (+1-1) - (modified) llvm/test/Instrumentation/AddressSanitizer/instrument_late_initializer.ll (+1-1) - (modified) llvm/test/Instrumentation/AddressSanitizer/local_alias.ll (+2-2) - (modified) llvm/test/Instrumentation/AddressSanitizer/odr-check-ignore.ll (+8-8) - (modified) llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll (+1-1) ``diff diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index cda35c5af84fff..2655f49c48e311 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -642,6 +642,10 @@ static uint64_t GetCtorAndDtorPriority(Triple &TargetTriple) { } } +static Twine genName(StringRef suffix) { + return Twine(kAsanGenPrefix) + suffix; +} + namespace { /// Helper RAII class to post-process inserted asan runtime calls during a /// pass on a single Function. Upon end of scope, detects and applies the @@ -2243,7 +2247,7 @@ void ModuleAddressSanitizer::SetComdatForGlobalMetadata( // If G is unnamed, it must be internal. Give it an artificial name // so we can put it in a comdat. assert(G->hasLocalLinkage()); - G->setName(Twine(kAsanGenPrefix) + "_anon_global"); + G->setName(genName("anon_global")); } if (!InternalSuffix.empty() && G->hasLocalLinkage()) { @@ -2538,10 +2542,10 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, // We shouldn't merge same module names, as this string serves as unique // module ID in runtime. GlobalVariable *ModuleName = - n != 0 - ? createPrivateGlobalForString(M, M.getModuleIdentifier(), - /*AllowMerging*/ false, kAsanGenPrefix) - : nullptr; + n != 0 ? createPrivateGlobalForString(M, M.getModuleIdentifier(), +/*AllowMerging*/ false, +genName("module")) + : nullptr; for (size_t i = 0; i < n; i++) { GlobalVariable *G = GlobalsToChange[i]; @@ -2556,7 +2560,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, std::string NameForGlobal = G->getName().str(); GlobalVariable *Name = createPrivateGlobalForString(M, llvm::demangle(NameForGlobal), - /*AllowMerging*/ true, kAsanGenPrefix); + /*AllowMerging*/ true, genName("global")); Type *Ty = G->getValueType(); const uint64_t SizeInBytes = DL.getTypeAllocSize(Ty); @@ -3583,7 +3587,7 @@ void FunctionStackPoisoner::processStaticAllocas() { IntptrPtrTy); GlobalVariable *StackDescriptionGlobal = createPrivateGlobalForString(*F.getParent(), DescriptionString, - /*AllowMerging*/ true, kAsanGenPrefix); + /*AllowMerging*/ true, genName("stack")); Value *Description = IRB.CreatePointerCast(StackDescriptionGlobal, IntptrTy); IRB.CreateStore(Description, BasePlus1); // Write the PC to redzone[2]. diff --git a/llvm/test/Instrumentation/AddressSanitizer/asan-funclet.ll b/llvm/test/Instrumentation/AddressSanitizer/asan-funclet.ll index 62c0a24c60d77f..e986f108542688 100644 --- a/llvm/test/Instrumentation/AddressSanitizer/asan-funclet.ll +++ b/llvm/test/Instrumentation/AddressSanitizer/asan-funclet.ll @@ -62,7 +62,7 @@ define void @FuncletPersonality(ptr %ptrParam) sanitize_address personality ptr ; CHECK-INLINE-NEXT:store i64 1102416563, ptr [[TMP23]], align 8 ; CHECK-INLINE-NEXT:[[TMP24:%.*]] = add i64 [[TMP12]], 8 ; CHECK-INLINE-NEXT:[[TMP25:%.*]] = inttoptr i64 [[TMP24]] to ptr -; CHECK-INLINE-NEXT:store i64 ptrtoint (ptr @___asan_gen_ to i64), ptr [[TMP25]], align 8 +; CHECK-INLINE-NEXT:store i64 ptrtoint (ptr @___asan_gen_stack to i64), ptr [[TMP25]], align 8 ; CHECK-INLINE-NEXT:[[TMP26:%.*]] = add i64 [[TMP12]], 16 ; CHECK-INL
[llvm-branch-commits] [NFC][asan] Create `ModuleName` lazily (PR #104729)
llvmbot wrote: @llvm/pr-subscribers-llvm-transforms Author: Vitaly Buka (vitalybuka) Changes Avoids tracking conditions when it's needed. --- Full diff: https://github.com/llvm/llvm-project/pull/104729.diff 1 Files Affected: - (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+22-18) ``diff diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 2655f49c48e31..01dbdc156f698 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -944,13 +944,14 @@ class ModuleAddressSanitizer { bool shouldInstrumentGlobal(GlobalVariable *G) const; bool ShouldUseMachOGlobalsSection() const; StringRef getGlobalMetadataSection() const; - void poisonOneInitializer(Function &GlobalInit, GlobalValue *ModuleName); - void createInitializerPoisonCalls(GlobalValue *ModuleName); + void poisonOneInitializer(Function &GlobalInit); + void createInitializerPoisonCalls(); uint64_t getMinRedzoneSizeForGlobal() const { return getRedzoneSizeForScale(Mapping.Scale); } uint64_t getRedzoneSizeForGlobal(uint64_t SizeInBytes) const; int GetAsanVersion() const; + GlobalVariable *getOrCreateModuleName(); Module &M; bool CompileKernel; @@ -978,6 +979,7 @@ class ModuleAddressSanitizer { Function *AsanCtorFunction = nullptr; Function *AsanDtorFunction = nullptr; + GlobalVariable *ModuleName = nullptr; }; // Stack poisoning does not play well with exception handling. @@ -1965,14 +1967,14 @@ void AddressSanitizer::instrumentUnusualSizeOrAlignment( } } -void ModuleAddressSanitizer::poisonOneInitializer(Function &GlobalInit, - GlobalValue *ModuleName) { +void ModuleAddressSanitizer::poisonOneInitializer(Function &GlobalInit) { // Set up the arguments to our poison/unpoison functions. IRBuilder<> IRB(&GlobalInit.front(), GlobalInit.front().getFirstInsertionPt()); // Add a call to poison all external globals before the given function starts. - Value *ModuleNameAddr = ConstantExpr::getPointerCast(ModuleName, IntptrTy); + Value *ModuleNameAddr = + ConstantExpr::getPointerCast(getOrCreateModuleName(), IntptrTy); IRB.CreateCall(AsanPoisonGlobals, ModuleNameAddr); // Add calls to unpoison all globals before each return instruction. @@ -1981,8 +1983,7 @@ void ModuleAddressSanitizer::poisonOneInitializer(Function &GlobalInit, CallInst::Create(AsanUnpoisonGlobals, "", RI->getIterator()); } -void ModuleAddressSanitizer::createInitializerPoisonCalls( -GlobalValue *ModuleName) { +void ModuleAddressSanitizer::createInitializerPoisonCalls() { GlobalVariable *GV = M.getGlobalVariable("llvm.global_ctors"); if (!GV) return; @@ -2002,7 +2003,7 @@ void ModuleAddressSanitizer::createInitializerPoisonCalls( // Don't instrument CTORs that will run before asan.module_ctor. if (Priority->getLimitedValue() <= GetCtorAndDtorPriority(TargetTriple)) continue; - poisonOneInitializer(*F, ModuleName); + poisonOneInitializer(*F); } } } @@ -2539,14 +2540,6 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, bool HasDynamicallyInitializedGlobals = false; - // We shouldn't merge same module names, as this string serves as unique - // module ID in runtime. - GlobalVariable *ModuleName = - n != 0 ? createPrivateGlobalForString(M, M.getModuleIdentifier(), -/*AllowMerging*/ false, -genName("module")) - : nullptr; - for (size_t i = 0; i < n; i++) { GlobalVariable *G = GlobalsToChange[i]; @@ -2647,7 +2640,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, ConstantInt::get(IntptrTy, SizeInBytes), ConstantInt::get(IntptrTy, SizeInBytes + RightRedzoneSize), ConstantExpr::getPointerCast(Name, IntptrTy), -ConstantExpr::getPointerCast(ModuleName, IntptrTy), +ConstantExpr::getPointerCast(getOrCreateModuleName(), IntptrTy), ConstantInt::get(IntptrTy, MD.IsDynInit), Constant::getNullValue(IntptrTy), ConstantExpr::getPointerCast(ODRIndicator, IntptrTy)); @@ -2694,7 +2687,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, // Create calls for poisoning before initializers run and unpoisoning after. if (HasDynamicallyInitializedGlobals) -createInitializerPoisonCalls(ModuleName); +createInitializerPoisonCalls(); LLVM_DEBUG(dbgs() << M); } @@ -2734,6 +2727,17 @@ int ModuleAddressSanitizer::GetAsanVersion() const { return Version; } +GlobalVariable *ModuleAddressSanitizer::getOrCreateModuleName() { + if (!ModuleName) { +// We shouldn't merge same module names, as this string serves as unique +// module ID in run
[llvm-branch-commits] [NFC][asan] Create `ModuleName` lazily (PR #104729)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes Avoids tracking conditions when it's needed. --- Full diff: https://github.com/llvm/llvm-project/pull/104729.diff 1 Files Affected: - (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+22-18) ``diff diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 2655f49c48e311..01dbdc156f698e 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -944,13 +944,14 @@ class ModuleAddressSanitizer { bool shouldInstrumentGlobal(GlobalVariable *G) const; bool ShouldUseMachOGlobalsSection() const; StringRef getGlobalMetadataSection() const; - void poisonOneInitializer(Function &GlobalInit, GlobalValue *ModuleName); - void createInitializerPoisonCalls(GlobalValue *ModuleName); + void poisonOneInitializer(Function &GlobalInit); + void createInitializerPoisonCalls(); uint64_t getMinRedzoneSizeForGlobal() const { return getRedzoneSizeForScale(Mapping.Scale); } uint64_t getRedzoneSizeForGlobal(uint64_t SizeInBytes) const; int GetAsanVersion() const; + GlobalVariable *getOrCreateModuleName(); Module &M; bool CompileKernel; @@ -978,6 +979,7 @@ class ModuleAddressSanitizer { Function *AsanCtorFunction = nullptr; Function *AsanDtorFunction = nullptr; + GlobalVariable *ModuleName = nullptr; }; // Stack poisoning does not play well with exception handling. @@ -1965,14 +1967,14 @@ void AddressSanitizer::instrumentUnusualSizeOrAlignment( } } -void ModuleAddressSanitizer::poisonOneInitializer(Function &GlobalInit, - GlobalValue *ModuleName) { +void ModuleAddressSanitizer::poisonOneInitializer(Function &GlobalInit) { // Set up the arguments to our poison/unpoison functions. IRBuilder<> IRB(&GlobalInit.front(), GlobalInit.front().getFirstInsertionPt()); // Add a call to poison all external globals before the given function starts. - Value *ModuleNameAddr = ConstantExpr::getPointerCast(ModuleName, IntptrTy); + Value *ModuleNameAddr = + ConstantExpr::getPointerCast(getOrCreateModuleName(), IntptrTy); IRB.CreateCall(AsanPoisonGlobals, ModuleNameAddr); // Add calls to unpoison all globals before each return instruction. @@ -1981,8 +1983,7 @@ void ModuleAddressSanitizer::poisonOneInitializer(Function &GlobalInit, CallInst::Create(AsanUnpoisonGlobals, "", RI->getIterator()); } -void ModuleAddressSanitizer::createInitializerPoisonCalls( -GlobalValue *ModuleName) { +void ModuleAddressSanitizer::createInitializerPoisonCalls() { GlobalVariable *GV = M.getGlobalVariable("llvm.global_ctors"); if (!GV) return; @@ -2002,7 +2003,7 @@ void ModuleAddressSanitizer::createInitializerPoisonCalls( // Don't instrument CTORs that will run before asan.module_ctor. if (Priority->getLimitedValue() <= GetCtorAndDtorPriority(TargetTriple)) continue; - poisonOneInitializer(*F, ModuleName); + poisonOneInitializer(*F); } } } @@ -2539,14 +2540,6 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, bool HasDynamicallyInitializedGlobals = false; - // We shouldn't merge same module names, as this string serves as unique - // module ID in runtime. - GlobalVariable *ModuleName = - n != 0 ? createPrivateGlobalForString(M, M.getModuleIdentifier(), -/*AllowMerging*/ false, -genName("module")) - : nullptr; - for (size_t i = 0; i < n; i++) { GlobalVariable *G = GlobalsToChange[i]; @@ -2647,7 +2640,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, ConstantInt::get(IntptrTy, SizeInBytes), ConstantInt::get(IntptrTy, SizeInBytes + RightRedzoneSize), ConstantExpr::getPointerCast(Name, IntptrTy), -ConstantExpr::getPointerCast(ModuleName, IntptrTy), +ConstantExpr::getPointerCast(getOrCreateModuleName(), IntptrTy), ConstantInt::get(IntptrTy, MD.IsDynInit), Constant::getNullValue(IntptrTy), ConstantExpr::getPointerCast(ODRIndicator, IntptrTy)); @@ -2694,7 +2687,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, // Create calls for poisoning before initializers run and unpoisoning after. if (HasDynamicallyInitializedGlobals) -createInitializerPoisonCalls(ModuleName); +createInitializerPoisonCalls(); LLVM_DEBUG(dbgs() << M); } @@ -2734,6 +2727,17 @@ int ModuleAddressSanitizer::GetAsanVersion() const { return Version; } +GlobalVariable *ModuleAddressSanitizer::getOrCreateModuleName() { + if (!ModuleName) { +// We shouldn't merge same module names, as this string serves as unique +// module I
[llvm-branch-commits] Reland "[asan] Catch `initialization-order-fiasco` in modules without…" (PR #104730)
llvmbot wrote: @llvm/pr-subscribers-llvm-transforms Author: Vitaly Buka (vitalybuka) Changes This reverts commit 34f941a2f96b804dd24c2a25770d899b018339ff. --- Full diff: https://github.com/llvm/llvm-project/pull/104730.diff 3 Files Affected: - (modified) compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp (-3) - (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+1-6) - (modified) llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll (+2) ``diff diff --git a/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp b/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp index 50698b2a7d06fc..369449303f3e08 100644 --- a/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp +++ b/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp @@ -1,9 +1,6 @@ // RUN: %clangxx_asan %min_macos_deployment_target=10.11 -O0 %s %p/Helpers/initialization-bug-extra.cpp -o %t // RUN: %env_asan_opts=check_initialization_order=true:strict_init_order=true not %run %t 2>&1 | FileCheck %s -// Not implemented. -// XFAIL: * - // Do not test with optimization -- the error may be optimized away. // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=186 diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 01dbdc156f698e..5de0a78d087968 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -2538,8 +2538,6 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, SmallVector NewGlobals(n); SmallVector Initializers(n); - bool HasDynamicallyInitializedGlobals = false; - for (size_t i = 0; i < n; i++) { GlobalVariable *G = GlobalsToChange[i]; @@ -2645,9 +2643,6 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, Constant::getNullValue(IntptrTy), ConstantExpr::getPointerCast(ODRIndicator, IntptrTy)); -if (ClInitializers && MD.IsDynInit) - HasDynamicallyInitializedGlobals = true; - LLVM_DEBUG(dbgs() << "NEW GLOBAL: " << *NewGlobal << "\n"); Initializers[i] = Initializer; @@ -2686,7 +2681,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, } // Create calls for poisoning before initializers run and unpoisoning after. - if (HasDynamicallyInitializedGlobals) + if (ClInitializers) createInitializerPoisonCalls(); LLVM_DEBUG(dbgs() << M); diff --git a/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll b/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll index c8a6541bacfdfa..b20de3eb80b786 100644 --- a/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll +++ b/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll @@ -18,7 +18,9 @@ define internal void @__late_ctor() sanitize_address section ".text.startup" { ; CHECK-LABEL: define internal void @__late_ctor( ; CHECK-SAME: ) #[[ATTR1:[0-9]+]] section ".text.startup" { ; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT:call void @__asan_before_dynamic_init(i64 ptrtoint (ptr @___asan_gen_module to i64)) ; CHECK-NEXT:call void @initializer() +; CHECK-NEXT:call void @__asan_after_dynamic_init() ; CHECK-NEXT:ret void ; ; NOINIT-LABEL: define internal void @__late_ctor( `` https://github.com/llvm/llvm-project/pull/104730 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Reland "[asan] Catch `initialization-order-fiasco` in modules without…" (PR #104730)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes This reverts commit 34f941a2f96b804dd24c2a25770d899b018339ff. --- Full diff: https://github.com/llvm/llvm-project/pull/104730.diff 3 Files Affected: - (modified) compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp (-3) - (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+1-6) - (modified) llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll (+2) ``diff diff --git a/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp b/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp index 50698b2a7d06fc..369449303f3e08 100644 --- a/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp +++ b/compiler-rt/test/asan/TestCases/initialization-bug-no-global.cpp @@ -1,9 +1,6 @@ // RUN: %clangxx_asan %min_macos_deployment_target=10.11 -O0 %s %p/Helpers/initialization-bug-extra.cpp -o %t // RUN: %env_asan_opts=check_initialization_order=true:strict_init_order=true not %run %t 2>&1 | FileCheck %s -// Not implemented. -// XFAIL: * - // Do not test with optimization -- the error may be optimized away. // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=186 diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 01dbdc156f698e..5de0a78d087968 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -2538,8 +2538,6 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, SmallVector NewGlobals(n); SmallVector Initializers(n); - bool HasDynamicallyInitializedGlobals = false; - for (size_t i = 0; i < n; i++) { GlobalVariable *G = GlobalsToChange[i]; @@ -2645,9 +2643,6 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, Constant::getNullValue(IntptrTy), ConstantExpr::getPointerCast(ODRIndicator, IntptrTy)); -if (ClInitializers && MD.IsDynInit) - HasDynamicallyInitializedGlobals = true; - LLVM_DEBUG(dbgs() << "NEW GLOBAL: " << *NewGlobal << "\n"); Initializers[i] = Initializer; @@ -2686,7 +2681,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB, } // Create calls for poisoning before initializers run and unpoisoning after. - if (HasDynamicallyInitializedGlobals) + if (ClInitializers) createInitializerPoisonCalls(); LLVM_DEBUG(dbgs() << M); diff --git a/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll b/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll index c8a6541bacfdfa..b20de3eb80b786 100644 --- a/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll +++ b/llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_without_global.ll @@ -18,7 +18,9 @@ define internal void @__late_ctor() sanitize_address section ".text.startup" { ; CHECK-LABEL: define internal void @__late_ctor( ; CHECK-SAME: ) #[[ATTR1:[0-9]+]] section ".text.startup" { ; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT:call void @__asan_before_dynamic_init(i64 ptrtoint (ptr @___asan_gen_module to i64)) ; CHECK-NEXT:call void @initializer() +; CHECK-NEXT:call void @__asan_after_dynamic_init() ; CHECK-NEXT:ret void ; ; NOINIT-LABEL: define internal void @__late_ctor( `` https://github.com/llvm/llvm-project/pull/104730 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Reland "[asan] Catch `initialization-order-fiasco` in modules without…" (PR #104730)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/104730 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Reland "[asan] Catch `initialization-order-fiasco` in modules without…" (PR #104730)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/104730 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Reland "[asan] Catch `initialization-order-fiasco` in modules without…" (PR #104730)
https://github.com/vitalybuka edited https://github.com/llvm/llvm-project/pull/104730 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [NFC][asan] Better `___asan_gen_` names (PR #104728)
https://github.com/MaskRay approved this pull request. The LLVM IR variable names are changed, so "NFC" probably should be removed. There is likely no object file difference due to private linkage. https://github.com/llvm/llvm-project/pull/104728 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang] Introduce ws loop nest generation for HLFIR lowering (PR #101445)
https://github.com/ivanradanov updated https://github.com/llvm/llvm-project/pull/101445 >From 2b23c8b52d3b5b680bbcf090fd8c08de6d86fe62 Mon Sep 17 00:00:00 2001 From: Ivan Radanov Ivanov Date: Wed, 31 Jul 2024 14:12:34 +0900 Subject: [PATCH 1/3] [flang] Introduce ws loop nest generation for HLFIR lowering --- .../flang/Optimizer/Builder/HLFIRTools.h | 12 +++-- flang/lib/Lower/ConvertCall.cpp | 2 +- flang/lib/Lower/OpenMP/ReductionProcessor.cpp | 4 +- flang/lib/Optimizer/Builder/HLFIRTools.cpp| 52 ++- .../HLFIR/Transforms/BufferizeHLFIR.cpp | 3 +- .../LowerHLFIROrderedAssignments.cpp | 30 +-- .../Transforms/OptimizedBufferization.cpp | 6 +-- 7 files changed, 69 insertions(+), 40 deletions(-) diff --git a/flang/include/flang/Optimizer/Builder/HLFIRTools.h b/flang/include/flang/Optimizer/Builder/HLFIRTools.h index 6b41025eea0780..14e42c6f358e46 100644 --- a/flang/include/flang/Optimizer/Builder/HLFIRTools.h +++ b/flang/include/flang/Optimizer/Builder/HLFIRTools.h @@ -357,8 +357,8 @@ hlfir::ElementalOp genElementalOp( /// Structure to describe a loop nest. struct LoopNest { - fir::DoLoopOp outerLoop; - fir::DoLoopOp innerLoop; + mlir::Operation *outerOp; + mlir::Block *body; llvm::SmallVector oneBasedIndices; }; @@ -366,11 +366,13 @@ struct LoopNest { /// \p isUnordered specifies whether the loops in the loop nest /// are unordered. LoopNest genLoopNest(mlir::Location loc, fir::FirOpBuilder &builder, - mlir::ValueRange extents, bool isUnordered = false); + mlir::ValueRange extents, bool isUnordered = false, + bool emitWsLoop = false); inline LoopNest genLoopNest(mlir::Location loc, fir::FirOpBuilder &builder, -mlir::Value shape, bool isUnordered = false) { +mlir::Value shape, bool isUnordered = false, +bool emitWsLoop = false) { return genLoopNest(loc, builder, getIndexExtents(loc, builder, shape), - isUnordered); + isUnordered, emitWsLoop); } /// Inline the body of an hlfir.elemental at the current insertion point diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp index fd873f55dd844e..0689d6e033dd9c 100644 --- a/flang/lib/Lower/ConvertCall.cpp +++ b/flang/lib/Lower/ConvertCall.cpp @@ -2128,7 +2128,7 @@ class ElementalCallBuilder { hlfir::genLoopNest(loc, builder, shape, !mustBeOrdered); mlir::ValueRange oneBasedIndices = loopNest.oneBasedIndices; auto insPt = builder.saveInsertionPoint(); - builder.setInsertionPointToStart(loopNest.innerLoop.getBody()); + builder.setInsertionPointToStart(loopNest.body); callContext.stmtCtx.pushScope(); for (auto &preparedActual : loweredActuals) if (preparedActual) diff --git a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp index c3c1f363033c27..72a90dd0d6f29d 100644 --- a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp @@ -375,7 +375,7 @@ static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc, // know this won't miss any opportuinties for clever elemental inlining hlfir::LoopNest nest = hlfir::genLoopNest( loc, builder, shapeShift.getExtents(), /*isUnordered=*/true); - builder.setInsertionPointToStart(nest.innerLoop.getBody()); + builder.setInsertionPointToStart(nest.body); mlir::Type refTy = fir::ReferenceType::get(seqTy.getEleTy()); auto lhsEleAddr = builder.create( loc, refTy, lhs, shapeShift, /*slice=*/mlir::Value{}, @@ -389,7 +389,7 @@ static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc, builder, loc, redId, refTy, lhsEle, rhsEle); builder.create(loc, scalarReduction, lhsEleAddr); - builder.setInsertionPointAfter(nest.outerLoop); + builder.setInsertionPointAfter(nest.outerOp); builder.create(loc, lhsAddr); } diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp index 8d0ae2f195178c..cd07cb741eb4bb 100644 --- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp +++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp @@ -20,6 +20,7 @@ #include "mlir/IR/IRMapping.h" #include "mlir/Support/LLVM.h" #include "llvm/ADT/TypeSwitch.h" +#include #include // Return explicit extents. If the base is a fir.box, this won't read it to @@ -855,26 +856,51 @@ mlir::Value hlfir::inlineElementalOp( hlfir::LoopNest hlfir::genLoopNest(mlir::Location loc, fir::FirOpBuilder &builder, - mlir::ValueRange extents, bool isUnordered) { + mlir::ValueRange extents, bool isUnordered, + bool emitWsLoop) { hlfir::LoopNest loopNest; assert(!extents.empty() &&
[llvm-branch-commits] [flang] [flang][omp] Emit omp.workshare in frontend (PR #101444)
https://github.com/ivanradanov updated https://github.com/llvm/llvm-project/pull/101444 >From 0eae392538510f736b630d93b14d46644d042e4f Mon Sep 17 00:00:00 2001 From: Ivan Radanov Ivanov Date: Wed, 31 Jul 2024 14:11:47 +0900 Subject: [PATCH 1/2] [flang][omp] Emit omp.workshare in frontend --- flang/lib/Lower/OpenMP/OpenMP.cpp | 30 ++ 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index 2b1839b5270d4f..f7bc565ea8cbc1 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -1270,6 +1270,15 @@ static void genTaskwaitClauses(lower::AbstractConverter &converter, loc, llvm::omp::Directive::OMPD_taskwait); } +static void genWorkshareClauses(lower::AbstractConverter &converter, +semantics::SemanticsContext &semaCtx, +lower::StatementContext &stmtCtx, +const List &clauses, mlir::Location loc, +mlir::omp::WorkshareOperands &clauseOps) { + ClauseProcessor cp(converter, semaCtx, clauses); + cp.processNowait(clauseOps); +} + static void genTeamsClauses(lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx, lower::StatementContext &stmtCtx, @@ -1890,6 +1899,22 @@ genTaskyieldOp(lower::AbstractConverter &converter, lower::SymMap &symTable, return converter.getFirOpBuilder().create(loc); } +static mlir::omp::WorkshareOp +genWorkshareOp(lower::AbstractConverter &converter, lower::SymMap &symTable, + semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval, + mlir::Location loc, const ConstructQueue &queue, + ConstructQueue::iterator item) { + lower::StatementContext stmtCtx; + mlir::omp::WorkshareOperands clauseOps; + genWorkshareClauses(converter, semaCtx, stmtCtx, item->clauses, loc, clauseOps); + + return genOpWithBody( + OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval, +llvm::omp::Directive::OMPD_workshare) + .setClauses(&item->clauses), + queue, item, clauseOps); +} + static mlir::omp::TeamsOp genTeamsOp(lower::AbstractConverter &converter, lower::SymMap &symTable, semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval, @@ -2249,10 +2274,7 @@ static void genOMPDispatch(lower::AbstractConverter &converter, llvm::omp::getOpenMPDirectiveName(dir) + ")"); // case llvm::omp::Directive::OMPD_workdistribute: case llvm::omp::Directive::OMPD_workshare: -// FIXME: Workshare is not a commonly used OpenMP construct, an -// implementation for this feature will come later. For the codes -// that use this construct, add a single construct for now. -genSingleOp(converter, symTable, semaCtx, eval, loc, queue, item); +genWorkshareOp(converter, symTable, semaCtx, eval, loc, queue, item); break; // Composite constructs >From 10b7a392916a1dd184c434e41b7be0738c811a38 Mon Sep 17 00:00:00 2001 From: Ivan Radanov Ivanov Date: Sun, 4 Aug 2024 16:02:37 +0900 Subject: [PATCH 2/2] Fix lower test for workshare --- flang/test/Lower/OpenMP/workshare.f90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flang/test/Lower/OpenMP/workshare.f90 b/flang/test/Lower/OpenMP/workshare.f90 index 1e11677a15e1f0..8e771952f5b6da 100644 --- a/flang/test/Lower/OpenMP/workshare.f90 +++ b/flang/test/Lower/OpenMP/workshare.f90 @@ -6,7 +6,7 @@ subroutine sb1(arr) integer :: arr(:) !CHECK: omp.parallel { !$omp parallel -!CHECK: omp.single { +!CHECK: omp.workshare { !$omp workshare arr = 0 !$omp end workshare @@ -20,7 +20,7 @@ subroutine sb2(arr) integer :: arr(:) !CHECK: omp.parallel { !$omp parallel -!CHECK: omp.single nowait { +!CHECK: omp.workshare nowait { !$omp workshare arr = 0 !$omp end workshare nowait @@ -33,7 +33,7 @@ subroutine sb2(arr) subroutine sb3(arr) integer :: arr(:) !CHECK: omp.parallel { -!CHECK: omp.single { +!CHECK: omp.workshare { !$omp parallel workshare arr = 0 !$omp end parallel workshare ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR][omp] Add omp.workshare op (PR #101443)
https://github.com/ivanradanov edited https://github.com/llvm/llvm-project/pull/101443 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][omp] Emit omp.workshare in frontend (PR #101444)
https://github.com/ivanradanov updated https://github.com/llvm/llvm-project/pull/101444 >From 69e85558ec78c7a74be9168b4227bb262f67225e Mon Sep 17 00:00:00 2001 From: Ivan Radanov Ivanov Date: Wed, 31 Jul 2024 14:11:47 +0900 Subject: [PATCH 1/2] [flang][omp] Emit omp.workshare in frontend --- flang/lib/Lower/OpenMP/OpenMP.cpp | 30 ++ 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index 2b1839b5270d4f..f7bc565ea8cbc1 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -1270,6 +1270,15 @@ static void genTaskwaitClauses(lower::AbstractConverter &converter, loc, llvm::omp::Directive::OMPD_taskwait); } +static void genWorkshareClauses(lower::AbstractConverter &converter, +semantics::SemanticsContext &semaCtx, +lower::StatementContext &stmtCtx, +const List &clauses, mlir::Location loc, +mlir::omp::WorkshareOperands &clauseOps) { + ClauseProcessor cp(converter, semaCtx, clauses); + cp.processNowait(clauseOps); +} + static void genTeamsClauses(lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx, lower::StatementContext &stmtCtx, @@ -1890,6 +1899,22 @@ genTaskyieldOp(lower::AbstractConverter &converter, lower::SymMap &symTable, return converter.getFirOpBuilder().create(loc); } +static mlir::omp::WorkshareOp +genWorkshareOp(lower::AbstractConverter &converter, lower::SymMap &symTable, + semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval, + mlir::Location loc, const ConstructQueue &queue, + ConstructQueue::iterator item) { + lower::StatementContext stmtCtx; + mlir::omp::WorkshareOperands clauseOps; + genWorkshareClauses(converter, semaCtx, stmtCtx, item->clauses, loc, clauseOps); + + return genOpWithBody( + OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval, +llvm::omp::Directive::OMPD_workshare) + .setClauses(&item->clauses), + queue, item, clauseOps); +} + static mlir::omp::TeamsOp genTeamsOp(lower::AbstractConverter &converter, lower::SymMap &symTable, semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval, @@ -2249,10 +2274,7 @@ static void genOMPDispatch(lower::AbstractConverter &converter, llvm::omp::getOpenMPDirectiveName(dir) + ")"); // case llvm::omp::Directive::OMPD_workdistribute: case llvm::omp::Directive::OMPD_workshare: -// FIXME: Workshare is not a commonly used OpenMP construct, an -// implementation for this feature will come later. For the codes -// that use this construct, add a single construct for now. -genSingleOp(converter, symTable, semaCtx, eval, loc, queue, item); +genWorkshareOp(converter, symTable, semaCtx, eval, loc, queue, item); break; // Composite constructs >From d17c55249b5d7065721225e62f10fef5e3da4f51 Mon Sep 17 00:00:00 2001 From: Ivan Radanov Ivanov Date: Sun, 4 Aug 2024 16:02:37 +0900 Subject: [PATCH 2/2] Fix lower test for workshare --- flang/test/Lower/OpenMP/workshare.f90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flang/test/Lower/OpenMP/workshare.f90 b/flang/test/Lower/OpenMP/workshare.f90 index 1e11677a15e1f0..8e771952f5b6da 100644 --- a/flang/test/Lower/OpenMP/workshare.f90 +++ b/flang/test/Lower/OpenMP/workshare.f90 @@ -6,7 +6,7 @@ subroutine sb1(arr) integer :: arr(:) !CHECK: omp.parallel { !$omp parallel -!CHECK: omp.single { +!CHECK: omp.workshare { !$omp workshare arr = 0 !$omp end workshare @@ -20,7 +20,7 @@ subroutine sb2(arr) integer :: arr(:) !CHECK: omp.parallel { !$omp parallel -!CHECK: omp.single nowait { +!CHECK: omp.workshare nowait { !$omp workshare arr = 0 !$omp end workshare nowait @@ -33,7 +33,7 @@ subroutine sb2(arr) subroutine sb3(arr) integer :: arr(:) !CHECK: omp.parallel { -!CHECK: omp.single { +!CHECK: omp.workshare { !$omp parallel workshare arr = 0 !$omp end parallel workshare ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [mlir] [MLIR][omp] Add omp.workshare op (PR #101443)
https://github.com/ivanradanov updated https://github.com/llvm/llvm-project/pull/101443 >From e453738aaa1bd74e2462025075ea4ac12868caac Mon Sep 17 00:00:00 2001 From: Ivan Radanov Ivanov Date: Wed, 31 Jul 2024 14:09:09 +0900 Subject: [PATCH 1/7] [MLIR][omp] Add omp.workshare op --- .../Dialect/OpenMP/OpenMPClauseOperands.h | 3 +++ mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 22 +++ mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 13 +++ 3 files changed, 38 insertions(+) diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h index 38e4d8f245e4fa..d14e5e17afbb08 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h @@ -17,6 +17,7 @@ #include "mlir/IR/BuiltinAttributes.h" #include "llvm/ADT/SmallVector.h" +#include #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc" @@ -316,6 +317,8 @@ using TeamsOperands = detail::Clauses; +using WorkshareOperands = detail::Clauses; + using WsloopOperands = detail::Clauses { + let summary = "workshare directive"; + let description = [{ +The workshare construct divides the execution of the enclosed structured +block into separate units of work, and causes the threads of the team to +share the work such that each unit is executed only once by one thread, in +the context of its implicit task + }] # clausesDescription; + + let builders = [ +OpBuilder<(ins CArg<"const WorkshareOperands &">:$clauses)> + ]; + + let hasVerifier = 1; +} + //===--===// // Loop Nest //===--===// diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index 11780f84697b15..9a189eb2059e01 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -1683,6 +1683,19 @@ LogicalResult SingleOp::verify() { getCopyprivateSyms()); } +//===--===// +// WorkshareOp +//===--===// + +void WorkshareOp::build(OpBuilder &builder, OperationState &state, +const WorkshareOperands &clauses) { + WorkshareOp::build(builder, state, clauses.nowait); +} + +LogicalResult WorkshareOp::verify() { + return (*this)->getRegion(0).getBlocks().size() == 1 ? success() : failure(); +} + //===--===// // WsloopOp //===--===// >From 13f5fa2b7628e78b308a3312fd045d87dd89d458 Mon Sep 17 00:00:00 2001 From: Ivan Radanov Ivanov Date: Fri, 2 Aug 2024 16:10:25 +0900 Subject: [PATCH 2/7] Add custom omp loop wrapper --- mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 11 +++ 1 file changed, 11 insertions(+) diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 5199ff50abb959..76f0c472cfdb14 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -308,6 +308,17 @@ def WorkshareOp : OpenMP_Op<"workshare", clauses = [ let hasVerifier = 1; } +def WorkshareLoopWrapperOp : OpenMP_Op<"workshare_loop_wrapper", traits = [ +DeclareOpInterfaceMethods, +RecursiveMemoryEffects, SingleBlock + ], singleRegion = true> { + let summary = "contains loop nests to be parallelized by workshare"; + + let builders = [ +OpBuilder<(ins), [{ build($_builder, $_state, {}); }]> + ]; +} + //===--===// // Loop Nest //===--===// >From f0915f426f03e3e867953de36e68fd0ccaf5b0ed Mon Sep 17 00:00:00 2001 From: Ivan Radanov Ivanov Date: Fri, 2 Aug 2024 16:08:58 +0900 Subject: [PATCH 3/7] Add recursive memory effects trait to workshare --- mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 76f0c472cfdb14..7d1c80333855e7 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -290,7 +290,9 @@ def SingleOp : OpenMP_Op<"single", traits = [ // 2.8.3 Workshare Construct //===--===// -def WorkshareOp : OpenMP_Op<"workshare", clauses = [ +def WorkshareOp : OpenMP_Op<"workshare", traits = [ +RecursiveMemoryEffects, + ], clauses = [ OpenMP_NowaitClause, ], singleRegion = true> { let summar
[llvm-branch-commits] [flang] [flang] Introduce ws loop nest generation for HLFIR lowering (PR #101445)
https://github.com/ivanradanov updated https://github.com/llvm/llvm-project/pull/101445 >From 38c581c8defc81105160a69bb46a9e489b56f10e Mon Sep 17 00:00:00 2001 From: Ivan Radanov Ivanov Date: Wed, 31 Jul 2024 14:12:34 +0900 Subject: [PATCH 1/3] [flang] Introduce ws loop nest generation for HLFIR lowering --- .../flang/Optimizer/Builder/HLFIRTools.h | 12 +++-- flang/lib/Lower/ConvertCall.cpp | 2 +- flang/lib/Lower/OpenMP/ReductionProcessor.cpp | 4 +- flang/lib/Optimizer/Builder/HLFIRTools.cpp| 52 ++- .../HLFIR/Transforms/BufferizeHLFIR.cpp | 3 +- .../LowerHLFIROrderedAssignments.cpp | 30 +-- .../Transforms/OptimizedBufferization.cpp | 6 +-- 7 files changed, 69 insertions(+), 40 deletions(-) diff --git a/flang/include/flang/Optimizer/Builder/HLFIRTools.h b/flang/include/flang/Optimizer/Builder/HLFIRTools.h index 6b41025eea0780..14e42c6f358e46 100644 --- a/flang/include/flang/Optimizer/Builder/HLFIRTools.h +++ b/flang/include/flang/Optimizer/Builder/HLFIRTools.h @@ -357,8 +357,8 @@ hlfir::ElementalOp genElementalOp( /// Structure to describe a loop nest. struct LoopNest { - fir::DoLoopOp outerLoop; - fir::DoLoopOp innerLoop; + mlir::Operation *outerOp; + mlir::Block *body; llvm::SmallVector oneBasedIndices; }; @@ -366,11 +366,13 @@ struct LoopNest { /// \p isUnordered specifies whether the loops in the loop nest /// are unordered. LoopNest genLoopNest(mlir::Location loc, fir::FirOpBuilder &builder, - mlir::ValueRange extents, bool isUnordered = false); + mlir::ValueRange extents, bool isUnordered = false, + bool emitWsLoop = false); inline LoopNest genLoopNest(mlir::Location loc, fir::FirOpBuilder &builder, -mlir::Value shape, bool isUnordered = false) { +mlir::Value shape, bool isUnordered = false, +bool emitWsLoop = false) { return genLoopNest(loc, builder, getIndexExtents(loc, builder, shape), - isUnordered); + isUnordered, emitWsLoop); } /// Inline the body of an hlfir.elemental at the current insertion point diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp index fd873f55dd844e..0689d6e033dd9c 100644 --- a/flang/lib/Lower/ConvertCall.cpp +++ b/flang/lib/Lower/ConvertCall.cpp @@ -2128,7 +2128,7 @@ class ElementalCallBuilder { hlfir::genLoopNest(loc, builder, shape, !mustBeOrdered); mlir::ValueRange oneBasedIndices = loopNest.oneBasedIndices; auto insPt = builder.saveInsertionPoint(); - builder.setInsertionPointToStart(loopNest.innerLoop.getBody()); + builder.setInsertionPointToStart(loopNest.body); callContext.stmtCtx.pushScope(); for (auto &preparedActual : loweredActuals) if (preparedActual) diff --git a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp index c3c1f363033c27..72a90dd0d6f29d 100644 --- a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp @@ -375,7 +375,7 @@ static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc, // know this won't miss any opportuinties for clever elemental inlining hlfir::LoopNest nest = hlfir::genLoopNest( loc, builder, shapeShift.getExtents(), /*isUnordered=*/true); - builder.setInsertionPointToStart(nest.innerLoop.getBody()); + builder.setInsertionPointToStart(nest.body); mlir::Type refTy = fir::ReferenceType::get(seqTy.getEleTy()); auto lhsEleAddr = builder.create( loc, refTy, lhs, shapeShift, /*slice=*/mlir::Value{}, @@ -389,7 +389,7 @@ static void genBoxCombiner(fir::FirOpBuilder &builder, mlir::Location loc, builder, loc, redId, refTy, lhsEle, rhsEle); builder.create(loc, scalarReduction, lhsEleAddr); - builder.setInsertionPointAfter(nest.outerLoop); + builder.setInsertionPointAfter(nest.outerOp); builder.create(loc, lhsAddr); } diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp index 8d0ae2f195178c..cd07cb741eb4bb 100644 --- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp +++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp @@ -20,6 +20,7 @@ #include "mlir/IR/IRMapping.h" #include "mlir/Support/LLVM.h" #include "llvm/ADT/TypeSwitch.h" +#include #include // Return explicit extents. If the base is a fir.box, this won't read it to @@ -855,26 +856,51 @@ mlir::Value hlfir::inlineElementalOp( hlfir::LoopNest hlfir::genLoopNest(mlir::Location loc, fir::FirOpBuilder &builder, - mlir::ValueRange extents, bool isUnordered) { + mlir::ValueRange extents, bool isUnordered, + bool emitWsLoop) { hlfir::LoopNest loopNest; assert(!extents.empty() &&
[llvm-branch-commits] [openmp] [OpenMP][AArch64] Fix branch protection in microtasks (#102317) (PR #103491)
tru wrote: @DanielKristofKiss can you have a look if we want to backport this to 19.x? At this point in the release process we only want to take regressions and serious bugs. It was hard for me to understand if this falls under that. https://github.com/llvm/llvm-project/pull/103491 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits