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

Clean up druntime fwd decls #1208

Merged
merged 2 commits into from
Nov 24, 2015
Merged

Conversation

JohanEngelen
Copy link
Member

WORK IN PROGRESS

Makes the code much prettier I hope.
The main motivation is to enable sret for dynamic arrays, see closed PR #901.

gABI->rewriteFunctionType(dty, irFty);
fn->setAttributes(attribset.addAttributes(
gIR->context(), 1,
llvm::AttributeSet::get(gIR->context(), 1, irFty.args[0]->attrs)));
Copy link
Member

Choose a reason for hiding this comment

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

Attributes index 1 is most likely wrong (1st LL parameter). You'll probably want llvm::AttributeSet::AttrIndex::FunctionIndex = ~0U for the function attributes and make sure that addAttributes() merges it with potential existing ones.

@kinke
Copy link
Member

kinke commented Nov 12, 2015

The main motivation is to enable sret for dynamic arrays

More precisely: passing (incl. sret) dynamic arrays (slices) as regular 16-bytes struct for the Win64 ABI. ;)
Looks way better already. I guess you can workaround the fnames initializer list issue for LLVM < 3.7 by declaring it as llvm::ArrayRef<const char *> instead.

@JohanEngelen
Copy link
Member Author

(I actually only have half a clue what "sret" means, lol :D)

@kinke
Copy link
Member

kinke commented Nov 12, 2015

@dnadlinger
Copy link
Member

While you are at it, could you please get rid of the LLVM_D_ prefix thing? It's not used anywhere else. I think our plan is to use ldc::, maybe ldc::runtime:: for this.

@JohanEngelen
Copy link
Member Author

OK, will do. Saving symbol name cleanup for last (note all the dumb "DD" prefixing for now).

@JohanEngelen
Copy link
Member Author

Unfortunately, LLVM3.5 has initializer list constructor of ArrayRef behind an #ifdef LLVM_HAS_INITIALIZER_LISTS. That define is really only set for Clang…

Edit: Sry Johan, I've edited your comment instead of adding my own (kinke). I don't see how I can restore it. :/

@dnadlinger
Copy link
Member

Thanks for tackling the naming cleanup. I'm wondering, by the way, whether we should really keep the separate runtime module, or whether it would be a better idea to just lazily create them in the real codegen modules. There doesn't seem to be any relevant extra overhead, if you are compiling a gazillion small D modules all at once, you'll run into other limitations first.

-DLLVM_HAS_INITIALIZER_LISTS

Seems like a sensible workaround.

@kinke
Copy link
Member

kinke commented Nov 12, 2015

-DLLVM_HAS_INITIALIZER_LISTS

Or std::vector<llvm::StringRef>. There'll be a lot more ArrayRefs anyway, and we all like initializer lists. ;)

@dnadlinger
Copy link
Member

We do know that all our target compilers support C++11, so I don't mind working around the LLVM issue at its source.

@JohanEngelen
Copy link
Member Author

I added a semi-overkill solution for ArrayRef :)
OK, added -DLLVM_HAS_INITIALIZER_LISTS to compile flags
Should have looked a little longer at LLVM's code. LLVM_HAS_INITIALIZER_LISTS is actively suppressed by the Support/Compiler.h header. So -D... won't work. For now, I think I'll go for the previous 'overkill' solution.

@JohanEngelen
Copy link
Member Author

(rebased to hide embarrassing coding error ;))

@JohanEngelen
Copy link
Member Author

@kinke I'm sorry I am sometimes flooding the AppVeyor build server with a string of new commits when trying to debug an issue that perhaps I don't see locally. Is there a way to cancel or remove jobs from the queue? (On Travis, I can click the "cancel job" button)

@kinke
Copy link
Member

kinke commented Nov 15, 2015

Hehe no worries. Unfortunately I have no idea how to give you guys proper access to the AppVeyor project. I just set some explicit permissions for the user role, but I haven't figured how to map GitHub accounts to roles. We may need an official ldc-developer account for AppVeyor.

@JohanEngelen
Copy link
Member Author

@kinke @klickverbot I think the clean-up is ready. What do you think?
(Next step is to move to Windows and see what breaks when I enable passing of dyn arrays as regular structs. What I remember from last time is that the codegen code assumes too much about the function signatures and will break when the Windows ABI changes.)

for (size_t i = 0, e = paramtypes.size(); i < e; ++i) {
fn->addAttributes(i + 1, attribset.getParamAttributes(
i + 1)); // func param index starts at 1
}
Copy link
Member

Choose a reason for hiding this comment

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

This should be replaceable by

fn->setAttributes(AttrSet(fn->getAttributes()).merge(attribset));

with #1217.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks!

@JohanEngelen JohanEngelen changed the title WIP: clean up druntime fwd decls Clean up druntime fwd decls Nov 21, 2015
FuncDeclaration *fdecl) {
IrFuncTy &irFty = getIrFunc(fdecl)->irFty;
AttrSet newAttrs = AttrSet::extractFunctionAndReturnAttributes(func);
AttrSet getParamAttrs(TypeFunction *f, IrFuncTy &irFty) {
Copy link
Member

Choose a reason for hiding this comment

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

Just one more thing - please convert this to a method of IrFuncTy, as it nearly exclusively depends upon it.

@JohanEngelen
Copy link
Member Author

It's still not super pretty. It's because IrFuncTy apparently does not know whether to passThisBeforeSret. Fixing it would require more surgery though :(

@kinke
Copy link
Member

kinke commented Nov 24, 2015

Lgtm, thanks Johan.

So the ABI rewrites are now applied when forward declaring all runtime functions [except for _d_dso_registry() on Linux, which is declared directly in IR].
That doesn't seem to have any effect so far, otherwise we'd already have the problem that we are facing next: applying the ABI rewrites for return value and arguments when calling a runtime function. For regular functions, that's all in DtoCall() and mainly depends on IrFuncTy. So we can't call the LLFunction returned by getRuntimeFunction() directly at IR level anymore.

kinke added a commit that referenced this pull request Nov 24, 2015
@kinke kinke merged commit 1bdc95a into ldc-developers:master Nov 24, 2015
@JohanEngelen
Copy link
Member Author

@thanks kinke.
Indeed, now we have to add a "callRuntimeFunction()" method I think.

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