From: Xinliang David Li Date: Sun, 3 Jan 2016 19:25:54 +0000 (+0000) Subject: [PGO] Cleanup: Use covmap header definition in the template file X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b0da766c2fd75462acaa976df5ef45ba191230f0;p=clang [PGO] Cleanup: Use covmap header definition in the template file This is one last remaining instrumentatation related structure that needs to be migrate to use the centralized template definition. With this change, instrumentation code related to coverage module header will be kept in sync with the coverage mapping reader. The remaining code which makes implicit assumption about covmap control structure layout in the the lowering pass will cleaned up in a different patch. This patch is not intended to have no functional change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256714 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp index eb6edeac44..1d4d7099e1 100644 --- a/lib/CodeGen/CoverageMappingGen.cpp +++ b/lib/CodeGen/CoverageMappingGen.cpp @@ -993,24 +993,30 @@ void CoverageMappingModuleGen::emit() { llvm::ArrayType::get(FunctionRecordTy, FunctionRecords.size()); auto RecordsVal = llvm::ConstantArray::get(RecordsTy, FunctionRecords); + llvm::Type *CovDataHeaderTypes[] = { +#define COVMAP_HEADER(Type, LLVMType, Name, Init) LLVMType, +#include "llvm/ProfileData/InstrProfData.inc" + }; + auto CovDataHeaderTy = + llvm::StructType::get(Ctx, makeArrayRef(CovDataHeaderTypes)); + llvm::Constant *CovDataHeaderVals[] = { +#define COVMAP_HEADER(Type, LLVMType, Name, Init) Init, +#include "llvm/ProfileData/InstrProfData.inc" + }; + auto CovDataHeaderVal = llvm::ConstantStruct::get( + CovDataHeaderTy, makeArrayRef(CovDataHeaderVals)); + // Create the coverage data record - llvm::Type *CovDataTypes[] = {Int32Ty, Int32Ty, - Int32Ty, Int32Ty, - RecordsTy, FilenamesAndMappingsVal->getType()}; + llvm::Type *CovDataTypes[] = {CovDataHeaderTy, RecordsTy, + FilenamesAndMappingsVal->getType()}; auto CovDataTy = llvm::StructType::get(Ctx, makeArrayRef(CovDataTypes)); - llvm::Constant *TUDataVals[] = { - llvm::ConstantInt::get(Int32Ty, FunctionRecords.size()), - llvm::ConstantInt::get(Int32Ty, FilenamesSize), - llvm::ConstantInt::get(Int32Ty, CoverageMappingSize), - llvm::ConstantInt::get(Int32Ty, - /*Version=*/CoverageMappingVersion1), - RecordsVal, FilenamesAndMappingsVal}; + llvm::Constant *TUDataVals[] = {CovDataHeaderVal, RecordsVal, + FilenamesAndMappingsVal}; auto CovDataVal = llvm::ConstantStruct::get(CovDataTy, makeArrayRef(TUDataVals)); - auto CovData = new llvm::GlobalVariable(CGM.getModule(), CovDataTy, true, - llvm::GlobalValue::InternalLinkage, - CovDataVal, - llvm::getCoverageMappingVarName()); + auto CovData = new llvm::GlobalVariable( + CGM.getModule(), CovDataTy, true, llvm::GlobalValue::InternalLinkage, + CovDataVal, llvm::getCoverageMappingVarName()); CovData->setSection(getCoverageSection(CGM)); CovData->setAlignment(8); diff --git a/test/CoverageMapping/ir.c b/test/CoverageMapping/ir.c index 4dbfb489f7..f94d34c0b9 100644 --- a/test/CoverageMapping/ir.c +++ b/test/CoverageMapping/ir.c @@ -9,4 +9,4 @@ int main(void) { return 0; } -// CHECK: @__llvm_coverage_mapping = internal constant { i32, i32, i32, i32, [2 x <{ i8*, i32, i32, i64 }>], [{{[0-9]+}} x i8] } { i32 2, i32 {{[0-9]+}}, i32 {{[0-9]+}}, i32 0, [2 x <{ i8*, i32, i32, i64 }>] [<{ i8*, i32, i32, i64 }> <{ i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i32 3, i32 9, i64 {{[0-9]+}} }>, <{ i8*, i32, i32, i64 }> <{ i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__profn_main, i32 0, i32 0), i32 4, i32 9, i64 {{[0-9]+}} }>] +// CHECK: @__llvm_coverage_mapping = internal constant { { i32, i32, i32, i32 }, [2 x <{ i8*, i32, i32, i64 }>], [{{[0-9]+}} x i8] } { { i32, i32, i32, i32 } { i32 2, i32 {{[0-9]+}}, i32 {{[0-9]+}}, i32 0 }, [2 x <{ i8*, i32, i32, i64 }>] [<{ i8*, i32, i32, i64 }> <{ i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i32 3, i32 9, i64 {{[0-9]+}} }>, <{ i8*, i32, i32, i64 }> <{ i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__profn_main, i32 0, i32 0), i32 4, i32 9, i64 {{[0-9]+}} }>]