Skip to content
Permalink
Browse files
8269122: The use of "extern const" for Register definitions generates…
… poor code

Reviewed-by: adinn, kbarrett, kvn
  • Loading branch information
Andrew Haley committed Jun 28, 2021
1 parent f45be15 commit 4d2412ef3e1068063acc954a00b4db0fa4b5affb
Showing 1 changed file with 6 additions and 45 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -45,55 +45,16 @@ class AbstractRegisterImpl {
int value() const { return (int)(intx)this; }
};


//
// Macros for use in defining Register instances. We'd like to be
// able to simply define const instances of the RegisterImpl* for each
// of the registers needed on a system in a header file. However many
// compilers don't handle this very well and end up producing a
// private definition in every file which includes the header file.
// Along with the static constructors necessary for initialization it
// can consume a significant amount of space in the result library.
//
// The following macros allow us to declare the instance in a .hpp and
// produce an enumeration value which has the same number. Then in a
// .cpp the the register instance can be defined using the enumeration
// value. This avoids the use of static constructors and multiple
// definitions per .cpp. In addition #defines for the register can be
// produced so that the constant registers can be inlined. These
// macros should not be used inside other macros, because you may get
// multiple evaluations of the macros which can give bad results.
//
// Here are some example uses and expansions. Note that the macro
// invocation is terminated with a ;.
//
// CONSTANT_REGISTER_DECLARATION(Register, G0, 0);
//
// extern const Register G0 ;
// enum { G0_RegisterEnumValue = 0 } ;
//
// REGISTER_DECLARATION(Register, Gmethod, G5);
//
// extern const Register Gmethod ;
// enum { Gmethod_RegisterEnumValue = G5_RegisterEnumValue } ;
//
// REGISTER_DEFINITION(Register, G0);
//
// const Register G0 = ( ( Register ) G0_RegisterEnumValue ) ;
//

#define AS_REGISTER(type,name) ((type)name##_##type##EnumValue)

#define CONSTANT_REGISTER_DECLARATION(type, name, value) \
extern const type name; \
#define CONSTANT_REGISTER_DECLARATION(type, name, value) \
const type name = ((type)value); \
enum { name##_##type##EnumValue = (value) }

#define REGISTER_DECLARATION(type, name, value) \
extern const type name; \
enum { name##_##type##EnumValue = value##_##type##EnumValue }
#define REGISTER_DECLARATION(type, name, value) \
const type name = ((type)value)

#define REGISTER_DEFINITION(type, name) \
const type name = ((type)name##_##type##EnumValue)
#define REGISTER_DEFINITION(type, name)

#include CPU_HEADER(register)

0 comments on commit 4d2412e

Please sign in to comment.