Skip to content

Commit

Permalink
[fix] add opcodehelper to enable github workflow testing
Browse files Browse the repository at this point in the history
  • Loading branch information
HobbitQia committed Nov 23, 2024
1 parent 83d04f3 commit 4153456
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ jobs:
run: |
clang-12 -emit-llvm -O3 -fno-unroll-loops -fno-vectorize -o nonlinear_test.bc -c nonlinear_test.cpp
opt-12 -load ../../build/src/libmapperPass.so -load ${LOCALBASE}/lib/libLLVMSupport.so -load ${LOCALBASE}/lib/libclangAST.so -mapperPass -verify -mapperPass nonlinear_test.bc
sh test.sh
- name: Test Idiv Feature
working-directory: ${{github.workspace}}/test/idiv_test
run: |
Expand Down
46 changes: 45 additions & 1 deletion src/DFGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "DFGNode.h"
#include "llvm/Demangle/Demangle.h"

int opcode_offset = 0;
string getOpcodeNameHelper(Instruction* inst);

DFGNode::DFGNode(int t_id, bool t_precisionAware, Instruction* t_inst,
StringRef t_stringRef) {
m_id = t_id;
Expand All @@ -19,7 +22,11 @@ DFGNode::DFGNode(int t_id, bool t_precisionAware, Instruction* t_inst,
m_stringRef = t_stringRef;
m_predNodes = NULL;
m_succNodes = NULL;
m_opcodeName = t_inst->getOpcodeName();
if (opcode_offset == 0) {
m_opcodeName = t_inst->getOpcodeName();
} else {
m_opcodeName = getOpcodeNameHelper(t_inst);
}
m_isMapped = false;
m_numConst = 0;
m_optType = "";
Expand Down Expand Up @@ -648,3 +655,40 @@ void DFGNode::removeConst() {
int DFGNode::getNumConst() {
return m_numConst;
}

string getOpcodeNameHelper(Instruction* inst) {

unsigned opcode = inst->getOpcode();
opcode -= opcode_offset;
if (opcode == Instruction::Mul) return "mul";
if (opcode == Instruction::FMul) return "fmul";
if (opcode == Instruction::Add) return "add";
if (opcode == Instruction::FAdd) return "fadd";
if (opcode == Instruction::Sub) return "sub";
if (opcode == Instruction::FSub) return "fsub";
if (opcode == Instruction::Xor) return "xor";
if (opcode == Instruction::Or) return "or";
if (opcode == Instruction::And) return "and";
if (opcode == Instruction::SDiv) return "sdiv";
if (opcode == Instruction::UDiv) return "udiv";
if (opcode == Instruction::SRem) return "srem";
if (opcode == Instruction::URem) return "urem";
if (opcode == Instruction::Trunc) return "trunc";
if (opcode == Instruction::ZExt) return "zext";
if (opcode == Instruction::SExt) return "sext";
if (opcode == Instruction::LShr) return "lshr";
if (opcode == Instruction::AShr) return "ashr";
if (opcode == Instruction::Load) return "load";
if (opcode == Instruction::Store) return "store";
if (opcode == Instruction::Br) return "br";
if (opcode == Instruction::PHI) return "phi";
if (opcode == Instruction::ICmp) return "icmp";
if (opcode == Instruction::FCmp) return "fcmp";
if (opcode == Instruction::BitCast) return "bitcast";
if (opcode == Instruction::GetElementPtr) return "getelementptr";
if (opcode == Instruction::Select) return "select";
if (opcode == Instruction::ExtractElement) return "extractelement";
if (opcode == Instruction::Call) return "call";

return "unknown";
}
4 changes: 4 additions & 0 deletions src/mapperPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "json.hpp"
#include "Mapper.h"

extern int opcode_offset;

using namespace llvm;
using namespace std;
using json = nlohmann::json;
Expand Down Expand Up @@ -142,6 +144,8 @@ namespace {
incrementalMapping = param["incrementalMapping"];
if (param.find("vectorFactorForIdiv ") != param.end())
vectorFactorForIdiv = param["vectorFactorForIdiv "];
if (param.find("opcodeOffset") != param.end())
opcode_offset = param["opcodeOffset"];
cout<<"Initialize opt latency for DFG nodes: "<<endl;
for (auto& opt : param["optLatency"].items()) {
cout<<opt.key()<<" : "<<opt.value()<<endl;
Expand Down
1 change: 1 addition & 0 deletions test/idiv_test/param.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"regConstraint" : 8,
"incrementalMapping" : false,
"vectorFactorForIdiv " : 4,
"opcodeOffset" : 2,
"optLatency" : {
"load" : 2,
"store": 2,
Expand Down
7 changes: 1 addition & 6 deletions test/idiv_test/test.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
echo "___________________________________________________________________\n"
cat dfg.json
echo "___________________________________________________________________\n"
icmpbr=$(grep -o 'sdiv' ./dfg.json | wc -l)
echo "icmpbr", $icmpbr

count=$(grep -o 'sdiv' dfg.json | wc -l)
if [ "$(grep -o 'sdiv' dfg.json | wc -l)" -eq 4 ]; then
if [ "$count" -eq 4 ]; then
echo "Idiv Test Pass!"
else
echo "Idiv Test Fail! The count of sdiv should be 4, but got 0."
Expand Down
1 change: 1 addition & 0 deletions test/nonlinear_test/param.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"regConstraint" : 8,
"incrementalMapping" : false,
"vectorFactorForIdiv " : 1,
"opcodeOffset" : 2,
"optLatency" : {
"load" : 2,
"store": 2,
Expand Down
10 changes: 10 additions & 0 deletions test/nonlinear_test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
icmpbr=$(grep -o 'icmpbr' dfg.json | wc -l)
phigetelementptr=$(grep -o 'phigetelementptr' dfg.json | wc -l)
fp2fx=$(grep -o 'fp2fx' dfg.json | wc -l)
faddmuladd=$(grep -o 'faddmuladd' dfg.json | wc -l)
if [ "$icmpbr" -eq 1 ] && [ "$phigetelementptr" -eq 1 ] && [ "$fp2fx" -eq 1 ] && [ "$faddmuladd" -eq 1 ]; then
echo "Nonlinear Test Pass!"
else
echo "Nonlinear Test Fail! icmpbr, phigetelementptr, fp2fx, faddmuladd should be 1, but got $icmpbr, $phigetelementptr, $fp2fx, $faddmuladd."
exit 1
fi
1 change: 1 addition & 0 deletions test/param.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"isStaticElasticCGRA" : false,
"ctrlMemConstraint" : 10,
"regConstraint" : 8,
"opcodeOffset" : 2,
"optLatency" : {
"load" : 2,
"store": 2
Expand Down

0 comments on commit 4153456

Please sign in to comment.