Skip to content

Commit

Permalink
Fix/testbench generation (ferrandi#109)
Browse files Browse the repository at this point in the history
* Verilog testbench output fix

* Testbench binary initialization file check

* Code refactoring

* Testbench expected output generator update

* C++ templates handling update

* Changed tolerance of frequency slack

* Added keep_hierarchy support.

* Support for hls::stream

* Dump GIMPLE clang plugin cpp name fix

* Improved ac_types library.

* Fix PIC variable clashing with -DPIC

* Fix gengtype detection

---------

Co-authored-by: Giovanni Gozzi <[email protected]>
Co-authored-by: Fabrizio Ferrandi <[email protected]>
Co-authored-by: Zebreus <[email protected]>
  • Loading branch information
4 people authored Feb 2, 2023
1 parent 8cade47 commit bc81cc4
Show file tree
Hide file tree
Showing 29 changed files with 668 additions and 772 deletions.
2 changes: 1 addition & 1 deletion .github/SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Use the following to install the required Python version through PyEnv and set i
```
CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.15
pyenv global 3.6.15
pip install -r /path/to/repo/et/scripts/requirements.txt
pip install -r /path/to/repo/etc/scripts/requirements.txt
```

Note that Github Runners are launched as systemd services, thus `~/.bashrc` or `~/.profile` are not loaded.
Expand Down
14 changes: 7 additions & 7 deletions etc/clang_plugin/llvm/eSSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,10 @@ namespace eSSAInfoClasses
if(llvm::isa<PredicateWithEdge>(ValInfo))
{
llvm::IRBuilder<> B(&llvm::cast<PredicateWithEdge>(ValInfo)->To->front());
auto* PIC = B.CreatePHI(Op->getType(), 1, Op->getName() + "." + llvm::Twine(Counter++));
PIC->addIncoming(Op, llvm::cast<PredicateWithEdge>(ValInfo)->From);
PredicateMap.insert({PIC, ValInfo});
Result.Def = PIC;
auto* pic = B.CreatePHI(Op->getType(), 1, Op->getName() + "." + llvm::Twine(Counter++));
pic->addIncoming(Op, llvm::cast<PredicateWithEdge>(ValInfo)->From);
PredicateMap.insert({pic, ValInfo});
Result.Def = pic;
}
else
{
Expand All @@ -497,9 +497,9 @@ namespace eSSAInfoClasses
// llvm::IRBuilder<> B(PAssume->AssumeInst);
// llvm::Function *IF = llvm::Intrinsic::getDeclaration(
// F.getParent(), llvm::Intrinsic::ssa_copy, Op->getType());
// llvm::CallInst *PIC = B.CreateCall(IF, Op);
// PredicateMap.insert({PIC, ValInfo});
// Result.Def = PIC;
// llvm::CallInst *pic = B.CreateCall(IF, Op);
// PredicateMap.insert({pic, ValInfo});
// Result.Def = pic;
}
}
return RenameStack.back().Def;
Expand Down
14 changes: 9 additions & 5 deletions etc/clang_plugin/plugin_ASTAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ namespace clang
QualType RemoveTypedef(QualType t) const
{
if(t->getTypeClass() == Type::Typedef)
{
return RemoveTypedef(t->getAs<TypedefType>()->getDecl()->getUnderlyingType());
}
else if(t->getTypeClass() == Type::TemplateSpecialization)
{
return t;
Expand Down Expand Up @@ -483,16 +485,16 @@ namespace clang
else
{
const auto paramTypeRemTD = RemoveTypedef(PT->getPointeeType());
ParamTypeName = GetTypeNameCanonical(paramTypeRemTD, pp) + " *";
ParamTypeNameOrig = paramTypeRemTD.getAsString(pp) + " *";
ParamTypeName = GetTypeNameCanonical(paramTypeRemTD, pp) + "*";
ParamTypeNameOrig = paramTypeRemTD.getAsString(pp) + "*";
ParamTypeInclude = getIncludes(paramTypeRemTD);
}
}
else if(const auto RT = dyn_cast<ReferenceType>(argType))
{
const auto paramTypeRemTD = RemoveTypedef(RT->getPointeeType());
ParamTypeName = GetTypeNameCanonical(paramTypeRemTD, pp) + " &";
ParamTypeNameOrig = paramTypeRemTD.getAsString(pp) + " &";
ParamTypeName = GetTypeNameCanonical(paramTypeRemTD, pp) + "&";
ParamTypeNameOrig = paramTypeRemTD.getAsString(pp) + "&";
ParamTypeInclude = getIncludes(paramTypeRemTD);
}
else
Expand All @@ -502,7 +504,9 @@ namespace clang
ParamTypeNameOrig = paramTypeRemTD.getAsString(pp);
ParamTypeInclude = getIncludes(paramTypeRemTD);
}
const auto is_channel_if = ParamTypeName.find("ac_channel<") == 0;
const auto is_channel_if = ParamTypeName.find("ac_channel<") == 0 ||
ParamTypeName.find("stream<") == 0 ||
ParamTypeName.find("hls::stream<") == 0;
interface = is_channel_if ? "fifo" : "ptrdefault";
if(attr_val.find("interface_type") != attr_val.end())
{
Expand Down
56 changes: 26 additions & 30 deletions etc/clang_plugin/plugin_dumpGimpleSSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
#include <sstream>
#include <string>

#ifdef CPP_LANGUAGE
#define CLANG_VERSION_SYMBOL_DUMP_SSA CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSACpp)
#define CLANG_VERSION_STRING_DUMP_SSA CLANG_VERSION_STRING(_plugin_dumpGimpleSSACpp)
#else
#define CLANG_VERSION_SYMBOL_DUMP_SSA CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)
#define CLANG_VERSION_STRING_DUMP_SSA CLANG_VERSION_STRING(_plugin_dumpGimpleSSA)
#endif

namespace llvm
{
cl::opt<std::string> TopFunctionName("panda-topfname", cl::desc("Specify the name of the top function"),
Expand All @@ -112,18 +120,16 @@ namespace llvm
cl::opt<std::string> CostTable("panda-cost-table", cl::desc("Specify the cost per operation"),
cl::value_desc("cost table"));

struct CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)
: public ModulePass
struct CLANG_VERSION_SYMBOL_DUMP_SSA : public ModulePass
#if __clang_major__ >= 13
,
public PassInfoMixin<CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)>
,
public PassInfoMixin<CLANG_VERSION_SYMBOL_DUMP_SSA>
#endif
{
static char ID;
bool earlyAnalysis;

CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)
(bool _earlyAnalysis = false) : ModulePass(ID), earlyAnalysis(_earlyAnalysis)
CLANG_VERSION_SYMBOL_DUMP_SSA(bool _earlyAnalysis = false) : ModulePass(ID), earlyAnalysis(_earlyAnalysis)
{
initializeLoopInfoWrapperPassPass(*PassRegistry::getPassRegistry());
initializeLazyValueInfoWrapperPassPass(*PassRegistry::getPassRegistry());
Expand All @@ -138,9 +144,8 @@ namespace llvm
}

#if __clang_major__ >= 13
CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)
(const CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA) & other)
: CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)(other.earlyAnalysis)
CLANG_VERSION_SYMBOL_DUMP_SSA(const CLANG_VERSION_SYMBOL_DUMP_SSA& other)
: CLANG_VERSION_SYMBOL_DUMP_SSA(other.earlyAnalysis)
{
}
#endif
Expand Down Expand Up @@ -284,7 +289,7 @@ namespace llvm

StringRef getPassName() const override
{
return CLANG_VERSION_STRING(_plugin_dumpGimpleSSA);
return CLANG_VERSION_STRING_DUMP_SSA;
}

void getAnalysisUsage(AnalysisUsage& AU) const override
Expand Down Expand Up @@ -336,33 +341,24 @@ namespace llvm
#endif
};

char CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)::ID = 0;
char CLANG_VERSION_SYMBOL_DUMP_SSA::ID = 0;

} // namespace llvm

// Currently there is no difference between c++ or c serialization
#if !defined(_WIN32)
#if CPP_LANGUAGE
// static llvm::RegisterPass<llvm::CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)<true>>
// XPassEarly(CLANG_VERSION_STRING(_plugin_dumpGimpleSSACppEarly), "Custom Value Range Based optimization step: LLVM
// pass", false /* Only looks at CFG */, false /* Analysis Pass */);
static llvm::RegisterPass<llvm::CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)>
XPass(CLANG_VERSION_STRING(_plugin_dumpGimpleSSACpp), "Dump gimple ssa raw format starting from LLVM IR: LLVM pass",
false /* Only looks at CFG */, false /* Analysis Pass */);
#else
// static llvm::RegisterPass<llvm::CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)<true>>
// static llvm::RegisterPass<llvm::CLANG_VERSION_SYMBOL_DUMP_SSA<true>>
// XPassEarly(CLANG_VERSION_STRING(_plugin_dumpGimpleSSAEarly), "Custom Value Range Based optimization step: LLVM pass",
// false /* Only looks at CFG */, false /* Analysis Pass */);
static llvm::RegisterPass<llvm::CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)>
XPass(CLANG_VERSION_STRING(_plugin_dumpGimpleSSA), "Dump gimple ssa raw format starting from LLVM IR: LLVM pass",
static llvm::RegisterPass<llvm::CLANG_VERSION_SYMBOL_DUMP_SSA>
XPass(CLANG_VERSION_STRING_DUMP_SSA, "Dump gimple ssa raw format starting from LLVM IR: LLVM pass",
false /* Only looks at CFG */, false /* Analysis Pass */);
#endif
#endif

#if __clang_major__ >= 13
llvm::PassPluginLibraryInfo CLANG_PLUGIN_INFO(_plugin_dumpGimpleSSA)()
{
return {LLVM_PLUGIN_API_VERSION, CLANG_VERSION_STRING(_plugin_dumpGimpleSSA), "v0.12", [](llvm::PassBuilder& PB) {
return {LLVM_PLUGIN_API_VERSION, CLANG_VERSION_STRING_DUMP_SSA, "v0.12", [](llvm::PassBuilder& PB) {
const auto load = [](llvm::ModulePassManager& MPM) {
llvm::FunctionPassManager FPM1;
FPM1.addPass(llvm::LowerAtomicPass());
Expand All @@ -375,12 +371,12 @@ llvm::PassPluginLibraryInfo CLANG_PLUGIN_INFO(_plugin_dumpGimpleSSA)()
FPM2.addPass(llvm::BreakCriticalEdgesPass());
FPM2.addPass(llvm::UnifyFunctionExitNodesPass());
MPM.addPass(llvm::createModuleToFunctionPassAdaptor(std::move(FPM2)));
MPM.addPass(llvm::CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)());
MPM.addPass(llvm::CLANG_VERSION_SYMBOL_DUMP_SSA());
return true;
};
PB.registerPipelineParsingCallback([&](llvm::StringRef Name, llvm::ModulePassManager& MPM,
llvm::ArrayRef<llvm::PassBuilder::PipelineElement>) {
if(Name == CLANG_VERSION_STRING(_plugin_dumpGimpleSSA))
if(Name == CLANG_VERSION_STRING_DUMP_SSA)
{
return load(MPM);
}
Expand Down Expand Up @@ -412,7 +408,7 @@ static void loadPass(const llvm::PassManagerBuilder&, llvm::legacy::PassManagerB
PM.add(llvm::createBreakCriticalEdgesPass());
PM.add(llvm::createUnifyFunctionExitNodesPass());

PM.add(new llvm::CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA)());
PM.add(new llvm::CLANG_VERSION_SYMBOL_DUMP_SSA());
}

static llvm::RegisterStandardPasses llvmtoolLoader_Ox(llvm::PassManagerBuilder::EP_OptimizerLast, loadPass);
Expand All @@ -422,7 +418,7 @@ static llvm::RegisterStandardPasses llvmtoolLoader_Ox(llvm::PassManagerBuilder::
// PM.add(llvm::createPromoteMemoryToRegisterPass());
// PM.add(llvm::createGlobalOptimizerPass());
// PM.add(llvm::createBreakCriticalEdgesPass());
// PM.add(new llvm::CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA) < true > ());
// PM.add(new llvm::CLANG_VERSION_SYMBOL_DUMP_SSA < true > ());
// }
// These constructors add our pass to a list of global extensions.

Expand All @@ -438,7 +434,7 @@ static llvm::RegisterStandardPasses llvmtoolLoader_Ox(llvm::PassManagerBuilder::
//
// using namespace llvm;
//
// INITIALIZE_PASS_BEGIN(CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA), CLANG_VERSION_STRING(_plugin_dumpGimpleSSA),
// INITIALIZE_PASS_BEGIN(CLANG_VERSION_SYMBOL_DUMP_SSA, CLANG_VERSION_STRING_DUMP_SSA,
// "Dump gimple ssa raw format starting from LLVM IR: LLVM pass", false, false)
// INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
// INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass)
Expand All @@ -450,5 +446,5 @@ static llvm::RegisterStandardPasses llvmtoolLoader_Ox(llvm::PassManagerBuilder::
// INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
// INITIALIZE_PASS_DEPENDENCY(DominanceFrontierWrapperPass)
// INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
// INITIALIZE_PASS_END(CLANG_VERSION_SYMBOL(_plugin_dumpGimpleSSA), CLANG_VERSION_STRING(_plugin_dumpGimpleSSA),
// INITIALIZE_PASS_END(CLANG_VERSION_SYMBOL_DUMP_SSA, CLANG_VERSION_STRING_DUMP_SSA,
// "Dump gimple ssa raw format starting from LLVM IR: LLVM pass", false, false)
2 changes: 1 addition & 1 deletion etc/devices/Xilinx_devices/Alveo-Ultrascale-VVD.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
<cmd name="power_opt_design" condition="${__power_optimization__}"/>
<cmd name="report_clock_utilization -file $outputDir/clock_util.rpt"/>
<cmd name="# Optionally run optimization if there are timing violations after placement"/>
<cmd name="if {[get_property SLACK [get_timing_paths -max_paths 1 -nworst 1 -setup]] &lt; 0.5} {"/>
<cmd name="if {[get_property SLACK [get_timing_paths -max_paths 1 -nworst 1 -setup]] &lt; [expr {0.05 * ${__clk_period__}}]} {"/>
<cmd name=" puts &quot;Found setup timing violations => running physical optimization&quot;"/>
<cmd name=" phys_opt_design -directive AlternateFlowWithRetiming"/>
<cmd name="}"/>
Expand Down
Loading

0 comments on commit bc81cc4

Please sign in to comment.