Skip to content

[libclc][remangler] Teach the remangler to emit text #8199

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
merged 1 commit into from
Feb 7, 2023
Merged
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
29 changes: 17 additions & 12 deletions libclc/utils/libclc-remangler/LibclcRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ static llvm::cl::OptionCategory
static cl::opt<std::string>
InputIRFilename("input-ir", cl::desc("<input bitcode>"),
cl::cat(LibCLCRemanglerToolCategory));
static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"));
static cl::opt<std::string> OutputFilename("o", cl::init("-"),
cl::desc("Output filename"));
static cl::opt<SupportedLongWidth>
LongWidth("long-width",
cl::values(clEnumValN(SupportedLongWidth::L32, "l32",
Expand All @@ -87,6 +88,9 @@ static cl::opt<Signedness> CharSignedness(
static cl::opt<bool> Verbose("v", cl::desc("Enable verbose output"),
cl::init(false),
cl::cat(LibCLCRemanglerToolCategory));
static cl::opt<bool> TextualOut("S", cl::desc("Emit LLVM textual assembly"),
cl::init(false),
cl::cat(LibCLCRemanglerToolCategory));
static cl::opt<bool> TestRun("t", cl::desc("Enable test run"), cl::init(false),
cl::cat(LibCLCRemanglerToolCategory));

Expand Down Expand Up @@ -842,8 +846,8 @@ class LibCLCRemangler : public ASTConsumer {
Function *NewF = CloneFunction(Clonee, Dummy);
NewF->setName(std::string(CloneName));
} else if (Verbose) {
std::cout << "Could not create copy " << CloneName.data() << " : missing "
<< CloneeName.data() << std::endl;
errs() << "Could not create copy " << CloneName.data() << " : missing "
<< CloneeName.data() << '\n';
}

return true;
Expand Down Expand Up @@ -874,16 +878,15 @@ class LibCLCRemangler : public ASTConsumer {

if (RemangledName != MangledName) {
if (Verbose || TestRun) {
std::cout << "Mangling changed:"
<< "\n"
<< "Original: " << MangledName << "\n"
<< "New: " << RemangledName << "\n"
<< std::endl;
errs() << "Mangling changed:"
<< "\n"
<< "Original: " << MangledName << "\n"
<< "New: " << RemangledName << "\n";
}
// In test run mode, where no substitution is made, change in mangling
// name represents a failure. Report an error.
if (TestRun) {
std::cout << "Test run failure!" << std::endl;
errs() << "Test run failure!\n";
return false;
}
Func.setName(RemangledName);
Expand Down Expand Up @@ -934,12 +937,14 @@ class LibCLCRemangler : public ASTConsumer {

if (TestRun) {
if (Verbose)
std::cout << "Successfully processed: " << NumProcessed << " functions."
<< std::endl;
errs() << "Successfully processed: " << NumProcessed << " functions.\n";
return;
}

WriteBitcodeToFile(*M, Out->os());
if (TextualOut)
M->print(Out->os(), nullptr, true);
else
WriteBitcodeToFile(*M, Out->os());

// Declare success.
Out->keep();
Expand Down