From c4f8ae6f32dadf9383c94ed13152d91f68631255 Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov <6532716+alexander-shaposhnikov@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:53:22 -0700 Subject: [LLVM][IR][Sanitizers] Add sanitize_numerical_stability attribute (#95051) Add sanitize_numerical_stability attribute. --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 35ea3c11396e..b08d5c50e5ae 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -828,6 +828,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) { return bitc::ATTR_KIND_SANITIZE_THREAD; case Attribute::SanitizeMemory: return bitc::ATTR_KIND_SANITIZE_MEMORY; + case Attribute::SanitizeNumericalStability: + return bitc::ATTR_KIND_SANITIZE_NUMERICAL_STABILITY; case Attribute::SpeculativeLoadHardening: return bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING; case Attribute::SwiftError: -- cgit v1.2.3 From 3ca17443ef4af21bdb1f3b4fbcfff672cbc6176c Mon Sep 17 00:00:00 2001 From: eddyz87 Date: Tue, 18 Jun 2024 10:23:25 +0300 Subject: [DebugInfo][BPF] Add 'annotations' field for DIBasicType & DISubroutineType (#91422) Extend `DIBasicType` and `DISubroutineType` with additional field `annotations`, e.g. as below: ``` !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed, annotations: !6) !6 = !{!7} !7 = !{!"btf:type_tag", !"tag1"} ``` The field would be used by BPF backend to generate DWARF attributes corresponding to `btf_type_tag` type attributes, e.g.: ``` 0x00000029: DW_TAG_base_type DW_AT_name ("int") DW_AT_encoding (DW_ATE_signed) DW_AT_byte_size (0x04) 0x0000002d: DW_TAG_LLVM_annotation DW_AT_name ("btf:type_tag") DW_AT_const_value ("tag1") ``` Such DWARF entries would be used to generate BTF definitions by tools like [pahole](https://github.com/acmel/dwarves). Note: similar fields with similar purposes are already present in DIDerivedType and DICompositeType. Currently "btf_type_tag" attributes are represented in debug information as 'annotations' fields in DIDerivedType with DW_TAG_pointer_type tag. The annotation on a pointer corresponds to pointee having the attributes in the final BTF. The discussion in [thread](https://lore.kernel.org/bpf/87r0w9jjoq.fsf@oracle.com/) came to conclusion, that such annotations should apply to the annotated type itself. Hence the necessity to extend `DIBasicType` & `DISubroutineType` types with 'annotations' field to represent cases like below: ``` int __attribute__((btf_type_tag("foo"))) bar; ``` This was previously tracked as differential revision: https://reviews.llvm.org/D143966 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index b08d5c50e5ae..f3e87310310e 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1816,6 +1816,7 @@ void ModuleBitcodeWriter::writeDIBasicType(const DIBasicType *N, Record.push_back(N->getAlignInBits()); Record.push_back(N->getEncoding()); Record.push_back(N->getFlags()); + Record.push_back(VE.getMetadataOrNullID(N->getRawAnnotations())); Stream.EmitRecord(bitc::METADATA_BASIC_TYPE, Record, Abbrev); Record.clear(); @@ -1911,6 +1912,7 @@ void ModuleBitcodeWriter::writeDISubroutineType( Record.push_back(N->getFlags()); Record.push_back(VE.getMetadataOrNullID(N->getTypeArray().get())); Record.push_back(N->getCC()); + Record.push_back(VE.getMetadataOrNullID(N->getRawAnnotations())); Stream.EmitRecord(bitc::METADATA_SUBROUTINE_TYPE, Record, Abbrev); Record.clear(); -- cgit v1.2.3 From 01ce74fe14fb98af42a3f2f7c8c6b04487761cf1 Mon Sep 17 00:00:00 2001 From: eddyz87 Date: Thu, 20 Jun 2024 21:28:02 +0300 Subject: =?UTF-8?q?Revert=20"[DebugInfo][BPF]=20Add=20'annotations'=20fiel?= =?UTF-8?q?d=20for=20DIBasicType=20&=20DI=E2=80=A6=20(#96172)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …SubroutineType (#91422)" This reverts commit 3ca17443ef4af21bdb1f3b4fbcfff672cbc6176c. As reported in [1,2] the commit above causes CI failure for powerpc-aix target. There is also a performance regression reported in [3]. Reverting to comply with the developer policy. [1] https://github.com/llvm/llvm-project/pull/91422#issuecomment-2179425473 [2] https://lab.llvm.org/buildbot/#/builders/64/builds/62 [3] https://github.com/llvm/llvm-project/pull/91422#issuecomment-2175631443 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index f3e87310310e..b08d5c50e5ae 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1816,7 +1816,6 @@ void ModuleBitcodeWriter::writeDIBasicType(const DIBasicType *N, Record.push_back(N->getAlignInBits()); Record.push_back(N->getEncoding()); Record.push_back(N->getFlags()); - Record.push_back(VE.getMetadataOrNullID(N->getRawAnnotations())); Stream.EmitRecord(bitc::METADATA_BASIC_TYPE, Record, Abbrev); Record.clear(); @@ -1912,7 +1911,6 @@ void ModuleBitcodeWriter::writeDISubroutineType( Record.push_back(N->getFlags()); Record.push_back(VE.getMetadataOrNullID(N->getTypeArray().get())); Record.push_back(N->getCC()); - Record.push_back(VE.getMetadataOrNullID(N->getRawAnnotations())); Stream.EmitRecord(bitc::METADATA_SUBROUTINE_TYPE, Record, Abbrev); Record.clear(); -- cgit v1.2.3 From 5ece35df8586d0cb8c104a9f44eaae771de025f5 Mon Sep 17 00:00:00 2001 From: Haopeng Liu <153236845+haopliu@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:09:00 -0700 Subject: Add the 'initializes' attribute langref and support (#84803) We propose adding a new LLVM attribute, `initializes((Lo1,Hi1),(Lo2,Hi2),...)`, which expresses the notion of memory space (i.e., intervals, in bytes) that the argument pointing to is initialized in the function. Will commit the attribute inferring in the follow-up PRs. https://discourse.llvm.org/t/rfc-llvm-new-initialized-parameter-attribute-for-improved-interprocedural-dse/77337 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index b08d5c50e5ae..ba16c0851e1f 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -33,6 +33,7 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Comdat.h" #include "llvm/IR/Constant.h" +#include "llvm/IR/ConstantRangeList.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DebugLoc.h" @@ -870,6 +871,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) { return bitc::ATTR_KIND_DEAD_ON_UNWIND; case Attribute::Range: return bitc::ATTR_KIND_RANGE; + case Attribute::Initializes: + return bitc::ATTR_KIND_INITIALIZES; case Attribute::EndAttrKinds: llvm_unreachable("Can not encode end-attribute kinds marker."); case Attribute::None: @@ -901,9 +904,10 @@ static void emitWideAPInt(SmallVectorImpl &Vals, const APInt &A) { } static void emitConstantRange(SmallVectorImpl &Record, - const ConstantRange &CR) { + const ConstantRange &CR, bool EmitBitWidth) { unsigned BitWidth = CR.getBitWidth(); - Record.push_back(BitWidth); + if (EmitBitWidth) + Record.push_back(BitWidth); if (BitWidth > 64) { Record.push_back(CR.getLower().getActiveWords() | (uint64_t(CR.getUpper().getActiveWords()) << 32)); @@ -954,11 +958,20 @@ void ModuleBitcodeWriter::writeAttributeGroupTable() { Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum())); if (Ty) Record.push_back(VE.getTypeID(Attr.getValueAsType())); - } else { - assert(Attr.isConstantRangeAttribute()); + } else if (Attr.isConstantRangeAttribute()) { Record.push_back(7); Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum())); - emitConstantRange(Record, Attr.getValueAsConstantRange()); + emitConstantRange(Record, Attr.getValueAsConstantRange(), + /*EmitBitWidth=*/true); + } else { + assert(Attr.isConstantRangeListAttribute()); + Record.push_back(8); + Record.push_back(getAttrKindEncoding(Attr.getKindAsEnum())); + ArrayRef Val = Attr.getValueAsConstantRangeList(); + Record.push_back(Val.size()); + Record.push_back(Val[0].getBitWidth()); + for (auto &CR : Val) + emitConstantRange(Record, CR, /*EmitBitWidth=*/false); } } @@ -2788,7 +2801,7 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal, Record.push_back(getOptimizationFlags(GO)); if (std::optional Range = GO->getInRange()) { Code = bitc::CST_CODE_CE_GEP_WITH_INRANGE; - emitConstantRange(Record, *Range); + emitConstantRange(Record, *Range, /*EmitBitWidth=*/true); } for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) { Record.push_back(VE.getTypeID(C->getOperand(i)->getType())); -- cgit v1.2.3 From 9acb533c38be833ec1d8daa06e127a9de8f0a5ef Mon Sep 17 00:00:00 2001 From: Alex Voicu Date: Tue, 25 Jun 2024 12:19:28 +0100 Subject: [clang][Driver] Add HIPAMD Driver support for AMDGCN flavoured SPIR-V (#95061) This patch augments the HIPAMD driver to allow it to target AMDGCN flavoured SPIR-V compilation. It's mostly straightforward, as we re-use some of the existing SPIRV infra, however there are a few notable additions: - we introduce an `amdgcnspirv` offload arch, rather than relying on using `generic` (this is already fairly overloaded) or simply using `spirv` or `spirv64` (we'll want to use these to denote unflavoured SPIRV, once we bring up that capability) - initially it is won't be possible to mix-in SPIR-V and concrete AMDGPU targets, as it would require some relatively intrusive surgery in the HIPAMD Toolchain and the Driver to deal with two triples (`spirv64-amd-amdhsa` and `amdgcn-amd-amdhsa`, respectively) - in order to retain user provided compiler flags and have them available at JIT time, we rely on embedding the command line via `-fembed-bitcode=marker`, which the bitcode writer had previously not implemented for SPIRV; we only allow it conditionally for AMDGCN flavoured SPIRV, and it is handled correctly by the Translator (it ends up as a string literal) Once the SPIRV BE is no longer experimental we'll switch to using that rather than the translator. There's some additional work that'll come via a separate PR around correctly piping through AMDGCN's implementation of `printf`, for now we merely handle its flags correctly. --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index ba16c0851e1f..7a228fb6c08b 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -5309,6 +5309,8 @@ static const char *getSectionNameForBitcode(const Triple &T) { llvm_unreachable("GOFF is not yet implemented"); break; case Triple::SPIRV: + if (T.getVendor() == Triple::AMD) + return ".llvmbc"; llvm_unreachable("SPIRV is not yet implemented"); break; case Triple::XCOFF: @@ -5334,6 +5336,8 @@ static const char *getSectionNameForCommandline(const Triple &T) { llvm_unreachable("GOFF is not yet implemented"); break; case Triple::SPIRV: + if (T.getVendor() == Triple::AMD) + return ".llvmcmd"; llvm_unreachable("SPIRV is not yet implemented"); break; case Triple::XCOFF: -- cgit v1.2.3