From 987c37b77751e4b50f23f9d9d66205ae080c8678 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sun, 22 Nov 2015 18:03:17 +0000 Subject: [PATCH] [MDBuilder] Simplify code using initializer lists. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253826 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/MDBuilder.cpp | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/lib/IR/MDBuilder.cpp b/lib/IR/MDBuilder.cpp index f333dcee4d1..4ce3ea2e9c0 100644 --- a/lib/IR/MDBuilder.cpp +++ b/lib/IR/MDBuilder.cpp @@ -36,8 +36,7 @@ MDNode *MDBuilder::createFPMath(float Accuracy) { MDNode *MDBuilder::createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight) { - uint32_t Weights[] = {TrueWeight, FalseWeight}; - return createBranchWeights(Weights); + return createBranchWeights({TrueWeight, FalseWeight}); } MDNode *MDBuilder::createBranchWeights(ArrayRef Weights) { @@ -58,13 +57,10 @@ MDNode *MDBuilder::createUnpredictable() { } MDNode *MDBuilder::createFunctionEntryCount(uint64_t Count) { - SmallVector Vals(2); - Vals[0] = createString("function_entry_count"); - Type *Int64Ty = Type::getInt64Ty(Context); - Vals[1] = createConstant(ConstantInt::get(Int64Ty, Count)); - - return MDNode::get(Context, Vals); + return MDNode::get(Context, + {createString("function_entry_count"), + createConstant(ConstantInt::get(Int64Ty, Count))}); } MDNode *MDBuilder::createRange(const APInt &Lo, const APInt &Hi) { @@ -80,8 +76,7 @@ MDNode *MDBuilder::createRange(Constant *Lo, Constant *Hi) { return nullptr; // Return the range [Lo, Hi). - Metadata *Range[2] = {createConstant(Lo), createConstant(Hi)}; - return MDNode::get(Context, Range); + return MDNode::get(Context, {createConstant(Lo), createConstant(Hi)}); } MDNode *MDBuilder::createAnonymousAARoot(StringRef Name, MDNode *Extra) { @@ -116,12 +111,10 @@ MDNode *MDBuilder::createTBAANode(StringRef Name, MDNode *Parent, bool isConstant) { if (isConstant) { Constant *Flags = ConstantInt::get(Type::getInt64Ty(Context), 1); - Metadata *Ops[3] = {createString(Name), Parent, createConstant(Flags)}; - return MDNode::get(Context, Ops); - } else { - Metadata *Ops[2] = {createString(Name), Parent}; - return MDNode::get(Context, Ops); + return MDNode::get(Context, + {createString(Name), Parent, createConstant(Flags)}); } + return MDNode::get(Context, {createString(Name), Parent}); } MDNode *MDBuilder::createAliasScopeDomain(StringRef Name) { @@ -129,8 +122,7 @@ MDNode *MDBuilder::createAliasScopeDomain(StringRef Name) { } MDNode *MDBuilder::createAliasScope(StringRef Name, MDNode *Domain) { - Metadata *Ops[2] = {createString(Name), Domain}; - return MDNode::get(Context, Ops); + return MDNode::get(Context, {createString(Name), Domain}); } /// \brief Return metadata for a tbaa.struct node with the given @@ -165,23 +157,19 @@ MDNode *MDBuilder::createTBAAStructTypeNode( MDNode *MDBuilder::createTBAAScalarTypeNode(StringRef Name, MDNode *Parent, uint64_t Offset) { ConstantInt *Off = ConstantInt::get(Type::getInt64Ty(Context), Offset); - Metadata *Ops[3] = {createString(Name), Parent, createConstant(Off)}; - return MDNode::get(Context, Ops); + return MDNode::get(Context, + {createString(Name), Parent, createConstant(Off)}); } /// \brief Return metadata for a TBAA tag node with the given /// base type, access type and offset relative to the base type. MDNode *MDBuilder::createTBAAStructTagNode(MDNode *BaseType, MDNode *AccessType, uint64_t Offset, bool IsConstant) { - Type *Int64 = Type::getInt64Ty(Context); + IntegerType *Int64 = Type::getInt64Ty(Context); + ConstantInt *Off = ConstantInt::get(Int64, Offset); if (IsConstant) { - Metadata *Ops[4] = {BaseType, AccessType, - createConstant(ConstantInt::get(Int64, Offset)), - createConstant(ConstantInt::get(Int64, 1))}; - return MDNode::get(Context, Ops); - } else { - Metadata *Ops[3] = {BaseType, AccessType, - createConstant(ConstantInt::get(Int64, Offset))}; - return MDNode::get(Context, Ops); + return MDNode::get(Context, {BaseType, AccessType, createConstant(Off), + createConstant(ConstantInt::get(Int64, 1))}); } + return MDNode::get(Context, {BaseType, AccessType, createConstant(Off)}); }