[llvm-commits] [llvm] r160237 - in /llvm/trunk: include/llvm/MDBuilder.h include/llvm/Support/MDBuilder.h lib/Transforms/Utils/LowerExpectIntrinsic.cpp lib/Transforms/Utils/SimplifyCFG.cpp unittests/Support/CMakeLists.txt unittests/Support/MDBuilderTest.cpp unittests/VMCore/CMakeLists.txt unittests/VMCore/InstructionsTest.cpp unittests/VMCore/MDBuilderTest.cpp
Chandler Carruth
chandlerc at gmail.com
Sun Jul 15 16:26:50 PDT 2012
Author: chandlerc
Date: Sun Jul 15 18:26:50 2012
New Revision: 160237
URL: http://llvm.org/viewvc/llvm-project?rev=160237&view=rev
Log:
Move llvm/Support/MDBuilder.h to llvm/MDBuilder.h, to live with
IRBuilder, DIBuilder, etc.
This is the proper layering as MDBuilder can't be used (or implemented)
without the Core Metadata representation.
Patches to Clang and Dragonegg coming up.
Added:
llvm/trunk/include/llvm/MDBuilder.h
- copied, changed from r160235, llvm/trunk/include/llvm/Support/MDBuilder.h
llvm/trunk/unittests/VMCore/MDBuilderTest.cpp
- copied, changed from r160235, llvm/trunk/unittests/Support/MDBuilderTest.cpp
Removed:
llvm/trunk/include/llvm/Support/MDBuilder.h
llvm/trunk/unittests/Support/MDBuilderTest.cpp
Modified:
llvm/trunk/lib/Transforms/Utils/LowerExpectIntrinsic.cpp
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/unittests/Support/CMakeLists.txt
llvm/trunk/unittests/VMCore/CMakeLists.txt
llvm/trunk/unittests/VMCore/InstructionsTest.cpp
Copied: llvm/trunk/include/llvm/MDBuilder.h (from r160235, llvm/trunk/include/llvm/Support/MDBuilder.h)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MDBuilder.h?p2=llvm/trunk/include/llvm/MDBuilder.h&p1=llvm/trunk/include/llvm/Support/MDBuilder.h&r1=160235&r2=160237&rev=160237&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MDBuilder.h (original)
+++ llvm/trunk/include/llvm/MDBuilder.h Sun Jul 15 18:26:50 2012
@@ -1,4 +1,4 @@
-//===---- llvm/Support/MDBuilder.h - Builder for LLVM metadata --*- C++ -*-===//
+//===---- llvm/MDBuilder.h - Builder for LLVM metadata ----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
Removed: llvm/trunk/include/llvm/Support/MDBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MDBuilder.h?rev=160236&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Support/MDBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/MDBuilder.h (removed)
@@ -1,141 +0,0 @@
-//===---- llvm/Support/MDBuilder.h - Builder for LLVM metadata --*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the MDBuilder class, which is used as a convenient way to
-// create LLVM metadata with a consistent and simplified interface.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_MDBUILDER_H
-#define LLVM_SUPPORT_MDBUILDER_H
-
-#include "llvm/Constants.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Metadata.h"
-#include "llvm/ADT/APInt.h"
-
-namespace llvm {
-
- class MDBuilder {
- LLVMContext &Context;
-
- public:
- MDBuilder(LLVMContext &context) : Context(context) {}
-
- /// \brief Return the given string as metadata.
- MDString *createString(StringRef Str) {
- return MDString::get(Context, Str);
- }
-
- //===------------------------------------------------------------------===//
- // FPMath metadata.
- //===------------------------------------------------------------------===//
-
- /// \brief Return metadata with the given settings. The special value 0.0
- /// for the Accuracy parameter indicates the default (maximal precision)
- /// setting.
- MDNode *createFPMath(float Accuracy) {
- if (Accuracy == 0.0)
- return 0;
- assert(Accuracy > 0.0 && "Invalid fpmath accuracy!");
- Value *Op = ConstantFP::get(Type::getFloatTy(Context), Accuracy);
- return MDNode::get(Context, Op);
- }
-
- //===------------------------------------------------------------------===//
- // Prof metadata.
- //===------------------------------------------------------------------===//
-
- /// \brief Return metadata containing two branch weights.
- MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight) {
- uint32_t Weights[] = { TrueWeight, FalseWeight };
- return createBranchWeights(Weights);
- }
-
- /// \brief Return metadata containing a number of branch weights.
- MDNode *createBranchWeights(ArrayRef<uint32_t> Weights) {
- assert(Weights.size() >= 2 && "Need at least two branch weights!");
-
- SmallVector<Value *, 4> Vals(Weights.size()+1);
- Vals[0] = createString("branch_weights");
-
- Type *Int32Ty = Type::getInt32Ty(Context);
- for (unsigned i = 0, e = Weights.size(); i != e; ++i)
- Vals[i+1] = ConstantInt::get(Int32Ty, Weights[i]);
-
- return MDNode::get(Context, Vals);
- }
-
- //===------------------------------------------------------------------===//
- // Range metadata.
- //===------------------------------------------------------------------===//
-
- /// \brief Return metadata describing the range [Lo, Hi).
- MDNode *createRange(const APInt &Lo, const APInt &Hi) {
- assert(Lo.getBitWidth() == Hi.getBitWidth() && "Mismatched bitwidths!");
- // If the range is everything then it is useless.
- if (Hi == Lo)
- return 0;
-
- // Return the range [Lo, Hi).
- Type *Ty = IntegerType::get(Context, Lo.getBitWidth());
- Value *Range[2] = { ConstantInt::get(Ty, Lo), ConstantInt::get(Ty, Hi) };
- return MDNode::get(Context, Range);
- }
-
-
- //===------------------------------------------------------------------===//
- // TBAA metadata.
- //===------------------------------------------------------------------===//
-
- /// \brief Return metadata appropriate for a TBAA root node. Each returned
- /// node is distinct from all other metadata and will never be identified
- /// (uniqued) with anything else.
- MDNode *createAnonymousTBAARoot() {
- // To ensure uniqueness the root node is self-referential.
- MDNode *Dummy = MDNode::getTemporary(Context, ArrayRef<Value*>());
- MDNode *Root = MDNode::get(Context, Dummy);
- // At this point we have
- // !0 = metadata !{} <- dummy
- // !1 = metadata !{metadata !0} <- root
- // Replace the dummy operand with the root node itself and delete the dummy.
- Root->replaceOperandWith(0, Root);
- MDNode::deleteTemporary(Dummy);
- // We now have
- // !1 = metadata !{metadata !1} <- self-referential root
- return Root;
- }
-
- /// \brief Return metadata appropriate for a TBAA root node with the given
- /// name. This may be identified (uniqued) with other roots with the same
- /// name.
- MDNode *createTBAARoot(StringRef Name) {
- return MDNode::get(Context, createString(Name));
- }
-
- /// \brief Return metadata for a non-root TBAA node with the given name,
- /// parent in the TBAA tree, and value for 'pointsToConstantMemory'.
- MDNode *createTBAANode(StringRef Name, MDNode *Parent,
- bool isConstant = false) {
- if (isConstant) {
- Constant *Flags = ConstantInt::get(Type::getInt64Ty(Context), 1);
- Value *Ops[3] = { createString(Name), Parent, Flags };
- return MDNode::get(Context, Ops);
- } else {
- Value *Ops[2] = { createString(Name), Parent };
- return MDNode::get(Context, Ops);
- }
- }
-
- };
-
-} // end namespace llvm
-
-#endif
Modified: llvm/trunk/lib/Transforms/Utils/LowerExpectIntrinsic.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LowerExpectIntrinsic.cpp?rev=160237&r1=160236&r2=160237&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LowerExpectIntrinsic.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LowerExpectIntrinsic.cpp Sun Jul 15 18:26:50 2012
@@ -12,19 +12,19 @@
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "lower-expect-intrinsic"
+#include "llvm/BasicBlock.h"
#include "llvm/Constants.h"
#include "llvm/Function.h"
-#include "llvm/BasicBlock.h"
-#include "llvm/LLVMContext.h"
#include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
+#include "llvm/LLVMContext.h"
+#include "llvm/MDBuilder.h"
#include "llvm/Metadata.h"
#include "llvm/Pass.h"
+#include "llvm/ADT/Statistic.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
-#include "llvm/Support/MDBuilder.h"
-#include "llvm/ADT/Statistic.h"
#include <vector>
using namespace llvm;
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=160237&r1=160236&r2=160237&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Sun Jul 15 18:26:50 2012
@@ -20,6 +20,7 @@
#include "llvm/Instructions.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/LLVMContext.h"
+#include "llvm/MDBuilder.h"
#include "llvm/Metadata.h"
#include "llvm/Operator.h"
#include "llvm/Type.h"
@@ -35,7 +36,6 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ConstantRange.h"
#include "llvm/Support/Debug.h"
-#include "llvm/Support/MDBuilder.h"
#include "llvm/Support/NoFolder.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetData.h"
Modified: llvm/trunk/unittests/Support/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CMakeLists.txt?rev=160237&r1=160236&r2=160237&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Support/CMakeLists.txt Sun Jul 15 18:26:50 2012
@@ -17,7 +17,6 @@
LeakDetectorTest.cpp
ManagedStatic.cpp
MathExtrasTest.cpp
- MDBuilderTest.cpp
Path.cpp
raw_ostream_test.cpp
RegexTest.cpp
Removed: llvm/trunk/unittests/Support/MDBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/MDBuilderTest.cpp?rev=160236&view=auto
==============================================================================
--- llvm/trunk/unittests/Support/MDBuilderTest.cpp (original)
+++ llvm/trunk/unittests/Support/MDBuilderTest.cpp (removed)
@@ -1,107 +0,0 @@
-//===- llvm/unittests/Support/MDBuilderTest.cpp - MDBuilder unit tests ----===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/IRBuilder.h"
-#include "llvm/Operator.h"
-#include "llvm/Support/MDBuilder.h"
-
-#include "gtest/gtest.h"
-
-using namespace llvm;
-
-namespace {
-
-class MDBuilderTest : public testing::Test {
-protected:
- LLVMContext Context;
-};
-
-TEST_F(MDBuilderTest, createString) {
- MDBuilder MDHelper(Context);
- MDString *Str0 = MDHelper.createString("");
- MDString *Str1 = MDHelper.createString("string");
- EXPECT_EQ(Str0->getString(), StringRef(""));
- EXPECT_EQ(Str1->getString(), StringRef("string"));
-}
-TEST_F(MDBuilderTest, createFPMath) {
- MDBuilder MDHelper(Context);
- MDNode *MD0 = MDHelper.createFPMath(0.0);
- MDNode *MD1 = MDHelper.createFPMath(1.0);
- EXPECT_EQ(MD0, (MDNode *)0);
- EXPECT_NE(MD1, (MDNode *)0);
- EXPECT_EQ(MD1->getNumOperands(), 1U);
- Value *Op = MD1->getOperand(0);
- EXPECT_TRUE(isa<ConstantFP>(Op));
- EXPECT_TRUE(Op->getType()->isFloatingPointTy());
- ConstantFP *Val = cast<ConstantFP>(Op);
- EXPECT_TRUE(Val->isExactlyValue(1.0));
-}
-TEST_F(MDBuilderTest, createRangeMetadata) {
- MDBuilder MDHelper(Context);
- APInt A(8, 1), B(8, 2);
- MDNode *R0 = MDHelper.createRange(A, A);
- MDNode *R1 = MDHelper.createRange(A, B);
- EXPECT_EQ(R0, (MDNode *)0);
- EXPECT_NE(R1, (MDNode *)0);
- EXPECT_EQ(R1->getNumOperands(), 2U);
- EXPECT_TRUE(isa<ConstantInt>(R1->getOperand(0)));
- EXPECT_TRUE(isa<ConstantInt>(R1->getOperand(1)));
- ConstantInt *C0 = cast<ConstantInt>(R1->getOperand(0));
- ConstantInt *C1 = cast<ConstantInt>(R1->getOperand(1));
- EXPECT_EQ(C0->getValue(), A);
- EXPECT_EQ(C1->getValue(), B);
-}
-TEST_F(MDBuilderTest, createAnonymousTBAARoot) {
- MDBuilder MDHelper(Context);
- MDNode *R0 = MDHelper.createAnonymousTBAARoot();
- MDNode *R1 = MDHelper.createAnonymousTBAARoot();
- EXPECT_NE(R0, R1);
- EXPECT_GE(R0->getNumOperands(), 1U);
- EXPECT_GE(R1->getNumOperands(), 1U);
- EXPECT_EQ(R0->getOperand(0), R0);
- EXPECT_EQ(R1->getOperand(0), R1);
- EXPECT_TRUE(R0->getNumOperands() == 1 || R0->getOperand(1) == 0);
- EXPECT_TRUE(R1->getNumOperands() == 1 || R1->getOperand(1) == 0);
-}
-TEST_F(MDBuilderTest, createTBAARoot) {
- MDBuilder MDHelper(Context);
- MDNode *R0 = MDHelper.createTBAARoot("Root");
- MDNode *R1 = MDHelper.createTBAARoot("Root");
- EXPECT_EQ(R0, R1);
- EXPECT_GE(R0->getNumOperands(), 1U);
- EXPECT_TRUE(isa<MDString>(R0->getOperand(0)));
- EXPECT_EQ(cast<MDString>(R0->getOperand(0))->getString(), "Root");
- EXPECT_TRUE(R0->getNumOperands() == 1 || R0->getOperand(1) == 0);
-}
-TEST_F(MDBuilderTest, createTBAANode) {
- MDBuilder MDHelper(Context);
- MDNode *R = MDHelper.createTBAARoot("Root");
- MDNode *N0 = MDHelper.createTBAANode("Node", R);
- MDNode *N1 = MDHelper.createTBAANode("edoN", R);
- MDNode *N2 = MDHelper.createTBAANode("Node", R, true);
- MDNode *N3 = MDHelper.createTBAANode("Node", R);
- EXPECT_EQ(N0, N3);
- EXPECT_NE(N0, N1);
- EXPECT_NE(N0, N2);
- EXPECT_GE(N0->getNumOperands(), 2U);
- EXPECT_GE(N1->getNumOperands(), 2U);
- EXPECT_GE(N2->getNumOperands(), 3U);
- EXPECT_TRUE(isa<MDString>(N0->getOperand(0)));
- EXPECT_TRUE(isa<MDString>(N1->getOperand(0)));
- EXPECT_TRUE(isa<MDString>(N2->getOperand(0)));
- EXPECT_EQ(cast<MDString>(N0->getOperand(0))->getString(), "Node");
- EXPECT_EQ(cast<MDString>(N1->getOperand(0))->getString(), "edoN");
- EXPECT_EQ(cast<MDString>(N2->getOperand(0))->getString(), "Node");
- EXPECT_EQ(N0->getOperand(1), R);
- EXPECT_EQ(N1->getOperand(1), R);
- EXPECT_EQ(N2->getOperand(1), R);
- EXPECT_TRUE(isa<ConstantInt>(N2->getOperand(2)));
- EXPECT_EQ(cast<ConstantInt>(N2->getOperand(2))->getZExtValue(), 1U);
-}
-}
Modified: llvm/trunk/unittests/VMCore/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/VMCore/CMakeLists.txt?rev=160237&r1=160236&r2=160237&view=diff
==============================================================================
--- llvm/trunk/unittests/VMCore/CMakeLists.txt (original)
+++ llvm/trunk/unittests/VMCore/CMakeLists.txt Sun Jul 15 18:26:50 2012
@@ -8,6 +8,7 @@
ConstantsTest.cpp
DominatorTreeTest.cpp
InstructionsTest.cpp
+ MDBuilderTest.cpp
MetadataTest.cpp
PassManagerTest.cpp
ValueMapTest.cpp
Modified: llvm/trunk/unittests/VMCore/InstructionsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/VMCore/InstructionsTest.cpp?rev=160237&r1=160236&r2=160237&view=diff
==============================================================================
--- llvm/trunk/unittests/VMCore/InstructionsTest.cpp (original)
+++ llvm/trunk/unittests/VMCore/InstructionsTest.cpp Sun Jul 15 18:26:50 2012
@@ -13,10 +13,10 @@
#include "llvm/IRBuilder.h"
#include "llvm/Instructions.h"
#include "llvm/LLVMContext.h"
+#include "llvm/MDBuilder.h"
#include "llvm/Operator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Analysis/ValueTracking.h"
-#include "llvm/Support/MDBuilder.h"
#include "llvm/Target/TargetData.h"
#include "gtest/gtest.h"
Copied: llvm/trunk/unittests/VMCore/MDBuilderTest.cpp (from r160235, llvm/trunk/unittests/Support/MDBuilderTest.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/VMCore/MDBuilderTest.cpp?p2=llvm/trunk/unittests/VMCore/MDBuilderTest.cpp&p1=llvm/trunk/unittests/Support/MDBuilderTest.cpp&r1=160235&r2=160237&rev=160237&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/MDBuilderTest.cpp (original)
+++ llvm/trunk/unittests/VMCore/MDBuilderTest.cpp Sun Jul 15 18:26:50 2012
@@ -1,4 +1,4 @@
-//===- llvm/unittests/Support/MDBuilderTest.cpp - MDBuilder unit tests ----===//
+//===- llvm/unittests/MDBuilderTest.cpp - MDBuilder unit tests ------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -8,8 +8,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/IRBuilder.h"
+#include "llvm/MDBuilder.h"
#include "llvm/Operator.h"
-#include "llvm/Support/MDBuilder.h"
#include "gtest/gtest.h"
More information about the llvm-commits
mailing list