Skip to content

Conversation

@Robertorosmaninho
Copy link
Contributor

No description provided.

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

You will have to put all of your code behind a #ifdef for versions of LDC that are not built with MLIR enabled (i.e. old verions of LLVM and those built without MLIR support).

@JohanEngelen
Copy link
Member

You will have to put all of your code behind a #ifdef for versions of LDC that are not built with MLIR enabled (i.e. old verions of LLVM and those built without MLIR support).

You can restrict #ifdef to the stuff that actually requires MLIR library calls. The rest of the code (like the commandline parsing) you can keep, and then let LDC output an error message saying that MLIR is not supported in case LDC was built without it (for which you do need to #ifdef stuff ;-) ).

driver/toobj.cpp Outdated
}

#if LDC_MLIR_ENABLED
void writeMLIRModule(::Module *m, mlir::MLIRContext &mlirContext,
Copy link
Member

Choose a reason for hiding this comment

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

why is this code not part of writeModule? (see e.g. line 415).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to have it in different functions, but I can also put it on writeModule, the problem is that I'll need some extra arguments on this function, so the function should be something like:

void writeModule(llvm::Module *m, const char *filename, ::Module *module,
    mlir::MLIRContext &mlirContext, IRState *irs);

In addition, writeAndFreeLLModulefrom CodeGenerator must also be changed to receive a dmodule as an argument to be used on write module

@JohanEngelen
Copy link
Member

JohanEngelen commented Mar 17, 2020

@Robertorosmaninho I looked more into this. I think I was confused and actually it looks like you have to fully rewrite the IR building code. I thought the same code can output IR and MLIR, but now it appears to me that those are completely separate IR build libraries. So you'd have to rewrite all D AST->MLIR generation from scratch. In that case, there is no point in trying to merge things into toobj.cpp. You have to create a new codegenerator, basically duplicate class CodeGenerator functionality. That is quite something different from DCompute codegen, and will require a lot of work. Start by creating a class MLIRCodeGenerator and have it output an mainly empty mlir file. Then slowly make it emit more and more stuff.

@Robertorosmaninho Robertorosmaninho requested a review from kinke May 12, 2020 01:12
@JohanEngelen
Copy link
Member

See my inline comments, otherwise looks good (I still don't like the addition to codegenerator, but let's live with it for now).
Main thing that is missing is test case(s).

@Robertorosmaninho
Copy link
Contributor Author

See my inline comments, otherwise looks good (I still don't like the addition to codegenerator, but let's live with it for now).
Main thing that is missing is test case(s).

Could you point me some test cases that test whether "file.ll" was created?

@JohanEngelen
Copy link
Member

JohanEngelen commented May 12, 2020

Could you point me some test cases that test whether "file.ll" was created?

Create folder tests/mlir and add your testcase there. Only enable that folder when MLIR is enabled: See how things are done for another conditional built-in capability like dynamic compile: https://github.com/ldc-developers/ldc/blob/master/tests/lit.site.cfg.in#L61-L63

Add a testcase, similar to anything in tests/codegen, like https://github.com/ldc-developers/ldc/blob/master/tests/codegen/wasi.d
More about testcases: https://wiki.dlang.org/LDC_Lit-based_testsuite

@Robertorosmaninho
Copy link
Contributor Author

Could you point me some test cases that test whether "file.ll" was created?

Create folder tests/mlir and add your testcase there. Only enable that folder when MLIR is enabled: See how things are done for another conditional built-in capability like dynamic compile: https://github.com/ldc-developers/ldc/blob/master/tests/lit.site.cfg.in#L61-L63

Thanks!

Add a testcase, similar to anything in tests/codegen, like https://github.com/ldc-developers/ldc/blob/master/tests/codegen/wasi.d
More about testcases: https://wiki.dlang.org/LDC_Lit-based_testsuite

These tests will be presented with the modifications that actually generate some code, another branch is already being prepared to be sent here as PR (https://github.com/Robertorosmaninho/ldc/tree/Introducing-MLIR-translation/tests/codegen_mlir).

Copy link
Member

@JohanEngelen JohanEngelen left a comment

Choose a reason for hiding this comment

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

Overall looks OK now after fixing my remarks. Looking forward to the next PR that adds actual output testing.

@JohanEngelen
Copy link
Member

lgtm

@thewilsonator thewilsonator dismissed JohanEngelen’s stale review May 20, 2020 02:37

Johan is satisied

@kinke kinke merged commit 6274217 into ldc-developers:master May 22, 2020
@kinke
Copy link
Member

kinke commented May 22, 2020

(ldc2 size increase is < 1% for the Azure packages, so no need to postpone this after v1.22 final.)

Thanks Roberto for hanging on, and the (much needed :)) reviewers. Looking forward to the follow ups.

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.

4 participants