From feed6dbc9f34d52d5d7a0a2b23af12ba0a64a234 Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Sat, 28 Nov 2015 05:47:34 +0000 Subject: [PATCH] [PGO] Add return code for vp rt record init routine to indicate error condition git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254220 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ProfileData/InstrProf.h | 11 +++++++---- lib/ProfileData/InstrProf.cpp | 9 ++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/llvm/ProfileData/InstrProf.h b/include/llvm/ProfileData/InstrProf.h index 8fd3d7f8ffd..b4e2206b00a 100644 --- a/include/llvm/ProfileData/InstrProf.h +++ b/include/llvm/ProfileData/InstrProf.h @@ -583,10 +583,13 @@ typedef struct ValueProfRuntimeRecord { ValueProfNode **NodesKind[IPVK_Last + 1]; } ValueProfRuntimeRecord; -/* Initialize the record for runtime value profile data. */ -void initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord, - uint16_t *NumValueSites, - ValueProfNode **Nodes); +/* Initialize the record for runtime value profile data. + * Return 0 if the initialization is successful, otherwise + * return 1. + */ +int initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord, + uint16_t *NumValueSites, + ValueProfNode **Nodes); /* Release memory allocated for the runtime record. */ void finalizeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord); diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 3bbc8249c3d..28626844812 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -271,9 +271,9 @@ ValueProfData::serializeFrom(const InstrProfRecord &Record) { * pre-compute the information needed to efficiently implement * ValueProfRecordClosure's callback interfaces. */ -void initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord, - uint16_t *NumValueSites, - ValueProfNode **Nodes) { +int initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord, + uint16_t *NumValueSites, + ValueProfNode **Nodes) { unsigned I, J, S = 0, NumValueKinds = 0; RuntimeRecord->NumValueSites = NumValueSites; RuntimeRecord->Nodes = Nodes; @@ -286,6 +286,8 @@ void initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord, NumValueKinds++; RuntimeRecord->SiteCountArray[I] = (uint8_t *)calloc(N, 1); RuntimeRecord->NodesKind[I] = &RuntimeRecord->Nodes[S]; + if (!RuntimeRecord->NodesKind[I]) + return 1; for (J = 0; J < N; J++) { uint8_t C = 0; ValueProfNode *Site = RuntimeRecord->Nodes[S + J]; @@ -300,6 +302,7 @@ void initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord, S += N; } RuntimeRecord->NumValueKinds = NumValueKinds; + return 0; } void finalizeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord) {