-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
186 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
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
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,52 @@ | ||
#include <iostream> | ||
#include <set> | ||
#include <string> | ||
|
||
#include "CompilerWarnings.h" | ||
IGNORE_COMPILER_WARNING("-Wunused-parameter") | ||
|
||
#include "config.h" | ||
#include "pocl.h" | ||
#include "pocl_llvm_api.h" | ||
|
||
#include "llvm/ADT/SmallPtrSet.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/Pass.h" | ||
#include "llvm/Support/CommandLine.h" | ||
#include <llvm/IR/Instructions.h> | ||
|
||
|
||
POP_COMPILER_DIAGS | ||
|
||
using namespace llvm; | ||
|
||
namespace { | ||
class PrintModule : public ModulePass { | ||
|
||
public: | ||
static char ID; | ||
PrintModule() : ModulePass(ID) {} | ||
|
||
virtual bool runOnModule(Module& M); | ||
}; | ||
|
||
} // namespace | ||
|
||
char PrintModule::ID = 0; | ||
static RegisterPass<PrintModule> | ||
X("print-module", | ||
"print module dump"); | ||
|
||
bool PrintModule::runOnModule(Module& M) | ||
{ | ||
{ | ||
std::string str; | ||
llvm::raw_string_ostream ostream { str }; | ||
M.print(ostream, nullptr, false); | ||
|
||
|
||
std::cout << "\n\n============================\n Print Module\n" | ||
<< str << std::endl; | ||
} | ||
return false; | ||
} |
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,106 @@ | ||
#include <iostream> | ||
#include <set> | ||
#include <string> | ||
|
||
#include "CompilerWarnings.h" | ||
IGNORE_COMPILER_WARNING("-Wunused-parameter") | ||
|
||
#include "config.h" | ||
#include "pocl.h" | ||
#include "pocl_llvm_api.h" | ||
|
||
#include "llvm/ADT/SmallPtrSet.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/Pass.h" | ||
#include "llvm/Support/CommandLine.h" | ||
#include <llvm/IR/Instructions.h> | ||
|
||
#include "Workgroup.h" | ||
|
||
POP_COMPILER_DIAGS | ||
|
||
using namespace llvm; | ||
|
||
namespace { | ||
class VortexRemoveAttr : public ModulePass { | ||
|
||
public: | ||
static char ID; | ||
VortexRemoveAttr() : ModulePass(ID) {} | ||
|
||
virtual bool runOnModule(Module& M); | ||
}; | ||
|
||
} // namespace | ||
|
||
char VortexRemoveAttr::ID = 0; | ||
static RegisterPass<VortexRemoveAttr> | ||
X("vortex-mno-riscv-attribute", | ||
"print module dump"); | ||
|
||
static void recursivelyFind(Function* F, llvm::Attribute attr) | ||
{ | ||
|
||
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) { | ||
for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE; ++BI) { | ||
|
||
Instruction* instr = dyn_cast<Instruction>(BI); | ||
if (!llvm::isa<CallInst>(instr)) | ||
continue; | ||
|
||
CallInst* call_inst = dyn_cast<CallInst>(instr); | ||
Function* callee = call_inst->getCalledFunction(); | ||
|
||
if ((callee == nullptr) || callee->getName().startswith("llvm.")) | ||
continue; | ||
|
||
if(callee->hasFnAttribute("target-features")){ | ||
callee->removeFnAttr("target-features"); | ||
callee->addFnAttr(attr.getKindAsString(), attr.getValueAsString()); | ||
|
||
}else if(callee->hasFnAttribute("target-cpu")){ | ||
callee->removeFnAttr("target-cpu"); | ||
} | ||
|
||
recursivelyFind(callee, attr); | ||
} | ||
} | ||
return; | ||
} | ||
|
||
|
||
bool VortexRemoveAttr::runOnModule(Module& M) | ||
{ | ||
std::string KernelName; | ||
getModuleStringMetadata(M, "KernelName", KernelName); | ||
|
||
if(KernelName == "") | ||
return false; | ||
|
||
for (llvm::Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { | ||
llvm::Function* F = &*I; | ||
if (F->isDeclaration()) | ||
continue; | ||
|
||
if (KernelName == F->getName().str() || pocl::Workgroup::isKernelToProcess(*F)) { | ||
|
||
/*{ | ||
const llvm::AttributeList& attrlist = F->getAttributes(); | ||
std::string str; | ||
llvm::raw_string_ostream ostream {str}; | ||
attrlist.print(ostream); | ||
std::cerr << "### VortexNoRISCVAttribute Pass running on " << KernelName | ||
<< str | ||
<< std::endl; | ||
}*/ | ||
|
||
if(F->hasFnAttribute("target-features")){ | ||
llvm::Attribute target_features = F->getFnAttribute("target-features"); | ||
recursivelyFind(F, target_features); | ||
} | ||
|
||
} | ||
} | ||
|
||
return true; | ||
} |
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 |
---|---|---|
|
@@ -136,6 +136,5 @@ bool VortexBarrierLowering::runOnModule(Module& M) | |
|
||
changed = true; | ||
} | ||
|
||
return changed; | ||
} |
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
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