1 /* Lambda matrix transformations.
2 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Daniel Berlin <dberlin@dberlin.org>.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA. */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "ggc.h"
27 #include "tree.h"
28 #include "target.h"
29 #include "lambda.h"
30
31 /* Allocate a new transformation matrix. */
32
33 lambda_trans_matrix
lambda_trans_matrix_new(int colsize,int rowsize)34 lambda_trans_matrix_new (int colsize, int rowsize)
35 {
36 lambda_trans_matrix ret;
37
38 ret = ggc_alloc (sizeof (*ret));
39 LTM_MATRIX (ret) = lambda_matrix_new (rowsize, colsize);
40 LTM_ROWSIZE (ret) = rowsize;
41 LTM_COLSIZE (ret) = colsize;
42 LTM_DENOMINATOR (ret) = 1;
43 return ret;
44 }
45
46 /* Return true if MAT is an identity matrix. */
47
48 bool
lambda_trans_matrix_id_p(lambda_trans_matrix mat)49 lambda_trans_matrix_id_p (lambda_trans_matrix mat)
50 {
51 if (LTM_ROWSIZE (mat) != LTM_COLSIZE (mat))
52 return false;
53 return lambda_matrix_id_p (LTM_MATRIX (mat), LTM_ROWSIZE (mat));
54 }
55
56
57 /* Compute the inverse of the transformation matrix MAT. */
58
59 lambda_trans_matrix
lambda_trans_matrix_inverse(lambda_trans_matrix mat)60 lambda_trans_matrix_inverse (lambda_trans_matrix mat)
61 {
62 lambda_trans_matrix inverse;
63 int determinant;
64
65 inverse = lambda_trans_matrix_new (LTM_ROWSIZE (mat), LTM_COLSIZE (mat));
66 determinant = lambda_matrix_inverse (LTM_MATRIX (mat), LTM_MATRIX (inverse),
67 LTM_ROWSIZE (mat));
68 LTM_DENOMINATOR (inverse) = determinant;
69 return inverse;
70 }
71
72
73 /* Print out a transformation matrix. */
74
75 void
print_lambda_trans_matrix(FILE * outfile,lambda_trans_matrix mat)76 print_lambda_trans_matrix (FILE *outfile, lambda_trans_matrix mat)
77 {
78 print_lambda_matrix (outfile, LTM_MATRIX (mat), LTM_ROWSIZE (mat),
79 LTM_COLSIZE (mat));
80 }
81