Skip to content

[SPIR-V] Rename internal command line flags for optimization level and mtriple used when passing options into the translate API call #123975

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions llvm/lib/Target/SPIRV/SPIRVAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ namespace {

// Mimic limited number of command line flags from llc to provide a better
// user experience when passing options into the translate API call.
static cl::opt<char> SpvOptLevel(" O", cl::Hidden, cl::Prefix, cl::init('0'));
static cl::opt<std::string> SpvTargetTriple(" mtriple", cl::Hidden,
cl::init(""));
static cl::opt<char> SpirvOptLevel("spirv-O", cl::Hidden, cl::Prefix,
cl::init('0'));
static cl::opt<std::string> SpirvTargetTriple("spirv-mtriple", cl::Hidden,
cl::init(""));

// Utility to accept options in a command line style.
void parseSPIRVCommandLineOptions(const std::vector<std::string> &Options,
Expand Down Expand Up @@ -94,7 +95,7 @@ SPIRVTranslateModule(Module *M, std::string &SpirvObj, std::string &ErrMsg,
}

llvm::CodeGenOptLevel OLevel;
if (auto Level = CodeGenOpt::parseLevel(SpvOptLevel)) {
if (auto Level = CodeGenOpt::parseLevel(SpirvOptLevel)) {
OLevel = *Level;
} else {
ErrMsg = "Invalid optimization level!";
Expand All @@ -115,9 +116,9 @@ SPIRVTranslateModule(Module *M, std::string &SpirvObj, std::string &ErrMsg,
// SPIR-V-specific target initialization.
InitializeSPIRVTarget();

Triple TargetTriple(SpvTargetTriple.empty()
Triple TargetTriple(SpirvTargetTriple.empty()
? M->getTargetTriple()
: Triple::normalize(SpvTargetTriple));
: Triple::normalize(SpirvTargetTriple));
if (TargetTriple.getTriple().empty()) {
TargetTriple.setTriple(DefaultTriple);
M->setTargetTriple(DefaultTriple);
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ TEST_F(SPIRVAPITest, checkTranslateOk) {
// Those command line arguments that overlap with registered by llc/codegen
// are to be started with the ' ' symbol.
std::vector<std::string> SetOfOpts[] = {
{}, {"- mtriple=spirv32-unknown-unknown"}};
{}, {"--spirv-mtriple=spirv32-unknown-unknown"}};
for (const auto &Opts : SetOfOpts) {
for (StringRef &Assembly : Assemblies) {
std::string Result, Error;
Expand All @@ -100,7 +100,7 @@ TEST_F(SPIRVAPITest, checkTranslateError) {
EXPECT_THAT(Error,
StartsWith("SPIRVTranslateModule: Unknown command line argument "
"'-mtriple=spirv32-unknown-unknown'"));
Status = toSpirv(OkAssembly, Result, Error, {}, {"- O 5"});
Status = toSpirv(OkAssembly, Result, Error, {}, {"--spirv-O 5"});
EXPECT_FALSE(Status);
EXPECT_TRUE(Result.empty());
EXPECT_EQ(Error, "Invalid optimization level!");
Expand Down
Loading