-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Makslevental/unison tblgen #150084
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
Closed
Closed
Makslevental/unison tblgen #150084
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can test this locally with the following command:darker --check --diff -r HEAD~1...HEAD llvm/tools/llc-unison/llc-unison.pyView the diff from darker here.--- llc-unison.py 2025-07-22 18:17:18.000000 +0000
+++ llc-unison.py 2025-07-22 18:37:11.922403 +0000
@@ -42,56 +42,70 @@
import sys
import argparse
import subprocess
import tempfile
+
def execute(cmd):
print(" ".join(cmd))
subprocess.call(cmd)
return
+
def temp_filename(ext):
return tempfile.NamedTemporaryFile(suffix=ext).name
+
# Intercept input file, output file, and Unison flags
-parser = argparse.ArgumentParser(description='Run llc with Unison. The option -o must be given.')
-parser.add_argument('infile', metavar='INPUT', help='input file')
-parser.add_argument('-o', metavar='OUTPUT', help='output file')
-parser.add_argument('--uni-flags', help='flags to be passed to Unison')
+parser = argparse.ArgumentParser(
+ description="Run llc with Unison. The option -o must be given."
+)
+parser.add_argument("infile", metavar="INPUT", help="input file")
+parser.add_argument("-o", metavar="OUTPUT", help="output file")
+parser.add_argument("--uni-flags", help="flags to be passed to Unison")
(args, llc_flags) = parser.parse_known_args()
-exit_pass = "phi-node-elimination"
+exit_pass = "phi-node-elimination"
entry_pass = "funclet-layout"
# Expect 'llc' in the same directory
llc = os.path.join(os.path.dirname(sys.argv[0]), "llc")
# Expect 'uni' in the PATH
uni = "uni"
# Generate main input to Unison (.ll -> .mir)
-mir = temp_filename('.mir')
-cmd_mir = [llc] + llc_flags + \
- ["-stop-before", exit_pass, "-unison-mir", "-o", mir, args.infile]
+mir = temp_filename(".mir")
+cmd_mir = (
+ [llc]
+ + llc_flags
+ + ["-stop-before", exit_pass, "-unison-mir", "-o", mir, args.infile]
+)
execute(cmd_mir)
# Generate initial solution for Unison (.ll -> .asm.mir)
-asm_mir = temp_filename('.asm.mir')
-cmd_asm_mir = [llc] + llc_flags + \
- ["-stop-before", entry_pass, "-unison-mir", "-o", asm_mir, args.infile]
+asm_mir = temp_filename(".asm.mir")
+cmd_asm_mir = (
+ [llc]
+ + llc_flags
+ + ["-stop-before", entry_pass, "-unison-mir", "-o", asm_mir, args.infile]
+)
execute(cmd_asm_mir)
# Run Unison (.mir -> .asm.mir -> .unison.mir)
-unison_mir = temp_filename('.unison.mir')
-cmd_uni = [uni, "run", "--llvm6", "--verbose"] + \
- ["-o", unison_mir, mir, "--basefile=" + asm_mir]
+unison_mir = temp_filename(".unison.mir")
+cmd_uni = [uni, "run", "--llvm6", "--verbose"] + [
+ "-o",
+ unison_mir,
+ mir,
+ "--basefile=" + asm_mir,
+]
if args.uni_flags is not None:
cmd_uni += [args.uni_flags]
execute(cmd_uni)
# Generate assembly code (.unison.mir -> .s)
-cmd_s = [llc] + llc_flags + \
- ["-start-before", entry_pass, "-o", args.o, unison_mir]
+cmd_s = [llc] + llc_flags + ["-start-before", entry_pass, "-o", args.o, unison_mir]
execute(cmd_s)
|
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- llvm/include/llvm/TableGen/Unison.h llvm/lib/CodeGen/UnisonMIRPrepare.cpp llvm/lib/TableGen/Unison.cpp llvm/include/llvm/CodeGen/Passes.h llvm/include/llvm/InitializePasses.h llvm/lib/CodeGen/CodeGen.cpp llvm/lib/CodeGen/MIRParser/MILexer.cpp llvm/lib/CodeGen/MIRParser/MILexer.h llvm/lib/CodeGen/MIRParser/MIParser.cpp llvm/lib/CodeGen/MIRPrinter.cpp llvm/lib/CodeGen/MIRPrintingPass.cpp llvm/utils/TableGen/Basic/TableGen.cppView the diff from clang-format here.diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index da0ff22ac..3a2bcc470 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -340,7 +340,7 @@ LLVM_ABI void initializeWindowsSecureHotPatchingPass(PassRegistry &);
LLVM_ABI void initializeWinEHPreparePass(PassRegistry &);
LLVM_ABI void initializeWriteBitcodePassPass(PassRegistry &);
LLVM_ABI void initializeXRayInstrumentationLegacyPass(PassRegistry &);
-LLVM_ABI void initializeUnisonMIRPreparePass(PassRegistry&);
+LLVM_ABI void initializeUnisonMIRPreparePass(PassRegistry &);
} // end namespace llvm
diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
index 90e037bfc..4c93a6204 100644
--- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
@@ -755,8 +755,9 @@ bool MIParser::parseBasicBlockDefinition(
break;
case MIToken::kw_freq:
// Unison MIR style extension: basic block execution frequency.
- lex();
- if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
+ lex();
+ if (Token.isNot(MIToken::IntegerLiteral) ||
+ Token.integerValue().isSigned())
return error("expected an integer literal");
lex();
break;
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index e9f8a3839..822770826 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -721,13 +721,11 @@ void printMBB(raw_ostream &OS, MFPrintState &State,
OS << LS << printMBBReference(**I);
// The Unison style uses a simpler formatting of the probabilities.
if (UnisonMIR && (!SimplifyMIR || !canPredictProbs))
- OS << '('
- << MBB.getSuccProbability(I).scale(100)
- << ')';
+ OS << '(' << MBB.getSuccProbability(I).scale(100) << ')';
else // Intentional indention to reduce merge conflicts.
- if (!SimplifyMIR || !canPredictProbs)
- OS << format("(0x%08" PRIx32 ")",
- MBB.getSuccProbability(I).getNumerator());
+ if (!SimplifyMIR || !canPredictProbs)
+ OS << format("(0x%08" PRIx32 ")",
+ MBB.getSuccProbability(I).getNumerator());
}
OS << "\n";
HasLineAttributes = true;
diff --git a/llvm/lib/CodeGen/MIRPrintingPass.cpp b/llvm/lib/CodeGen/MIRPrintingPass.cpp
index eff731521..f76c1704a 100644
--- a/llvm/lib/CodeGen/MIRPrintingPass.cpp
+++ b/llvm/lib/CodeGen/MIRPrintingPass.cpp
@@ -14,11 +14,11 @@
#include "llvm/CodeGen/MIRPrinter.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
-#include "llvm/CodeGen/UnisonMIRPrepare.h"
#include "llvm/CodeGen/Passes.h"
+#include "llvm/CodeGen/UnisonMIRPrepare.h"
#include "llvm/IR/Function.h"
-#include "llvm/Support/CommandLine.h"
#include "llvm/InitializePasses.h"
+#include "llvm/Support/CommandLine.h"
using namespace llvm;
diff --git a/llvm/lib/CodeGen/UnisonMIRPrepare.cpp b/llvm/lib/CodeGen/UnisonMIRPrepare.cpp
index e01b69cac..246019578 100644
--- a/llvm/lib/CodeGen/UnisonMIRPrepare.cpp
+++ b/llvm/lib/CodeGen/UnisonMIRPrepare.cpp
@@ -39,15 +39,14 @@
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/UnisonMIRPrepare.h"
-#include "llvm/Pass.h"
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
-#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/Constants.h"
-#include "llvm/InitializePasses.h"
#include "llvm/IR/MDBuilder.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
using namespace llvm;
@@ -66,10 +65,9 @@ MDNode *createMDTaggedTuple(MachineFunction &MF, std::string Tag,
uint64_t Val) {
LLVMContext &Context = MF.getFunction().getContext();
MDBuilder Builder(Context);
- return MDNode::get(Context,
- {Builder.createString(Tag),
- Builder.createConstant(
- ConstantInt::get(Type::getInt64Ty(Context), Val))});
+ return MDNode::get(Context, {Builder.createString(Tag),
+ Builder.createConstant(ConstantInt::get(
+ Type::getInt64Ty(Context), Val))});
}
UnisonMIRPrepare::UnisonMIRPrepare() : MachineFunctionPass(ID) {
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.