[llvm] r220994 - IR: MDNode => Value: Instruction::setMetadata()

Eric Christopher echristo at gmail.com
Tue Nov 4 15:06:00 PST 2014


On Fri Oct 31 2014 at 1:29:34 PM Duncan P. N. Exon Smith <
dexonsmith at apple.com> wrote:

> Author: dexonsmith
> Date: Fri Oct 31 15:13:11 2014
> New Revision: 220994
>
> URL: http://llvm.org/viewvc/llvm-project?rev=220994&view=rev
> Log:
> IR: MDNode => Value: Instruction::setMetadata()
>
> Change `Instruction::setMetadata()` API to accept `Value` instead of
> `MDNode`.  Part of PR21433.
>
> Modified:
>     llvm/trunk/include/llvm/IR/IRBuilder.h
>     llvm/trunk/include/llvm/IR/Instruction.h
>     llvm/trunk/lib/IR/Metadata.cpp
>
> Modified: llvm/trunk/include/llvm/IR/IRBuilder.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/
> llvm/IR/IRBuilder.h?rev=220994&r1=220993&r2=220994&view=diff
> ============================================================
> ==================
> --- llvm/trunk/include/llvm/IR/IRBuilder.h (original)
> +++ llvm/trunk/include/llvm/IR/IRBuilder.h Fri Oct 31 15:13:11 2014
> @@ -23,12 +23,12 @@
>  #include "llvm/IR/DataLayout.h"
>  #include "llvm/IR/Instructions.h"
>  #include "llvm/IR/LLVMContext.h"
> +#include "llvm/IR/Metadata.h"
>  #include "llvm/IR/Operator.h"
>  #include "llvm/IR/ValueHandle.h"
>  #include "llvm/Support/CBindingWrapping.h"
>
>  namespace llvm {
> -  class MDNode;
>
>  /// \brief This provides the default implementation of the IRBuilder
>  /// 'InsertHelper' method that is called whenever an instruction is
> created by
>
> Modified: llvm/trunk/include/llvm/IR/Instruction.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/
> llvm/IR/Instruction.h?rev=220994&r1=220993&r2=220994&view=diff
> ============================================================
> ==================
> --- llvm/trunk/include/llvm/IR/Instruction.h (original)
> +++ llvm/trunk/include/llvm/IR/Instruction.h Fri Oct 31 15:13:11 2014
> @@ -176,9 +176,9 @@ public:
>
>    /// setMetadata - Set the metadata of the specified kind to the
> specified
>    /// node.  This updates/replaces metadata if already present, or
> removes it if
> -  /// Node is null.
> -  void setMetadata(unsigned KindID, MDNode *Node);
> -  void setMetadata(StringRef Kind, MDNode *Node);
> +  /// MD is null.
> +  void setMetadata(unsigned KindID, Value *MD);
> +  void setMetadata(StringRef Kind, Value *MD);
>
>    /// \brief Drop unknown metadata.
>    /// Passes are required to drop metadata they don't understand. This is
> a
>
> Modified: llvm/trunk/lib/IR/Metadata.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/
> Metadata.cpp?rev=220994&r1=220993&r2=220994&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/IR/Metadata.cpp (original)
> +++ llvm/trunk/lib/IR/Metadata.cpp Fri Oct 31 15:13:11 2014
> @@ -600,9 +600,9 @@ StringRef NamedMDNode::getName() const {
>  // Instruction Metadata method implementations.
>  //
>
> -void Instruction::setMetadata(StringRef Kind, MDNode *Node) {
> -  if (!Node && !hasMetadata()) return;
> -  setMetadata(getContext().getMDKindID(Kind), Node);
> +void Instruction::setMetadata(StringRef Kind, Value *MD) {
> +  if (!MD && !hasMetadata()) return;
> +  setMetadata(getContext().getMDKindID(Kind), MD);
>  }
>
>  MDNode *Instruction::getMetadataImpl(StringRef Kind) const {
> @@ -655,9 +655,12 @@ void Instruction::dropUnknownMetadata(Ar
>
>  /// setMetadata - Set the metadata of of the specified kind to the
> specified
>  /// node.  This updates/replaces metadata if already present, or removes
> it if
> -/// Node is null.
> -void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
> -  if (!Node && !hasMetadata()) return;
> +/// MD is null.
> +void Instruction::setMetadata(unsigned KindID, Value *MD) {
> +  if (!MD && !hasMetadata()) return;
> +



> +  // For now, we only expect MDNodes here.
> +  MDNode *Node = cast<MDNode>(MD);
>
>
Hrm. Is cast guaranteed to assert? If not, could you add one please?

Thanks!

-eric


>    // Handle 'dbg' as a special case since it is not stored in the hash
> table.
>    if (KindID == LLVMContext::MD_dbg) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141104/c4cd14ab/attachment.html>


More information about the llvm-commits mailing list