[llvm-dev] Help with pass manager
Mehdi Amini via llvm-dev
llvm-dev at lists.llvm.org
Wed Mar 23 17:53:36 PDT 2016
This code path is not likely to crash usually. Did you build LLVM yourself? Which version are you using and can you reduce the test case to be "minimal" so that someone can reproduce?
(for instance you don't need a module to create a pass manager)
--
Mehdi
> On Mar 23, 2016, at 5:50 PM, Lorenzo Laneve <lore97drk at icloud.com> wrote:
>
> Sorry, that's a pure crash I think, assertions are not triggered.
> Xcode doesn’t map those 2 functions to line numbers because they’re in precompiled libraries
>
>
> On Mar 24, 2016, at 1:44 AM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote:
>
>>
>>> On Mar 23, 2016, at 5:41 PM, Lorenzo Laneve <lore97drk at icloud.com <mailto:lore97drk at icloud.com>> wrote:
>>>
>>> The stack trace:
>>> llvm::PMTopLevelManager::addImmutablePass(llvm::ImmutablePass*)
>>> llvm::PMTopLevelManager::schedulePass(llvm::Pass*)
>>> moduleToObjectFile(llvm::Module*,std::string&,llvm::LLVMContext&)
>>
>>
>> Without mapping to line numbers this is not very helpful: moduleToObjectFile never calls schedulePass.
>>
>> Also you didn't answer my previous question about the crash.
>>
>>
>>> Sometimes it doesn't crash because TargetRegistry::lookupTarget() returns an error which says it doesn't support the current target
>>
>> Do you mean that running it multiple time does not always produce the same behavior in the call to lookupTarget?
>> That's unexpected and I'd be worried about my program.
>>
>> --
>> Mehdi
>>
>>
>>
>>>
>>> On Mar 24, 2016, at 1:14 AM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote:
>>>
>>>> Assuming you are talking about this line:
>>>>
>>>> passmanager.add(tliwp);
>>>>
>>>> I don't see anything obviously wrong.
>>>> Are you hitting an assertion or a pure crash? (if LLVM not built with assertions, please rebuild).
>>>> What does your debugger gives you as a stracktrace?
>>>>
>>>> --
>>>> Mehdi
>>>>
>>>>
>>>>
>>>>> On Mar 23, 2016, at 3:44 PM, Lorenzo Laneve via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
>>>>>
>>>>> Sorry in advance for the stupid question, i still don’t understand some concepts like passes.
>>>>> I took a piece of code from llc, and I used it to write a function that creates an object (or assembly) file from an IR module.
>>>>> It compiles without any problems. But program crashes when it reaches add() method of the pass manager.
>>>>> Can you help me figuring out what’s the problem please? here is my function
>>>>>
>>>>>
>>>>> int moduleToObjectFile(llvm::Module *module, std::string &srcname, llvm::LLVMContext &Context) {
>>>>> SMDiagnostic error;
>>>>> Triple moduletriple = Triple(module->getTargetTriple());
>>>>>
>>>>> if (moduletriple.getTriple().empty())
>>>>> moduletriple.setTriple(sys::getDefaultTargetTriple());
>>>>>
>>>>> std::string lookuperror;
>>>>> const Target *moduletarget = TargetRegistry::lookupTarget(MArch, moduletriple, lookuperror);
>>>>>
>>>>> if (!moduletarget) {
>>>>> errs() << lookuperror;
>>>>> return 1;
>>>>> }
>>>>>
>>>>> std::string cpuname = getCPUStr(),
>>>>> ftrlist = getFeaturesStr();
>>>>>
>>>>> CodeGenOpt::Level OLvl = CodeGenOpt::Default;
>>>>> switch ('2') {
>>>>> default:
>>>>> errs() << "invalid optimization level.\n";
>>>>> return 1;
>>>>> case ' ': break;
>>>>> case '0': OLvl = CodeGenOpt::None; break;
>>>>> case '1': OLvl = CodeGenOpt::Less; break;
>>>>> case '2': OLvl = CodeGenOpt::Default; break;
>>>>> case '3': OLvl = CodeGenOpt::Aggressive; break;
>>>>> }
>>>>>
>>>>> TargetOptions targetopts = InitTargetOptionsFromCodeGenFlags();
>>>>>
>>>>> std::unique_ptr<TargetMachine> tmachine(moduletarget->createTargetMachine(moduletriple.getTriple(), cpuname, ftrlist, targetopts, Reloc::Default, CodeModel::Default, OLvl));
>>>>>
>>>>> assert(tmachine && "Could not allocate target machine!");
>>>>>
>>>>> assert(module && "Should have exited if we didn't have a module!");
>>>>> if (FloatABIForCalls != FloatABI::Default)
>>>>> targetopts.FloatABIType = FloatABIForCalls;
>>>>>
>>>>>
>>>>> std::unique_ptr<tool_output_file> objoutstream = getOutputFileStream(module, srcname);
>>>>> if (!objoutstream) return 1;
>>>>>
>>>>> legacy::PassManager passmanager;
>>>>>
>>>>> TargetLibraryInfoImpl TLII(moduletriple);
>>>>>
>>>>> TargetLibraryInfoWrapperPass *tliwp = new TargetLibraryInfoWrapperPass(TLII);
>>>>>
>>>>> passmanager.add(tliwp);
>>>>>
>>>>> module->setDataLayout(tmachine->createDataLayout());
>>>>>
>>>>> setFunctionAttributes(cpuname, ftrlist, *module);
>>>>>
>>>>> if (RelaxAll.getNumOccurrences() > 0 &&
>>>>> FileType != TargetMachine::CGFT_ObjectFile)
>>>>> errs() << "warning: ignoring -mc-relax-all because filetype != obj";
>>>>>
>>>>> {
>>>>> raw_pwrite_stream *outstream = &objoutstream->os();
>>>>>
>>>>> SmallVector<char, 0> filebuf;
>>>>> std::unique_ptr<raw_svector_ostream> BOS;
>>>>> if ((FileType != TargetMachine::CGFT_AssemblyFile && !objoutstream->os().supportsSeeking())) {
>>>>> BOS = make_unique<raw_svector_ostream>(filebuf);
>>>>> outstream = BOS.get();
>>>>> }
>>>>>
>>>>> AnalysisID StartBeforeID = nullptr;
>>>>> AnalysisID StartAfterID = nullptr;
>>>>> AnalysisID StopAfterID = nullptr;
>>>>> const PassRegistry *PR = PassRegistry::getPassRegistry();
>>>>> if (!RunPass.empty()) {
>>>>> if (!StartAfter.empty() || !StopAfter.empty()) {
>>>>> errs() << "start-after and/or stop-after passes are redundant when run-pass is specified.\n";
>>>>> return 1;
>>>>> }
>>>>> const PassInfo *PI = PR->getPassInfo(RunPass);
>>>>> if (!PI) {
>>>>> errs() << "run-pass pass is not registered.\n";
>>>>> return 1;
>>>>> }
>>>>> StopAfterID = StartBeforeID = PI->getTypeInfo();
>>>>> } else {
>>>>> if (!StartAfter.empty()) {
>>>>> const PassInfo *PI = PR->getPassInfo(StartAfter);
>>>>> if (!PI) {
>>>>> errs() << "start-after pass is not registered.\n";
>>>>> return 1;
>>>>> }
>>>>> StartAfterID = PI->getTypeInfo();
>>>>> }
>>>>> if (!StopAfter.empty()) {
>>>>> const PassInfo *PI = PR->getPassInfo(StopAfter);
>>>>> if (!PI) {
>>>>> errs() << "stop-after pass is not registered.\n";
>>>>> return 1;
>>>>> }
>>>>> StopAfterID = PI->getTypeInfo();
>>>>> }
>>>>> }
>>>>>
>>>>> if (tmachine->addPassesToEmitFile(passmanager, *outstream, FileType, false, StartBeforeID, StartAfterID, StopAfterID)) {
>>>>> errs() << "target does not support generation of this file type!\n";
>>>>> return 1;
>>>>> }
>>>>>
>>>>> passmanager.run(*module);
>>>>>
>>>>> if (BOS) {
>>>>> objoutstream->os() << filebuf;
>>>>> }
>>>>> }
>>>>>
>>>>> objoutstream->keep();
>>>>>
>>>>> return 0;
>>>>> }
>>>>> _______________________________________________
>>>>> LLVM Developers mailing list
>>>>> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
>>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
>>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160323/349e0cc6/attachment.html>
More information about the llvm-dev
mailing list