This repository has been archived by the owner on Jan 19, 2025. It is now read-only.
forked from NN-complr-tech/llvm
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kozyreva Ekaterina. Lab 3. Option 1. (#127)
- Loading branch information
1 parent
5e96e69
commit 57afc2c
Showing
3 changed files
with
609 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
llvm/lib/Target/X86/lab3/kozyreva_ekaterina/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
set(PluginName X86KozyrevaPass) | ||
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h) | ||
add_llvm_pass_plugin(${PluginName} | ||
${ALL_SOURCE_FILES} | ||
DEPENDS | ||
intrinsics_gen | ||
X86 | ||
BUILDTREE_ONLY) | ||
|
||
target_include_directories(${PluginName} PUBLIC ${PATH_TO_X86}) | ||
|
||
set(LLVM_TEST_DEPENDS ${PluginName} ${LLVM_TEST_DEPENDS} PARENT_SCOPE) |
70 changes: 70 additions & 0 deletions
70
llvm/lib/Target/X86/lab3/kozyreva_ekaterina/X86KozyrevaPass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "X86.h" | ||
#include "X86InstrInfo.h" | ||
#include "X86Subtarget.h" | ||
#include "llvm/CodeGen/MachineFunctionPass.h" | ||
#include "llvm/CodeGen/MachineInstrBuilder.h" | ||
#include <utility> | ||
#include <vector> | ||
|
||
using namespace llvm; | ||
|
||
namespace { | ||
class X86KozyrevaPass : public MachineFunctionPass { | ||
public: | ||
static char ID; | ||
X86KozyrevaPass() : MachineFunctionPass(ID) {} | ||
bool runOnMachineFunction(MachineFunction &MF) override; | ||
}; | ||
|
||
char X86KozyrevaPass::ID = 0; | ||
|
||
bool X86KozyrevaPass::runOnMachineFunction(MachineFunction &pFunction) { | ||
const TargetInstrInfo *instrInfo = pFunction.getSubtarget().getInstrInfo(); | ||
bool isModified = false; | ||
std::vector<std::pair<MachineInstr *, MachineInstr *>> toDelete; | ||
|
||
for (auto &basicBlock : pFunction) { | ||
MachineInstr *mulInstruction = nullptr; | ||
MachineInstr *addInstruction = nullptr; | ||
|
||
for (auto &instr : basicBlock) { | ||
if (instr.getOpcode() == X86::MULPDrr) { | ||
mulInstruction = &instr; | ||
|
||
for (auto next = std::next(instr.getIterator()); | ||
next != basicBlock.end(); ++next) { | ||
if (next->getOpcode() == X86::ADDPDrr) { | ||
addInstruction = &*next; | ||
if (mulInstruction->getOperand(0).getReg() == | ||
addInstruction->getOperand(1).getReg()) { | ||
toDelete.emplace_back(mulInstruction, addInstruction); | ||
isModified = true; | ||
break; | ||
} | ||
} else if (next->definesRegister( | ||
mulInstruction->getOperand(0).getReg())) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (const auto &[mulInstr, addInstr] : toDelete) { | ||
MachineInstrBuilder builder = | ||
BuildMI(*mulInstr->getParent(), *mulInstr, mulInstr->getDebugLoc(), | ||
instrInfo->get(X86::VFMADD213PDZ128r)); | ||
builder.addReg(addInstr->getOperand(0).getReg(), RegState::Define); | ||
builder.addReg(mulInstr->getOperand(1).getReg()); | ||
builder.addReg(mulInstr->getOperand(2).getReg()); | ||
builder.addReg(addInstr->getOperand(2).getReg()); | ||
mulInstr->eraseFromParent(); | ||
addInstr->eraseFromParent(); | ||
} | ||
|
||
return isModified; | ||
} | ||
} // namespace | ||
|
||
static RegisterPass<X86KozyrevaPass> X("x86-kozyreva-pass", "X86 Kozyreva Pass", | ||
false, false); |
Oops, something went wrong.