Skip to content

Commit 922892c

Browse files
authored
Merge pull request #245 from ferrandi/feature/support_llvm_sqrt
2 parents 162dfbc + 1099d18 commit 922892c

File tree

130 files changed

+2383
-2717
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+2383
-2717
lines changed

.devcontainer/library-scripts/appimage-setup.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ mkdir -p ${pkg_dir}
1616
echo "Inifating compilers..."
1717
bash ${script_dir}/compiler-download.sh $@
1818

19-
GCC_BINS=("`find ${pkg_dir}/usr/bin -type f -regextype posix-extended -regex '.*g(cc|\+\+)-[0-9]+\.?[0-9]?'`")
20-
CLANG_BINS=("`find ${pkg_dir}/clang+llvm-*/bin -type f -regextype posix-extended -regex '.*clang-[0-9]+\.?[0-9]?'`")
19+
GCC_BINS=("`find ${pkg_dir}/usr/bin -type f -regextype posix-extended -regex '.*g(cc|\+\+)-[0-9]+\.?[0-9]?' 2> /dev/null`")
20+
CLANG_BINS=("`find ${pkg_dir}/clang+llvm-*/bin -type f -regextype posix-extended -regex '.*clang-[0-9]+\.?[0-9]?' 2> /dev/null`")
2121
CLANG_EXES=("clang" "clang++" "clang-cl" "clang-cpp" "ld.lld" "lld" "lld-link" "llvm-ar" "llvm-config" "llvm-dis" "llvm-link" "llvm-lto" "llvm-lto2" "llvm-ranlib" "mlir-opt" "mlir-translate" "opt")
2222
NO_DELETE="-name clang"
2323
for bin in ${CLANG_BINS}
@@ -69,6 +69,9 @@ Type=Application
6969
Terminal=true
7070
Categories=Development;
7171
EOF
72+
# Change back to OWD - Original Working Directory
73+
# Set by AppImage
74+
# see https://github.com/AppImage/AppImageKit/blob/master/src/runtime.c
7275
cat > ${pkg_dir}/usr/bin/tool_select.sh << EOF
7376
#!/bin/bash
7477
export LC_ALL="C"
@@ -82,6 +85,7 @@ fi
8285
if [ ! -e "\$BINARY_PATH" ]; then
8386
BINARY_PATH="\$APPDIR/usr/bin/bambu"
8487
fi
88+
cd "\$OWD"
8589
\$BINARY_PATH "\$@"
8690
EOF
8791
chmod a+x ${pkg_dir}/usr/bin/tool_select.sh

.devcontainer/library-scripts/compiler-setup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ set -e
1111

1212
ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
1313

14-
GCC_BINS=("`find /usr/bin -type f -regextype posix-extended -regex '.*g(cc|\+\+)-[0-9]+\.?[0-9]?'`")
15-
CLANG_BINS=("`find /clang+llvm-*/bin -type f -regextype posix-extended -regex '.*clang-[0-9]+\.?[0-9]?'`")
14+
GCC_BINS=("`find /usr/bin -type f -regextype posix-extended -regex '.*g(cc|\+\+)-[0-9]+\.?[0-9]?' 2> /dev/null`")
15+
CLANG_BINS=("`find /clang+llvm-*/bin -type f -regextype posix-extended -regex '.*clang-[0-9]+\.?[0-9]?' 2> /dev/null`")
1616
CLANG_EXES=("clang" "clang++" "clang-cl" "clang-cpp" "ld.lld" "lld" "lld-link" "llvm-ar" "llvm-config" "llvm-dis" "llvm-link" "llvm-lto" "llvm-lto2" "llvm-ranlib" "mlir-opt" "mlir-translate" "opt")
1717

1818
for clang_exe in ${CLANG_BINS}

.github/actions/generate-appimage/entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ Type=Application
137137
Terminal=true
138138
Categories=Development;
139139
EOF
140+
# Change back to OWD - Original Working Directory
141+
# Set by AppImage
142+
# see https://github.com/AppImage/AppImageKit/blob/master/src/runtime.c
140143
cat > $dist_dir/usr/bin/tool_select.sh << EOF
141144
#!/bin/bash
142145
export LC_ALL="C"
@@ -150,6 +153,7 @@ fi
150153
if [ ! -e "\$BINARY_PATH" ]; then
151154
BINARY_PATH="\$APPDIR/usr/bin/bambu"
152155
fi
156+
cd "\$OWD"
153157
\$BINARY_PATH "\$@"
154158
EOF
155159
chmod a+x $dist_dir/usr/bin/tool_select.sh

etc/clang_plugin/dumpGimple.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ namespace llvm
575575
return ci->use_empty() ? assignCode(t, GT(GIMPLE_CALL)) : assignCode(t, GT(GIMPLE_ASSIGN));
576576
case llvm::Intrinsic::fabs:
577577
return assignCode(t, GT(GIMPLE_ASSIGN));
578+
case llvm::Intrinsic::sqrt:
579+
return assignCode(t, GT(GIMPLE_ASSIGN));
578580
case llvm::Intrinsic::rint:
579581
return assignCode(t, GT(GIMPLE_ASSIGN));
580582
case llvm::Intrinsic::fmuladd:
@@ -729,6 +731,15 @@ namespace llvm
729731
return "fabsl";
730732
fd->print(llvm::errs());
731733
report_fatal_error("Plugin Error");
734+
case llvm::Intrinsic::sqrt:
735+
if(fd->getReturnType()->isFloatTy())
736+
return "sqrtf";
737+
else if(fd->getReturnType()->isDoubleTy())
738+
return "sqrt";
739+
else if(fd->getReturnType()->isFP128Ty())
740+
return "sqrtl";
741+
fd->print(llvm::errs());
742+
report_fatal_error("Plugin Error");
732743
case llvm::Intrinsic::memcpy:
733744
{
734745
auto funType = cast<llvm::FunctionType>(fd->getValueType());
@@ -5518,6 +5529,7 @@ namespace llvm
55185529
switch(id)
55195530
{
55205531
case llvm::Intrinsic::fabs:
5532+
case llvm::Intrinsic::sqrt:
55215533
case llvm::Intrinsic::memcpy:
55225534
case llvm::Intrinsic::memset:
55235535
case llvm::Intrinsic::memmove:

etc/clang_plugin/plugin_ASTAnalyzer.cpp

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -222,22 +222,18 @@ namespace clang
222222
{
223223
return getBaseTypeDecl(ty->getAs<ElaboratedType>()->getNamedType());
224224
}
225-
if(isa<TypedefType>(ty))
225+
if(isa<TypedefType>(ty) || ty->getTypeClass() == Type::Typedef)
226226
{
227-
ND = ty->getAs<TypedefType>()->getDecl();
227+
return getBaseTypeDecl(ty->getAs<TypedefType>()->getDecl()->getUnderlyingType());
228228
}
229-
else if(ty->isRecordType())
229+
if(ty->isRecordType())
230230
{
231231
ND = ty->getAs<RecordType>()->getDecl();
232232
}
233233
else if(ty->isEnumeralType())
234234
{
235235
ND = ty->getAs<EnumType>()->getDecl();
236236
}
237-
else if(ty->getTypeClass() == Type::Typedef)
238-
{
239-
ND = ty->getAs<TypedefType>()->getDecl();
240-
}
241237
else if(ty->isArrayType())
242238
{
243239
return getBaseTypeDecl(ty->castAsArrayTypeUnsafe()->getElementType());
@@ -339,7 +335,6 @@ namespace clang
339335
for(const auto& location_argument : attr_map)
340336
{
341337
const auto& loc = location_argument.first;
342-
const auto& aattr = location_argument.second;
343338
if((prev.isInvalid() || prev < loc) && (loc < locEnd))
344339
{
345340
fun_arg_attr[fname].insert(attr_map[loc].begin(), attr_map[loc].end());
@@ -397,10 +392,11 @@ namespace clang
397392
std::string ParamTypeInclude;
398393
const auto getIncludes = [&](const clang::QualType& type) {
399394
std::string includes;
400-
401395
if(const auto BTD = getBaseTypeDecl(type))
402396
{
403-
includes = SM.getPresumedLoc(BTD->getSourceRange().getBegin(), false).getFilename();
397+
const auto include_file =
398+
SM.getPresumedLoc(BTD->getSourceRange().getBegin(), false).getFilename();
399+
includes = include_file;
404400
}
405401
const auto tmpl_decl =
406402
llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(type->getAsTagDecl());
@@ -414,8 +410,9 @@ namespace clang
414410
{
415411
if(const auto BTD = getBaseTypeDecl(argT.getAsType()))
416412
{
417-
includes += std::string(";") +
418-
SM.getPresumedLoc(BTD->getSourceRange().getBegin(), false).getFilename();
413+
const auto include_file =
414+
SM.getPresumedLoc(BTD->getSourceRange().getBegin(), false).getFilename();
415+
includes += std::string(";") + include_file;
419416
}
420417
}
421418
}
@@ -457,42 +454,40 @@ namespace clang
457454
}
458455
const auto paramTypeRemTD = RemoveTypedef(CA->getElementType());
459456
ParamTypeName = GetTypeNameCanonical(paramTypeRemTD, pp) + " *";
460-
ParamTypeNameOrig =
461-
paramTypeRemTD.getAsString(pp) + (Dimensions == "" ? " *" : " (*)" + Dimensions);
457+
ParamTypeNameOrig = GetTypeNameCanonical(CA->getElementType(), pp) +
458+
(Dimensions == "" ? " *" : " (*)" + Dimensions);
462459
ParamTypeInclude = getIncludes(paramTypeRemTD);
463460
};
464-
const auto getSizeInBytes = [&](QualType T) {
461+
const auto getSizeInBytes = [&](QualType T) -> int64_t {
465462
if(T->isIncompleteType() || T->isTemplateTypeParmType() || isa<TemplateSpecializationType>(T))
466463
{
467-
attr_val["SizeInBytes"] = "1";
468-
return;
464+
return 1;
469465
}
470-
attr_val["SizeInBytes"] = std::to_string(FD->getASTContext()
471-
.getTypeInfoDataSizeInChars(T)
472-
.
466+
return FD->getASTContext()
467+
.getTypeInfoDataSizeInChars(T)
468+
.
473469
#if __clang_major__ <= 11
474-
first
470+
first
475471
#else
476-
Width
472+
Width
477473
#endif
478-
.getQuantity());
474+
.getQuantity();
479475
};
480476

481477
if(isa<DecayedType>(argType))
482478
{
483479
const auto DT = cast<DecayedType>(argType)->getOriginalType().IgnoreParens();
484-
getSizeInBytes(DT);
480+
attr_val["SizeInBytes"] = std::to_string(getSizeInBytes(DT));
485481
if(isa<ConstantArrayType>(DT))
486482
{
487483
manageArray(cast<ConstantArrayType>(DT), true);
488484
}
489485
else
490486
{
491487
const auto paramTypeRemTD = RemoveTypedef(argType);
492-
const auto paramTypeOrigTD = argType;
493488
ParamTypeName = GetTypeNameCanonical(paramTypeRemTD, pp);
494-
ParamTypeNameOrig = paramTypeOrigTD.getAsString(pp);
495-
ParamTypeInclude = getIncludes(paramTypeOrigTD);
489+
ParamTypeNameOrig = GetTypeNameCanonical(argType, pp);
490+
ParamTypeInclude = getIncludes(argType);
496491
}
497492
if(attr_val.find("interface_type") != attr_val.end())
498493
{
@@ -513,20 +508,19 @@ namespace clang
513508
}
514509
else if(argType->isPointerType() || argType->isReferenceType())
515510
{
516-
if(isa<ConstantArrayType>(argType->getPointeeType().IgnoreParens()))
511+
const auto ptdType = argType->getPointeeType().IgnoreParens();
512+
attr_val["SizeInBytes"] = std::to_string(getSizeInBytes(ptdType));
513+
if(isa<ConstantArrayType>(ptdType))
517514
{
518-
getSizeInBytes(argType->getPointeeType().IgnoreParens());
519-
manageArray(cast<ConstantArrayType>(argType->getPointeeType().IgnoreParens()), false);
515+
manageArray(cast<ConstantArrayType>(ptdType), false);
520516
}
521517
else
522518
{
523519
const auto suffix = argType->isPointerType() ? "*" : "&";
524-
const auto paramTypeOrigTD = argType->getPointeeType();
525-
const auto paramTypeRemTD = RemoveTypedef(paramTypeOrigTD);
526-
getSizeInBytes(paramTypeRemTD);
520+
const auto paramTypeRemTD = RemoveTypedef(ptdType);
527521
ParamTypeName = GetTypeNameCanonical(paramTypeRemTD, pp) + suffix;
528-
ParamTypeNameOrig = paramTypeOrigTD.getAsString(pp) + suffix;
529-
ParamTypeInclude = getIncludes(paramTypeOrigTD);
522+
ParamTypeNameOrig = GetTypeNameCanonical(argType, pp);
523+
ParamTypeInclude = getIncludes(ptdType);
530524
}
531525
const auto is_channel_if = ParamTypeName.find("ac_channel<") == 0 ||
532526
ParamTypeName.find("stream<") == 0 ||
@@ -549,12 +543,11 @@ namespace clang
549543
}
550544
else
551545
{
552-
const auto paramTypeOrigTD = argType;
553546
const auto paramTypeRemTD = RemoveTypedef(argType);
554-
getSizeInBytes(paramTypeRemTD);
547+
attr_val["SizeInBytes"] = std::to_string(getSizeInBytes(paramTypeRemTD));
555548
ParamTypeName = GetTypeNameCanonical(paramTypeRemTD, pp);
556-
ParamTypeNameOrig = paramTypeOrigTD.getAsString(pp);
557-
ParamTypeInclude = getIncludes(paramTypeOrigTD);
549+
ParamTypeNameOrig = GetTypeNameCanonical(argType, pp);
550+
ParamTypeInclude = getIncludes(argType);
558551
if(!argType->isBuiltinType() && !argType->isEnumeralType())
559552
{
560553
interface = "none";
@@ -722,7 +715,6 @@ namespace clang
722715
std::string pname;
723716
std::string interface;
724717
const auto loc = PragmaTok.getLocation();
725-
const auto filename = PP.getSourceManager().getPresumedLoc(loc, false).getFilename();
726718
const auto end_parse = [&]() {
727719
PP.Lex(Tok);
728720
if(Tok.isNot(tok::eod))
@@ -849,13 +841,6 @@ namespace clang
849841
D.Report(Tok.getLocation(), D.getCustomDiagID(DiagnosticsEngine::Error, "#pragma HLS_cache %0"))
850842
.AddString(msg);
851843
};
852-
const auto end_parse = [&]() {
853-
PP.Lex(Tok);
854-
if(Tok.isNot(tok::eod))
855-
{
856-
print_error("malformed pragma, expecting end)");
857-
}
858-
};
859844
const auto bundle_parse = [&]() {
860845
PP.Lex(Tok);
861846
if(Tok.isNot(tok::equal))

examples/function_pointers/bambu.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)