Skip to content

Add support for LLVM 19 and 20 (not CI tested) #13

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

Open
wants to merge 5 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 13 additions & 5 deletions cgcollector/lib/include/MetaCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,20 @@ class FilePropertyCollector : public MetaCollector {
const auto sourceLocation = decl->getLocation();
auto& astCtx = decl->getASTContext();
const auto fullSrcLoc = astCtx.getFullLoc(sourceLocation);
const auto fileEntry = fullSrcLoc.getFileEntry();
if (!fileEntry) {
return result;
std::string fileNameStr = "UNKNOWN";
if (fullSrcLoc.isValid()) {
#if LLVM_VERSION_MAJOR >= 18
const auto fileEntry = fullSrcLoc.getFileEntryRef();
#else
const auto fileEntry = fullSrcLoc.getFileEntry();
#endif
if (!fileEntry) {
return result;
}

const auto fileName = fileEntry->getName();
fileNameStr = fileName.str();
}
const auto fileName = fileEntry->getName();
std::string fileNameStr = fileName.str();

result->isFromSystemInclude = astCtx.getSourceManager().isInSystemHeader(sourceLocation);

Expand Down
2 changes: 1 addition & 1 deletion cgcollector/lib/src/AAUSR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool implementation::printLoc(llvm::raw_ostream& OS, SourceLocation BeginLoc, So
const auto EndLocOffset = SM.getDecomposedLoc(EndLocExpansion).second;
const std::pair<FileID, unsigned>& Decomposed = SM.getDecomposedLoc(BeginLocExpansion);
if (PrintFilename) {
const FileEntry* FE = SM.getFileEntryForID(Decomposed.first);
auto FE = SM.getFileEntryRefForID(Decomposed.first);
if (FE) {
OS << llvm::sys::path::filename(FE->getName());
} else {
Expand Down
10 changes: 9 additions & 1 deletion cgcollector/lib/src/AliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,16 @@ bool ASTInformationExtractor::TraverseConstructorInitializer(clang::CXXCtorIniti
return RecursiveASTVisitor::TraverseConstructorInitializer(CtorInit);
}

[[nodiscard]] inline bool isUnnamedBitField(clang::FieldDecl* FD) {
#if LLVM_VERSION_MAJOR < 19
return FD->isUnnamedBitfield();
#else
return FD->isUnnamedBitField();
#endif
}

bool ASTInformationExtractor::VisitFieldDecl(clang::FieldDecl* FD) {
if (FD->isUnnamedBitfield()) {
if (isUnnamedBitField(FD)) {
// Unnamed bitfields can not be referenced
return true;
}
Expand Down
17 changes: 15 additions & 2 deletions cgcollector/lib/src/CallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,12 @@ class CGBuilder : public StmtVisitor<CGBuilder> {
// std::cout << "Visiting the lambda expression: " << LEstr.front() << " @ " << LE->getCallOperator() <<
// std::endl;
auto lambdaStaticInvoker = LE->getLambdaClass()->getLambdaStaticInvoker();
addCalledDecl(lambdaStaticInvoker, LE->getCallOperator(), nullptr);
if (lambdaStaticInvoker) {
addCalledDecl(lambdaStaticInvoker, LE->getCallOperator(), nullptr);
} else {
llvm::errs() << "Static invoker in null\n";
// LE->dump();
}
for (auto conversionIt = LE->getLambdaClass()->conversion_begin();
conversionIt != LE->getLambdaClass()->conversion_end(); ++conversionIt) {
if (auto conv = *conversionIt) {
Expand Down Expand Up @@ -1165,6 +1170,14 @@ CallGraph::CallGraph() : Root(getOrInsertNode(nullptr)) {}

CallGraph::~CallGraph() = default;

[[nodiscard]] inline bool starts_with(llvm::StringRef Str, llvm::StringRef Prefix) {
#if LLVM_VERSION_MAJOR < 17
return Str.startswith(Prefix);
#else
return Str.starts_with(Prefix);
#endif
}

bool CallGraph::includeInGraph(const Decl* D) {
assert(D);

Expand All @@ -1184,7 +1197,7 @@ bool CallGraph::includeInGraph(const Decl* D) {

IdentifierInfo* II = FD->getIdentifier();
// TODO not sure whether we want to include __inline marked functions
if (II && II->getName().startswith("__inline")) {
if (II && starts_with(II->getName(), "__inline")) {
return true;
}
}
Expand Down
18 changes: 15 additions & 3 deletions cgcollector/lib/src/GlobalCallDepth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@
#include <set>
#include <string>

#include <chrono>
#include <llvm/Support/raw_ostream.h>


#define MAX_CALLDEPTH_TIME 10

int getCallDepth(const std::string& entry, const llvm::StringMap<llvm::StringMap<int>>& callDepths,
const llvm::StringMap<int>& localLoopDepth, llvm::StringMap<int>& globalLoopDepth,
llvm::StringMap<bool>& visited) {
llvm::StringMap<bool>& visited, std::chrono::high_resolution_clock::time_point start) {
std::chrono::duration<double> elapsed = std::chrono::high_resolution_clock::now() - start;
if (elapsed.count() > MAX_CALLDEPTH_TIME) {
llvm::errs() << "Call depth computation took too long!\n";
return 0;
}
// First mark ourselves as visited, to infinite loops
visited.insert_or_assign(entry, true);
int maxChildDepth = 0;
Expand All @@ -18,7 +29,7 @@ int getCallDepth(const std::string& entry, const llvm::StringMap<llvm::StringMap
for (const auto& child : children) {
if (visited.find(child.first()) == visited.end()) {
maxChildDepth = std::max(maxChildDepth, child.second + getCallDepth(std::string(child.first()), callDepths,
localLoopDepth, globalLoopDepth, visited));
localLoopDepth, globalLoopDepth, visited, start));
}
}
// Remove mark
Expand Down Expand Up @@ -86,7 +97,8 @@ void calculateGlobalCallDepth(nlohmann::json& j, bool useOnlyMainEntry) {
}

for (const auto& entry : entryPoints) {
globalLoopDepth.insert_or_assign(entry, getCallDepth(entry, callDepths, localLoopDepth, globalLoopDepth, visited));
auto start = std::chrono::high_resolution_clock::now();
globalLoopDepth.insert_or_assign(entry, getCallDepth(entry, callDepths, localLoopDepth, globalLoopDepth, visited, start));
}

for (auto& [key, val] : cg.items()) {
Expand Down
3 changes: 2 additions & 1 deletion cmake/ClangLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function(test_llvm_major_version version_string)
endif()

if(NOT ${valid_version})
message(SEND_ERROR "LLVM/Clang version 10, 13, 14, 15, 16, 17, and 18 are supported and tested")
message(WARNING "Support for LLVM Version ${version_string} is not tested! Proceed with care.")
message(WARNING "LLVM/Clang version 10, 13, 14, 15, 16, 17, 18 are supported and tested")
endif()
endfunction()

Expand Down
2 changes: 1 addition & 1 deletion graph/include/CgNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class CgNode {
}

auto nmd = new T(args...);
this->template addMetaData(nmd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think this is a change that is not related to the ability to use newer llvm versions. Am I missing something?
Will this break some GCC compatibility with older versions or so?

this->addMetaData(nmd);
return nmd;
}

Expand Down
6 changes: 3 additions & 3 deletions graph/include/metadata/MetaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class MetaDataFactory {
template <class... T>
static CRTPBase* create(const std::string& s, const nlohmann::json& j) {
if (data().find(s) == data().end()) {
MCGLogger::instance().getErrConsole()->template warn(
"Could not create: {}, the Metadata is unknown in you application", s);
MCGLogger::instance().getErrConsole()->warn("Could not create: {}, the Metadata is unknown in you application",
s);
Comment on lines +39 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to have the error in one single line, instead of having only the formatting parameter in a new line.

Suggested change
MCGLogger::instance().getErrConsole()->warn("Could not create: {}, the Metadata is unknown in you application",
s);
MCGLogger::instance().getErrConsole()->warn(
"Could not create: {}, the Metadata is unknown in you application", s);

return nullptr;
}
return data().at(s)(j);
Expand All @@ -48,7 +48,7 @@ class MetaDataFactory {
friend T;

static bool registerT() {
MCGLogger::instance().getConsole()->template trace("Registering {} \n", T::key);
MCGLogger::instance().getConsole()->trace("Registering {} \n", T::key);
const auto name = T::key;
MetaDataFactory::data()[name] = [](const nlohmann::json& j) -> CRTPBase* { return new T(j); };
return true;
Expand Down
8 changes: 5 additions & 3 deletions graph/src/io/VersionTwoMCGWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ void metacg::io::VersionTwoMCGWriter::downgradeV3FormatToV2Format(nlohmann::json
j["CG"][nodeName] = std::move(node.at(1));

// if we have attached origin information move it to Fileproperty data
if (j["CG"][nodeName]["origin"] != "unknownOrigin") {
j["CG"][nodeName].at("meta")["fileProperties"] = {{"origin", j["CG"][nodeName]["origin"]},
{"systemInclude", false}};
// if (j["CG"][nodeName]["origin"] != "unknownOrigin") {
if (j["CG"][nodeName].at("meta").contains("fileProperties")) {
j["CG"][nodeName].at("meta")["fileProperties"]["origin"] = j["CG"][nodeName]["origin"];
}

// }
j["CG"][nodeName].erase("origin");

// if we have override metadata, use it to generate override information
Expand Down
12 changes: 6 additions & 6 deletions pgis/lib/include/MetaData/CgNodeMetaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ class PiraOneData : public metacg::MetaData::Registrar<PiraOneData> {
template <typename T>
inline void setPiraOneData(T node, int numStmts = 0, bool hasBody = false, bool dominantRuntime = false,
bool inPrevProfile = false) {
const auto& [has, data] = node->template checkAndGet<PiraOneData>();
if (has) {
data->setNumberOfStatements(numStmts);
data->setHasBody(hasBody);
data->setDominantRuntime(dominantRuntime);
data->setComesFromCube(inPrevProfile);
const auto& [has, data] = node->template checkAndGet<PiraOneData>();
if (has) {
data->setNumberOfStatements(numStmts);
data->setHasBody(hasBody);
data->setDominantRuntime(dominantRuntime);
data->setComesFromCube(inPrevProfile);
Comment on lines +243 to +248
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a formatting error or correction?

} else {
assert_pira_one_data();
}
Expand Down