Giter Site home page Giter Site logo

Comments (3)

yugr avatar yugr commented on July 2, 2024 1

The issue is caused by

%0 = llvm.mlir.constant(#cir.global_view<@a> : !cir.ptr<!cir.int<s, 32>>) : !llvm.ptr

which should have been llvm.mlir.addressof instead. This is caused by generation of

%0 = cir.const(#cir.global_view<@a> : !cir.ptr<!s32i>)

rather than cir.get_global in ScalarExprEmitter::VisitDeclRefExpr:

    if (CIRGenFunction::ConstantEmission Constant = CGF.tryEmitAsConstant(E)) {
      return CGF.buildScalarConstant(Constant, E);
    }

from clangir.

yugr avatar yugr commented on July 2, 2024

A simple workaround is to handle this at lowering stage:

diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 076c0eb814b4..8b23213c70f2 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1100,6 +1100,13 @@ public:
       return op.emitError() << "unsupported constant type " << op.getType();
 
+    if (auto GV = dyn_cast<mlir::cir::GlobalViewAttr>(attr)) {
+      auto newOp = lowerCirAttrAsValue(op, GV, rewriter, getTypeConverter());
+      rewriter.replaceOp(op, newOp);
+      return mlir::success();
+    }
+
     rewriter.replaceOpWithNewOp<mlir::LLVM::ConstantOp>(
         op, getTypeConverter()->convertType(op.getType()), attr);

but I suspect we may not want to generate the problematic cir.const at all.

from clangir.

yugr avatar yugr commented on July 2, 2024

Fixed by #363

from clangir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.