-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Codegen][LLVM] Add ability to turn on fast math flags #9223
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
Changes from all commits
18ca603
1c8da0f
444e51a
6938d70
17fa49c
2795510
02cd251
3d6c2c3
b244dec
0c5d38b
c9ac146
99ae59f
d9e3524
5466663
cfeb699
2abbed5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,8 @@ void CodeGenLLVM::Init(const std::string& module_name, llvm::TargetMachine* tm, | |
| this->InitTarget(tm); | ||
| } | ||
|
|
||
| void CodeGenLLVM::SetFastMathFlag(llvm::FastMathFlags fmf) { builder_->setFastMathFlags(fmf); } | ||
|
|
||
| void CodeGenLLVM::InitTarget(llvm::TargetMachine* tm) { | ||
| module_->setTargetTriple(tm->getTargetTriple().str()); | ||
| module_->setDataLayout(tm->createDataLayout()); | ||
|
|
@@ -343,7 +345,26 @@ void CodeGenLLVM::Optimize() { | |
|
|
||
| // place optimization pass | ||
| llvm::PassManagerBuilder builder; | ||
| builder.OptLevel = 3; | ||
|
|
||
| // Use the same opt-level as specified in TargetMachine for running passes | ||
| llvm::CodeGenOpt::Level opt_level = target_machine_->getOptLevel(); | ||
|
|
||
| switch (opt_level) { | ||
| case llvm::CodeGenOpt::Level::None: | ||
| builder.OptLevel = 0; | ||
| break; | ||
| case llvm::CodeGenOpt::Level::Less: | ||
| builder.OptLevel = 1; | ||
| break; | ||
|
|
||
| case llvm::CodeGenOpt::Level::Default: | ||
| builder.OptLevel = 2; | ||
| break; | ||
|
|
||
| default: | ||
| // CodeGenOpt::Level::Aggressive | ||
| builder.OptLevel = 3; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A related comment: This code path should hit by default, otherwise this change would introduce regression.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I see fair enough, I think OptLevel 3 should not be the default but let me get some data to support this first. Changed to make OptLevel 3 the default.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we just inherited opt level being 3 by default from Halide: https://github.com/halide/Halide/blob/ed87acb466f13144be235a33a30f242e30a6a74f/src/CodeGen_LLVM.cpp#L1145 |
||
| } | ||
|
|
||
| #if TVM_LLVM_VERSION >= 50 | ||
| builder.Inliner = llvm::createFunctionInliningPass(builder.OptLevel, 0, false); | ||
|
|
@@ -410,7 +431,7 @@ llvm::Type* CodeGenLLVM::DTypeToLLVMType(const DataType& dtype) const { | |
| } else { | ||
| return etype; | ||
| } | ||
| } | ||
| } // namespace codegen | ||
|
|
||
| llvm::Type* CodeGenLLVM::GetLLVMType(const Type& type) const { | ||
| if (auto* ptr = type.as<PrimTypeNode>()) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.