Skip to content

Commit

Permalink
Changed design for eun in LLVMTargetOptions and added enum in flatbuf…
Browse files Browse the repository at this point in the history
…fer schema
  • Loading branch information
inho9606 committed Feb 3, 2021
1 parent b68655f commit ba4b9ef
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion iree/compiler/Dialect/HAL/Target/LLVM/LLVMAOTTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class LLVMAOTTargetBackend final : public TargetBackend {
return targetOp.emitError() << "failed to translate the MLIR LLVM "
"dialect to the native llvm::Module";
}
if (options_.sanitizerKind == static_cast<int>(sanitizer::address)) {
if (options_.sanitizerKind == LLVMTargetOptions::Sanitizer::ADDRESS) {
for(auto &function : llvmModule->getFunctionList())
function.addFnAttr(llvm::Attribute::SanitizeAddress);
}
Expand Down
24 changes: 12 additions & 12 deletions iree/compiler/Dialect/HAL/Target/LLVM/LLVMIRPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@ LogicalResult runLLVMIRPasses(const LLVMTargetOptions &options,
passBuilder.registerLoopAnalyses(loopAnalysisManager);
passBuilder.crossRegisterProxies(loopAnalysisManager, functionAnalysisManager,
cGSCCAnalysisManager, moduleAnalysisManager);
if (options.sanitizerKind == static_cast<int>(sanitizer::address)) {
bool CompileKernel = false;
bool Recover = false;
bool UseAfterScope = true;
bool ModuleUseAfterScope = false; // asanUseGlobalsGC(TargetTriple, CodeGenOpts);
bool UseOdrIndicator = false; // CodeGenOpts.SanitizeAddressUseOdrIndicator;
if (options.sanitizerKind == LLVMTargetOptions::Sanitizer::ADDRESS) {
bool compileKernel = false;
bool recover = false;
bool useAfterScope = true;
bool moduleUseAfterScope = false;
bool useOdrIndicator = false;
passBuilder.registerOptimizerLastEPCallback(
[CompileKernel, Recover, UseAfterScope, ModuleUseAfterScope,
UseOdrIndicator](llvm::ModulePassManager &modulePassManager,
[compileKernel, recover, useAfterScope, moduleUseAfterScope,
useOdrIndicator](llvm::ModulePassManager &modulePassManager,
llvm::PassBuilder::OptimizationLevel Level) {
modulePassManager.addPass(
llvm::RequireAnalysisPass<llvm::ASanGlobalsMetadataAnalysis, llvm::Module>());
modulePassManager.addPass(llvm::ModuleAddressSanitizerPass(CompileKernel, Recover,
ModuleUseAfterScope,
UseOdrIndicator));
modulePassManager.addPass(llvm::ModuleAddressSanitizerPass(compileKernel, recover,
moduleUseAfterScope,
useOdrIndicator));
modulePassManager.addPass(createModuleToFunctionPassAdaptor(
llvm::AddressSanitizerPass(CompileKernel, Recover, UseAfterScope)));
llvm::AddressSanitizerPass(compileKernel, recover, useAfterScope)));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ LLVMTargetOptions getLLVMTargetOptionsFromFlags() {
"Specify LLVM sanitize feature such as 'address' ETC"),
llvm::cl::init(""));
if (clSanitizerKind == "address")
llvmTargetOptions.sanitizerKind = static_cast<int>(sanitizer::address);
llvmTargetOptions.sanitizerKind = LLVMTargetOptions::Sanitizer::ADDRESS;

static llvm::cl::opt<std::string> clTargetABI(
"iree-llvm-target-abi",
Expand Down
13 changes: 8 additions & 5 deletions iree/compiler/Dialect/HAL/Target/LLVM/LLVMTargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ namespace iree_compiler {
namespace IREE {
namespace HAL {

enum class sanitizer {
none = 0,
address
};

struct LLVMTargetOptions {
// Target machine configuration.
Expand All @@ -43,7 +39,14 @@ struct LLVMTargetOptions {
// information is valid) it may significantly change the output program
// and benchmarking
bool debugSymbols = true;
int sanitizerKind = 0;

// Define kinds of sanitizer.
enum Sanitizer {
NONE = 0,
ADDRESS = 1
};

Sanitizer sanitizerKind = NONE;

// Link any required runtime libraries into the produced binaries statically.
// This increases resulting binary size but enables the binaries to be used on
Expand Down
7 changes: 6 additions & 1 deletion iree/schemas/dylib_executable_def.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
// limitations under the License.

namespace iree;
// Define kinds of sanitizer used to connect CPU kernels and runtime
enum Sanitizer : ubyte {
NONE = 0,
ADDRESS
}

// 'Dynamic Library (dylib) Executable'.

Expand All @@ -30,7 +35,7 @@ table DyLibExecutableDef {

debug_database_filename:string;
debug_database_embedded:[ubyte];
sanitized_kind:ubyte = 0;
sanitized_kind:Sanitizer = NONE;

// TODO(scotttodd): Relative file path from this flatbuffer file
}
Expand Down

0 comments on commit ba4b9ef

Please sign in to comment.