Skip to content

Commit

Permalink
Add unit tests for the Power binary encoder (#4721)
Browse files Browse the repository at this point in the history
Add unit tests for the Power binary encoder
  • Loading branch information
fjeremic authored Jan 30, 2020
2 parents c7746c3 + 3c75b24 commit 68104ca
Show file tree
Hide file tree
Showing 6 changed files with 3,090 additions and 52 deletions.
87 changes: 36 additions & 51 deletions compiler/p/codegen/OMRInstOpCodeProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10502,7 +10502,8 @@
/* .opcode = */ 0xF0000318,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_DoubleFP |
/* .properties = */ PPCOpProp_HasRecordForm |
PPCOpProp_DoubleFP |
PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp,
Expand All @@ -10512,14 +10513,10 @@
/* .mnemonic = */ OMR::InstOpCode::xvcmpeqdp_r,
/* .name = */ "xvcmpeqdp.",
/* .description = "VSX Vector Compare Equal To Double-Precision", */
/* .opcode = */ 0xF0000718,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_DoubleFP |
PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp |
PPCOpProp_IsRecordForm,
/* .opcode = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpeqdp].opcode | 0x400,
/* .format = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpeqdp].format,
/* .minimumALS = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpeqdp].minimumALS,
/* .properties = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpeqdp].properties & ~PPCOpProp_HasRecordForm | PPCOpProp_IsRecordForm,
},

{
Expand All @@ -10529,7 +10526,8 @@
/* .opcode = */ 0xF0000398,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_DoubleFP |
/* .properties = */ PPCOpProp_HasRecordForm |
PPCOpProp_DoubleFP |
PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp,
Expand All @@ -10539,14 +10537,10 @@
/* .mnemonic = */ OMR::InstOpCode::xvcmpgedp_r,
/* .name = */ "xvcmpgedp.",
/* .description = "VSX Vector Compare Greater Than Or Equal To Double-Precision", */
/* .opcode = */ 0xF0000798,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_DoubleFP |
PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp |
PPCOpProp_IsRecordForm,
/* .opcode = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgedp].opcode | 0x400,
/* .format = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgedp].format,
/* .minimumALS = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgedp].minimumALS,
/* .properties = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgedp].properties & ~PPCOpProp_HasRecordForm | PPCOpProp_IsRecordForm,
},

{
Expand All @@ -10556,7 +10550,8 @@
/* .opcode = */ 0xF0000358,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_DoubleFP |
/* .properties = */ PPCOpProp_HasRecordForm |
PPCOpProp_DoubleFP |
PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp,
Expand All @@ -10566,14 +10561,10 @@
/* .mnemonic = */ OMR::InstOpCode::xvcmpgtdp_r,
/* .name = */ "xvcmpgtdp.",
/* .description = "VSX Vector Compare Greater Than Double-Precision", */
/* .opcode = */ 0xF0000758,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_DoubleFP |
PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp |
PPCOpProp_IsRecordForm,
/* .opcode = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgtdp].opcode | 0x400,
/* .format = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgtdp].format,
/* .minimumALS = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgtdp].minimumALS,
/* .properties = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgtdp].properties & ~PPCOpProp_HasRecordForm | PPCOpProp_IsRecordForm,
},

/* { */
Expand Down Expand Up @@ -11474,7 +11465,8 @@
/* .opcode = */ 0xF0000218,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_IsVSX |
/* .properties = */ PPCOpProp_HasRecordForm |
PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp,
},
Expand All @@ -11483,13 +11475,10 @@
/* .mnemonic = */ OMR::InstOpCode::xvcmpeqsp_r,
/* .name = */ "xvcmpeqsp.",
/* .description = "Vector Compare Equal To Single-Precision & record CR6", */
/* .opcode = */ 0xF0000618,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp |
PPCOpProp_IsRecordForm,
/* .opcode = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpeqsp].opcode | 0x400,
/* .format = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpeqsp].format,
/* .minimumALS = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpeqsp].minimumALS,
/* .properties = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpeqsp].properties & ~PPCOpProp_HasRecordForm | PPCOpProp_IsRecordForm,
},

{
Expand All @@ -11499,7 +11488,8 @@
/* .opcode = */ 0xF0000298,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_IsVSX |
/* .properties = */ PPCOpProp_HasRecordForm |
PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp,
},
Expand All @@ -11508,13 +11498,10 @@
/* .mnemonic = */ OMR::InstOpCode::xvcmpgesp_r,
/* .name = */ "xvcmpgesp.",
/* .description = "Vector Compare Greater Than or Equal To Single-Precision & record CR6", */
/* .opcode = */ 0xF0000698,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp |
PPCOpProp_IsRecordForm,
/* .opcode = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgesp].opcode | 0x400,
/* .format = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgesp].format,
/* .minimumALS = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgesp].minimumALS,
/* .properties = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgesp].properties & ~PPCOpProp_HasRecordForm | PPCOpProp_IsRecordForm,
},

{
Expand All @@ -11524,7 +11511,8 @@
/* .opcode = */ 0xF0000258,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_IsVSX |
/* .properties = */ PPCOpProp_HasRecordForm |
PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp,
},
Expand All @@ -11533,13 +11521,10 @@
/* .mnemonic = */ OMR::InstOpCode::xvcmpgtsp_r,
/* .name = */ "xvcmpgtsp.",
/* .description = "Vector Compare Greater Than Single-Precision & record CR6", */
/* .opcode = */ 0xF0000658,
/* .format = */ XX3_FORMAT,
/* .minimumALS = */ TR_Processor::TR_PPCp7,
/* .properties = */ PPCOpProp_IsVSX |
PPCOpProp_SyncSideEffectFree |
PPCOpProp_CompareOp |
PPCOpProp_IsRecordForm,
/* .opcode = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgtsp].opcode | 0x400,
/* .format = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgtsp].format,
/* .minimumALS = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgtsp].minimumALS,
/* .properties = */ OMR::Power::InstOpCode::metadata[OMR::InstOpCode::xvcmpgtsp].properties & ~PPCOpProp_HasRecordForm | PPCOpProp_IsRecordForm,
},

{
Expand Down
8 changes: 7 additions & 1 deletion fvtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2017, 2018 IBM Corp. and others
# Copyright (c) 2017, 2020 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -55,4 +55,10 @@ endif()
if(OMR_JITBUILDER_TEST)
add_subdirectory(tril)
add_subdirectory(compilertriltest)

# Currently, there are only unit tests for the Power codegen. To avoid unnecessarily compiling and running an
# executable with no tests, compilerunittest is thus disabled on other architectures.
if(OMR_ARCH_POWER)
add_subdirectory(compilerunittest)
endif()
endif()
54 changes: 54 additions & 0 deletions fvtest/compilerunittest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
###############################################################################
# Copyright (c) 2020, 2020 IBM Corp. and others
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License 2.0 which accompanies this
# distribution and is available at http://eclipse.org/legal/epl-2.0
# or the Apache License, Version 2.0 which accompanies this distribution
# and is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# This Source Code may also be made available under the following Secondary
# Licenses when the conditions for such availability set forth in the
# Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
# version 2 with the GNU Classpath Exception [1] and GNU General Public
# License, version 2 with the OpenJDK Assembly Exception [2].
#
# [1] https://www.gnu.org/software/classpath/license.html
# [2] http://openjdk.java.net/legal/assembly-exception.html
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
###############################################################################

cmake_minimum_required(VERSION 3.2 FATAL_ERROR)

project(compunittest LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)

set(COMPCGTEST_FILES
main.cpp
)

if(OMR_ARCH_POWER)
list(APPEND COMPCGTEST_FILES
p/BinaryEncoder.cpp
)
endif()

add_executable(compunittest ${COMPCGTEST_FILES})

# For the time being, link against Tril even though we don't really need Tril itself. This is done
# to avoid needing to duplicate the boilerplate in Tril's CMakeLists.txt.
target_link_libraries(compunittest
omrGtestGlue
tril
)

set_property(TARGET compunittest PROPERTY FOLDER fvtest)

add_test(
NAME compunittest
COMMAND compunittest --gtest_color=yes --gtest_output=xml:${CMAKE_CURRENT_BINARY_DIR}/compunittest-results.xml
)
105 changes: 105 additions & 0 deletions fvtest/compilerunittest/CodeGenTest.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*******************************************************************************
* Copyright (c) 2020, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at http://eclipse.org/legal/epl-2.0
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

#ifndef CODEGENTEST_HPP
#define CODEGENTEST_HPP

#include <gtest/gtest.h>
#include <exception>

#include "Jit.hpp"
#include "codegen/CodeGenerator.hpp"
#include "compile/Compilation.hpp"
#include "env/ConcreteFE.hpp"
#include "env/SystemSegmentProvider.hpp"
#include "ilgen/IlGenRequest.hpp"
#include "ilgen/IlGeneratorMethodDetails.hpp"
#include "ilgen/TypeDictionary.hpp"

#include "codegen/CodeGenerator_inlines.hpp"
#include "compile/Compilation_inlines.hpp"
#include "ilgen/IlGeneratorMethodDetails_inlines.hpp"

namespace TRTest {

class NullIlGenRequest : public TR::IlGenRequest {
TR::IlGeneratorMethodDetails _details;

public:
NullIlGenRequest() : TR::IlGenRequest(_details) {}

virtual TR_IlGenerator *getIlGenerator(
TR::ResolvedMethodSymbol *methodSymbol,
TR_FrontEnd *fe,
TR::Compilation *comp,
TR::SymbolReferenceTable *symRefTab
) {
throw std::runtime_error("The mock JIT environment does not support calling TR::IlGenRequest::getIlGenerator");
}

virtual void print(TR_FrontEnd *fe, TR::FILE *file, const char *suffix) {}
};

class JitInitializer {
public:
JitInitializer() {
initializeJit();
}

~JitInitializer() {
shutdownJit();
}
};

class CodeGenTest : public ::testing::Test {
JitInitializer _jitInit;

TR::RawAllocator _rawAllocator;
TR::SystemSegmentProvider _segmentProvider;
TR::Region _dispatchRegion;
TR_Memory _trMemory;

TR::TypeDictionary _types;

TR::Options _options;
NullIlGenRequest _ilGenRequest;
TR::ResolvedMethod _method;
TR::Compilation _comp;
public:
CodeGenTest() :
_jitInit(),
_rawAllocator(),
_segmentProvider(1 << 16, _rawAllocator),
_dispatchRegion(_segmentProvider, _rawAllocator),
_trMemory(*OMR::FrontEnd::singleton().persistentMemory(), _dispatchRegion),
_types(),
_options(),
_ilGenRequest(),
_method("compunittest", "0", "test", 0, NULL, _types.NoType, NULL, NULL),
_comp(0, NULL, &OMR::FrontEnd::singleton(), &_method, _ilGenRequest, _options, _dispatchRegion, &_trMemory, TR_OptimizationPlan::alloc(warm)) {
}

TR::CodeGenerator* cg() { return _comp.cg(); }
};

}

#endif
32 changes: 32 additions & 0 deletions fvtest/compilerunittest/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2020, 2020 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at http://eclipse.org/legal/epl-2.0
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

#include "omrTest.h"

extern "C" {
int omr_main_entry(int argc, char **argv, char **envp);
}

int omr_main_entry(int argc, char **argv, char **envp) {
::testing::InitGoogleTest(&argc, argv);
OMREventListener::setDefaultTestListener();
return RUN_ALL_TESTS();
}
Loading

0 comments on commit 68104ca

Please sign in to comment.