-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[tools] LLVM Advisor - compilation wrapper with artifact collection and analysis #147451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
miguelcsx
wants to merge
10
commits into
llvm:main
Choose a base branch
from
miguelcsx:feat/remarks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c86d304
[llvm-advisor] add initial project structure and configuration
miguelcsx 181e445
[llvm-advisor] Add utility for file and process management
miguelcsx 44997ca
[llvm-advisor] Add basic build/compilation data models
miguelcsx 047afa0
[llvm-advisor] Add command analyzer helper
miguelcsx 2bcbcee
[llvm-advisor] Add support for builds with extra compiler data
miguelcsx 00c1ad3
[llvm-advisor] Add build coordinator support
miguelcsx ed61ffd
[llvm-advisor] Add support for collecting extra build outputs
miguelcsx bc8d356
[llvm-advisor] Add support for detecting compilation units
miguelcsx cbf5731
[llvm-advisor] Add main command-line driver
miguelcsx 9658c85
[llvm-advisor] Add llvm copyright and use code styling
miguelcsx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 3.18) | ||
|
||
set(LLVM_TOOL_LLVM_ADVISOR_BUILD_DEFAULT ON) | ||
set(LLVM_REQUIRE_EXE_NAMES llvm-advisor) | ||
|
||
add_subdirectory(src) | ||
|
||
# Set the executable name | ||
set_target_properties(llvm-advisor PROPERTIES | ||
OUTPUT_NAME llvm-advisor) | ||
|
||
# Install the binary | ||
install(TARGETS llvm-advisor | ||
RUNTIME DESTINATION bin | ||
COMPONENT llvm-advisor) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"outputDir": ".llvm-advisor", | ||
"verbose": false, | ||
"keepTemps": false, | ||
"runProfiler": true, | ||
"timeout": 60 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Gather all .cpp sources in this directory tree | ||
file(GLOB_RECURSE LLVM_ADVISOR_SOURCES CONFIGURE_DEPENDS | ||
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp | ||
) | ||
|
||
# Define the executable target | ||
add_llvm_tool(llvm-advisor | ||
${LLVM_ADVISOR_SOURCES} | ||
) | ||
|
||
# Link required LLVM libraries | ||
target_link_libraries(llvm-advisor PRIVATE | ||
LLVMSupport | ||
LLVMCore | ||
LLVMIRReader | ||
LLVMBitWriter | ||
LLVMRemarks | ||
LLVMProfileData | ||
) | ||
|
||
# Set include directories | ||
target_include_directories(llvm-advisor PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
# Install the Python view module alongside the binary | ||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../view/ | ||
DESTINATION ${CMAKE_INSTALL_BINDIR}/view | ||
FILES_MATCHING | ||
PATTERN "*.py" | ||
PATTERN "*.html" | ||
PATTERN "*.css" | ||
PATTERN "*.js" | ||
PATTERN "*.md" | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//===------------------ AdvisorConfig.cpp - LLVM Advisor ------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This is the AdvisorConfig code generator driver. It provides a convenient | ||
// command-line interface for generating an assembly file or a relocatable file, | ||
// given LLVM bitcode. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "AdvisorConfig.h" | ||
#include "llvm/Support/FileSystem.h" | ||
#include "llvm/Support/JSON.h" | ||
#include "llvm/Support/MemoryBuffer.h" | ||
#include "llvm/Support/Path.h" | ||
|
||
namespace llvm { | ||
namespace advisor { | ||
|
||
AdvisorConfig::AdvisorConfig() { | ||
// Use relative path as default, will be resolved by CompilationManager | ||
OutputDir_ = ".llvm-advisor"; | ||
} | ||
|
||
Expected<bool> AdvisorConfig::loadFromFile(llvm::StringRef path) { | ||
auto BufferOrError = MemoryBuffer::getFile(path); | ||
if (!BufferOrError) { | ||
return createStringError(BufferOrError.getError(), | ||
"Cannot read config file"); | ||
} | ||
|
||
auto Buffer = std::move(*BufferOrError); | ||
Expected<json::Value> JsonOrError = json::parse(Buffer->getBuffer()); | ||
if (!JsonOrError) { | ||
return JsonOrError.takeError(); | ||
} | ||
|
||
auto &Json = *JsonOrError; | ||
auto *Obj = Json.getAsObject(); | ||
if (!Obj) { | ||
return createStringError(std::make_error_code(std::errc::invalid_argument), | ||
"Config file must contain JSON object"); | ||
} | ||
|
||
if (auto outputDirOpt = Obj->getString("outputDir"); outputDirOpt) { | ||
OutputDir_ = outputDirOpt->str(); | ||
} | ||
|
||
if (auto verboseOpt = Obj->getBoolean("verbose"); verboseOpt) { | ||
Verbose_ = *verboseOpt; | ||
} | ||
|
||
if (auto keepTempsOpt = Obj->getBoolean("keepTemps"); keepTempsOpt) { | ||
KeepTemps_ = *keepTempsOpt; | ||
} | ||
|
||
if (auto runProfileOpt = Obj->getBoolean("runProfiler"); runProfileOpt) { | ||
RunProfiler_ = *runProfileOpt; | ||
} | ||
|
||
if (auto timeoutOpt = Obj->getInteger("timeout"); timeoutOpt) { | ||
TimeoutSeconds_ = static_cast<int>(*timeoutOpt); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
std::string AdvisorConfig::getToolPath(llvm::StringRef tool) const { | ||
// For now, just return the tool name and rely on PATH | ||
return tool.str(); | ||
} | ||
|
||
} // namespace advisor | ||
} // namespace llvm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//===------------------- AdvisorConfig.h - LLVM Advisor -------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This is the AdvisorConfig code generator driver. It provides a convenient | ||
// command-line interface for generating an assembly file or a relocatable file, | ||
// given LLVM bitcode. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_ADVISOR_CONFIG_H | ||
#define LLVM_ADVISOR_CONFIG_H | ||
|
||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/Error.h" | ||
#include <string> | ||
|
||
namespace llvm { | ||
namespace advisor { | ||
|
||
class AdvisorConfig { | ||
public: | ||
AdvisorConfig(); | ||
|
||
Expected<bool> loadFromFile(llvm::StringRef path); | ||
|
||
void setOutputDir(const std::string &dir) { OutputDir_ = dir; } | ||
void setVerbose(bool verbose) { Verbose_ = verbose; } | ||
void setKeepTemps(bool keep) { KeepTemps_ = keep; } | ||
void setRunProfiler(bool run) { RunProfiler_ = run; } | ||
void setTimeout(int seconds) { TimeoutSeconds_ = seconds; } | ||
|
||
const std::string &getOutputDir() const { return OutputDir_; } | ||
bool getVerbose() const { return Verbose_; } | ||
bool getKeepTemps() const { return KeepTemps_; } | ||
bool getRunProfiler() const { return RunProfiler_; } | ||
int getTimeout() const { return TimeoutSeconds_; } | ||
|
||
std::string getToolPath(llvm::StringRef tool) const; | ||
|
||
private: | ||
std::string OutputDir_; | ||
bool Verbose_ = false; | ||
bool KeepTemps_ = false; | ||
bool RunProfiler_ = true; | ||
int TimeoutSeconds_ = 60; | ||
}; | ||
|
||
} // namespace advisor | ||
} // namespace llvm | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//===------------------- BuildContext.h - LLVM Advisor --------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This is the BuildContext code generator driver. It provides a convenient | ||
// command-line interface for generating an assembly file or a relocatable file, | ||
// given LLVM bitcode. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_ADVISOR_CORE_BUILDCONTEXT_H | ||
#define LLVM_ADVISOR_CORE_BUILDCONTEXT_H | ||
|
||
#include "llvm/ADT/DenseMap.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
namespace llvm { | ||
namespace advisor { | ||
|
||
enum class BuildPhase { | ||
Unknown, | ||
Preprocessing, | ||
Compilation, | ||
Assembly, | ||
Linking, | ||
Archiving, | ||
CMakeConfigure, | ||
CMakeBuild, | ||
MakefileBuild | ||
}; | ||
|
||
enum class BuildTool { | ||
Unknown, | ||
Clang, | ||
GCC, | ||
LLVM_Tools, | ||
CMake, | ||
Make, | ||
Ninja, | ||
Linker, | ||
Archiver | ||
}; | ||
|
||
struct BuildContext { | ||
BuildPhase phase; | ||
BuildTool tool; | ||
std::string workingDirectory; | ||
std::string outputDirectory; | ||
llvm::SmallVector<std::string, 8> inputFiles; | ||
llvm::SmallVector<std::string, 8> outputFiles; | ||
llvm::SmallVector<std::string, 8> expectedGeneratedFiles; | ||
std::unordered_map<std::string, std::string> metadata; | ||
bool hasOffloading = false; | ||
bool hasDebugInfo = false; | ||
bool hasOptimization = false; | ||
}; | ||
|
||
} // namespace advisor | ||
} // namespace llvm | ||
|
||
#endif // LLVM_ADVISOR_CORE_BUILDCONTEXT_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and other places:
LLVM Coding standard
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, get familiar with:
https://llvm.org/docs/CodingStandards.html