From 4dbe82eef34e5ab8a9b0dabdbca194ff6858fc7f Mon Sep 17 00:00:00 2001 From: kuter Date: Sun, 12 Jul 2020 02:23:21 +0300 Subject: [PATCH 1/2] [Attributor] Introudce attribute seed allow list. --- llvm/include/llvm/Transforms/IPO/Attributor.h | 22 +++++++++++++ llvm/lib/Transforms/IPO/Attributor.cpp | 13 ++++++++ llvm/test/Transforms/Attributor/allow_list.ll | 33 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 llvm/test/Transforms/Attributor/allow_list.ll diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h index c6261845b765ac..d2666d4b86827d 100644 --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -891,6 +891,13 @@ struct Attributor { // No matching attribute found, create one. // Use the static create method. auto &AA = AAType::createForPosition(IRP, *this); + + // If we are currenty seeding attributes, enforce seeding rules. + if (SeedingPeriod && !shouldSeedAttribute(AA)) { + AA.getState().indicatePessimisticFixpoint(); + return AA; + } + registerAA(AA); // For now we ignore naked and optnone functions. @@ -918,8 +925,15 @@ struct Attributor { return AA; } + // Allow seeded attributes to declare dependencies. + // Remember the seeding state. + bool OldSeedingPeriod = SeedingPeriod; + SeedingPeriod = false; + updateAA(AA); + SeedingPeriod = OldSeedingPeriod; + if (TrackDependence && AA.getState().isValidState()) recordDependence(AA, const_cast(*QueryingAA), DepClass); @@ -1345,6 +1359,10 @@ struct Attributor { ChangeStatus rewriteFunctionSignatures(SmallPtrSetImpl &ModifiedFns); + /// Check if the Attribute \p AA should be seeded. + /// See getOrCreateAAFor. + bool shouldSeedAttribute(AbstractAttribute &AA); + /// The set of all abstract attributes. ///{ using AAVector = SmallVector; @@ -1410,6 +1428,10 @@ struct Attributor { /// Invoke instructions with at least a single dead successor block. SmallVector InvokeWithDeadSuccessor; + /// Wheather attributes are being `seeded`, always false after ::run function + /// gets called \see getOrCreateAAFor. + bool SeedingPeriod = true; + /// Functions, blocks, and instructions we delete after manifest is done. /// ///{ diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 7f252079e05326..6e5625d26c38b3 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -78,6 +78,12 @@ static cl::opt "wrappers for non-exact definitions."), cl::init(false)); +static cl::list + SeedAllowList("attributor-seed-allow-list", cl::Hidden, + cl::desc("Comma seperated list of attrbute names that are " + "allowed to be seeded."), + cl::ZeroOrMore, cl::CommaSeparated); + /// Logic operators for the change status enum class. /// ///{ @@ -1256,6 +1262,7 @@ ChangeStatus Attributor::cleanupIR() { } ChangeStatus Attributor::run() { + SeedingPeriod = false; runTillFixpoint(); ChangeStatus ManifestChange = manifestAttributes(); ChangeStatus CleanupChange = cleanupIR(); @@ -1452,6 +1459,12 @@ bool Attributor::registerFunctionSignatureRewrite( return true; } +bool Attributor::shouldSeedAttribute(AbstractAttribute &AA) { + if (SeedAllowList.size() == 0) + return true; + return std::count(SeedAllowList.begin(), SeedAllowList.end(), AA.getName()); +} + ChangeStatus Attributor::rewriteFunctionSignatures( SmallPtrSetImpl &ModifiedFns) { ChangeStatus Changed = ChangeStatus::UNCHANGED; diff --git a/llvm/test/Transforms/Attributor/allow_list.ll b/llvm/test/Transforms/Attributor/allow_list.ll new file mode 100644 index 00000000000000..7670090cb03b7f --- /dev/null +++ b/llvm/test/Transforms/Attributor/allow_list.ll @@ -0,0 +1,33 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes +; RUN: opt -S -passes=attributor --attributor-seed-allow-list asd < %s | FileCheck %s --check-prefixes=CHECK_DISABLED +; RUN: opt -S -passes=attributor --attributor-seed-allow-list AAValueSimplify < %s | FileCheck %s --check-prefixes=CHECK_ENABLED + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +; Function Attrs: nounwind uwtable +define internal i32 @range_test(i32 %a) #0 { +; CHECK_DISABLED-LABEL: define {{[^@]+}}@range_test +; CHECK_DISABLED-SAME: (i32 [[A:%.*]]) +; CHECK_DISABLED-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A]], 100 +; CHECK_DISABLED-NEXT: [[TMP2:%.*]] = zext i1 [[TMP1]] to i32 +; CHECK_DISABLED-NEXT: ret i32 [[TMP2]] +; + %1 = icmp sgt i32 %a, 100 + %2 = zext i1 %1 to i32 + ret i32 %2 +} + +; Function Attrs: nounwind uwtable +define i32 @range_use() #0 { +; CHECK_DISABLED-LABEL: define {{[^@]+}}@range_use() +; CHECK_DISABLED-NEXT: [[TMP1:%.*]] = call i32 @range_test(i32 123) +; CHECK_DISABLED-NEXT: ret i32 [[TMP1]] +; +; CHECK_ENABLED-LABEL: define {{[^@]+}}@range_use() +; CHECK_ENABLED-NEXT: ret i32 1 +; + %1 = call i32 @range_test(i32 123) + ret i32 %1 +} + +attributes #0 = { nounwind uwtable noinline } \ No newline at end of file From d1bcddb5c1fe7135e712b0e08874ed64c70f3e49 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 11 Jul 2020 16:44:34 -0700 Subject: [PATCH 2/2] [llvm-objdump][test] Move tests after dc4a6f5db4f0178bae43ef615cc8902c759d6195 Move RISCV/ to ELF/RISCV/ as well. --- llvm/test/tools/llvm-objdump/ARM/lit.local.cfg | 2 -- llvm/test/tools/llvm-objdump/{ => ELF}/ARM/Inputs/debug.c | 0 llvm/test/tools/llvm-objdump/{ => ELF}/ARM/Inputs/wide-char.c | 0 .../llvm-objdump/{ => ELF}/ARM/debug-vars-dwarf4-sections.s | 0 llvm/test/tools/llvm-objdump/{ => ELF}/ARM/debug-vars-dwarf4.s | 0 .../llvm-objdump/{ => ELF}/ARM/debug-vars-dwarf5-sections.s | 0 llvm/test/tools/llvm-objdump/{ => ELF}/ARM/debug-vars-dwarf5.s | 0 .../tools/llvm-objdump/{ => ELF}/ARM/debug-vars-wide-chars.s | 0 llvm/test/tools/llvm-objdump/{ => ELF}/PowerPC/debug-vars.s | 0 llvm/test/tools/llvm-objdump/{ => ELF}/RISCV/lit.local.cfg | 0 .../tools/llvm-objdump/{ => ELF}/RISCV/unknown-arch-attr.test | 0 llvm/test/tools/llvm-objdump/PowerPC/lit.local.cfg | 2 -- 12 files changed, 4 deletions(-) delete mode 100644 llvm/test/tools/llvm-objdump/ARM/lit.local.cfg rename llvm/test/tools/llvm-objdump/{ => ELF}/ARM/Inputs/debug.c (100%) rename llvm/test/tools/llvm-objdump/{ => ELF}/ARM/Inputs/wide-char.c (100%) rename llvm/test/tools/llvm-objdump/{ => ELF}/ARM/debug-vars-dwarf4-sections.s (100%) rename llvm/test/tools/llvm-objdump/{ => ELF}/ARM/debug-vars-dwarf4.s (100%) rename llvm/test/tools/llvm-objdump/{ => ELF}/ARM/debug-vars-dwarf5-sections.s (100%) rename llvm/test/tools/llvm-objdump/{ => ELF}/ARM/debug-vars-dwarf5.s (100%) rename llvm/test/tools/llvm-objdump/{ => ELF}/ARM/debug-vars-wide-chars.s (100%) rename llvm/test/tools/llvm-objdump/{ => ELF}/PowerPC/debug-vars.s (100%) rename llvm/test/tools/llvm-objdump/{ => ELF}/RISCV/lit.local.cfg (100%) rename llvm/test/tools/llvm-objdump/{ => ELF}/RISCV/unknown-arch-attr.test (100%) delete mode 100644 llvm/test/tools/llvm-objdump/PowerPC/lit.local.cfg diff --git a/llvm/test/tools/llvm-objdump/ARM/lit.local.cfg b/llvm/test/tools/llvm-objdump/ARM/lit.local.cfg deleted file mode 100644 index 236e1d34416659..00000000000000 --- a/llvm/test/tools/llvm-objdump/ARM/lit.local.cfg +++ /dev/null @@ -1,2 +0,0 @@ -if not 'ARM' in config.root.targets: - config.unsupported = True diff --git a/llvm/test/tools/llvm-objdump/ARM/Inputs/debug.c b/llvm/test/tools/llvm-objdump/ELF/ARM/Inputs/debug.c similarity index 100% rename from llvm/test/tools/llvm-objdump/ARM/Inputs/debug.c rename to llvm/test/tools/llvm-objdump/ELF/ARM/Inputs/debug.c diff --git a/llvm/test/tools/llvm-objdump/ARM/Inputs/wide-char.c b/llvm/test/tools/llvm-objdump/ELF/ARM/Inputs/wide-char.c similarity index 100% rename from llvm/test/tools/llvm-objdump/ARM/Inputs/wide-char.c rename to llvm/test/tools/llvm-objdump/ELF/ARM/Inputs/wide-char.c diff --git a/llvm/test/tools/llvm-objdump/ARM/debug-vars-dwarf4-sections.s b/llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4-sections.s similarity index 100% rename from llvm/test/tools/llvm-objdump/ARM/debug-vars-dwarf4-sections.s rename to llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4-sections.s diff --git a/llvm/test/tools/llvm-objdump/ARM/debug-vars-dwarf4.s b/llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s similarity index 100% rename from llvm/test/tools/llvm-objdump/ARM/debug-vars-dwarf4.s rename to llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf4.s diff --git a/llvm/test/tools/llvm-objdump/ARM/debug-vars-dwarf5-sections.s b/llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf5-sections.s similarity index 100% rename from llvm/test/tools/llvm-objdump/ARM/debug-vars-dwarf5-sections.s rename to llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf5-sections.s diff --git a/llvm/test/tools/llvm-objdump/ARM/debug-vars-dwarf5.s b/llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf5.s similarity index 100% rename from llvm/test/tools/llvm-objdump/ARM/debug-vars-dwarf5.s rename to llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-dwarf5.s diff --git a/llvm/test/tools/llvm-objdump/ARM/debug-vars-wide-chars.s b/llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-wide-chars.s similarity index 100% rename from llvm/test/tools/llvm-objdump/ARM/debug-vars-wide-chars.s rename to llvm/test/tools/llvm-objdump/ELF/ARM/debug-vars-wide-chars.s diff --git a/llvm/test/tools/llvm-objdump/PowerPC/debug-vars.s b/llvm/test/tools/llvm-objdump/ELF/PowerPC/debug-vars.s similarity index 100% rename from llvm/test/tools/llvm-objdump/PowerPC/debug-vars.s rename to llvm/test/tools/llvm-objdump/ELF/PowerPC/debug-vars.s diff --git a/llvm/test/tools/llvm-objdump/RISCV/lit.local.cfg b/llvm/test/tools/llvm-objdump/ELF/RISCV/lit.local.cfg similarity index 100% rename from llvm/test/tools/llvm-objdump/RISCV/lit.local.cfg rename to llvm/test/tools/llvm-objdump/ELF/RISCV/lit.local.cfg diff --git a/llvm/test/tools/llvm-objdump/RISCV/unknown-arch-attr.test b/llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test similarity index 100% rename from llvm/test/tools/llvm-objdump/RISCV/unknown-arch-attr.test rename to llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test diff --git a/llvm/test/tools/llvm-objdump/PowerPC/lit.local.cfg b/llvm/test/tools/llvm-objdump/PowerPC/lit.local.cfg deleted file mode 100644 index 091332439b1867..00000000000000 --- a/llvm/test/tools/llvm-objdump/PowerPC/lit.local.cfg +++ /dev/null @@ -1,2 +0,0 @@ -if not 'PowerPC' in config.root.targets: - config.unsupported = True