aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llc/llc.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-07-26 19:36:28 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-07-26 19:36:28 +0000
commitcfca06d7963fa0909f90483b42a6d7d194d01e08 (patch)
tree209fb2a2d68f8f277793fc8df46c753d31bc853b /llvm/tools/llc/llc.cpp
parent706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff)
downloadsrc-cfca06d7963fa0909f90483b42a6d7d194d01e08.tar.gz
src-cfca06d7963fa0909f90483b42a6d7d194d01e08.zip
Vendor import of llvm-project master 2e10b7a39b9, the last commit beforevendor/llvm-project/llvmorg-11-init-20887-g2e10b7a39b9vendor/llvm-project/master
the llvmorg-12-init tag, from which release/11.x was branched.
Notes
Notes: svn path=/vendor/llvm-project/master/; revision=363578 svn path=/vendor/llvm-project/llvmorg-11-init-20887-g2e10b7a39b9/; revision=363579; tag=vendor/llvm-project/llvmorg-11-init-20887-g2e10b7a39b9
Diffstat (limited to 'llvm/tools/llc/llc.cpp')
-rw-r--r--llvm/tools/llc/llc.cpp192
1 files changed, 117 insertions, 75 deletions
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index b35f8e853c30..95f2963ecbd6 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -15,7 +15,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
-#include "llvm/CodeGen/CommandFlags.inc"
+#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
#include "llvm/CodeGen/LinkAllCodegenComponents.h"
#include "llvm/CodeGen/MIRParser/MIRParser.h"
@@ -29,9 +29,9 @@
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/LLVMRemarkStreamer.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/RemarkStreamer.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/InitializePasses.h"
@@ -50,11 +50,14 @@
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/WithColor.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include <memory>
using namespace llvm;
+static codegen::RegisterCodeGenFlags CGF;
+
// General options for llc. Other pass-specific options are specified
// within the corresponding llc passes, and target-specific options
// and back-end code generation options are specified with the target machine.
@@ -171,7 +174,7 @@ struct RunPassOption {
SmallVector<StringRef, 8> PassNames;
StringRef(Val).split(PassNames, ',', -1, false);
for (auto PassName : PassNames)
- RunPassNames->push_back(PassName);
+ RunPassNames->push_back(std::string(PassName));
}
};
}
@@ -196,13 +199,13 @@ static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
// If InputFilename ends in .bc or .ll, remove it.
StringRef IFN = InputFilename;
if (IFN.endswith(".bc") || IFN.endswith(".ll"))
- OutputFilename = IFN.drop_back(3);
+ OutputFilename = std::string(IFN.drop_back(3));
else if (IFN.endswith(".mir"))
- OutputFilename = IFN.drop_back(4);
+ OutputFilename = std::string(IFN.drop_back(4));
else
- OutputFilename = IFN;
+ OutputFilename = std::string(IFN);
- switch (FileType) {
+ switch (codegen::getFileType()) {
case CGFT_AssemblyFile:
if (TargetName[0] == 'c') {
if (TargetName[1] == 0)
@@ -229,7 +232,7 @@ static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
// Decide if we need "binary" output.
bool Binary = false;
- switch (FileType) {
+ switch (codegen::getFileType()) {
case CGFT_AssemblyFile:
break;
case CGFT_ObjectFile:
@@ -316,6 +319,7 @@ int main(int argc, char **argv) {
initializeScalarizeMaskedMemIntrinPass(*Registry);
initializeExpandReductionsPass(*Registry);
initializeHardwareLoopsPass(*Registry);
+ initializeTransformUtils(*Registry);
// Initialize debugging passes.
initializeScavengerTestPass(*Registry);
@@ -334,9 +338,9 @@ int main(int argc, char **argv) {
Context.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, &HasError);
Expected<std::unique_ptr<ToolOutputFile>> RemarksFileOrErr =
- setupOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
- RemarksFormat, RemarksWithHotness,
- RemarksHotnessThreshold);
+ setupLLVMOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
+ RemarksFormat, RemarksWithHotness,
+ RemarksHotnessThreshold);
if (Error E = RemarksFileOrErr.takeError()) {
WithColor::error(errs(), argv[0]) << toString(std::move(E)) << '\n';
return 1;
@@ -383,8 +387,9 @@ static bool addPass(PassManagerBase &PM, const char *argv0,
return true;
}
std::string Banner = std::string("After ") + std::string(P->getPassName());
+ TPC.addMachinePrePasses();
PM.add(P);
- TPC.printAndVerify(Banner);
+ TPC.addMachinePostPasses(Banner);
return false;
}
@@ -395,51 +400,18 @@ static int compileModule(char **argv, LLVMContext &Context) {
std::unique_ptr<Module> M;
std::unique_ptr<MIRParser> MIR;
Triple TheTriple;
- std::string CPUStr = getCPUStr(), FeaturesStr = getFeaturesStr();
+ std::string CPUStr = codegen::getCPUStr(),
+ FeaturesStr = codegen::getFeaturesStr();
// Set attributes on functions as loaded from MIR from command line arguments.
auto setMIRFunctionAttributes = [&CPUStr, &FeaturesStr](Function &F) {
- setFunctionAttributes(CPUStr, FeaturesStr, F);
+ codegen::setFunctionAttributes(CPUStr, FeaturesStr, F);
};
- bool SkipModule = MCPU == "help" ||
+ auto MAttrs = codegen::getMAttrs();
+ bool SkipModule = codegen::getMCPU() == "help" ||
(!MAttrs.empty() && MAttrs.front() == "help");
- // If user just wants to list available options, skip module loading
- if (!SkipModule) {
- if (InputLanguage == "mir" ||
- (InputLanguage == "" && StringRef(InputFilename).endswith(".mir"))) {
- MIR = createMIRParserFromFile(InputFilename, Err, Context,
- setMIRFunctionAttributes);
- if (MIR)
- M = MIR->parseIRModule();
- } else
- M = parseIRFile(InputFilename, Err, Context, false);
- if (!M) {
- Err.print(argv[0], WithColor::error(errs(), argv[0]));
- return 1;
- }
-
- // If we are supposed to override the target triple, do so now.
- if (!TargetTriple.empty())
- M->setTargetTriple(Triple::normalize(TargetTriple));
- TheTriple = Triple(M->getTargetTriple());
- } else {
- TheTriple = Triple(Triple::normalize(TargetTriple));
- }
-
- if (TheTriple.getTriple().empty())
- TheTriple.setTriple(sys::getDefaultTargetTriple());
-
- // Get the target specific parser.
- std::string Error;
- const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
- Error);
- if (!TheTarget) {
- WithColor::error(errs(), argv[0]) << Error;
- return 1;
- }
-
CodeGenOpt::Level OLvl = CodeGenOpt::Default;
switch (OptLevel) {
default:
@@ -452,7 +424,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
case '3': OLvl = CodeGenOpt::Aggressive; break;
}
- TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
+ TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags();
Options.DisableIntegratedAS = NoIntegratedAssembler;
Options.MCOptions.ShowMCEncoding = ShowMCEncoding;
Options.MCOptions.MCUseDwarfDirectory = EnableDwarfDirectory;
@@ -461,21 +433,97 @@ static int compileModule(char **argv, LLVMContext &Context) {
Options.MCOptions.IASSearchPaths = IncludeDirs;
Options.MCOptions.SplitDwarfFile = SplitDwarfFile;
- std::unique_ptr<TargetMachine> Target(TheTarget->createTargetMachine(
- TheTriple.getTriple(), CPUStr, FeaturesStr, Options, getRelocModel(),
- getCodeModel(), OLvl));
+ Optional<Reloc::Model> RM = codegen::getExplicitRelocModel();
+
+ const Target *TheTarget = nullptr;
+ std::unique_ptr<TargetMachine> Target;
+
+ // If user just wants to list available options, skip module loading
+ if (!SkipModule) {
+ auto SetDataLayout =
+ [&](StringRef DataLayoutTargetTriple) -> Optional<std::string> {
+ // If we are supposed to override the target triple, do so now.
+ std::string IRTargetTriple = DataLayoutTargetTriple.str();
+ if (!TargetTriple.empty())
+ IRTargetTriple = Triple::normalize(TargetTriple);
+ TheTriple = Triple(IRTargetTriple);
+ if (TheTriple.getTriple().empty())
+ TheTriple.setTriple(sys::getDefaultTargetTriple());
+
+ std::string Error;
+ TheTarget =
+ TargetRegistry::lookupTarget(codegen::getMArch(), TheTriple, Error);
+ if (!TheTarget) {
+ WithColor::error(errs(), argv[0]) << Error;
+ exit(1);
+ }
+
+ // On AIX, setting the relocation model to anything other than PIC is
+ // considered a user error.
+ if (TheTriple.isOSAIX() && RM.hasValue() && *RM != Reloc::PIC_) {
+ WithColor::error(errs(), argv[0])
+ << "invalid relocation model, AIX only supports PIC.\n";
+ exit(1);
+ }
- assert(Target && "Could not allocate target machine!");
+ Target = std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
+ TheTriple.getTriple(), CPUStr, FeaturesStr, Options, RM,
+ codegen::getExplicitCodeModel(), OLvl));
+ assert(Target && "Could not allocate target machine!");
- // If we don't have a module then just exit now. We do this down
- // here since the CPU/Feature help is underneath the target machine
- // creation.
- if (SkipModule)
+ return Target->createDataLayout().getStringRepresentation();
+ };
+ if (InputLanguage == "mir" ||
+ (InputLanguage == "" && StringRef(InputFilename).endswith(".mir"))) {
+ MIR = createMIRParserFromFile(InputFilename, Err, Context,
+ setMIRFunctionAttributes);
+ if (MIR)
+ M = MIR->parseIRModule(SetDataLayout);
+ } else {
+ M = parseIRFile(InputFilename, Err, Context, SetDataLayout);
+ }
+ if (!M) {
+ Err.print(argv[0], WithColor::error(errs(), argv[0]));
+ return 1;
+ }
+ if (!TargetTriple.empty())
+ M->setTargetTriple(Triple::normalize(TargetTriple));
+ } else {
+ TheTriple = Triple(Triple::normalize(TargetTriple));
+ if (TheTriple.getTriple().empty())
+ TheTriple.setTriple(sys::getDefaultTargetTriple());
+
+ // Get the target specific parser.
+ std::string Error;
+ TheTarget =
+ TargetRegistry::lookupTarget(codegen::getMArch(), TheTriple, Error);
+ if (!TheTarget) {
+ WithColor::error(errs(), argv[0]) << Error;
+ return 1;
+ }
+
+ // On AIX, setting the relocation model to anything other than PIC is
+ // considered a user error.
+ if (TheTriple.isOSAIX() && RM.hasValue() && *RM != Reloc::PIC_) {
+ WithColor::error(errs(), argv[0])
+ << "invalid relocation model, AIX only supports PIC.\n";
+ return 1;
+ }
+
+ Target = std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
+ TheTriple.getTriple(), CPUStr, FeaturesStr, Options, RM,
+ codegen::getExplicitCodeModel(), OLvl));
+ assert(Target && "Could not allocate target machine!");
+
+ // If we don't have a module then just exit now. We do this down
+ // here since the CPU/Feature help is underneath the target machine
+ // creation.
return 0;
+ }
assert(M && "Should have exited if we didn't have a module!");
- if (FloatABIForCalls != FloatABI::Default)
- Options.FloatABIType = FloatABIForCalls;
+ if (codegen::getFloatABIForCalls() != FloatABI::Default)
+ Options.FloatABIType = codegen::getFloatABIForCalls();
// Figure out where we are going to send the output.
std::unique_ptr<ToolOutputFile> Out =
@@ -504,13 +552,6 @@ static int compileModule(char **argv, LLVMContext &Context) {
TLII.disableAllFunctions();
PM.add(new TargetLibraryInfoWrapperPass(TLII));
- // Add the target data from the target machine, if it exists, or the module.
- M->setDataLayout(Target->createDataLayout());
-
- // This needs to be done after setting datalayout since it calls verifier
- // to check debug info whereas verifier relies on correct datalayout.
- UpgradeDebugInfo(*M);
-
// Verify module immediately to catch problems before doInitialization() is
// called on any passes.
if (!NoVerify && verifyModule(*M, &errs())) {
@@ -522,10 +563,9 @@ static int compileModule(char **argv, LLVMContext &Context) {
// Override function attributes based on CPUStr, FeaturesStr, and command line
// flags.
- setFunctionAttributes(CPUStr, FeaturesStr, *M);
+ codegen::setFunctionAttributes(CPUStr, FeaturesStr, *M);
- if (RelaxAll.getNumOccurrences() > 0 &&
- FileType != CGFT_ObjectFile)
+ if (mc::getExplicitRelaxAll() && codegen::getFileType() != CGFT_ObjectFile)
WithColor::warning(errs(), argv[0])
<< ": warning: ignoring -mc-relax-all because filetype != obj";
@@ -536,7 +576,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
// so we can memcmp the contents in CompileTwice mode
SmallVector<char, 0> Buffer;
std::unique_ptr<raw_svector_ostream> BOS;
- if ((FileType != CGFT_AssemblyFile &&
+ if ((codegen::getFileType() != CGFT_AssemblyFile &&
!Out->os().supportsSeeking()) ||
CompileTwice) {
BOS = std::make_unique<raw_svector_ostream>(Buffer);
@@ -575,15 +615,17 @@ static int compileModule(char **argv, LLVMContext &Context) {
TPC.setInitialized();
PM.add(createPrintMIRPass(*OS));
PM.add(createFreeMachineFunctionPass());
- } else if (Target->addPassesToEmitFile(PM, *OS,
- DwoOut ? &DwoOut->os() : nullptr,
- FileType, NoVerify, MMIWP)) {
+ } else if (Target->addPassesToEmitFile(
+ PM, *OS, DwoOut ? &DwoOut->os() : nullptr,
+ codegen::getFileType(), NoVerify, MMIWP)) {
WithColor::warning(errs(), argv[0])
<< "target does not support generation of this"
<< " file type!\n";
return 1;
}
+ const_cast<TargetLoweringObjectFile *>(LLVMTM.getObjFileLowering())
+ ->Initialize(MMIWP->getMMI().getContext(), *Target);
if (MIR) {
assert(MMIWP && "Forgot to create MMIWP?");
if (MIR->parseMachineFunctions(*M, MMIWP->getMMI()))