[PATCH] D28538: [CodeGen] [CUDA] Add the ability set default attrs on functions in linked modules.

Hal Finkel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 06:41:05 PST 2017

hfinkel added inline comments.

Comment at: clang/lib/CodeGen/CGCall.cpp:1720
+      getLLVMContext(), llvm::AttributeSet::FunctionIndex, FuncAttrs);
+  F.addAttributes(llvm::AttributeSet::FunctionIndex, AS);
mehdi_amini wrote:
> jlebar wrote:
> > mehdi_amini wrote:
> > > Are we sure it always work? What if a function is annotated with an attribute incompatible with the attributes you're gonna add?
> > I have no idea -- what is going to happen?
> > 
> > In the CUDA use-case we make tons of assumptions about the contents of libdevice -- if we're making an additional assumption here, I'm fine with that.  Obviously we don't just want to nuke all of the attributes on the incoming function, because some of them might be derived from the IR as opposed to the codegen options.
> > I have no idea -- what is going to happen?
> (The verifier will fail)
I think we need to decide what happens here. We can either remove attributes we're going to set, merge them properly, or skip them. I think that we should do the following:

 1. Merge attributes properly (or just skip those already present on the function)
 2. Add a flag to Clang, that can be used when compiling libdevice (or whatever), that causes functions to be generated with only minimal attributes (i.e. keep readnone/only for pure/const, but don't add unsafe-math flags or target info).

Also, higher-level question: Why is this bitcode-linking functionality specific to CUDA at all?


More information about the llvm-commits mailing list