Commit eaf0fde3 by Tianqi Chen Committed by GitHub

[LLVM] More optimized option, allow emit assembly (#187)

parent 54450614
......@@ -46,6 +46,7 @@ GetLLVMTargetMachine(const std::string& target_str) {
std::string target_triple = "";
std::string cpu = "generic";
std::string attr = "";
bool soft_float_abi = false;
std::string key, value;
if (target_str.length() > 5) {
std::istringstream is(target_str.substr(5, target_str.length() - 5));
......@@ -67,6 +68,14 @@ GetLLVMTargetMachine(const std::string& target_str) {
cpu = value;
} else if (key == "-mattr") {
attr = value;
} else if (key == "-mfloat-abi") {
if (value == "hard") {
soft_float_abi = false;
} else if (value == "soft") {
soft_float_abi = true;
} else {
LOG(FATAL) << "invalid -mfloat-abi option " << value;
}
} else {
LOG(FATAL) << "unknown option " << key;
}
......@@ -80,7 +89,18 @@ GetLLVMTargetMachine(const std::string& target_str) {
const llvm::Target* target =
llvm::TargetRegistry::lookupTarget(target_triple, err);
CHECK(target) << err << " target_triple=" << target_triple;
// set target option
llvm::TargetOptions opt;
opt.LessPreciseFPMADOption = true;
opt.AllowFPOpFusion = llvm::FPOpFusion::Fast;
opt.UnsafeFPMath = true;
opt.NoInfsFPMath = true;
opt.NoNaNsFPMath = true;
if (soft_float_abi) {
opt.FloatABIType = llvm::FloatABI::Soft;
} else {
opt.FloatABIType = llvm::FloatABI::Hard;
}
auto rmodel = llvm::Reloc::PIC_;
llvm::TargetMachine* tm =
target->createTargetMachine(target_triple, cpu, attr, opt, rmodel);
......
......@@ -66,6 +66,13 @@ class LLVMModuleNode final : public runtime::ModuleNode {
pass, dest, llvm::TargetMachine::CGFT_ObjectFile) == 0)
<< "Cannot emit target CGFT_ObjectFile";
pass.run(*mptr_);
} else if (fmt == "s" || fmt == "asm") {
llvm::legacy::PassManager pass;
CHECK(tm_);
CHECK(tm_->addPassesToEmitFile(
pass, dest, llvm::TargetMachine::CGFT_AssemblyFile) == 0)
<< "Cannot emit target CGFT_AssemblyFile";
pass.run(*mptr_);
} else if (fmt == "ll") {
mptr_->print(dest, nullptr);
} else if (fmt == "bc") {
......
......@@ -45,6 +45,8 @@ def test_llvm_add_pipeline():
path = temp.relpath("myadd.o")
f.save(path)
verify_elf(path, 0x28)
asm_path = temp.relpath("myadd.asm")
f.save(asm_path)
# Do a RPC verification, launch kernel on Arm Board if available.
host = os.environ.get('TVM_RPC_ARM_HOST', None)
remote = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment