Chris Bieneman
2014-Dec-01 17:43 UTC
[LLVMdev] Fwd: [RFC] Embedding command line options in bitcode (PR21471)
Forwarding this to LLVMDev. I think Mark accidentally hit reply instead of reply all.> Begin forwarded message: > > From: Mark Schimmel <Mark.Schimmel at synopsys.com> > To: Chris Bieneman <cbieneman at apple.com> > Subject: RE: [LLVMdev] [RFC] Embedding command line options in bitcode (PR21471) > Date: November 21, 2014 at 4:00:59 PM PST > > I’d like to see per function property metadata. Something like “metadata property A=16”. Think of something like pragma FP Contract. Targets could record anything they want to and query it in their backends. We have a need to add something like this that would inhibit a function being inlined when properties didn’t match. I’m abusing function attributes to get it done at the moment, but would love to have something much more generic.-Chris> > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Chris Bieneman > Sent: Friday, November 14, 2014 2:58 PM > To: Duncan P. N. Exon Smith > Cc: LLVM Developers Mailing List > Subject: Re: [LLVMdev] [RFC] Embedding command line options in bitcode (PR21471) > > There are parts of this proposal that I really like, and there are others that I think are actually at opposition to the work we’re trying to do with cl::opt. > > On Nov 14, 2014, at 2:44 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com <mailto:dexonsmith at apple.com>> wrote: > > +chrisb > > > On 2014-Nov-13, at 16:33, Akira Hatanaka <ahatanak at gmail.com <mailto:ahatanak at gmail.com>> wrote: > > I'm working on fixing PR21471, which is about embedding codegen command line options into the bitcode as function or module-level attributes so that they don't get ignored when doing LTO. > > http://llvm.org/bugs/show_bug.cgi?id=21471 <http://llvm.org/bugs/show_bug.cgi?id=21471> > > I have an initial patch (attached to this email) which enables clang/llvm to recognize one command line option, write it to the IR, and read it out in a backend pass. I'm looking to get feedback from the community on whether I'm headed in the right direction or whether there are alternate ideas before I go all the way on fixing the PR. Specifically, I'd like to know the answers to the following questions: > > 1. How do we make sure we continue to be able to use the command line options we've been using for llc and other tools? > > In discussions about the new cl::opt API I believe the general idea was that most of the options expressed using cl::opt are actually only relevant as debug options, so I think one big part of this work is really going to be identifying a subset of the current options which are actually relevant to expose in the IR. > > > 2. How to handle cases where two functions in a module have different sets of command line options? > > Today I don’t believe we have this ability. > > > 3. Where should the command line options or module/function attributes be stored once they are read out from the IR? > > My suggestion would be the OptionStore that I proposed here: http://reviews.llvm.org/D6207 <http://reviews.llvm.org/D6207> > > > > The short description of the approach I took in my patch is that command line options that are important to codegen are collected by cl::ParseCommandLineOptions, written to the bitcode as function or module attributes, and read out directly by the optimization passes that need them. cl::opt options are replaced with CodeGenOpt options (subclass of cl::opt), which are needed only to parse the command line and provide the default value when the corresponding options are not in the bitcode. > > I like this approach, since it means the frontend doesn't have to understand > options in order to pass them on to the backend. > > The static variables should be straightforward to migrate to an LLVMContext > once ParseCommandLineOptions stores things there instead of in globals. > > I also think that the OptionStore in conjunction with the OptionRegistry (rather than any of the cl APIs) should have all the parsing code. In fact, you shouldn’t have to call ParseCommandLineOptions, we could make encoding and decoding the stored options associated with a module part of loading and storing the module. > > > > > diff --git a/lib/CodeGen/CodeGenOption.cpp b/lib/CodeGen/CodeGenOption.cpp > new file mode 100644 > index 0000000..2d74c2f > --- /dev/null > +++ b/lib/CodeGen/CodeGenOption.cpp > @@ -0,0 +1,59 @@ > +//===- CodeGen/CodeGenOptions.cpp - Code-gen option. --*- C++ -*-===// > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open Source > +// License. See LICENSE.TXT for details. > +// > +//===----------------------------------------------------------------------===// > +// > +//===----------------------------------------------------------------------===// > + > +#include "llvm/CodeGen/CodeGenOption.h" > +#include "llvm/IR/Attributes.h" > +#include "llvm/IR/Module.h" > + > +using namespace llvm; > + > +static std::map<std::string, bool> FunctionBoolAttrs; > +static std::map<std::string, bool> ModuleBoolAttrs; > + > > @Chris, should these be using ManagedStatic? > > I’d much rather they just weren’t static at all. Using globals to store state that inherently isn’t global just feels wrong. > > -Chris-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141201/9e255f34/attachment.html>