Skip to content

Conversation

girishpai
Copy link
Contributor

@girishpai girishpai commented Nov 9, 2023

The upstream change to !llvm.ptr has triggered a lot of churn in the LLHD side of CIRCT. We currently don't rely on llhd-sim for anything in-tree. A few breakages remain in the interaction between the llhd-sim runtime and the generated code:

  • test/Dialect/LLHD/Simulator/sim_formats.mlir
  • test/Dialect/LLHD/Simulator/sim_process.mlir
  • test/Dialect/LLHD/Simulator/sim_reg.mlir
  • test/Dialect/LLHD/Simulator/sim_wait.mlir

These are now gated behind a REQUIRES: llhd-sim-fixed in order to unblock the LLVM bump and allow for them to be fixed in parallel. We might want to introduce a few intermediate ops in the LLHD dialect to reduce the pretty big abstraction gap between LLHD ops and LLVM. A lot of things can now go through the SCF dialect (and maybe memrefs?).

@girishpai
Copy link
Contributor Author

@fabianschuiki @maerhart - needed your help based on @mikeurbach suggestion - getting the following compile errors on the latest bump.

 error: no matching function for call to 'mlir::LLVM::LLVMPointerType::get(mlir::Type)'
           LLVM::LLVMPointerType::get(adaptor.getInput().getType()), oneC,
In file included from /scratch/girishp/circt_clones/circt/llvm/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h:51,
                 from /scratch/girishp/circt_clones/circt/llvm/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h:17,
/scratch/girishp/circt_clones/circt/lib/Conversion/HWToLLVM/HWToLLVM.cpp:170:55: error: 'class mlir::LLVM::LLVMPointerType' has no member named 'isOpaque'
     if (cast<LLVM::LLVMPointerType>(arrPtr.getType()).isOpaque())
                                                       ^~~~~~~~

@fabianschuiki
Copy link
Contributor

I'll drop the isOpaque parts now that that seems to have migrated fully.

@fabianschuiki
Copy link
Contributor

I've pushed my tweaks. I didn't catch everything yet. There's quite a bit of pointer stuff going on on the LLHD side -- I probably missed a few there.

@girishpai
Copy link
Contributor Author

I've pushed my tweaks. I didn't catch everything yet. There's quite a bit of pointer stuff going on on the LLHD side -- I probably missed a few there.

Thanks @fabianschuiki looks like CI still failed - should we wait on @maerhart for the rest of the fixes?

@girishpai
Copy link
Contributor Author

@fabianschuiki @maerhart continuing to see errors - unfortunately seems like lot of onion peeling. Could either of you look into this?

/scratch/girishp/circt_clones/circt/lib/Conversion/LLHDToLLVM/LLHDToLLVM.cpp:1424:59: error: no matching function for call to ‘mlir::LLVM::LLVMPointerType::get(mlir::Type&)’
           op->getLoc(), LLVM::LLVMPointerType::get(finalTy), sigDetail[0]);
                                                           ^
In file included from /scratch/girishp/circt_clones/circt/llvm/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h:51,
                 from /scratch/girishp/circt_clones/circt/llvm/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h:17,
                 from /scratch/girishp/circt_clones/circt/llvm/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h:18,
                 from /scratch/girishp/circt_clones/circt/lib/Conversion/LLHDToLLVM/LLHDToLLVM.cpp:30:
/scratch/girishp/circt_clones/circt/llvm/build/tools/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h.inc:104:26: note: candidate: ‘static mlir::LLVM::LLVMPointerType mlir::LLVM::LLVMPointerType::get(mlir::MLIRContext*, unsigned int)’
   static LLVMPointerType get(::mlir::MLIRContext *context, unsigned addressSpace = 0);
                          ^~~
/scratch/girishp/circt_clones/circt/llvm/build/tools/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h.inc:104:26: note:   no known conversion for argument 1 from ‘mlir::Type’ to ‘mlir::MLIRContext*’
/scratch/girishp/circt_clones/circt/lib/Conversion/LLHDToLLVM/LLHDToLLVM.cpp: In member function ‘virtual mlir::LogicalResult {anonymous}::DrvOpConversion::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const’:
/scratch/girishp/circt_clones/circt/lib/Conversion/LLHDToLLVM/LLHDToLLVM.cpp:1478:78: error: no matching function for call to ‘mlir::LLVM::LLVMPointerType::get(mlir::Type)’
           LLVM::LLVMPointerType::get(typeConverter->convertType(underlyingTy));
                                                                              ^
In file included from /scratch/girishp/circt_clones/circt/llvm/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h:51,
                 from /scratch/girishp/circt_clones/circt/llvm/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h:17,
                 from /scratch/girishp/circt_clones/circt/llvm/mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h:18,
                 from /scratch/girishp/circt_clones/circt/lib/Conversion/LLHDToLLVM/LLHDToLLVM.cpp:30:
/scratch/girishp/circt_clones/circt/llvm/build/tools/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h.inc:104:26: note: candidate: ‘static mlir::LLVM::LLVMPointerType mlir::LLVM::LLVMPointerType::get(mlir::MLIRContext*, unsigned int)’
   static LLVMPointerType get(::mlir::MLIRContext *context, unsigned addressSpace = 0);
                          ^~~
/scratch/girishp/circt_clones/circt/llvm/build/tools/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h.inc:104:26: note:   no known conversion for argument 1 from ‘mlir::Type’ to ‘mlir::MLIRContext*’
/scratch/girishp/circt_clones/circt/lib/Conversion/LLHDToLLVM/LLHDToLLVM.cpp:1526:55: error: no matching function for call to ‘mlir::LLVM::LLVMPointerType::get(mlir::Type&)’
         op->getLoc(), LLVM::LLVMPointerType::get(valTy), oneConst, 4);

@fabianschuiki
Copy link
Contributor

Going to do another pass here to get us through the build.

@fabianschuiki
Copy link
Contributor

Fixed all the compilation errors. Things now build properly and then fail in the tests. Most of them are probably just changes in MLIR text output and not actual breakages. Going to take a look at those next.

We currently don't rely on `llhd-sim` for anything in-tree. The upstream
change to `!llvm.ptr` has triggered a lot of churn in the LLHD side of
CIRCT. A few breakages remain in the interaction between the llhd-sim
runtime and the generated code. These are now gated behind a
`REQUIRES: llhd-sim-fixed` in order to unblock the LLVM bump and allow
for them to be fixed in parallel.
Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

I've fixed the remaining breakages in the LLHD, HW, and Arc conversions to LLVM. There are still a few runtime breakages in llhd-sim itself, but I've disabled the corresponding tests for now to unblock this LLVM bump. Some of those breakages are likely very subtle and will take some time to track down.

@girishpai You probably want to do a "Squash and Merge" to compress all the small fix commits into one big bump commit, and preserve the PR message as commit message to leave a few breadcrumbs regarding the disabled llhd-sim tests.

@girishpai
Copy link
Contributor Author

Thanks @fabianschuiki - I am seeing some failures in short integration tests - related to Python bindnigs

Failed Tests (2):
  CIRCT :: Bindings/Python/dialects/hw.py
  CIRCT :: Bindings/Python/dialects/om.py


Testing Time: 16.01s

Total Discovered Tests: 89
  Unsupported:  3 (3.37%)
  Passed     : 84 (94.38%)
  Failed     :  2 (2.25%)
FAILED: tools/circt/integration_test/CMakeFiles/check-circt-integration /__w/circt/circt/build/tools/circt/integration_test/CMakeFiles/check-circt-integration 
cd /__w/circt/circt/build/tools/circt/integration_test && /usr/bin/python3.9 /__w/circt/circt/build/./bin/llvm-lit -v --show-unsupported /__w/circt/circt/build/tools/circt/integration_test

@mikeurbach any chance its related to your area of expertise?

@mikeurbach
Copy link
Contributor

Let me take a look at those failures.

@mikeurbach
Copy link
Contributor

@makslevental do you have any idea about this Python issue? What I'm observing is with the latest LLVM update, the automatic downcasting is not working. I'm wondering if you have any idea what might be wrong since you were poking around in here for the value casters since the last time CIRCT updated LLVM.

For example, one of the errors is here:

if hasattr(cls, "sym_name") and cls.sym_name.value == "Paths"

In this case, cls.sym_name is expected to be a StringAttr, but now it is just Attribute. I've tried calling cls.sym_name.maybe_downcast(), and this returns Attribute, if that helps pinpoint the issue at all.

Another example is here:

# CHECK-NEXT: [IntegerType(i2), IntegerType(i32), Type(!hw.inout<i32>)]
print(module_type.input_types)

ModuleType is our own type, and its input_types returns a list of MlirType:

.def_property_readonly(

Previously, the IntegerTypes would automatically be downcast, which our test was checking. Now they are coming back as just Type.

I looked through recent commits to MLIR, and I don't see anything that was obviously updated here, so I'm curious if you have any ideas.

@makslevental
Copy link
Contributor

I suspect it's this change that's malfunctioning here for you llvm/llvm-project@7c85086#diff-9f49e93375e3ede73d748a7b5f9809da29e96c7f62674cd8b9eaf50181bd17ed, since all of these types and attributes are mlir_sub... things. I can't figure it out just by looking at it (because you guys don't have getTypeIDFunction functions?) but let me clone/debug.

@mikeurbach
Copy link
Contributor

Thanks for taking a look, but I think I've got it. It's actually related to this: llvm/llvm-project@5192e29#diff-1f295ae31d665f9a778ea210c0816a22c621c34d54bf5b83b21686bf0432a918R126.

With that change, loadDialectModule now returns a boolean if it successfully loaded the dialect or had already loaded it, and lookupTypeCaster and friends only proceed if it returned true.

What do the Attribute and Type I mentioned previously have in common? They're builtin. There is nothing to load, so within loadDialectModule, loaded.is_none() is always true, that method returns false, and lookupTypeCaster exits early.

I'm pretty sure this is it, with a small patch the automatic downcasting is working again. I'll make a small test case to show the issue and send a PR.

@mikeurbach
Copy link
Contributor

@girishpai I'm not sure if there's any way to work around this in CIRCT, so let's hold this PR. If I'm on the right track, we might want to wait until the fix is in MLIR and update again.

@makslevental
Copy link
Contributor

What do the Attribute and Type I mentioned previously have in common? They're builtin. There is nothing to load, so

What do you mean by "builtin"? I think you mean mlir_sub...?

that method returns false, and lookupTypeCaster exits early.

If you don't have a dialect (which I know you do) none of the typeCasters would be usable for you, so the bail is warranted.

I'm not sure if there's any way to work around this in CIRCT, so let's hold this PR. If I'm on the right track, we might want to wait until the fix is in MLIR and update again.

There is a means and it's described in the same PR but it's only for unregistered dialects so I don't know how it could be something that worked for you previously.

@mikeurbach
Copy link
Contributor

@makslevental helped me figure this out. The issue I described above was the root cause, but the fix is actually simpler: make sure the builtin dialect actually gets loaded. This is something we can control in CIRCT, and the latest commit fixes this. We're discussing that we probably shouldn't have to do this manually, but for now we can proceed.

@mikeurbach
Copy link
Contributor

I'm going to go ahead and merge this. No sense in waiting.

@mikeurbach
Copy link
Contributor

@teqdruid you might not hit the same issue in PyCDE, but I just remembered that you have your own CMake setup there. I didn't update it, but if there is any problem, the short term solution is to apply the last commit on this PR. The longer term solution would be the linked PR.

@girishpai
Copy link
Contributor Author

Thanks a lot @mikeurbach @fabianschuiki @maerhart for taking care of all the issues promptly!!

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