Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm-project
Submodule llvm-project updated 2289 files
44 changes: 30 additions & 14 deletions tools/mlir-clang/Lib/clang-mlir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit,
}

ValueCategory MLIRScanner::VisitVarDecl(clang::VarDecl *decl) {
decl = decl->getCanonicalDecl();
mlir::Type subType = getMLIRType(decl->getType());
ValueCategory inite = nullptr;
unsigned memtype = decl->hasAttr<CUDASharedAttr>() ? 5 : 0;
Expand Down Expand Up @@ -3190,6 +3191,17 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) {
}
case clang::CastKind::CK_LValueToRValue: {
if (auto dr = dyn_cast<DeclRefExpr>(E->getSubExpr())) {
if (auto VD = dyn_cast<VarDecl>(dr->getDecl()->getCanonicalDecl())) {
if (NOUR_Constant == dr->isNonOdrUse()) {
auto VarD = cast<VarDecl>(VD);
if (!VarD->getInit()) {
E->dump();
VarD->dump();
}
assert(VarD->getInit());
return Visit(VarD->getInit());
}
}
if (dr->getDecl()->getIdentifier() &&
dr->getDecl()->getName() == "warpSize") {
auto mlirType = getMLIRType(E->getType());
Expand Down Expand Up @@ -3708,10 +3720,12 @@ MLIRASTConsumer::GetOrCreateLLVMGlobal(const ValueDecl *FD,
}

LLVM::Linkage lnk;
if (!isa<VarDecl>(FD))
auto VD = dyn_cast<VarDecl>(FD);
if (!VD)
FD->dump();
auto linkage =
CGM.getLLVMLinkageVarDefinition(cast<VarDecl>(FD), /*isConstant*/ false);
VD = VD->getCanonicalDecl();

auto linkage = CGM.getLLVMLinkageVarDefinition(VD, /*isConstant*/ false);
switch (linkage) {
case llvm::GlobalValue::LinkageTypes::InternalLinkage:
lnk = LLVM::Linkage::Internal;
Expand Down Expand Up @@ -3756,16 +3770,14 @@ MLIRASTConsumer::GetOrCreateLLVMGlobal(const ValueDecl *FD,
auto glob = builder.create<LLVM::GlobalOp>(
module->getLoc(), rt, /*constant*/ false, lnk, name, mlir::Attribute());

if (cast<VarDecl>(FD)->getInit() ||
cast<VarDecl>(FD)->isThisDeclarationADefinition() ==
VarDecl::Definition ||
cast<VarDecl>(FD)->isThisDeclarationADefinition() ==
VarDecl::TentativeDefinition) {
if (VD->getInit() ||
VD->isThisDeclarationADefinition() == VarDecl::Definition ||
VD->isThisDeclarationADefinition() == VarDecl::TentativeDefinition) {
Block *blk = new Block();
glob.getInitializerRegion().push_back(blk);
builder.setInsertionPointToStart(blk);
mlir::Value res;
if (auto init = cast<VarDecl>(FD)->getInit()) {
if (auto init = VD->getInit()) {
MLIRScanner ms(*this, module, LTInfo);
ms.setEntryAndAllocBlock(blk);
res = ms.Visit(const_cast<Expr *>(init)).getValue(builder);
Expand Down Expand Up @@ -3807,15 +3819,19 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix,
mlir::OpBuilder builder(module->getContext());
builder.setInsertionPointToStart(module->getBody());

if (cast<VarDecl>(FD)->isThisDeclarationADefinition() ==
VarDecl::Definition) {
auto VD = dyn_cast<VarDecl>(FD);
if (!VD)
FD->dump();
VD = VD->getCanonicalDecl();

if (VD->isThisDeclarationADefinition() == VarDecl::Definition) {
initial_value = builder.getUnitAttr();
} else if (cast<VarDecl>(FD)->isThisDeclarationADefinition() ==
} else if (VD->isThisDeclarationADefinition() ==
VarDecl::TentativeDefinition) {
initial_value = builder.getUnitAttr();
}

switch (CGM.getLLVMLinkageVarDefinition(cast<VarDecl>(FD),
switch (CGM.getLLVMLinkageVarDefinition(VD,
/*isConstant*/ false)) {
case llvm::GlobalValue::LinkageTypes::InternalLinkage:
lnk = mlir::SymbolTable::Visibility::Private;
Expand Down Expand Up @@ -3861,7 +3877,7 @@ MLIRASTConsumer::GetOrCreateGlobal(const ValueDecl *FD, std::string prefix,
globals[name] = std::make_pair(globalOp, isArray);

if (tryInit)
if (auto init = cast<VarDecl>(FD)->getInit()) {
if (auto init = VD->getInit()) {
MLIRScanner ms(*this, module, LTInfo);
mlir::Block *B = new Block();
ms.setEntryAndAllocBlock(B);
Expand Down
26 changes: 9 additions & 17 deletions tools/mlir-clang/Test/Verification/constexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,17 @@ int foo() {
return sum(sz);
}

// CHECK: memref.global "private" @_ZL3num : memref<1xi32> = dense<14>
// CHECK: func @_Z3foov() -> i32 attributes {llvm.linkage = #llvm.linkage<external>} {
// CHECK-NEXT: %c1_i32 = arith.constant 1 : i32
// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32
// CHECK-NEXT: %c1 = arith.constant 1 : index
// CHECK-NEXT: %c0 = arith.constant 0 : index
// CHECK-NEXT: %c14 = arith.constant 14 : index
// CHECK-NEXT: %0 = memref.alloca() : memref<14xi32>
// CHECK-NEXT: %1 = memref.get_global @_ZL3num : memref<1xi32>
// CHECK-NEXT: %2 = scf.while (%arg0 = %c0_i32) : (i32) -> i32 {
// CHECK-NEXT: %5 = affine.load %1[0] : memref<1xi32>
// CHECK-NEXT: %6 = arith.cmpi slt, %arg0, %5 : i32
// CHECK-NEXT: scf.condition(%6) %arg0 : i32
// CHECK-NEXT: } do {
// CHECK-NEXT: ^bb0(%arg0: i32):
// CHECK-NEXT: %5 = arith.index_cast %arg0 : i32 to index
// CHECK-NEXT: memref.store %arg0, %0[%5] : memref<14xi32>
// CHECK-NEXT: %6 = arith.addi %arg0, %c1_i32 : i32
// CHECK-NEXT: scf.yield %6 : i32
// CHECK-NEXT: scf.for %arg0 = %c0 to %c14 step %c1 {
// CHECK-NEXT: %3 = arith.index_cast %arg0 : index to i32
// CHECK-NEXT: memref.store %3, %0[%arg0] : memref<14xi32>
// CHECK-NEXT: }
// CHECK-NEXT: %3 = memref.cast %0 : memref<14xi32> to memref<?xi32>
// CHECK-NEXT: %4 = call @_Z3sumPi(%3) : (memref<?xi32>) -> i32
// CHECK-NEXT: return %4 : i32
// CHECK-NEXT: %1 = memref.cast %0 : memref<14xi32> to memref<?xi32>
// CHECK-NEXT: %2 = call @_Z3sumPi(%1) : (memref<?xi32>) -> i32
// CHECK-NEXT: return %2 : i32
// CHECK-NEXT: }

9 changes: 2 additions & 7 deletions tools/mlir-clang/Test/Verification/templatemember.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ bool add_kernel_cuda() {
return Info<House>::has_infinity;
}

// CHECK: llvm.mlir.global external @_ZN4InfoI5HouseE12has_infinityE() : i8 {
// CHECK-NEXT: %c1_i8 = arith.constant 1 : i8
// CHECK-NEXT: llvm.return %c1_i8 : i8
// CHECK-NEXT: }
// CHECK: func @_Z15add_kernel_cudav() -> i8 attributes {llvm.linkage = #llvm.linkage<external>} {
// CHECK-NEXT: %0 = llvm.mlir.addressof @_ZN4InfoI5HouseE12has_infinityE : !llvm.ptr<i8>
// CHECK-NEXT: %1 = llvm.load %0 : !llvm.ptr<i8>
// CHECK-NEXT: return %1 : i8
// CHECK-NEXT: %c1_i8 = arith.constant 1 : i8
// CHECK-NEXT: return %c1_i8 : i8
// CHECK-NEXT: }
28 changes: 28 additions & 0 deletions tools/mlir-clang/Test/Verification/twotemplatevardecls.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: mlir-clang %s --function=* -S | FileCheck %s

template<typename _Tp, _Tp __v>
struct integral_constant
{
static constexpr _Tp value = __v;
};

template<typename _Tp, _Tp __v>
constexpr _Tp integral_constant<_Tp, __v>::value;

bool failure() {
return integral_constant<bool, true>::value;
}

unsigned char conv() {
return integral_constant<bool, true>::value;
}


// CHECK: func @_Z7failurev() -> i8
// CHECK-NEXT: %c1_i8 = arith.constant 1 : i8
// CHECK-NEXT: return %c1_i8 : i8
// CHECK-NEXT: }
// CHECK: func @_Z4convv() -> i8
// CHECK-NEXT: %c1_i8 = arith.constant 1 : i8
// CHECK-NEXT: return %c1_i8 : i8
// CHECK-NEXT: }