Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ecf591c
Update CurLineNum anc CurColNum in sync with movement in text
Bertik23 Jul 29, 2025
06926e9
Remove remains from cherry pick from LSP branch
Bertik23 Aug 4, 2025
1fdf13c
Make isLabelTail more safe and rename it to better show what it does
Bertik23 Aug 4, 2025
2772cd8
Remove dangling comment
Bertik23 Aug 4, 2025
b05d11a
Fix typo
Bertik23 Aug 12, 2025
458599b
Add location tracking to IR parser
Bertik23 Aug 28, 2025
ee39ed1
Fix some OOB posibilities
Bertik23 Aug 28, 2025
b0c5318
Fix clang format
Bertik23 Aug 28, 2025
416514e
Move private members to top of class definition
Bertik23 Aug 29, 2025
35ca1a5
Use SourceMgr to resolve Line:Column position
Bertik23 Sep 2, 2025
b3d8254
Fix zeroindexing on token positions
Bertik23 Sep 2, 2025
23dcc6b
Replace Line:Column storage with Poiters and on demand conversion
Bertik23 Sep 3, 2025
06d5265
Use nullptr as missing value
Bertik23 Sep 4, 2025
4e08921
Enclose debug prints of tests in LLVM_DEBUG
Bertik23 Sep 4, 2025
3da9e9d
Decapitalize DEBUG_TYPE
Bertik23 Sep 15, 2025
4b3bc0e
Move FileLoc from Value.h to FileLoc.h
Bertik23 Sep 26, 2025
ed7a04a
Rename include guard defines to reflext filename
Bertik23 Sep 26, 2025
f9728f6
Merge remote-tracking branch 'upstream/main' into lsp-server-upstreaming
Bertik23 Oct 1, 2025
4a749d2
LSP server
Bertik23 Oct 1, 2025
d870571
Update LLVMBuild.txt in accordance to CMakeLists.txt
Bertik23 Oct 1, 2025
53bf014
Update LSP capabilities in README
Bertik23 Oct 1, 2025
bd6d352
Merge branch 'llvm:main' into lsp-server-upstreaming
Bertik23 Oct 1, 2025
5aef2db
Fix clang-format
Bertik23 Oct 8, 2025
ddfa5dd
Fix heat-colors-graph test
Bertik23 Oct 13, 2025
c533c05
Downgrade C++ from 23 to 20
Bertik23 Oct 14, 2025
09e555a
Merge branch 'main' into lsp-server-upstreaming
Bertik23 Oct 27, 2025
cb9c2c3
Remove optimization runs
Bertik23 Nov 5, 2025
a1bbd5e
Remove OOB changes from Lexer
Bertik23 Nov 5, 2025
416ea50
Fix open CFG on BB label crash
Bertik23 Nov 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions llvm/include/llvm/Analysis/CFGPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "llvm/Support/DOTGraphTraits.h"
#include "llvm/Support/FormatVariadic.h"

#include <functional>
#include <sstream>

namespace llvm {
class ModuleSlotTracker;

Expand Down Expand Up @@ -69,13 +72,18 @@ class DOTFuncInfo {
bool ShowHeat;
bool EdgeWeights;
bool RawWeights;
using NodeIdFormatterTy =
std::function<std::optional<std::string>(const BasicBlock *)>;
std::optional<NodeIdFormatterTy> NodeIdFormatter;

public:
DOTFuncInfo(const Function *F) : DOTFuncInfo(F, nullptr, nullptr, 0) {}
LLVM_ABI ~DOTFuncInfo();

LLVM_ABI DOTFuncInfo(const Function *F, const BlockFrequencyInfo *BFI,
const BranchProbabilityInfo *BPI, uint64_t MaxFreq);
LLVM_ABI
DOTFuncInfo(const Function *F, const BlockFrequencyInfo *BFI,
const BranchProbabilityInfo *BPI, uint64_t MaxFreq,
std::optional<NodeIdFormatterTy> NodeIdFormatter = std::nullopt);

const BlockFrequencyInfo *getBFI() const { return BFI; }

Expand All @@ -102,6 +110,10 @@ class DOTFuncInfo {
void setEdgeWeights(bool EdgeWeights) { this->EdgeWeights = EdgeWeights; }

bool showEdgeWeights() { return EdgeWeights; }

std::optional<NodeIdFormatterTy> getNodeIdFormatter() {
return NodeIdFormatter;
}
};

template <>
Expand Down Expand Up @@ -311,21 +323,27 @@ struct DOTGraphTraits<DOTFuncInfo *> : public DefaultDOTGraphTraits {
}

std::string getNodeAttributes(const BasicBlock *Node, DOTFuncInfo *CFGInfo) {
std::stringstream Attrs;

if (auto NodeIdFmt = CFGInfo->getNodeIdFormatter())
if (auto NodeId = (*NodeIdFmt)(Node))
Attrs << "id=\"" << *NodeId << "\"";

if (CFGInfo->showHeatColors()) {
uint64_t Freq = CFGInfo->getFreq(Node);
std::string Color = getHeatColor(Freq, CFGInfo->getMaxFreq());
std::string EdgeColor = (Freq <= (CFGInfo->getMaxFreq() / 2))
? (getHeatColor(0))
: (getHeatColor(1));
if (!Attrs.str().empty())
Attrs << ",";
Attrs << "color=\"" << EdgeColor << "ff\", style=filled, "
<< "fillcolor=\"" << Color << "70\", " << "fontname=\"Courier\"";
}

if (!CFGInfo->showHeatColors())
return "";

uint64_t Freq = CFGInfo->getFreq(Node);
std::string Color = getHeatColor(Freq, CFGInfo->getMaxFreq());
std::string EdgeColor = (Freq <= (CFGInfo->getMaxFreq() / 2))
? (getHeatColor(0))
: (getHeatColor(1));

std::string Attrs = "color=\"" + EdgeColor + "ff\", style=filled," +
" fillcolor=\"" + Color + "70\"" +
" fontname=\"Courier\"";
return Attrs;
return Attrs.str();
}

LLVM_ABI bool isNodeHidden(const BasicBlock *Node,
const DOTFuncInfo *CFGInfo);
LLVM_ABI void computeDeoptOrUnreachablePaths(const Function *F);
Expand Down
17 changes: 17 additions & 0 deletions llvm/include/llvm/Support/LSP/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,23 @@ struct CodeAction {
/// Add support for JSON serialization.
llvm::json::Value toJSON(const CodeAction &);

//===----------------------------------------------------------------------===//
// ShowMessageParams
//===----------------------------------------------------------------------===//

enum class MessageType { Error = 1, Warning = 2, Info = 3, Log = 4, Debug = 5 };

struct ShowMessageParams {
ShowMessageParams(MessageType Type, std::string Message)
: type(Type), message(Message) {}
MessageType type;
/// The actual message.
std::string message;
};

/// Add support for JSON serialization.
llvm::json::Value toJSON(const ShowMessageParams &Params);

} // namespace lsp
} // namespace llvm

Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Analysis/CFGPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ static void viewCFG(Function &F, const BlockFrequencyInfo *BFI,
}

DOTFuncInfo::DOTFuncInfo(const Function *F, const BlockFrequencyInfo *BFI,
const BranchProbabilityInfo *BPI, uint64_t MaxFreq)
: F(F), BFI(BFI), BPI(BPI), MaxFreq(MaxFreq) {
const BranchProbabilityInfo *BPI, uint64_t MaxFreq,
std::optional<NodeIdFormatterTy> NodeIdFormatter)
: F(F), BFI(BFI), BPI(BPI), MaxFreq(MaxFreq),
NodeIdFormatter(NodeIdFormatter) {
ShowHeat = false;
EdgeWeights = !!BPI; // Print EdgeWeights when BPI is available.
RawWeights = !!BFI; // Print RawWeights when BFI is available.
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Support/LSP/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,3 +1037,14 @@ llvm::json::Value llvm::lsp::toJSON(const CodeAction &Value) {
CodeAction["edit"] = *Value.edit;
return std::move(CodeAction);
}

//===----------------------------------------------------------------------===//
// ShowMessageParams
//===----------------------------------------------------------------------===//

llvm::json::Value llvm::lsp::toJSON(const ShowMessageParams &Params) {
return llvm::json::Object{
{"type", static_cast<int>(Params.type)},
{"message", Params.message},
};
}
17 changes: 17 additions & 0 deletions llvm/tools/llvm-lsp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(LLVM_LINK_COMPONENTS
Core
IRReader
Support
Analysis
Passes
SupportLSP
TransformUtils
AsmParser
)

add_llvm_tool(llvm-lsp-server
llvm-lsp-server.cpp
Protocol.cpp
)

target_compile_features(llvm-lsp-server PRIVATE cxx_std_20)
Loading
Loading