[llvm-commits] [gcc-plugin] r81095 - in /gcc-plugin/trunk: bits_and_bobs.cpp bits_and_bobs.h llvm-backend.cpp llvm-internal.h
Duncan Sands
baldrick at free.fr
Sat Sep 5 13:37:53 PDT 2009
Author: baldrick
Date: Sat Sep 5 15:37:52 2009
New Revision: 81095
URL: http://llvm.org/viewvc/llvm-project?rev=81095&view=rev
Log:
Clean up the mapping between gcc declarations and
LLVM values (DECL_LLVM and friends) a bit.
Modified:
gcc-plugin/trunk/bits_and_bobs.cpp
gcc-plugin/trunk/bits_and_bobs.h
gcc-plugin/trunk/llvm-backend.cpp
gcc-plugin/trunk/llvm-internal.h
Modified: gcc-plugin/trunk/bits_and_bobs.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/bits_and_bobs.cpp?rev=81095&r1=81094&r2=81095&view=diff
==============================================================================
--- gcc-plugin/trunk/bits_and_bobs.cpp (original)
+++ gcc-plugin/trunk/bits_and_bobs.cpp Sat Sep 5 15:37:52 2009
@@ -16,35 +16,10 @@
#include "tree.h"
}
-// Plugin headers
-extern "C" {
-#include "llvm-cache.h"
-}
-
using namespace llvm;
bool flag_odr = false;
-Value *llvm_set_decl (tree t, Value *V) {
- assert(HAS_RTL_P(t) && "Expected a gcc decl with RTL!");
- llvm_set_cached(t, V);
- return V;
-}
-
-extern Value *make_decl_llvm(tree decl);
-
-Value *llvm_get_decl(tree t) {
- assert(HAS_RTL_P(t) && "Expected a gcc decl with RTL!");
- if (Value *V = (Value *)llvm_get_cached(t))
- return V;
- return make_decl_llvm(t);
-}
-
-bool llvm_set_decl_p(tree t) {
- assert(HAS_RTL_P(t) && "Expected a gcc decl with RTL!");
- return llvm_has_cached(t);
-}
-
void eraseLocalLLVMValues() {
abort();
}
Modified: gcc-plugin/trunk/bits_and_bobs.h
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/bits_and_bobs.h?rev=81095&r1=81094&r2=81095&view=diff
==============================================================================
--- gcc-plugin/trunk/bits_and_bobs.h (original)
+++ gcc-plugin/trunk/bits_and_bobs.h Sat Sep 5 15:37:52 2009
@@ -4,21 +4,6 @@
union tree_node;
-namespace llvm { class Value; }
-
-extern Value *llvm_set_decl (union tree_node *, Value *);
-extern Value *llvm_get_decl(union tree_node *);
-#define DECL_LLVM(NODE) (llvm_get_decl(NODE))
-#define SET_DECL_LLVM(NODE, LLVM) (llvm_set_decl (NODE,LLVM))
-
-/* Returns nonzero if the DECL_LLVM for NODE has already been set. */
-extern bool llvm_set_decl_p(union tree_node *);
-#define DECL_LLVM_SET_P(NODE) (HAS_RTL_P (NODE) && llvm_set_decl_p(NODE))
-
-/* The DECL_LLVM for NODE, if it is set, or NULL, if it is not set. */
-#define DECL_LLVM_IF_SET(NODE) \
- (DECL_LLVM_SET_P (NODE) ? DECL_LLVM (NODE) : NULL)
-
// emit_global_to_llvm - Emit the specified VAR_DECL to LLVM as a global
// variable.
// FIXME: Should not be here
Modified: gcc-plugin/trunk/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-backend.cpp?rev=81095&r1=81094&r2=81095&view=diff
==============================================================================
--- gcc-plugin/trunk/llvm-backend.cpp (original)
+++ gcc-plugin/trunk/llvm-backend.cpp Sat Sep 5 15:37:52 2009
@@ -134,85 +134,22 @@
static void createPerModuleOptimizationPasses();
//TODOstatic void destroyOptimizationPasses();
-//TODO//===----------------------------------------------------------------------===//
-//TODO// Matching LLVM Values with GCC DECL trees
-//TODO//===----------------------------------------------------------------------===//
-//TODO//
-//TODO// LLVMValues is a vector of LLVM Values. GCC tree nodes keep track of LLVM
-//TODO// Values using this vector's index. It is easier to save and restore the index
-//TODO// than the LLVM Value pointer while using PCH.
-//TODO
-//TODO// Collection of LLVM Values
-//TODOstatic std::vector<Value *> LLVMValues;
-//TODOtypedef DenseMap<Value *, unsigned> LLVMValuesMapTy;
-//TODOstatic LLVMValuesMapTy LLVMValuesMap;
-//TODO
-//TODO/// LocalLLVMValueIDs - This is the set of local IDs we have in our mapping,
-//TODO/// this allows us to efficiently identify and remove them. Local IDs are IDs
-//TODO/// for values that are local to the current function being processed. These do
-//TODO/// not need to go into the PCH file, but DECL_LLVM still needs a valid index
-//TODO/// while converting the function. Using "Local IDs" allows the IDs for
-//TODO/// function-local decls to be recycled after the function is done.
-//TODOstatic std::vector<unsigned> LocalLLVMValueIDs;
-//TODO
-//TODO/// llvm_set_decl - Remember the LLVM value for GCC tree node.
-//TODOvoid llvm_set_decl(tree Tr, Value *V) {
-//TODO
-//TODO // If there is not any value then do not add new LLVMValues entry.
-//TODO // However clear Tr index if it is non zero.
-//TODO if (!V) {
-//TODO if (GET_DECL_LLVM_INDEX(Tr))
-//TODO SET_DECL_LLVM_INDEX(Tr, 0);
-//TODO return;
-//TODO }
-//TODO
-//TODO unsigned &ValueSlot = LLVMValuesMap[V];
-//TODO if (ValueSlot) {
-//TODO // Already in map
-//TODO SET_DECL_LLVM_INDEX(Tr, ValueSlot);
-//TODO return;
-//TODO }
-//TODO
-//TODO LLVMValues.push_back(V);
-//TODO unsigned Index = LLVMValues.size();
-//TODO SET_DECL_LLVM_INDEX(Tr, Index);
-//TODO LLVMValuesMap[V] = Index;
-//TODO
-//TODO // Remember local values.
-//TODO if (!isa<Constant>(V))
-//TODO LocalLLVMValueIDs.push_back(Index);
-//TODO}
-//TODO
-//TODO/// llvm_set_decl_p - Return TRUE if there is a LLVM Value associate with GCC
-//TODO/// tree node.
-//TODObool llvm_set_decl_p(tree Tr) {
-//TODO unsigned Index = GET_DECL_LLVM_INDEX(Tr);
-//TODO if (Index == 0)
-//TODO return false;
-//TODO
-//TODO return LLVMValues[Index - 1] != 0;
-//TODO}
-//TODO
-//TODO/// llvm_get_decl - Get LLVM Value for the GCC tree node based on LLVMValues
-//TODO/// vector index. If there is not any value associated then use
-//TODO/// make_decl_llvm() to make LLVM value. When GCC tree node is initialized, it
-//TODO/// has 0 as the index value. This is why all recorded indices are offset by 1.
-//TODOValue *llvm_get_decl(tree Tr) {
-//TODO
-//TODO unsigned Index = GET_DECL_LLVM_INDEX(Tr);
-//TODO if (Index == 0) {
-//TODO make_decl_llvm(Tr);
-//TODO Index = GET_DECL_LLVM_INDEX(Tr);
-//TODO
-//TODO // If there was an error, we may have disabled creating LLVM values.
-//TODO if (Index == 0) return 0;
-//TODO }
-//TODO assert((Index - 1) < LLVMValues.size() && "Invalid LLVM value index");
-//TODO assert(LLVMValues[Index - 1] && "Trying to use deleted LLVM value!");
-//TODO
-//TODO return LLVMValues[Index - 1];
-//TODO}
-//TODO
+//===----------------------------------------------------------------------===//
+// Matching LLVM Values with GCC DECL trees
+//===----------------------------------------------------------------------===//
+
+/// set_decl_llvm - Remember the LLVM value for a GCC declaration.
+Value *set_decl_llvm (tree t, Value *V) {
+ assert(HAS_RTL_P(t) && "Expected a declaration with RTL!");
+ return (Value *)llvm_set_cached(t, V);
+}
+
+/// get_decl_llvm - Retrieve the LLVM value for a GCC declaration, or NULL.
+Value *get_decl_llvm(tree t) {
+ assert(HAS_RTL_P(t) && "Expected a declaration with RTL!");
+ return (Value *)llvm_get_cached(t);
+}
+
//TODO/// changeLLVMConstant - Replace Old with New everywhere, updating all maps
//TODO/// (except for AttributeAnnotateGlobals, which is a different kind of animal).
//TODO/// At this point we know that New is not in any of these maps.
@@ -1428,6 +1365,10 @@
/// This function corresponds to make_decl_rtl in varasm.c, and is implicitly
/// called by DECL_LLVM if a decl doesn't have an LLVM set.
Value *make_decl_llvm(tree decl) {
+ // If we already made the LLVM, then return it.
+ if (Value *V = get_decl_llvm(decl))
+ return V;
+
#ifdef ENABLE_CHECKING
// Check that we are not being given an automatic variable.
// A weak alias has TREE_PUBLIC set but not the other bits.
@@ -1442,15 +1383,9 @@
LLVMContext &Context = getGlobalContext();
- // For a duplicate declaration, we can be called twice on the
- // same DECL node. Don't discard the LLVM already made.
- if (Value *V = (Value *)llvm_get_cached(decl))
- return V;
-
if (errorcount || sorrycount)
return NULL; // Do not process broken code.
-
// Global register variable with asm name, e.g.:
// register unsigned long esp __asm__("ebp");
if (TREE_CODE(decl) != FUNCTION_DECL && DECL_REGISTER(decl)) {
Modified: gcc-plugin/trunk/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-internal.h?rev=81095&r1=81094&r2=81095&view=diff
==============================================================================
--- gcc-plugin/trunk/llvm-internal.h (original)
+++ gcc-plugin/trunk/llvm-internal.h Sat Sep 5 15:37:52 2009
@@ -67,6 +67,8 @@
typedef IRBuilder<true, TargetFolder> LLVMBuilder;
+// Global state.
+
/// TheModule - This is the current global module that we are compiling into.
///
extern llvm::Module *TheModule;
@@ -94,6 +96,27 @@
/// annotate attribute to a vector to be emitted later.
extern void AddAnnotateAttrsToGlobal(GlobalValue *GV, union tree_node* decl);
+// Mapping between GCC declarations and LLVM values.
+
+/// DECL_LLVM - Holds the LLVM expression for the value of a variable or
+/// function. This value can be evaluated lazily for functions and variables
+/// with static storage duration.
+extern Value *make_decl_llvm(union tree_node *);
+#define DECL_LLVM(NODE) make_decl_llvm(NODE)
+
+/// SET_DECL_LLVM - Set the DECL_LLVM for NODE to LLVM.
+extern Value *set_decl_llvm(union tree_node *, Value *);
+#define SET_DECL_LLVM(NODE, LLVM) set_decl_llvm(NODE, LLVM)
+
+/// DECL_LLVM_IF_SET - The DECL_LLVM for NODE, if it is set, or NULL, if it is
+/// not set.
+extern Value *get_decl_llvm(union tree_node *);
+#define DECL_LLVM_IF_SET(NODE) (HAS_RTL_P(NODE) ? get_decl_llvm(NODE) : NULL)
+
+/// DECL_LLVM_SET_P - Returns nonzero if the DECL_LLVM for NODE has already
+/// been set.
+#define DECL_LLVM_SET_P(NODE) (DECL_LLVM_IF_SET(NODE) != NULL)
+
void changeLLVMConstant(Constant *Old, Constant *New);
void readLLVMTypesStringTable();
void writeLLVMTypesStringTable();
More information about the llvm-commits
mailing list