Skip to content
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

Preliminary LLVM 20 support #4843

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

Conversation

liushuyu
Copy link
Contributor

This pull request adds basic LLVM 20 support for LDC.

LLVM 20 changed a lot of APIs again, especially how passes are structured.

@kinke
Copy link
Member

kinke commented Feb 21, 2025

Nice, thanks! How about becoming a member of ldc-developers, any interest? :)

@kassane kassane mentioned this pull request Sep 17, 2024
Copy link
Contributor

@the-horo the-horo left a comment

Choose a reason for hiding this comment

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

In gen_gccbuiltins.cpp you can get away with retroactively applying const instead of the LLVM_20_CONST conditional.

One more change that github doesn't let me submit:

-    return TableGenMain(argv[0], emit);
+    // Since LLVM-20 `records` needs to be const&
+    return TableGenMain(argv[0], [](raw_ostream &os, auto &records){
+      return emit(os, records);
+    });

Comment on lines +34 to +40
#if LDC_LLVM_VER >= 2000
#define LLVM_20_CONST const
#else
#define LLVM_20_CONST
#endif

string dtype(LLVM_20_CONST Record* rec, bool readOnlyMem)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#if LDC_LLVM_VER >= 2000
#define LLVM_20_CONST const
#else
#define LLVM_20_CONST
#endif
string dtype(LLVM_20_CONST Record* rec, bool readOnlyMem)
string dtype(const Record* rec, bool readOnlyMem)

{
Init* typeInit = rec->getValueInit("VT");
LLVM_20_CONST Init* typeInit = rec->getValueInit("VT");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LLVM_20_CONST Init* typeInit = rec->getValueInit("VT");
auto typeInit = rec->getValueInit("VT");

@@ -72,7 +78,7 @@ string dtype(Record* rec, bool readOnlyMem)
return "";
}

StringRef attributes(ListInit* propertyList)
StringRef attributes(LLVM_20_CONST ListInit* propertyList)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
StringRef attributes(LLVM_20_CONST ListInit* propertyList)
StringRef attributes(const ListInit* propertyList)

@@ -100,13 +106,13 @@ void processRecord(raw_ostream& os, Record& rec, string arch)
replace(name.begin(), name.end(), '_', '.');
name = string("llvm.") + name;

ListInit* propsList = rec.getValueAsListInit("IntrProperties");
LLVM_20_CONST ListInit* propsList = rec.getValueAsListInit("IntrProperties");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LLVM_20_CONST ListInit* propsList = rec.getValueAsListInit("IntrProperties");
auto propsList = rec.getValueAsListInit("IntrProperties");

const StringRef prop =
propsList->size() ? propsList->getElementAsRecord(0)->getName() : "";

bool readOnlyMem = prop == "IntrReadArgMem" || prop == "IntrReadMem";

ListInit* paramsList = rec.getValueAsListInit("ParamTypes");
LLVM_20_CONST ListInit* paramsList = rec.getValueAsListInit("ParamTypes");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LLVM_20_CONST ListInit* paramsList = rec.getValueAsListInit("ParamTypes");
auto paramsList = rec.getValueAsListInit("ParamTypes");

@@ -117,7 +123,7 @@ void processRecord(raw_ostream& os, Record& rec, string arch)
params.push_back(t);
}

ListInit* retList = rec.getValueAsListInit("RetTypes");
LLVM_20_CONST ListInit* retList = rec.getValueAsListInit("RetTypes");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LLVM_20_CONST ListInit* retList = rec.getValueAsListInit("RetTypes");
auto retList = rec.getValueAsListInit("RetTypes");

@@ -145,7 +151,7 @@ void processRecord(raw_ostream& os, Record& rec, string arch)

std::string arch;

bool emit(raw_ostream& os, RecordKeeper& records)
bool emit(raw_ostream& os, LLVM_20_CONST RecordKeeper& records)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bool emit(raw_ostream& os, LLVM_20_CONST RecordKeeper& records)
bool emit(raw_ostream& os, const RecordKeeper& records)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants