From 29441e4f5fa5f5c7709f7cf180815ba97f611297 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 29 Jan 2025 16:56:47 +0100 Subject: [IR] Convert from nocapture to captures(none) (#123181) This PR removes the old `nocapture` attribute, replacing it with the new `captures` attribute introduced in #116990. This change is intended to be essentially NFC, replacing existing uses of `nocapture` with `captures(none)` without adding any new analysis capabilities. Making use of non-`none` values is left for a followup. Some notes: * `nocapture` will be upgraded to `captures(none)` by the bitcode reader. * `nocapture` will also be upgraded by the textual IR reader. This is to make it easier to use old IR files and somewhat reduce the test churn in this PR. * Helper APIs like `doesNotCapture()` will check for `captures(none)`. * MLIR import will convert `captures(none)` into an `llvm.nocapture` attribute. The representation in the LLVM IR dialect should be updated separately. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 551dfd4af88b..e16e8a0f4703 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1865,7 +1865,7 @@ static uint64_t getRawAttributeMask(Attribute::AttrKind Val) { case Attribute::StackProtect: return 1 << 14; case Attribute::StackProtectReq: return 1 << 15; case Attribute::Alignment: return 31 << 16; - case Attribute::NoCapture: return 1 << 21; + // 1ULL << 21 is NoCapture, which is upgraded separately. case Attribute::NoRedZone: return 1 << 22; case Attribute::NoImplicitFloat: return 1 << 23; case Attribute::Naked: return 1 << 24; @@ -1986,6 +1986,12 @@ static void decodeLLVMAttributesForBitcode(AttrBuilder &B, B.addMemoryAttr(ME); } + // Upgrade nocapture to captures(none). + if (Attrs & (1ULL << 21)) { + Attrs &= ~(1ULL << 21); + B.addCapturesAttr(CaptureInfo::none()); + } + addRawAttributeValue(B, Attrs); } @@ -2098,8 +2104,6 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) { return Attribute::NoBuiltin; case bitc::ATTR_KIND_NO_CALLBACK: return Attribute::NoCallback; - case bitc::ATTR_KIND_NO_CAPTURE: - return Attribute::NoCapture; case bitc::ATTR_KIND_NO_DIVERGENCE_SOURCE: return Attribute::NoDivergenceSource; case bitc::ATTR_KIND_NO_DUPLICATE: @@ -2349,6 +2353,11 @@ Error BitcodeReader::parseAttributeGroupBlock() { upgradeOldMemoryAttribute(ME, EncodedKind)) continue; + if (EncodedKind == bitc::ATTR_KIND_NO_CAPTURE) { + B.addCapturesAttr(CaptureInfo::none()); + continue; + } + if (Error Err = parseAttrKind(EncodedKind, &Kind)) return Err; -- cgit v1.2.3