|
| 1 | +// Copyright 2024 The IREE Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | + |
| 7 | +#include "PeanoDriver.h" |
| 8 | + |
| 9 | +#include <filesystem> |
| 10 | +#include <string> |
| 11 | +#include <vector> |
| 12 | + |
| 13 | +#include "llvm/Support/Error.h" |
| 14 | + |
| 15 | +using Path = std::filesystem::path; |
| 16 | + |
| 17 | +void addExternCSystemInclude(std::vector<std::string> &CC1Args, |
| 18 | + const std::string &Path) { |
| 19 | + CC1Args.push_back("-internal-externc-isystem"); |
| 20 | + CC1Args.push_back(Path); |
| 21 | +} |
| 22 | + |
| 23 | +void addSystemInclude(std::vector<std::string> &CC1Args, |
| 24 | + const std::string &Path) { |
| 25 | + CC1Args.push_back("-internal-isystem"); |
| 26 | + CC1Args.push_back(Path); |
| 27 | +} |
| 28 | + |
| 29 | +void AddClangSystemIncludeArgs(std::vector<std::string> &CC1Args, |
| 30 | + const Path &peanoDir, const std::string &target, |
| 31 | + bool novitisheaders, bool nostdlibinc) { |
| 32 | + // Always include our instrinsics, for compatibility with existing toolchain. |
| 33 | + if (!novitisheaders) { |
| 34 | + std::string path; |
| 35 | + if (target.rfind("aie2-", 0) == 0) { |
| 36 | + path = peanoDir / "lib" / "clang" / "19" / "include" / "aiev2intrin.h"; |
| 37 | + } else { |
| 38 | + llvm::report_fatal_error(("unsupported target: " + target).c_str()); |
| 39 | + } |
| 40 | + CC1Args.push_back("-include"); |
| 41 | + CC1Args.push_back(path); |
| 42 | + } |
| 43 | + |
| 44 | + CC1Args.push_back("-D__AIENGINE__"); |
| 45 | + if (target.rfind("aie2-", 0) == 0) { |
| 46 | + CC1Args.push_back("-D__AIEARCH__=20"); |
| 47 | + } else { |
| 48 | + llvm::report_fatal_error(("unsupported target: " + target).c_str()); |
| 49 | + } |
| 50 | + |
| 51 | + // Don't pull in system headers from /usr/include or /usr/local/include. |
| 52 | + // All the basic headers that we need come from the compiler. |
| 53 | + CC1Args.push_back("-nostdsysteminc"); |
| 54 | + |
| 55 | + if (nostdlibinc) return; |
| 56 | + addExternCSystemInclude(CC1Args, peanoDir / "include" / target); |
| 57 | +} |
| 58 | + |
| 59 | +void addLibCxxIncludePaths(std::vector<std::string> &CC1Args, |
| 60 | + const Path &peanoDir, const std::string &target, |
| 61 | + bool nostdinc, bool nostdlibinc, bool nostdincxx) { |
| 62 | + if (nostdinc || nostdlibinc || nostdincxx) return; |
| 63 | + addSystemInclude(CC1Args, peanoDir / "include" / target / "c++" / "v1"); |
| 64 | + // Second add the generic one. |
| 65 | + addSystemInclude(CC1Args, peanoDir / "include" / "c++" / "v1"); |
| 66 | +} |
| 67 | + |
| 68 | +void addOptTargetOptions(std::vector<std::string> &CC1Args) { |
| 69 | + // For now, we disable the auto-vectorizers by default, as the backend cannot |
| 70 | + // handle many vector types. For experimentation the vectorizers can still be |
| 71 | + // enabled explicitly by the user |
| 72 | + CC1Args.push_back("-vectorize-loops=false"); |
| 73 | + CC1Args.push_back("-vectorize-slp=false"); |
| 74 | + // An if-then-else cascade requires at least 5 delay slots for evaluating the |
| 75 | + // condition and 5 delay slots for one of the branches, thus speculating 10 |
| 76 | + // instructions should be fine |
| 77 | + CC1Args.push_back("--two-entry-phi-node-folding-threshold=10"); |
| 78 | + // Make sure to perform most optimizations before mandatory inlinings, |
| 79 | + // otherwise noalias attributes can get lost and hurt AA results. |
| 80 | + CC1Args.push_back("-mandatory-inlining-before-opt=false"); |
| 81 | + // Perform complete AA analysis on phi nodes. |
| 82 | + CC1Args.push_back("-basic-aa-full-phi-analysis=true"); |
| 83 | + // Extend the max limit of the search depth in BasicAA |
| 84 | + CC1Args.push_back("-basic-aa-max-lookup-search-depth=10"); |
| 85 | +} |
| 86 | + |
| 87 | +void addClangTargetOptions(std::vector<std::string> &CC1Args, |
| 88 | + const std::string &target) { |
| 89 | + CC1Args.emplace_back("-target=" + target); |
| 90 | + CC1Args.push_back("-fno-use-init-array"); |
| 91 | + // Pass -fno-threadsafe-statics to prevent dependence on lock acquire/release |
| 92 | + // handling for static local variables. |
| 93 | + CC1Args.push_back("-fno-threadsafe-statics"); |
| 94 | + std::vector<std::string> peanoArgs; |
| 95 | + addOptTargetOptions(peanoArgs); |
| 96 | + CC1Args.reserve(CC1Args.size() + 2 * peanoArgs.size()); |
| 97 | + for (const std::string &item : peanoArgs) { |
| 98 | + CC1Args.emplace_back("-mllvm"); |
| 99 | + CC1Args.emplace_back(item); |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +// Avoid using newer dwarf versions, as the simulator doesn't understand newer |
| 104 | +// dwarf. |
| 105 | +unsigned getMaxDwarfVersion() { return 4; } |
0 commit comments