Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Patmos Stack Cache Optimization #13

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
95d63ac
add function call test to check how stack cache is used
R3freshReload Apr 2, 2024
2cf09f0
fix comment
R3freshReload Apr 16, 2024
0efb412
add struct test
R3freshReload Apr 16, 2024
314cafd
identify point of interest for stack cache optimization
R3freshReload Apr 16, 2024
29d4f33
add PatmosStackCachePromotion pass
R3freshReload Apr 16, 2024
752be0e
add res and free to PatmosStackCachePromotion pass
R3freshReload Apr 16, 2024
edb0afc
add stack cache alloc/dealloc
R3freshReload Apr 17, 2024
e5fadf5
add debug logs to PatmosStackCachePromotion pass
R3freshReload Apr 17, 2024
0331f60
add debug logs to PatmosStackCachePromotion pass
R3freshReload Apr 17, 2024
2159171
add instruction replacement to stack cache promotion pass
R3freshReload Apr 17, 2024
c9c6439
fix PatmosStackCachePromotion pass erros
R3freshReload Apr 17, 2024
8155faf
fix PatmosStackCachePromotion pass erros
R3freshReload Apr 17, 2024
dbb9254
prevent useless stack operations from beeing emitted
Gernedl Apr 18, 2024
1b62643
check for stackCacheSize before reserving
Gernedl Apr 18, 2024
6636351
fix weird loop condition
R3freshReload Apr 19, 2024
7553e4f
add lws asm test
R3freshReload Apr 23, 2024
5404acb
add stack cache assignment to frame lowering
R3freshReload Apr 23, 2024
1942fb4
add FI-SC assignment to PatmosStackCachePromotion pass
R3freshReload May 8, 2024
a22e213
add correction for non-FI lwcs to lws
R3freshReload May 30, 2024
ac948a3
fix Load correction
R3freshReload May 30, 2024
e66ae1d
refactor Load correction
R3freshReload May 30, 2024
737986d
cut dependency cycles
Gernedl Jun 7, 2024
9685363
dont replace instructions with direct FI operands
Gernedl Jun 7, 2024
a412c43
dont replace instructions with direct FI operands
Gernedl Jun 7, 2024
3670bfd
remove faulty test
Gernedl Jun 7, 2024
5fdba6e
fix LWS test args
R3freshReload Jun 10, 2024
2856464
add stack cache optimization flags to assert_correct.py
R3freshReload Jun 10, 2024
52b8a04
fix assert_correct.py argument combinations
R3freshReload Jun 10, 2024
e46906e
add check for external symbols
R3freshReload Jun 13, 2024
4721b35
add check for external symbols
R3freshReload Jun 17, 2024
2040f03
fix check for external symbols
R3freshReload Jun 17, 2024
4742187
add attribute to enable sco for functions
R3freshReload Jun 20, 2024
fa1726f
fix attribute to enable sco for functions
R3freshReload Jun 20, 2024
4523b1b
fix typo
R3freshReload Jun 20, 2024
e397da3
fix annotation parsing
R3freshReload Jun 20, 2024
f3d8fd2
add debugs
R3freshReload Jun 20, 2024
48fe7d6
remove external linkage check
R3freshReload Jun 20, 2024
c82c2b2
remove external linkage check
R3freshReload Jun 20, 2024
de5dd11
remove annotation check
R3freshReload Jun 20, 2024
1ecb90b
add check if depends on global
R3freshReload Jun 20, 2024
d1570fa
add check if pointer to FI
R3freshReload Jun 20, 2024
6f679ed
add check if pointer to FI
R3freshReload Jun 20, 2024
bbc2d83
fix dependency calculation
R3freshReload Jun 21, 2024
b13fc4b
fix dependency calculation
R3freshReload Jun 21, 2024
7aaaa24
cleanup
R3freshReload Jun 21, 2024
2632b87
try simplified version of SC optimisation
R3freshReload Jun 23, 2024
3031b6b
try simplified version of SC optimisation
R3freshReload Jun 24, 2024
5c5a455
try simplified version of SC optimisation
R3freshReload Jun 24, 2024
7a222d5
improve library check for sco pass
R3freshReload Jun 24, 2024
1515881
improve library check for sco pass
R3freshReload Jun 24, 2024
5f1d39c
fix library check for sco pass
R3freshReload Jun 24, 2024
02106d6
remove logs
R3freshReload Jun 24, 2024
c746330
add aliased object check
R3freshReload Jun 24, 2024
523fcc1
add minimal functional version
R3freshReload Jun 24, 2024
24e9b5c
finish minimal functional version
R3freshReload Jun 24, 2024
c270025
cleanup
R3freshReload Jun 24, 2024
b07ce94
cleanup
R3freshReload Jun 24, 2024
a2571dd
disable call check for inline assembly
R3freshReload Jun 28, 2024
6bf7e1f
trigger ci
R3freshReload Jul 16, 2024
e95c194
add arm64 mac target support
R3freshReload Sep 10, 2024
0e54d77
add texinfo to test for pipeline error
R3freshReload Sep 10, 2024
fae93a5
change CI newlib to fork to test for mac error
R3freshReload Sep 11, 2024
4eccd6a
add additional mac targets to ci
R3freshReload Sep 11, 2024
e34a0d7
Merge remote-tracking branch 'origin/master'
R3freshReload Sep 11, 2024
8991041
add simple working solution for array opt
R3freshReload Oct 15, 2024
54a24ba
Update test cases to check everything except singlepath with stach-ca…
Gernedl Nov 15, 2024
dc25362
Merge branch 'master' of github.com:R3freshReload/patmos-llvm-project
Gernedl Nov 15, 2024
6469be5
Fix PML output
Emoun Jan 15, 2025
3fba0c4
temp fixes
Emoun Jan 15, 2025
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
4 changes: 2 additions & 2 deletions .github/actions/build-test-all/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ runs:
- name: Download Newlib
if: inputs.enable-package == 'true'
env:
NEWLIB_COMMIT: 4a74fe0ca51e6f462999446f8adbfd8f6b8c91e5
NEWLIB_COMMIT: 79b0b16dfc224c2d63b31e5c314bc2a5c430f01e
shell: bash
run: |
git clone https://github.com/t-crest/patmos-newlib ${{env.NEWLIB_PATH}}
git clone https://github.com/R3freshReload/patmos-newlib.git ${{env.NEWLIB_PATH}}
cd ${{env.NEWLIB_PATH}}
git checkout $NEWLIB_COMMIT
# Builds newlib to Patmos assembly (instead of bitcode)
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ runs:
name: Install GNU-tar as 'tar'
shell: bash
run: |
brew install gnu-tar
brew install gnu-tar texinfo
# Set gtar to be available as 'tar'
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
- name: Create Installation Directory
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/patmos-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ jobs:
- platform: ubuntu-20.04
cc: gcc
cxx: g++
- platform: macos-latest
- platform: macos-latest # ARM
cc: clang
cxx: clang++
- platform: macos-12
- platform: macos-14 # ARM
cc: clang
cxx: clang++
- platform: macos-13 # x86
cc: clang
cxx: clang++
- platform: macos-12 # x86
cc: clang
cxx: clang++

Expand Down Expand Up @@ -105,10 +111,16 @@ jobs:
- platform: ubuntu-20.04
cc: gcc
cxx: g++
- platform: macos-latest
- platform: macos-latest # ARM
cc: clang
cxx: clang++
- platform: macos-12
- platform: macos-14 # ARM
cc: clang
cxx: clang++
- platform: macos-13 # x86
cc: clang
cxx: clang++
- platform: macos-12 # x86
cc: clang
cxx: clang++
needs: [package-patmos]
Expand Down
2 changes: 2 additions & 0 deletions llvm/cmake/platforms/Patmos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if (${DUMP_MACHINE} MATCHES "x86_64-linux-gnu")
set( TARGET_TRIPLE "x86_64-linux-gnu")
elseif(${DUMP_MACHINE} MATCHES "x86_64-apple-darwin.*")
set( TARGET_TRIPLE "x86_64-apple-darwin")
elseif(${DUMP_MACHINE} MATCHES "arm64-apple-darwin.*")
set( TARGET_TRIPLE "arm64-apple-darwin")
else()
message(FATAL_ERROR "Unsupported platform for packaging")
endif()
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/Support/Signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#define LLVM_SUPPORT_SIGNALS_H

#include <string>
#include <cstdint>


namespace llvm {
class StringRef;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/Patmos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_llvm_target(PatmosCodeGen
PatmosSelectionDAGInfo.cpp
PatmosAsmPrinter.cpp
PatmosMCInstLower.cpp
PatmosStackCachePromotion.cpp
PatmosDelaySlotFiller.cpp
PatmosFunctionSplitter.cpp
PatmosDelaySlotKiller.cpp
Expand Down
27 changes: 12 additions & 15 deletions llvm/lib/Target/Patmos/PMLExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ template <> struct FlowGraphTrait<const BasicBlock> {
return llvm::succ_end(BB);
}
static StringValue getName(const BasicBlock *BB) {
return BB->getName().str();
return BB->getNameOrAsOperand();
}
};
template <> struct FlowGraphTrait<MachineBasicBlock> {
Expand Down Expand Up @@ -221,10 +221,10 @@ yaml::FlowFact<yaml::StringValue> *PMLBitcodeExport::createLoopFact(const BasicB

auto *FF = new yaml::FlowFact<yaml::StringValue>(yaml::level_bitcode);

FF->setLoopScope(Fn->getName().str(), BB->getName().str());
FF->setLoopScope(Fn->getName().str(), BB->getNameOrAsOperand());

yaml::ProgramPoint *Block =
yaml::ProgramPoint::CreateBlock(Fn->getName().str(), BB->getName().str());
yaml::ProgramPoint::CreateBlock(Fn->getName().str(), BB->getNameOrAsOperand());

FF->addTermLHS(Block, 1LL);
FF->RHS = RHS;
Expand All @@ -247,27 +247,24 @@ void PMLBitcodeExport::serialize(MachineFunction &MF)
yaml::BitcodeFunction *F = new yaml::BitcodeFunction(Fn.getName().str());
F->Level = yaml::level_bitcode;
yaml::BitcodeBlock *B;
for (Function::const_iterator BI = Fn.begin(), BE = Fn.end(); BI != BE;
for (auto BI = Fn.begin(), BE = Fn.end(); BI != BE;
++BI) {
if (BI->getName().empty()) {
llvm::errs() << "warning: unnamed bit-code BB in PML export\n";
}
B = F->addBlock(new yaml::BitcodeBlock(BI->getName().str()));
B = F->addBlock(new yaml::BitcodeBlock(BI->getNameOrAsOperand()));

Loop *Loop = LI.getLoopFor(&*BI);
while (Loop) {
B->Loops.push_back(Loop->getHeader()->getName().str());
B->Loops.push_back(Loop->getHeader()->getNameOrAsOperand());
Loop = Loop->getParentLoop();
}

/// B->MapsTo = (maybe C-source debug info?)
for (const_pred_iterator PI = pred_begin(&*BI), PE = pred_end(&*BI);
for (auto PI = pred_begin(&*BI), PE = pred_end(&*BI);
PI != PE; ++PI) {
B->Predecessors.push_back((*PI)->getName().str());
B->Predecessors.push_back((*PI)->getNameOrAsOperand());
}
for (auto SI = succ_begin(&*BI), SE = succ_end(&*BI);
SI != SE; ++SI) {
B->Successors.push_back((*SI)->getName().str());
B->Successors.push_back((*SI)->getNameOrAsOperand());
}

unsigned Index = 0;
Expand Down Expand Up @@ -849,7 +846,7 @@ void addProgressNodes(yaml::RelationGraph *RG,
}
else {
RN = RG->addNode(yaml::rnt_progress);
RN->setSrcBlock(IQI->first->getName().str());
RN->setSrcBlock(IQI->first->getNameOrAsOperand());
RN->setDstBlock(MQI->first->getNumber());
RMap.insert(std::make_pair(PNID, RN));
RTodo.push_back(std::make_pair(PNID, RN));
Expand Down Expand Up @@ -935,7 +932,7 @@ void PMLRelationGraphExport::serialize(MachineFunction &MF)
auto *SrcScope = new yaml::RelationScope<yaml::StringValue>(
BF.getName().str(), yaml::level_bitcode);
RG = new yaml::RelationGraph(SrcScope, DstScope);
RG->getEntryNode()->setSrcBlock(BF.getEntryBlock().getName().str());
RG->getEntryNode()->setSrcBlock(BF.getEntryBlock().getNameOrAsOperand());
RG->getEntryNode()->setDstBlock(MF.front().getNumber());
UnmatchedEvents.clear();

Expand Down Expand Up @@ -974,7 +971,7 @@ void PMLRelationGraphExport::serialize(MachineFunction &MF)
// MBB, resp.), which results in new src/dst nodes being created, and
// two bitcode and machinecode-level maps from events to a list of
// (bitcode/machine block, list of RG predecessor blocks) pairs
expandProgressNode(RG, RN, yaml::rnt_src, [](auto *node, auto* block){node->setSrcBlock(block->getName().str());}, IBB, IEventMap, IEvents);
expandProgressNode(RG, RN, yaml::rnt_src, [](auto *node, auto* block){node->setSrcBlock(block->getNameOrAsOperand());}, IBB, IEventMap, IEvents);
expandProgressNode(RG, RN, yaml::rnt_dst, [](auto *node, auto* block){node->setDstBlock(block->getNumber());}, MBB, MEventMap, MEvents);

// For each event and corresponding bitcode list IList and machinecode
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/Patmos/Patmos.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace llvm {
FunctionPass *createPatmosSPBundlingPass(const PatmosTargetMachine &tm);
FunctionPass *createOppositePredicateCompensationPass(const PatmosTargetMachine &tm);
FunctionPass *createDataCacheAccessEliminationPass(const PatmosTargetMachine &tm);
FunctionPass *createPatmosStackCachePromotionPass(const PatmosTargetMachine &tm);
FunctionPass *createMemoryAccessNormalizationPass(const PatmosTargetMachine &tm);
FunctionPass *createPatmosSPReducePass(const PatmosTargetMachine &tm);
FunctionPass *createPreRegallocReduce(const PatmosTargetMachine &tm);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Patmos/PatmosExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace llvm {
// FIXME
// we don't add it immediately to PMF, as we only support
// arguments in registers at this point
std::string ArgName = ("%" + I->getName()).str();
std::string ArgName = I->getNameOrAsOperand();
yaml::Argument *Arg = new yaml::Argument(ArgName, FAIdx);
bool allInRegs = true;

Expand Down
7 changes: 6 additions & 1 deletion llvm/lib/Target/Patmos/PatmosFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ void PatmosFrameLowering::assignFIsToStackCache(MachineFunction &MF,
// find all spill slots and locations for callee saved registers
if (MFI.isSpillSlotObjectIndex(FI))
SCFIs[FI] = true;


const std::vector<int> &StackCacheAllocatable = PMFI.getStackCacheAnalysisFIs();
for(unsigned i=0; i<StackCacheAllocatable.size(); i++) {
SCFIs[StackCacheAllocatable[i]] = true;
}
}
}

Expand Down Expand Up @@ -330,7 +336,6 @@ void PatmosFrameLowering::emitPrologue(MachineFunction &MF, MachineBasicBlock &M
MI->setFlag(MachineInstr::FrameSetup);
}
}

}

void PatmosFrameLowering::emitEpilogue(MachineFunction &MF,
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/Patmos/PatmosInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,6 @@ PatmosII::MemType PatmosInstrInfo::getMemType(const MachineInstr &MI) {
case SWM: case SHM: case SBM:
return PatmosII::MEM_M;
default:
MI.dump();
llvm_unreachable("Unexpected memory access instruction!");
}

Expand Down
18 changes: 18 additions & 0 deletions llvm/lib/Target/Patmos/PatmosMachineFunctionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class PatmosMachineFunctionInfo : public MachineFunctionInfo {
/// | LoopCnts | S0Spills | ExcessSpills |
std::vector<int> SinglePathFIs;

/// FIs determined to be movable to stack cache
std::vector<int> StackCacheAnalysisFIs;

// Index to the SinglePathFIs where the S0 spill slots start
unsigned SPS0SpillOffset;

Expand Down Expand Up @@ -259,6 +262,21 @@ class PatmosMachineFunctionInfo : public MachineFunctionInfo {
return SinglePathFIs.size();
}

const std::vector<int>& getStackCacheAnalysisFIs(void) const {
return StackCacheAnalysisFIs;
}

void removeStackCacheAnalysisFIs(int fi) {
std::vector<int>::iterator position = std::find(StackCacheAnalysisFIs.begin(), StackCacheAnalysisFIs.end(), fi);

if (position != StackCacheAnalysisFIs.end()) // == myVector.end() means the element was not found
StackCacheAnalysisFIs.erase(position);
}

void addStackCacheAnalysisFI(int fi) {
StackCacheAnalysisFIs.push_back(fi);
}

PatmosAnalysisInfo &getAnalysisInfo() { return AnalysisInfo; }

const PatmosAnalysisInfo &getAnalysisInfo() const { return AnalysisInfo; }
Expand Down
Loading