Skip to content

Commit a6970c1

Browse files
committed
Handle endl
1 parent 2f304a3 commit a6970c1

File tree

2 files changed

+36
-79
lines changed

2 files changed

+36
-79
lines changed

llvm-project

tools/mlir-clang/Lib/clang-mlir.cc

Lines changed: 35 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,11 @@ MLIRScanner::EmitGPUCallExpr(clang::CallExpr *expr) {
15641564
builder.create<mlir::NVVM::Barrier0Op>(loc);
15651565
return make_pair(ValueCategory(), true);
15661566
}
1567+
if (sr->getDecl()->getIdentifier() &&
1568+
sr->getDecl()->getName() == "cudaFuncSetCacheConfig") {
1569+
llvm::errs() << " Not emitting GPU option: cudaFuncSetCacheConfig\n";
1570+
return make_pair(ValueCategory(), true);
1571+
}
15671572
// TODO move free out.
15681573
if (sr->getDecl()->getIdentifier() &&
15691574
(sr->getDecl()->getName() == "free" ||
@@ -2728,6 +2733,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) {
27282733
}
27292734

27302735
if (!callee || callee->isVariadic()) {
2736+
bool isReference = expr->isLValue() || expr->isXValue();
27312737
std::vector<mlir::Value> args;
27322738
for (auto a : expr->arguments()) {
27332739
args.push_back(getLLVM(a));
@@ -2739,91 +2745,31 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) {
27392745
builder.create<mlir::LLVM::CallOp>(loc, strcmpF, args).getResult(0);
27402746
} else {
27412747
args.insert(args.begin(), getLLVM(expr->getCallee()));
2742-
called =
2743-
builder
2744-
.create<mlir::LLVM::CallOp>(
2745-
loc,
2746-
std::vector<mlir::Type>({Glob.typeTranslator.translateType(
2747-
anonymize(getLLVMType(expr->getType())))}),
2748-
args)
2749-
.getResult(0);
2748+
auto CT = expr->getType();
2749+
if (isReference)
2750+
CT = Glob.CGM.getContext().getLValueReferenceType(CT);
2751+
auto rt = Glob.typeTranslator.translateType(anonymize(getLLVMType(CT)));
2752+
auto ft = args[0]
2753+
.getType()
2754+
.cast<LLVM::LLVMPointerType>()
2755+
.getElementType()
2756+
.cast<LLVM::LLVMFunctionType>();
2757+
assert(rt == ft.getReturnType());
2758+
called = builder
2759+
.create<mlir::LLVM::CallOp>(
2760+
loc, std::vector<mlir::Type>({rt}), args)
2761+
.getResult(0);
27502762
}
2751-
bool isReference = expr->isLValue() || expr->isXValue();
27522763
if (isReference) {
27532764
if (!(called.getType().isa<LLVM::LLVMPointerType>() ||
27542765
called.getType().isa<MemRefType>())) {
27552766
expr->dump();
2767+
expr->getType()->dump();
27562768
llvm::errs() << " call: " << called << "\n";
27572769
}
27582770
}
27592771
return ValueCategory(called, isReference);
27602772
}
2761-
#if 0
2762-
if (auto ic = dyn_cast<ImplicitCastExpr>(expr->getCallee()))
2763-
if (auto sr = dyn_cast<DeclRefExpr>(ic->getSubExpr())) {
2764-
if (sr->getDecl()->getIdentifier() &&
2765-
sr->getDecl()->getName() == "gettimeofday") {
2766-
auto tocall = EmitCallee(expr->getCallee());
2767-
auto fprintfF = Glob.GetOrCreateLLVMFunction(tocall);
2768-
std::vector<mlir::Value> args;
2769-
size_t i = 0;
2770-
mlir::Value tostore = nullptr;
2771-
mlir::Value alloc;
2772-
for (auto a : expr->arguments()) {
2773-
2774-
if (i == 0) {
2775-
tostore = Visit(a).getValue(builder);
2776-
auto mt = tostore.getType().cast<MemRefType>();
2777-
auto shape = std::vector<int64_t>(mt.getShape());
2778-
mlir::Value res;
2779-
shape.erase(shape.begin());
2780-
auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(),
2781-
MemRefLayoutAttrInterface(),
2782-
mt.getMemorySpace());
2783-
tostore = builder.create<polygeist::SubIndexOp>(
2784-
loc, mt0, tostore, getConstantIndex(0));
2785-
i++;
2786-
auto indexType = mlir::IntegerType::get(module->getContext(), 64);
2787-
OpBuilder abuilder(builder.getContext());
2788-
abuilder.setInsertionPointToStart(allocationScope);
2789-
auto one = abuilder.create<ConstantIntOp>(loc, 1, indexType);
2790-
alloc = abuilder.create<mlir::LLVM::AllocaOp>(
2791-
loc,
2792-
Glob.typeTranslator.translateType(
2793-
anonymize(getLLVMType(a->getType()))),
2794-
one, 0);
2795-
args.push_back(alloc);
2796-
continue;
2797-
}
2798-
auto llvmType = Glob.typeTranslator.translateType(
2799-
anonymize(getLLVMType(a->getType())));
2800-
2801-
if (auto IC1 = dyn_cast<ImplicitCastExpr>(a)) {
2802-
if (IC1->getCastKind() == clang::CastKind::CK_NullToPointer) {
2803-
args.push_back(builder.create<mlir::LLVM::NullOp>(loc, llvmType));
2804-
i++;
2805-
continue;
2806-
}
2807-
}
2808-
mlir::Value val = Visit(a).getValue(builder);
2809-
args.push_back(val);
2810-
i++;
2811-
}
2812-
assert(alloc);
2813-
2814-
auto co = builder.create<mlir::LLVM::CallOp>(loc, fprintfF, args)
2815-
.getResult(0);
2816-
// co = builder.create<IndexCastOp>( // was DialectCastOp
2817-
// loc, getMLIRType(expr->getType()), co);
2818-
auto ret = co;
2819-
2820-
auto allV = ValueCategory(alloc, /*isReference*/ true);
2821-
ValueCategory(tostore, /*isReference*/ true)
2822-
.store(builder, allV, /*isArray*/ true);
2823-
return ValueCategory(ret, /*isReference*/ false);
2824-
}
2825-
}
2826-
#endif
28272773

28282774
auto tocall = EmitDirectCallee(callee);
28292775

@@ -4911,7 +4857,9 @@ MLIRASTConsumer::GetOrCreateLLVMFunction(const FunctionDecl *FD) {
49114857
lnk = LLVM::Linkage::External;
49124858
break;
49134859
case llvm::GlobalValue::LinkageTypes::AvailableExternallyLinkage:
4914-
lnk = LLVM::Linkage::AvailableExternally;
4860+
// Available Externally not supported in MLIR LLVM Dialect
4861+
// lnk = LLVM::Linkage::AvailableExternally;
4862+
lnk = LLVM::Linkage::External;
49154863
break;
49164864
case llvm::GlobalValue::LinkageTypes::LinkOnceAnyLinkage:
49174865
lnk = LLVM::Linkage::Linkonce;
@@ -5782,6 +5730,15 @@ mlir::Type MLIRASTConsumer::getMLIRType(clang::QualType qt, bool *implicitRef,
57825730
return mlir::MemRefType::get({size}, ET);
57835731
}
57845732

5733+
if (auto FT = dyn_cast<clang::FunctionProtoType>(t)) {
5734+
auto RT = getMLIRType(FT->getReturnType());
5735+
SmallVector<mlir::Type> Args;
5736+
for (auto T : FT->getParamTypes()) {
5737+
Args.push_back(getMLIRType(T));
5738+
}
5739+
return LLVM::LLVMFunctionType::get(RT, Args, FT->isVariadic());
5740+
}
5741+
57855742
if (isa<clang::PointerType, clang::ReferenceType>(t)) {
57865743
int64_t outer = (isa<clang::PointerType>(t)) ? -1 : -1;
57875744
auto PTT = isa<clang::PointerType>(t) ? cast<clang::PointerType>(t)
@@ -5791,7 +5748,7 @@ mlir::Type MLIRASTConsumer::getMLIRType(clang::QualType qt, bool *implicitRef,
57915748
->getPointeeType()
57925749
->getUnqualifiedDesugaredType();
57935750

5794-
if (PTT->isCharType() || PTT->isVoidType() || PTT->isFunctionType()) {
5751+
if (PTT->isCharType() || PTT->isVoidType()) {
57955752
llvm::Type *T = CGM.getTypes().ConvertType(QualType(t, 0));
57965753
return typeTranslator.translateType(T);
57975754
}
@@ -5803,7 +5760,7 @@ mlir::Type MLIRASTConsumer::getMLIRType(clang::QualType qt, bool *implicitRef,
58035760
&subRef, /*allowMerge*/ true);
58045761

58055762
if (subType.isa<LLVM::LLVMArrayType, LLVM::LLVMStructType,
5806-
LLVM::LLVMPointerType>())
5763+
LLVM::LLVMPointerType, LLVM::LLVMFunctionType>())
58075764
return LLVM::LLVMPointerType::get(subType);
58085765

58095766
if (isa<clang::ArrayType>(PTT)) {

0 commit comments

Comments
 (0)