[llvm-branch-commits] [polly] [Polly] Introduce PhaseManager and remove LPM support (PR #125442)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/125442 ___ 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] [polly] [Polly] Introduce PhaseManager and remove LPM support (PR #125442)
@@ -0,0 +1,419 @@ +//===-- PhaseManager.cpp *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "polly/Pass/PhaseManager.h" +#include "polly/CodeGen/CodeGeneration.h" +#include "polly/CodeGen/IslAst.h" +#include "polly/CodePreparation.h" +#include "polly/DeLICM.h" +#include "polly/DeadCodeElimination.h" +#include "polly/DependenceInfo.h" +#include "polly/FlattenSchedule.h" +#include "polly/ForwardOpTree.h" +#include "polly/JSONExporter.h" +#include "polly/MaximalStaticExpansion.h" +#include "polly/PruneUnprofitable.h" +#include "polly/ScheduleOptimizer.h" +#include "polly/ScopDetection.h" +#include "polly/ScopDetectionDiagnostic.h" +#include "polly/ScopGraphPrinter.h" +#include "polly/ScopInfo.h" +#include "polly/Simplify.h" +#include "llvm/Analysis/AssumptionCache.h" +#include "llvm/Analysis/OptimizationRemarkEmitter.h" +#include "llvm/IR/Module.h" + +#define DEBUG_TYPE "polly-pass" + +using namespace polly; +using namespace llvm; + +namespace { + +/// Recurse through all subregions and all regions and add them to RQ. +static void addRegionIntoQueue(Region &R, SmallVector &RQ) { + RQ.push_back(&R); + for (const auto &E : R) +addRegionIntoQueue(*E, RQ); +} + +/// The phase pipeline of Polly to be embedded into another pass manager than +/// runs passes on functions. +/// +/// Polly holds state besides LLVM-IR (RegionInfo and ScopInfo) between phases +/// that LLVM pass managers do not consider when scheduling analyses and passes. +/// That is, the ScopInfo must persist between phases that a pass manager must +/// not invalidate to recompute later. +class PhaseManager { +private: + Function &F; + FunctionAnalysisManager &FAM; + PollyPassOptions Opts; + +public: + PhaseManager(Function &F, FunctionAnalysisManager &FAM, PollyPassOptions Opts) + : F(F), FAM(FAM), Opts(std::move(Opts)) {} + + /// Execute Polly's phases as indicated by the options. + bool run() { +// Get analyses from the function pass manager. +// These must be preserved during all phases so that if processing one SCoP +// has finished, the next SCoP can still use them. Recomputing is not an +// option because ScopDetection stores references to the old results. +// TODO: CodePreparation doesn't actually need these analysis, it just keeps +// them up-to-date. If they are not computed yet, can also compute after the +// prepare phase. +auto &LI = FAM.getResult(F); +auto &DT = FAM.getResult(F); +bool ModifiedIR = false; + +// Phase: prepare +// TODO: Setting ModifiedIR will invalidate any anlysis, even if DT, LI are +// preserved. +if (Opts.isPhaseEnabled(PassPhase::Prepare)) + ModifiedIR |= runCodePreparation(F, &DT, &LI, nullptr); + +// Can't do anything without detection +if (!Opts.isPhaseEnabled(PassPhase::Detection)) + return false; + +auto &AA = FAM.getResult(F); +auto &SE = FAM.getResult(F); +auto &ORE = FAM.getResult(F); + +// ScopDetection is modifying RegionInfo, do not cache it, nor use a cached +// version. +RegionInfo RI = RegionInfoAnalysis().run(F, FAM); + +// Phase: detection +ScopDetection SD(DT, SE, LI, RI, AA, ORE); +SD.detect(F); +if (Opts.isPhaseEnabled(PassPhase::PrintDetect)) { + outs() << "Detected Scops in Function " << F.getName() << "\n"; + for (const Region *R : SD.ValidRegions) +outs() << "Valid Region for Scop: " << R->getNameStr() << '\n'; + outs() << "\n"; +} + +if (Opts.isPhaseEnabled(PassPhase::DotScops)) + printGraphForFunction(F, &SD, "scops", false); +if (Opts.isPhaseEnabled(PassPhase::DotScopsOnly)) + printGraphForFunction(F, &SD, "scopsonly", true); + +auto ViewScops = [&](const char *Name, bool IsSimply) { + if (Opts.ViewFilter.empty() && !F.getName().count(Opts.ViewFilter)) +return; + + if (Opts.ViewAll || std::distance(SD.begin(), SD.end()) > 0) +viewGraphForFunction(F, &SD, Name, IsSimply); +}; +if (Opts.isPhaseEnabled(PassPhase::ViewScops)) + ViewScops("scops", false); +if (Opts.isPhaseEnabled(PassPhase::ViewScopsOnly)) + ViewScops("scopsonly", true); + +// Phase: scops +auto &AC = FAM.getResult(F); +const DataLayout &DL = F.getParent()->getDataLayout(); +ScopInfo Info(DL, SD, SE, LI, AA, DT, AC, ORE); Meinersbur wrote: Can you clarify? ScopS there iterated over twice: 1. For `-print-scops`: This PR's code reuses the LPM did: https://github.com/llvm/llvm-project/blob/5a91ecf5f004d9defce3ba5f7b08015a1f2073f9/polly/lib/Pass/PhaseManager.cpp#L131 vs https://github.com/llvm/llvm-project/blob/4504e775509483ec20912bc1d8057
[llvm-branch-commits] [polly] [Polly] Introduce PhaseManager and remove LPM support (PR #125442)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/125442 ___ 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] [clang-tools-extra] [clang-doc] Extract Info into JSON values (PR #138063)
@@ -162,15 +162,264 @@ Error MustacheHTMLGenerator::generateDocs( return Error::success(); } +static json::Value +extractValue(const Location &L, + std::optional RepositoryUrl = std::nullopt) { + Object Obj = Object(); + // Should there be Start/End line numbers? evelez7 wrote: outdated comment? ```suggestion ``` https://github.com/llvm/llvm-project/pull/138063 ___ 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] [clang-tools-extra] [clang-doc] Extract Info into JSON values (PR #138063)
@@ -162,15 +162,264 @@ Error MustacheHTMLGenerator::generateDocs( return Error::success(); } +static json::Value +extractValue(const Location &L, + std::optional RepositoryUrl = std::nullopt) { + Object Obj = Object(); + // Should there be Start/End line numbers? + Obj.insert({"LineNumber", L.StartLineNumber}); + Obj.insert({"Filename", L.Filename}); + + if (!L.IsFileInRootDir || !RepositoryUrl) +return Obj; + SmallString<128> FileURL(*RepositoryUrl); + sys::path::append(FileURL, sys::path::Style::posix, L.Filename); + FileURL += "#" + std::to_string(L.StartLineNumber); + Obj.insert({"FileURL", FileURL}); + + return Obj; +} + +static json::Value extractValue(const Reference &I, +StringRef CurrentDirectory) { + SmallString<64> Path = I.getRelativeFilePath(CurrentDirectory); + sys::path::append(Path, I.getFileBaseName() + ".html"); + sys::path::native(Path, sys::path::Style::posix); + Object Obj = Object(); + Obj.insert({"Link", Path}); + Obj.insert({"Name", I.Name}); + Obj.insert({"QualName", I.QualName}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + return Obj; +} + +static json::Value extractValue(const TypedefInfo &I) { + // Not Supported + return nullptr; +} + +static json::Value extractValue(const CommentInfo &I) { + assert((I.Kind == "BlockCommandComment" || I.Kind == "FullComment" || + I.Kind == "ParagraphComment" || I.Kind == "TextComment") && + "Unknown Comment type in CommentInfo."); + + Object Obj = Object(); + json::Value Child = Object(); + + // TextComment has no children, so return it. + if (I.Kind == "TextComment") { +Obj.insert({"TextComment", I.Text}); +return Obj; + } + + // BlockCommandComment needs to generate a Command key. + if (I.Kind == "BlockCommandComment") +Child.getAsObject()->insert({"Command", I.Name}); + + // Use the same handling for everything else. + // Only valid for: + // - BlockCommandComment + // - FullComment + // - ParagraphComment + json::Value ChildArr = Array(); + auto &CARef = *ChildArr.getAsArray(); + CARef.reserve(I.Children.size()); + for (const auto &C : I.Children) +CARef.emplace_back(extractValue(*C)); + Child.getAsObject()->insert({"Children", ChildArr}); + Obj.insert({I.Kind, Child}); + + return Obj; +} + +static void maybeInsertLocation(std::optional Loc, +const ClangDocContext &CDCtx, Object &Obj) { + if (!Loc) +return; + Location L = *Loc; + Obj.insert({"Location", extractValue(L, CDCtx.RepositoryUrl)}); +} + +static void extractDescriptionFromInfo(ArrayRef Descriptions, + json::Object &EnumValObj) { + if (Descriptions.empty()) +return; + json::Value ArrDesc = Array(); + json::Array &ADescRef = *ArrDesc.getAsArray(); + for (const CommentInfo &Child : Descriptions) +ADescRef.emplace_back(extractValue(Child)); + EnumValObj.insert({"EnumValueComments", ArrDesc}); +} + +static json::Value extractValue(const FunctionInfo &I, StringRef ParentInfoDir, +const ClangDocContext &CDCtx) { + Object Obj = Object(); + Obj.insert({"Name", I.Name}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + Obj.insert({"Access", getAccessSpelling(I.Access).str()}); + Obj.insert({"ReturnType", extractValue(I.ReturnType.Type, ParentInfoDir)}); + + json::Value ParamArr = Array(); + for (const auto Val : enumerate(I.Params)) { +json::Value V = Object(); +auto &VRef = *V.getAsObject(); +VRef.insert({"Name", Val.value().Name}); +VRef.insert({"Type", Val.value().Type.Name}); +VRef.insert({"End", Val.index() + 1 == I.Params.size()}); +ParamArr.getAsArray()->emplace_back(V); evelez7 wrote: nit?: Not using the same pattern here as elsewhere where an Array reference is created to `emplace_back` values. I'm assuming the pattern is to not use `getAsArray` so much. https://github.com/llvm/llvm-project/pull/138063 ___ 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] [clang-tools-extra] [clang-doc] Extract Info into JSON values (PR #138063)
@@ -162,15 +162,264 @@ Error MustacheHTMLGenerator::generateDocs( return Error::success(); } +static json::Value +extractValue(const Location &L, + std::optional RepositoryUrl = std::nullopt) { + Object Obj = Object(); + // Should there be Start/End line numbers? + Obj.insert({"LineNumber", L.StartLineNumber}); + Obj.insert({"Filename", L.Filename}); + + if (!L.IsFileInRootDir || !RepositoryUrl) +return Obj; + SmallString<128> FileURL(*RepositoryUrl); + sys::path::append(FileURL, sys::path::Style::posix, L.Filename); + FileURL += "#" + std::to_string(L.StartLineNumber); + Obj.insert({"FileURL", FileURL}); + + return Obj; +} + +static json::Value extractValue(const Reference &I, +StringRef CurrentDirectory) { + SmallString<64> Path = I.getRelativeFilePath(CurrentDirectory); + sys::path::append(Path, I.getFileBaseName() + ".html"); + sys::path::native(Path, sys::path::Style::posix); + Object Obj = Object(); + Obj.insert({"Link", Path}); + Obj.insert({"Name", I.Name}); + Obj.insert({"QualName", I.QualName}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + return Obj; +} + +static json::Value extractValue(const TypedefInfo &I) { + // Not Supported + return nullptr; +} + +static json::Value extractValue(const CommentInfo &I) { + assert((I.Kind == "BlockCommandComment" || I.Kind == "FullComment" || + I.Kind == "ParagraphComment" || I.Kind == "TextComment") && + "Unknown Comment type in CommentInfo."); + + Object Obj = Object(); + json::Value Child = Object(); + + // TextComment has no children, so return it. + if (I.Kind == "TextComment") { +Obj.insert({"TextComment", I.Text}); +return Obj; + } + + // BlockCommandComment needs to generate a Command key. + if (I.Kind == "BlockCommandComment") +Child.getAsObject()->insert({"Command", I.Name}); + + // Use the same handling for everything else. + // Only valid for: + // - BlockCommandComment + // - FullComment + // - ParagraphComment + json::Value ChildArr = Array(); + auto &CARef = *ChildArr.getAsArray(); + CARef.reserve(I.Children.size()); + for (const auto &C : I.Children) +CARef.emplace_back(extractValue(*C)); + Child.getAsObject()->insert({"Children", ChildArr}); + Obj.insert({I.Kind, Child}); + + return Obj; +} + +static void maybeInsertLocation(std::optional Loc, +const ClangDocContext &CDCtx, Object &Obj) { + if (!Loc) +return; + Location L = *Loc; + Obj.insert({"Location", extractValue(L, CDCtx.RepositoryUrl)}); +} + +static void extractDescriptionFromInfo(ArrayRef Descriptions, + json::Object &EnumValObj) { + if (Descriptions.empty()) +return; + json::Value ArrDesc = Array(); + json::Array &ADescRef = *ArrDesc.getAsArray(); + for (const CommentInfo &Child : Descriptions) +ADescRef.emplace_back(extractValue(Child)); + EnumValObj.insert({"EnumValueComments", ArrDesc}); +} + +static json::Value extractValue(const FunctionInfo &I, StringRef ParentInfoDir, +const ClangDocContext &CDCtx) { + Object Obj = Object(); + Obj.insert({"Name", I.Name}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + Obj.insert({"Access", getAccessSpelling(I.Access).str()}); + Obj.insert({"ReturnType", extractValue(I.ReturnType.Type, ParentInfoDir)}); + + json::Value ParamArr = Array(); + for (const auto Val : enumerate(I.Params)) { +json::Value V = Object(); +auto &VRef = *V.getAsObject(); +VRef.insert({"Name", Val.value().Name}); +VRef.insert({"Type", Val.value().Type.Name}); +VRef.insert({"End", Val.index() + 1 == I.Params.size()}); +ParamArr.getAsArray()->emplace_back(V); + } + Obj.insert({"Params", ParamArr}); + + maybeInsertLocation(I.DefLoc, CDCtx, Obj); + return Obj; +} + +static json::Value extractValue(const EnumInfo &I, +const ClangDocContext &CDCtx) { + Object Obj = Object(); + std::string EnumType = I.Scoped ? "enum class " : "enum "; + EnumType += I.Name; + bool HasComment = std::any_of( + I.Members.begin(), I.Members.end(), + [](const EnumValueInfo &M) { return !M.Description.empty(); }); + Obj.insert({"EnumName", EnumType}); + Obj.insert({"HasComment", HasComment}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + json::Value Arr = Array(); evelez7 wrote: ```suggestion json::Value EnumArr = Array(); ``` nit: Arrays in the other `extractValue` functions have type+"Arr" names. Same for the reference. https://github.com/llvm/llvm-project/pull/138063 ___ 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] [clang-tools-extra] [clang-doc] Extract Info into JSON values (PR #138063)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/138063 ___ 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] [clang-tools-extra] [clang-doc] Extract Info into JSON values (PR #138063)
@@ -162,15 +162,264 @@ Error MustacheHTMLGenerator::generateDocs( return Error::success(); } +static json::Value +extractValue(const Location &L, + std::optional RepositoryUrl = std::nullopt) { + Object Obj = Object(); + // Should there be Start/End line numbers? + Obj.insert({"LineNumber", L.StartLineNumber}); + Obj.insert({"Filename", L.Filename}); + + if (!L.IsFileInRootDir || !RepositoryUrl) +return Obj; + SmallString<128> FileURL(*RepositoryUrl); + sys::path::append(FileURL, sys::path::Style::posix, L.Filename); + FileURL += "#" + std::to_string(L.StartLineNumber); + Obj.insert({"FileURL", FileURL}); + + return Obj; +} + +static json::Value extractValue(const Reference &I, +StringRef CurrentDirectory) { + SmallString<64> Path = I.getRelativeFilePath(CurrentDirectory); + sys::path::append(Path, I.getFileBaseName() + ".html"); + sys::path::native(Path, sys::path::Style::posix); + Object Obj = Object(); + Obj.insert({"Link", Path}); + Obj.insert({"Name", I.Name}); + Obj.insert({"QualName", I.QualName}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + return Obj; +} + +static json::Value extractValue(const TypedefInfo &I) { + // Not Supported + return nullptr; +} + +static json::Value extractValue(const CommentInfo &I) { + assert((I.Kind == "BlockCommandComment" || I.Kind == "FullComment" || + I.Kind == "ParagraphComment" || I.Kind == "TextComment") && + "Unknown Comment type in CommentInfo."); + + Object Obj = Object(); + json::Value Child = Object(); + + // TextComment has no children, so return it. + if (I.Kind == "TextComment") { +Obj.insert({"TextComment", I.Text}); +return Obj; + } + + // BlockCommandComment needs to generate a Command key. + if (I.Kind == "BlockCommandComment") +Child.getAsObject()->insert({"Command", I.Name}); + + // Use the same handling for everything else. + // Only valid for: + // - BlockCommandComment + // - FullComment + // - ParagraphComment + json::Value ChildArr = Array(); + auto &CARef = *ChildArr.getAsArray(); + CARef.reserve(I.Children.size()); + for (const auto &C : I.Children) +CARef.emplace_back(extractValue(*C)); + Child.getAsObject()->insert({"Children", ChildArr}); + Obj.insert({I.Kind, Child}); + + return Obj; +} + +static void maybeInsertLocation(std::optional Loc, +const ClangDocContext &CDCtx, Object &Obj) { + if (!Loc) +return; + Location L = *Loc; + Obj.insert({"Location", extractValue(L, CDCtx.RepositoryUrl)}); +} + +static void extractDescriptionFromInfo(ArrayRef Descriptions, + json::Object &EnumValObj) { + if (Descriptions.empty()) +return; + json::Value ArrDesc = Array(); + json::Array &ADescRef = *ArrDesc.getAsArray(); + for (const CommentInfo &Child : Descriptions) +ADescRef.emplace_back(extractValue(Child)); + EnumValObj.insert({"EnumValueComments", ArrDesc}); +} + +static json::Value extractValue(const FunctionInfo &I, StringRef ParentInfoDir, +const ClangDocContext &CDCtx) { + Object Obj = Object(); + Obj.insert({"Name", I.Name}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + Obj.insert({"Access", getAccessSpelling(I.Access).str()}); + Obj.insert({"ReturnType", extractValue(I.ReturnType.Type, ParentInfoDir)}); + + json::Value ParamArr = Array(); + for (const auto Val : enumerate(I.Params)) { +json::Value V = Object(); +auto &VRef = *V.getAsObject(); +VRef.insert({"Name", Val.value().Name}); +VRef.insert({"Type", Val.value().Type.Name}); +VRef.insert({"End", Val.index() + 1 == I.Params.size()}); +ParamArr.getAsArray()->emplace_back(V); + } + Obj.insert({"Params", ParamArr}); + + maybeInsertLocation(I.DefLoc, CDCtx, Obj); + return Obj; +} + +static json::Value extractValue(const EnumInfo &I, +const ClangDocContext &CDCtx) { + Object Obj = Object(); + std::string EnumType = I.Scoped ? "enum class " : "enum "; + EnumType += I.Name; + bool HasComment = std::any_of( + I.Members.begin(), I.Members.end(), + [](const EnumValueInfo &M) { return !M.Description.empty(); }); + Obj.insert({"EnumName", EnumType}); + Obj.insert({"HasComment", HasComment}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + json::Value Arr = Array(); + json::Array &ARef = *Arr.getAsArray(); + for (const EnumValueInfo &M : I.Members) { +json::Value EnumValue = Object(); +auto &EnumValObj = *EnumValue.getAsObject(); +EnumValObj.insert({"Name", M.Name}); +if (!M.ValueExpr.empty()) + EnumValObj.insert({"ValueExpr", M.ValueExpr}); +else + EnumValObj.insert({"Value", M.Value}); + +extractDescriptionFromInfo(M.Description, EnumValObj); +ARef.emplace_back(EnumValue); + } + Obj.insert({"EnumValues", Arr}); + + extractDescriptionFromInfo(I.Description, Obj); + maybeInsertLocation(I.DefLoc,
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Extract Info into JSON values (PR #138063)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/138063 ___ 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] [clang-tools-extra] [clang-doc] Extract Info into JSON values (PR #138063)
@@ -162,15 +162,264 @@ Error MustacheHTMLGenerator::generateDocs( return Error::success(); } +static json::Value +extractValue(const Location &L, + std::optional RepositoryUrl = std::nullopt) { + Object Obj = Object(); + // Should there be Start/End line numbers? + Obj.insert({"LineNumber", L.StartLineNumber}); + Obj.insert({"Filename", L.Filename}); + + if (!L.IsFileInRootDir || !RepositoryUrl) +return Obj; + SmallString<128> FileURL(*RepositoryUrl); + sys::path::append(FileURL, sys::path::Style::posix, L.Filename); + FileURL += "#" + std::to_string(L.StartLineNumber); + Obj.insert({"FileURL", FileURL}); + + return Obj; +} + +static json::Value extractValue(const Reference &I, +StringRef CurrentDirectory) { + SmallString<64> Path = I.getRelativeFilePath(CurrentDirectory); + sys::path::append(Path, I.getFileBaseName() + ".html"); + sys::path::native(Path, sys::path::Style::posix); + Object Obj = Object(); + Obj.insert({"Link", Path}); + Obj.insert({"Name", I.Name}); + Obj.insert({"QualName", I.QualName}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + return Obj; +} + +static json::Value extractValue(const TypedefInfo &I) { + // Not Supported + return nullptr; +} + +static json::Value extractValue(const CommentInfo &I) { + assert((I.Kind == "BlockCommandComment" || I.Kind == "FullComment" || + I.Kind == "ParagraphComment" || I.Kind == "TextComment") && + "Unknown Comment type in CommentInfo."); + + Object Obj = Object(); + json::Value Child = Object(); + + // TextComment has no children, so return it. + if (I.Kind == "TextComment") { +Obj.insert({"TextComment", I.Text}); +return Obj; + } + + // BlockCommandComment needs to generate a Command key. + if (I.Kind == "BlockCommandComment") +Child.getAsObject()->insert({"Command", I.Name}); + + // Use the same handling for everything else. + // Only valid for: + // - BlockCommandComment + // - FullComment + // - ParagraphComment + json::Value ChildArr = Array(); + auto &CARef = *ChildArr.getAsArray(); + CARef.reserve(I.Children.size()); + for (const auto &C : I.Children) +CARef.emplace_back(extractValue(*C)); + Child.getAsObject()->insert({"Children", ChildArr}); + Obj.insert({I.Kind, Child}); + + return Obj; +} + +static void maybeInsertLocation(std::optional Loc, +const ClangDocContext &CDCtx, Object &Obj) { + if (!Loc) +return; + Location L = *Loc; + Obj.insert({"Location", extractValue(L, CDCtx.RepositoryUrl)}); +} + +static void extractDescriptionFromInfo(ArrayRef Descriptions, + json::Object &EnumValObj) { + if (Descriptions.empty()) +return; + json::Value ArrDesc = Array(); + json::Array &ADescRef = *ArrDesc.getAsArray(); + for (const CommentInfo &Child : Descriptions) +ADescRef.emplace_back(extractValue(Child)); + EnumValObj.insert({"EnumValueComments", ArrDesc}); +} + +static json::Value extractValue(const FunctionInfo &I, StringRef ParentInfoDir, +const ClangDocContext &CDCtx) { + Object Obj = Object(); + Obj.insert({"Name", I.Name}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + Obj.insert({"Access", getAccessSpelling(I.Access).str()}); + Obj.insert({"ReturnType", extractValue(I.ReturnType.Type, ParentInfoDir)}); + + json::Value ParamArr = Array(); + for (const auto Val : enumerate(I.Params)) { +json::Value V = Object(); +auto &VRef = *V.getAsObject(); +VRef.insert({"Name", Val.value().Name}); +VRef.insert({"Type", Val.value().Type.Name}); +VRef.insert({"End", Val.index() + 1 == I.Params.size()}); +ParamArr.getAsArray()->emplace_back(V); + } + Obj.insert({"Params", ParamArr}); + + maybeInsertLocation(I.DefLoc, CDCtx, Obj); + return Obj; +} + +static json::Value extractValue(const EnumInfo &I, +const ClangDocContext &CDCtx) { + Object Obj = Object(); + std::string EnumType = I.Scoped ? "enum class " : "enum "; + EnumType += I.Name; + bool HasComment = std::any_of( + I.Members.begin(), I.Members.end(), + [](const EnumValueInfo &M) { return !M.Description.empty(); }); + Obj.insert({"EnumName", EnumType}); + Obj.insert({"HasComment", HasComment}); + Obj.insert({"ID", toHex(toStringRef(I.USR))}); + json::Value Arr = Array(); + json::Array &ARef = *Arr.getAsArray(); + for (const EnumValueInfo &M : I.Members) { +json::Value EnumValue = Object(); +auto &EnumValObj = *EnumValue.getAsObject(); +EnumValObj.insert({"Name", M.Name}); +if (!M.ValueExpr.empty()) + EnumValObj.insert({"ValueExpr", M.ValueExpr}); +else + EnumValObj.insert({"Value", M.Value}); + +extractDescriptionFromInfo(M.Description, EnumValObj); +ARef.emplace_back(EnumValue); + } + Obj.insert({"EnumValues", Arr}); + + extractDescriptionFromInfo(I.Description, Obj); + maybeInsertLocation(I.DefLoc,
[llvm-branch-commits] Implement src:*=sanitize for UBSan. (PR #140489)
https://github.com/qinkunbao created https://github.com/llvm/llvm-project/pull/140489 None ___ 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] Implement src:*=sanitize for UBSan. (PR #140489)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- clang/include/clang/Basic/SanitizerSpecialCaseList.h clang/lib/Basic/NoSanitizeList.cpp clang/lib/Basic/SanitizerSpecialCaseList.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/Basic/SanitizerSpecialCaseList.h b/clang/include/clang/Basic/SanitizerSpecialCaseList.h index dd01a786d..a77f63d7e 100644 --- a/clang/include/clang/Basic/SanitizerSpecialCaseList.h +++ b/clang/include/clang/Basic/SanitizerSpecialCaseList.h @@ -44,9 +44,9 @@ public: StringRef Category = StringRef()) const; // Query ignorelisted entries if any bit in Mask matches the entry's section. - // Return 0 if not found. If found, return the line number (starts with 1). + // Return 0 if not found. If found, return the line number (starts with 1). unsigned inSectionBlame(SanitizerMask Mask, StringRef Prefix, StringRef Query, - StringRef Category = StringRef()) const; + StringRef Category = StringRef()) const; protected: // Initialize SanitizerSections. `` https://github.com/llvm/llvm-project/pull/140489 ___ 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] [clang] Implement src:*=sanitize for UBSan. (PR #140489)
https://github.com/qinkunbao updated https://github.com/llvm/llvm-project/pull/140489 >From d383fc3d23c0c302d134a76d39491c87547526a1 Mon Sep 17 00:00:00 2001 From: Qinkun Bao Date: Mon, 19 May 2025 02:45:30 + Subject: [PATCH] fix format Created using spr 1.3.6 --- clang/include/clang/Basic/SanitizerSpecialCaseList.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/SanitizerSpecialCaseList.h b/clang/include/clang/Basic/SanitizerSpecialCaseList.h index dd01a786dee01..25d518e7128cf 100644 --- a/clang/include/clang/Basic/SanitizerSpecialCaseList.h +++ b/clang/include/clang/Basic/SanitizerSpecialCaseList.h @@ -44,9 +44,9 @@ class SanitizerSpecialCaseList : public llvm::SpecialCaseList { StringRef Category = StringRef()) const; // Query ignorelisted entries if any bit in Mask matches the entry's section. - // Return 0 if not found. If found, return the line number (starts with 1). + // Return 0 if not found. If found, return the line number (starts with 1). unsigned inSectionBlame(SanitizerMask Mask, StringRef Prefix, StringRef Query, - StringRef Category = StringRef()) const; + StringRef Category = StringRef()) const; protected: // Initialize SanitizerSections. @@ -54,7 +54,7 @@ class SanitizerSpecialCaseList : public llvm::SpecialCaseList { struct SanitizerSection { SanitizerSection(SanitizerMask SM, SectionEntries &E) -: Mask(SM), Entries(E){}; +: Mask(SM), Entries(E) {}; SanitizerMask Mask; SectionEntries &Entries; ___ 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] Implement src:*=sanitize for UBSan. (PR #140489)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Qinkun Bao (qinkunbao) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/140489.diff 4 Files Affected: - (modified) clang/include/clang/Basic/SanitizerSpecialCaseList.h (+5) - (modified) clang/lib/Basic/NoSanitizeList.cpp (+7) - (modified) clang/lib/Basic/SanitizerSpecialCaseList.cpp (+16-5) - (added) clang/test/CodeGen/ubsan-src-ignorelist-category.test (+37) ``diff diff --git a/clang/include/clang/Basic/SanitizerSpecialCaseList.h b/clang/include/clang/Basic/SanitizerSpecialCaseList.h index d024b7dfc2e85..dd01a786dee01 100644 --- a/clang/include/clang/Basic/SanitizerSpecialCaseList.h +++ b/clang/include/clang/Basic/SanitizerSpecialCaseList.h @@ -43,6 +43,11 @@ class SanitizerSpecialCaseList : public llvm::SpecialCaseList { bool inSection(SanitizerMask Mask, StringRef Prefix, StringRef Query, StringRef Category = StringRef()) const; + // Query ignorelisted entries if any bit in Mask matches the entry's section. + // Return 0 if not found. If found, return the line number (starts with 1). + unsigned inSectionBlame(SanitizerMask Mask, StringRef Prefix, StringRef Query, + StringRef Category = StringRef()) const; + protected: // Initialize SanitizerSections. void createSanitizerSections(); diff --git a/clang/lib/Basic/NoSanitizeList.cpp b/clang/lib/Basic/NoSanitizeList.cpp index e7e63c1f419e6..811480f914ec5 100644 --- a/clang/lib/Basic/NoSanitizeList.cpp +++ b/clang/lib/Basic/NoSanitizeList.cpp @@ -44,6 +44,13 @@ bool NoSanitizeList::containsFunction(SanitizerMask Mask, bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName, StringRef Category) const { + unsigned nosanline = SSCL->inSectionBlame(Mask, "src", FileName, Category); + unsigned sanline = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize"); + // If we have two cases such as `src:a.cpp=sanitize` and `src:a.cpp`, the + // current entry override the previous entry. + if (nosanline > 0 && sanline > 0) { +return nosanline > sanline; + } return SSCL->inSection(Mask, "src", FileName, Category); } diff --git a/clang/lib/Basic/SanitizerSpecialCaseList.cpp b/clang/lib/Basic/SanitizerSpecialCaseList.cpp index 2dbf04c6ede97..3bf79876235db 100644 --- a/clang/lib/Basic/SanitizerSpecialCaseList.cpp +++ b/clang/lib/Basic/SanitizerSpecialCaseList.cpp @@ -56,10 +56,21 @@ void SanitizerSpecialCaseList::createSanitizerSections() { bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, StringRef Prefix, StringRef Query, StringRef Category) const { - for (auto &S : SanitizerSections) -if ((S.Mask & Mask) && -SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category)) - return true; + return inSectionBlame(Mask, Prefix, Query, Category) > 0; +} - return false; +unsigned SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask, + StringRef Prefix, + StringRef Query, + StringRef Category) const { + for (auto &S : SanitizerSections) { +if (S.Mask & Mask) { + unsigned lineNum = + SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category); + if (lineNum > 0) { +return lineNum; + } +} + } + return 0; } diff --git a/clang/test/CodeGen/ubsan-src-ignorelist-category.test b/clang/test/CodeGen/ubsan-src-ignorelist-category.test new file mode 100644 index 0..f32dc5cbb9e13 --- /dev/null +++ b/clang/test/CodeGen/ubsan-src-ignorelist-category.test @@ -0,0 +1,37 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist -emit-llvm %t/test1.c -o - | FileCheck %s -check-prefix=CHECK-ALLOWLIST +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist -emit-llvm %t/test2.c -o - | FileCheck %s -check-prefix=CHECK-IGNORELIST +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist.contradict1 -emit-llvm %t/test1.c -o - | FileCheck %s -check-prefix=CHECK-ALLOWLISTOVERIDE1 +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow -fsanitize-ignorelist=%t/src.ignorelist.contradict2 -emit-llvm %t/test1.c -o - | FileCheck %s -check-prefix=CHECK-ALLOWLISTOVERIDE2 + + +// Verify ubsan only emits checks for files in the allowlist + +//--- src.ignorelist +src:* +src:*/test1.c=sanitize + +//--- src.ignorelist.contradict1 +src:* +src:*/test1.c=sanitize +src:*/test1.c + +//--- src.ignorelist.contradict1 +src:* +src:*/test1.c +src:*/test1.c=sanitize + +//--- test1.c +int add1(int a, int b) { +//
[llvm-branch-commits] [clang] Implement src:*=sanitize for UBSan. (PR #140489)
https://github.com/qinkunbao edited https://github.com/llvm/llvm-project/pull/140489 ___ 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] Implement src:*=sanitize for UBSan. (PR #140489)
https://github.com/qinkunbao edited https://github.com/llvm/llvm-project/pull/140489 ___ 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] [clang] Implement src:*=sanitize for UBSan. (PR #140489)
https://github.com/qinkunbao converted_to_draft https://github.com/llvm/llvm-project/pull/140489 ___ 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] [polly] [Polly] Introduce PhaseManager and remove LPM support (PR #125442)
@@ -0,0 +1,419 @@ +//===-- PhaseManager.cpp *- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "polly/Pass/PhaseManager.h" +#include "polly/CodeGen/CodeGeneration.h" +#include "polly/CodeGen/IslAst.h" +#include "polly/CodePreparation.h" +#include "polly/DeLICM.h" +#include "polly/DeadCodeElimination.h" +#include "polly/DependenceInfo.h" +#include "polly/FlattenSchedule.h" +#include "polly/ForwardOpTree.h" +#include "polly/JSONExporter.h" +#include "polly/MaximalStaticExpansion.h" +#include "polly/PruneUnprofitable.h" +#include "polly/ScheduleOptimizer.h" +#include "polly/ScopDetection.h" +#include "polly/ScopDetectionDiagnostic.h" +#include "polly/ScopGraphPrinter.h" +#include "polly/ScopInfo.h" +#include "polly/Simplify.h" +#include "llvm/Analysis/AssumptionCache.h" +#include "llvm/Analysis/OptimizationRemarkEmitter.h" +#include "llvm/IR/Module.h" + +#define DEBUG_TYPE "polly-pass" + +using namespace polly; +using namespace llvm; + +namespace { + +/// Recurse through all subregions and all regions and add them to RQ. +static void addRegionIntoQueue(Region &R, SmallVector &RQ) { + RQ.push_back(&R); + for (const auto &E : R) +addRegionIntoQueue(*E, RQ); +} + +/// The phase pipeline of Polly to be embedded into another pass manager than +/// runs passes on functions. +/// +/// Polly holds state besides LLVM-IR (RegionInfo and ScopInfo) between phases +/// that LLVM pass managers do not consider when scheduling analyses and passes. +/// That is, the ScopInfo must persist between phases that a pass manager must +/// not invalidate to recompute later. +class PhaseManager { +private: + Function &F; + FunctionAnalysisManager &FAM; + PollyPassOptions Opts; + +public: + PhaseManager(Function &F, FunctionAnalysisManager &FAM, PollyPassOptions Opts) + : F(F), FAM(FAM), Opts(std::move(Opts)) {} + + /// Execute Polly's phases as indicated by the options. + bool run() { +// Get analyses from the function pass manager. +// These must be preserved during all phases so that if processing one SCoP +// has finished, the next SCoP can still use them. Recomputing is not an +// option because ScopDetection stores references to the old results. +// TODO: CodePreparation doesn't actually need these analysis, it just keeps +// them up-to-date. If they are not computed yet, can also compute after the +// prepare phase. +auto &LI = FAM.getResult(F); +auto &DT = FAM.getResult(F); +bool ModifiedIR = false; + +// Phase: prepare +// TODO: Setting ModifiedIR will invalidate any anlysis, even if DT, LI are +// preserved. +if (Opts.isPhaseEnabled(PassPhase::Prepare)) + ModifiedIR |= runCodePreparation(F, &DT, &LI, nullptr); + Meinersbur wrote: I agree, analyses that CodePreparation does not preserve should be barred from being used in later phases. https://github.com/llvm/llvm-project/pull/125442 ___ 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] fix format in SpecialCaseList.cpp (PR #140479)
https://github.com/qinkunbao created https://github.com/llvm/llvm-project/pull/140479 None ___ 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] fix format in SpecialCaseList.cpp (PR #140479)
https://github.com/qinkunbao closed https://github.com/llvm/llvm-project/pull/140479 ___ 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] fix format in SpecialCaseList.cpp (PR #140479)
llvmbot wrote: @llvm/pr-subscribers-llvm-support Author: Qinkun Bao (qinkunbao) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/140479.diff 1 Files Affected: - (modified) llvm/unittests/Support/SpecialCaseListTest.cpp (-1) ``diff diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp index 15dc0222a57c3..f9185ea7483ca 100644 --- a/llvm/unittests/Support/SpecialCaseListTest.cpp +++ b/llvm/unittests/Support/SpecialCaseListTest.cpp @@ -325,5 +325,4 @@ TEST_F(SpecialCaseListTest, Version3) { EXPECT_EQ(4u, SCL->inSectionBlame("sect1", "fun", "barz")); EXPECT_EQ(6u, SCL->inSectionBlame("sect2", "fun", "def")); } - } `` https://github.com/llvm/llvm-project/pull/140479 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits